db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/query AbstractQueryImpl.java QueryByCriteria.java
Date Sat, 02 Aug 2003 09:24:00 GMT
olegnitz    2003/08/02 02:24:00

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java SqlSelectStatement.java
               src/java/org/apache/ojb/broker/query AbstractQueryImpl.java
                        QueryByCriteria.java
  Log:
  Now object projection attributes really work ;-)
  
  Revision  Changes    Path
  1.48      +32 -4     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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- SqlQueryStatement.java	2 Aug 2003 08:27:22 -0000	1.47
  +++ SqlQueryStatement.java	2 Aug 2003 09:24:00 -0000	1.48
  @@ -89,6 +89,8 @@
       Logger m_logger = LoggerFactory.getLogger(SqlQueryStatement.class);
       /** the target table of the query */
       private TableAlias m_root;
  +    /** the search table of the query */
  +    private TableAlias m_search;
       /** the query */
       private QueryByCriteria m_query;
       /** the columns to select (null means all) */
  @@ -108,12 +110,29 @@
        */
       public SqlQueryStatement(Platform pf, ClassDescriptor cld, String[] columns, Query
query, Logger logger)
       {
  -        this.m_root = createTableAlias(cld, null,"");
           this.m_query = (QueryByCriteria) query;
           this.m_columns = columns;
           this.pf = pf;
           this.m_searchCld = cld;
  -        this.m_baseCld = cld.getRepository().getDescriptorFor(query.getBaseClass());
  +        if ((m_query == null) 
  +                || (m_query.getBaseClass() == m_query.getSearchClass()))
  +        {
  +            this.m_baseCld = m_searchCld;
  +        }
  +        else
  +        {
  +            this.m_baseCld = cld.getRepository().getDescriptorFor(query.getBaseClass());
  +        }
  +        this.m_root = createTableAlias(m_baseCld, null,"");
  +        if (m_searchCld == m_baseCld)
  +        {
  +            this.m_search = m_root;
  +        }
  +        else
  +        {
  +            this.m_search = getTableAlias(m_query.getObjectProjectionAttribute(),
  +                                          false, null, null);
  +        }
   
           // In some cases it is necessary to split the query criteria
           // and then to generate UNION of several SELECTs
  @@ -254,7 +273,7 @@
   
   		return result;
   	}
  -    
  +
       /**
        * Add the Column to the StringBuffer <br>
        *
  @@ -281,7 +300,7 @@
           {
               buf.append(suffix);
           }
  -        
  +
           return true;
       }
   
  @@ -1392,6 +1411,15 @@
       protected void setRoot(TableAlias root)
       {
           this.m_root = root;
  +    }
  +
  +    /**
  +     * Gets the search table of this query.
  +     * @return Returns a TableAlias
  +     */
  +    protected TableAlias getSearchTable()
  +    {
  +        return m_search;
       }
   
       /**
  
  
  
  1.14      +1 -1      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SqlSelectStatement.java	2 Aug 2003 08:27:22 -0000	1.13
  +++ SqlSelectStatement.java	2 Aug 2003 09:24:00 -0000	1.14
  @@ -117,7 +117,7 @@
                   {
                       buf.append(",");
                   }
  -                buf.append(getRoot().alias);
  +                buf.append(getSearchTable().alias);
                   buf.append(".");
                   buf.append(field.getColumnName());
                   columnList.add(field.getAttributeName());
  
  
  
  1.7       +2 -2      db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java
  
  Index: AbstractQueryImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractQueryImpl.java	2 Aug 2003 08:27:22 -0000	1.6
  +++ AbstractQueryImpl.java	2 Aug 2003 09:24:00 -0000	1.7
  @@ -69,7 +69,7 @@
       private int m_endAtIndex = Query.NO_END_AT_INDEX;
       private int m_fullSize = 0;
       protected Class m_searchClass;
  -    private Class m_baseClass;
  +    protected Class m_baseClass;
   
       public AbstractQueryImpl()
       {
  
  
  
  1.20      +20 -0     db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
  
  Index: QueryByCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/QueryByCriteria.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- QueryByCriteria.java	2 Aug 2003 08:27:22 -0000	1.19
  +++ QueryByCriteria.java	2 Aug 2003 09:24:00 -0000	1.20
  @@ -63,6 +63,7 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.FieldHelper;
   import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -548,6 +549,25 @@
       public String getObjectProjectionAttribute()
       {
           return m_objectProjectionAttribute;
  +    }
  +
  +    /**
  +     * Use this method to query some related class by object references,
  +     * for example query.setObjectProjectionAttribute("ref1.ref2.ref3");
  +     */
  +    public void setObjectProjectionAttribute(String objectProjectionAttribute)
  +    {
  +        ClassDescriptor baseCld = MetadataManager.getInstance().getRepository().getDescriptorFor(m_baseClass);
  +        ArrayList descs = baseCld.getAttributeDescriptorsForPath(objectProjectionAttribute);
  +        int pathLen = descs.size();
  +
  +        if ((pathLen > 0) && (descs.get(pathLen - 1) instanceof ObjectReferenceDescriptor))
  +        {
  +            ObjectReferenceDescriptor ord =
  +                    ((ObjectReferenceDescriptor) descs.get(pathLen - 1));
  +            setObjectProjectionAttribute(objectProjectionAttribute,
  +                                         ord.getItemClass());
  +        }
       }
   
       public void setObjectProjectionAttribute(String objectProjectionAttribute,
  
  
  

---------------------------------------------------------------------
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