db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlQueryStatement.java
Date Mon, 14 Feb 2005 19:32:13 GMT
brj         2005/02/14 11:32:13

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
  Log:
  getAttributeInfo() caches the created attributes
  
  Revision  Changes    Path
  1.97      +55 -18    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- SqlQueryStatement.java	13 Feb 2005 10:18:46 -0000	1.96
  +++ SqlQueryStatement.java	14 Feb 2005 19:32:13 -0000	1.97
  @@ -63,7 +63,9 @@
       private QueryByCriteria m_query;
   
       private TableAliasHandler m_tableAliasHandler;
  -        
  +    
  +    private Map m_attributeCache = new HashMap();
  +    
       /**
        * Constructor for SqlCriteriaStatement.
        * @param aPlatform the Platform
  @@ -137,6 +139,7 @@
        * <pre>
        * [0.9, * , ( sai(price), * , sai(stock), )]
        * </pre> 
  +     * The attribute infos are cached for later use.
        * @param attr the attribute or expression
        * @param useOuterJoins
        * @param aUserAlias
  @@ -145,30 +148,64 @@
        */
   	protected AttributeInfo getAttributeInfo(String attr, boolean useOuterJoins, UserAlias
aUserAlias, Map pathClasses)
       {
  -        AttributeInfo result;
  +        String cacheKey = createAttributeCacheKey(attr, useOuterJoins, aUserAlias, pathClasses);
  +        AttributeInfo result = (AttributeInfo) m_attributeCache.get(cacheKey);
   
  -        StringTokenizer st = SqlHelper.tokenizeAttribute(attr);
  -        result = new AttributeInfo();
  -        List elements = result.elements;
  -
  -        while (st.hasMoreTokens())
  +        if (result == null)
           {
  -            String token = st.nextToken();
  -            if (SqlHelper.isAttribute(token))
  -            {
  -                elements.add(getSingleAttributeInfo(token, useOuterJoins, aUserAlias, pathClasses));
  -            }
  -            else
  +            StringTokenizer st = SqlHelper.tokenizeAttribute(attr);
  +            result = new AttributeInfo();
  +            List elements = result.elements;
  +
  +            while (st.hasMoreTokens())
               {
  -                elements.add(token);
  +                String token = st.nextToken();
  +                if (SqlHelper.isAttribute(token))
  +                {
  +                    elements.add(getSingleAttributeInfo(token, useOuterJoins, aUserAlias,
pathClasses));
  +                }
  +                else
  +                {
  +                    elements.add(token);
  +                }
               }
  -        }
   
  -        result.attribute = attr;
  +            result.attribute = attr;
  +            m_attributeCache.put(cacheKey, result);
  +        }
  +        else
  +        {
  +            result.extentAliasIndex = 0;    // Reset extent index
  +        }
   
           return result;
       }
  -    
  +
  +    /**
  +     * Create a cache key for the attribute.
  +     * @param attr
  +     * @param useOuterJoins
  +     * @param aUserAlias
  +     * @param pathClasses
  +     * @return
  +     */
  +    private String createAttributeCacheKey(String attr, boolean useOuterJoins, UserAlias
aUserAlias, Map pathClasses)
  +    {
  +        StringBuffer buf = new StringBuffer(attr);
  +
  +        buf.append(useOuterJoins);
  +        if (aUserAlias != null)
  +        {
  +            buf.append(aUserAlias.getName());
  +        }
  +        if (pathClasses != null)
  +        {
  +            buf.append(pathClasses.hashCode());
  +        }
  +
  +        return buf.toString();
  +    }
  +        
       /**
        * Get the Attribute info for a single attribute.
        * 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message