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 Tue, 08 Apr 2003 19:07:05 GMT
brj         2003/04/08 12:07:05

  Modified:    src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlQueryStatement.java
  Log:
  fixed NULL table bug when base class is abstract
  
  Revision  Changes    Path
  1.34      +61 -54    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.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- SqlQueryStatement.java	7 Apr 2003 16:41:50 -0000	1.33
  +++ SqlQueryStatement.java	8 Apr 2003 19:07:05 -0000	1.34
  @@ -62,6 +62,7 @@
   import java.util.List;
   import java.util.Map;
   
  +import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -832,11 +833,6 @@
       {
           TableAlias alias;
           boolean lookForExtents = false;
  - 
  -        if (cld.isAbstract())
  -        {
  -            getLogger().warn("Creating TableAlias for abstract ClassDescriptor: " + cld.getClassNameOfObject());
  -        }
        
           if (!cld.getExtentClasses().isEmpty() && path.length() > 0)
           {
  @@ -877,6 +873,11 @@
       {
           TableAlias alias;
   
  +        if (table == null)
  +        {
  +            getLogger().warn("Creating TableAlias without table for path: " + path);
  +        }
  +
           alias = new TableAlias(table, "A" + m_pathToAlias.size());
           m_pathToAlias.put(path, alias);
   
  @@ -1021,9 +1022,7 @@
   
           if (!(joinSyntax == SQL92_NOPAREN_JOIN_SYNTAX && alias != getRoot()))
           {
  -            buf.append(alias.table);
  -            buf.append(" ");
  -            buf.append(alias.alias);
  +            buf.append(alias.getTableAndAlias());
   
               if (getQuery() instanceof MtoNQuery)
               {
  @@ -1117,9 +1116,7 @@
               buf.append(" INNER JOIN ");
           }
           
  -        buf.append(join.right.table);
  -        buf.append(" ");
  -        buf.append(join.right.alias);
  +        buf.append(join.right.getTableAndAlias());
           buf.append(" ON ");
           join.appendJoinEqualities(buf);
                 
  @@ -1315,61 +1312,81 @@
        */
       static final class TableAlias
       {
  -        final ClassDescriptor cld; // Is null for indirection table of M:N relation
  -        final String table;
  +        ClassDescriptor cld; // Is null for indirection table of M:N relation
  +        String table;
           final String alias;
           private List extents = new ArrayList();
           private List joins;
   
  -        TableAlias(String table, String alias)
  +        TableAlias(String aTable, String anAlias)
           {
               this.cld = null;
  -            this.table = table;
  -            this.alias = alias;
  +            this.table = aTable;
  +            this.alias = anAlias;
           }
   
  -        TableAlias(ClassDescriptor cld, String alias)
  +        TableAlias(ClassDescriptor aCld, String anAlias)
           {
  -            this(cld, alias, false);
  +            this(aCld, anAlias, false);
           }
   
  -		TableAlias(ClassDescriptor cld, String alias, boolean lookForExtents)
  -		{
  -			this.cld = cld;
  -			this.table = cld.getFullTableName();
  -			this.alias = alias;
  +		TableAlias(ClassDescriptor aCld, String anAlias, boolean lookForExtents)
  +		{          
  +			this.cld = aCld;
  +			this.table = aCld.getFullTableName();
  +			this.alias = anAlias;
   
               // BRJ : build alias for extents, only one per Table
   			if (lookForExtents)
   			{
  -				List extClasses = cld.getRepository().getConcreteSubclassesOf(cld.getClassOfObject());
  +				List extClasses = aCld.getRepository().getConcreteSubclassesOf(aCld.getClassOfObject());
   				ClassDescriptor extCd;
  -                String extTable;
  -                Map extMap = new HashMap();     // only one Alias per Table
  +				String extTable;
  +				Map extMap = new HashMap(); // only one Alias per Table
   
  -          		for (int i = 0; i < extClasses.size(); i++)
  +				for (int i = 0; i < extClasses.size(); i++)
   				{
  -					extCd = cld.getRepository().getDescriptorFor((Class) extClasses.get(i));
  -                    extTable = extCd.getFullTableName();
  -                    
  -                    // Add a new extent entry only if the table of the extent
  -                    // does not match the table of the 'base' class.
  -                    if (extMap.get(extTable) == null && !extTable.equals(table))
  
  -                    {
  -                        extMap.put(extTable, new TableAlias(extCd, alias + "E" + i, false));
  -                    }         
  +					extCd = aCld.getRepository().getDescriptorFor((Class) extClasses.get(i));
  +					extTable = extCd.getFullTableName();
  +
  +					// BRJ : Use the first non abstract extent
  +                    // if the main cld is abstract       
  +					if (aCld.isAbstract() && i == 0)
  +					{
  +                        this.cld = extCd;
  +						this.table = extTable;
  +					}
  +					else
  +					{
  +						// Add a new extent entry only if the table of the extent
  +						// does not match the table of the 'base' class.
  +						if (extMap.get(extTable) == null && !extTable.equals(table))
  +						{
  +							extMap.put(extTable, new TableAlias(extCd, anAlias + "E" + i, false));
  +						}
  +					}
   				}
  -                
  -                extents.addAll(extMap.values()); 
  +
  +				extents.addAll(extMap.values());
   			}
  +            
  +            if (cld == null)
  +            {
  +                throw new PersistenceBrokerSQLException("Table is NULL for alias: " + alias);
  +            }
   		}
   
  -        public boolean hasExtents()
  +        String getTableAndAlias()
  +        {
  +            return table + " " + alias;    
  +        }
  +        
  +        boolean hasExtents()
           {
               return (!extents.isEmpty());
           }
   
  -        public Iterator iterateExtents()
  +        Iterator iterateExtents()
           {
               return extents.iterator();
           }
  @@ -1383,32 +1400,22 @@
               joins.add(join);
           }
   
  -        public Iterator iterateJoins()
  +        Iterator iterateJoins()
           {
               return joins.iterator();
           }
   
  -        public boolean hasJoins()
  +        boolean hasJoins()
           {
               return (joins != null);
           }
   
  -        public void removeAllJoins()
  -        {
  -            if (joins != null)
  -            {
  -                joins.clear();
  -            }
  -        }
  -
           public String toString()
           {
               StringBuffer sb = new StringBuffer(1024);
               boolean first = true;
   
  -            sb.append(table);
  -            sb.append(" ");
  -            sb.append(alias);
  +            sb.append(getTableAndAlias());
               if (joins != null)
               {
                   sb.append(" [");
  
  
  

Mime
View raw message