Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 92375 invoked from network); 5 Sep 2003 16:58:32 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 5 Sep 2003 16:58:32 -0000 Received: (qmail 19050 invoked by uid 500); 5 Sep 2003 16:57:51 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 19020 invoked by uid 500); 5 Sep 2003 16:57:51 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 18951 invoked by uid 500); 5 Sep 2003 16:57:50 -0000 Received: (qmail 18929 invoked from network); 5 Sep 2003 16:57:49 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 5 Sep 2003 16:57:49 -0000 Received: (qmail 92125 invoked by uid 1510); 5 Sep 2003 16:57:54 -0000 Date: 5 Sep 2003 16:57:54 -0000 Message-ID: <20030905165754.92124.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlQueryStatement.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N arminw 2003/09/05 09:57:54 Modified: src/java/org/apache/ojb/broker/accesslayer/sql SqlQueryStatement.java Log: - add fix posted by Edson Richter: I've discovered the problem. The error is related to if( fld.getClassDescriptor().getFullTableName() != aTableAlias.table ) It should not be if( ! fld.getClassDescriptor().getFullTableName().equals( aTableAlias.table ) ) - improve Logger handling - fix javadoc Revision Changes Path 1.53 +82 -85 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.52 retrieving revision 1.53 diff -u -r1.52 -r1.53 --- SqlQueryStatement.java 4 Sep 2003 13:52:33 -0000 1.52 +++ SqlQueryStatement.java 5 Sep 2003 16:57:54 -0000 1.53 @@ -82,7 +82,7 @@ { private SqlQueryStatement m_parentStatement; /** the logger */ - Logger m_logger = LoggerFactory.getLogger(SqlQueryStatement.class); + Logger m_logger; /** the target table of the query */ private TableAlias m_root; /** the search table of the query */ @@ -116,6 +116,7 @@ */ public SqlQueryStatement(SqlQueryStatement parent, Platform pf, ClassDescriptor cld, String[] columns, Query query, Logger logger) { + m_logger = logger != null ? logger : LoggerFactory.getLogger(SqlQueryStatement.class); this.m_parentStatement = parent; this.m_query = (QueryByCriteria) query; this.m_columns = columns; @@ -211,8 +212,8 @@ String pathName = colName.substring(0, sp); String[] fieldNameRef = { colName.substring(sp + 1)}; - // BRJ: - // check if we refer to an attribute in the parent query + // BRJ: + // check if we refer to an attribute in the parent query // this prefix is temporary ! if (pathName.equals("parentQuery") && m_parentStatement != null) { @@ -252,13 +253,13 @@ * Answer the column name for alias and path info
* if translate try to convert attribute name into column name otherwise use attribute name
* if a FieldDescriptor is found for the attribute name the column name is taken from - * there prefixed with the alias (firstname -> A0.F_NAME). - * + * there prefixed with the alias (firstname -> A0.F_NAME). + * * @param aTableAlias * @param aPathInfo * @param translate * @return - */ + */ protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate) { FieldDescriptor fld = null; @@ -273,7 +274,7 @@ if (fld != null) { // added to suport the super reference descriptor - if( fld.getClassDescriptor().getFullTableName() != aTableAlias.table ) + if(!fld.getClassDescriptor().getFullTableName().equals( aTableAlias.table)) { Iterator itr = aTableAlias.joins.iterator(); while( itr.hasNext() ) @@ -347,7 +348,7 @@ /** * Get the FieldDescriptor for the PathInfo - * + * * @param aTableAlias * @param aPathInfo * @return FieldDescriptor @@ -386,7 +387,7 @@ private FieldDescriptor getFldFromJoin(TableAlias aTableAlias, String aColName) { FieldDescriptor fld = null; - + // Search Join Structure for attribute if( aTableAlias.joins != null ) { @@ -403,8 +404,8 @@ { break; } - - } + + } } } return fld; @@ -419,7 +420,7 @@ private FieldDescriptor getFldFromReference(TableAlias aTableAlias, ObjectReferenceDescriptor anOrd) { FieldDescriptor fld = null; - + if (aTableAlias == getRoot()) { // no path expression @@ -443,7 +444,7 @@ fld = aTableAlias.cld.getFieldDescriptorByName(cld.getPkFields()[0].getPersistentField().getName()); } } - + return fld; } @@ -463,7 +464,7 @@ return appendColName(tableAlias, attrInfo.pathInfo, true, buf); } - + /** * appends a WHERE-clause to the Statement */ @@ -531,7 +532,7 @@ } /** - * @param criteria Selection criteria + * selection criteria */ private String asSQLStatement(Criteria crit) { @@ -641,7 +642,7 @@ buf.append(c.getClause()); if (c.isTranslateField()) - { + { appendColName((String) c.getValue(), false, c.getAlias(), buf); } else @@ -700,10 +701,6 @@ /** * Answer the SQL-Clause for a SqlCriteria * - * @param alias - * @param pathInfo - * @param c SqlCriteria - * @param buf */ private void appendSQLCriteria(SqlCriteria c, StringBuffer buf) { @@ -712,7 +709,7 @@ /** * Answer the SQL-Clause for a SelectionCriteria - * + * * @param c * @param buf */ @@ -720,12 +717,12 @@ { appendColName(alias, pathInfo, c.isTranslateAttribute(), buf); buf.append(c.getClause()); - appendParameter(c.getValue(), buf); + appendParameter(c.getValue(), buf); } /** * Answer the SQL-Clause for a SelectionCriteria - * + * * @param alias * @param pathInfo * @param c SelectionCriteria @@ -758,9 +755,9 @@ appendExistsCriteria((ExistsCriteria) c, buf); } else - { - appendSelectionCriteria(alias,pathInfo,c,buf); - } + { + appendSelectionCriteria(alias,pathInfo,c,buf); + } } /** @@ -773,17 +770,17 @@ { AttributeInfo attrInfo = getAttributeInfo(c.getAttribute(), false, c.getAlias()); TableAlias alias = attrInfo.tableAlias; - + if (alias != null) { boolean hasExtents = alias.hasExtents(); - + if (hasExtents) { // BRJ : surround with braces if alias has extents buf.append("("); appendCriteria(alias, attrInfo.pathInfo, c, buf); - + c.setNumberOfExtentsToBind(alias.extents.size()); Iterator iter = alias.iterateExtents(); while (iter.hasNext()) @@ -798,7 +795,7 @@ { // no extents appendCriteria(alias, attrInfo.pathInfo, c, buf); - } + } } else { @@ -807,7 +804,7 @@ } } - + /** * Append the Parameter @@ -848,7 +845,7 @@ } sql = new SqlSelectStatement(this ,m_platform, cld, columns, subQuery, m_logger).getStatement(); } - + buf.append(" ("); buf.append(sql); buf.append(") "); @@ -857,11 +854,11 @@ /** * Get TableAlias by the path from the target table of the query. - * @param path the path from the target table of the query to this TableAlias. + * @param aPath the path from the target table of the query to this TableAlias. * @param useOuterJoins use outer join to join this table with the previous * table in the path. * @param aUserAlias - * @param fieldRef String[1] contains the field name. + * @param fieldRef String[1] contains the field name. * In the case of related table's primary key the "related.pk" attribute * must not add new join, but use the value of foreign key */ @@ -1019,14 +1016,14 @@ * * extents on the left : copy alias on right, extents point to copies * A1 -> A2 - * A1E0 -> A2C0 - * + * A1E0 -> A2C0 + * * extents on the left and right * A1 -> A2 * A1 -> A2E0 * A1E0 -> A2C0 * A1E0 -> A2E0C0 - * + * * @param left * @param leftKeys * @param right @@ -1034,16 +1031,16 @@ * @param outer * @param name */ - private void addJoin(TableAlias left, Object[] leftKeys, TableAlias right, Object[] rightKeys, boolean outer, String name) + private void addJoin(TableAlias left, Object[] leftKeys, TableAlias right, Object[] rightKeys, boolean outer, String name) { Join join; TableAlias extAlias, rightCopy; - + join = new Join(left, leftKeys, right, rightKeys, outer, name); - left.addJoin(join); + left.addJoin(join); // build join between left and extents of right - if (right.hasExtents()) + if (right.hasExtents()) { for (int i = 0; i < right.extents.size(); i++) { @@ -1052,7 +1049,7 @@ left.addJoin(join); } } - + // we need to copy the alias on the right for each extent on the left if (left.hasExtents()) { @@ -1060,30 +1057,30 @@ { extAlias = (TableAlias) left.extents.get(i); rightCopy = right.copy("C" + i); - - // copies are treated like normal extents + + // copies are treated like normal extents right.extents.add(rightCopy); right.extents.addAll(rightCopy.extents); - + addJoin(extAlias, leftKeys, rightCopy ,rightKeys, true ,name); } } - - - } - + + + } + private char getAliasChar() { char result = 'A'; - + if (m_parentStatement != null) { result = (char)(m_parentStatement.getAliasChar() + 1); } - + return result; } - + /** * Create a TableAlias for path or userAlias * @param aCld @@ -1092,13 +1089,13 @@ * @param anOriginalPath * @param hints a List os Class objects to be used as hints for path expressions * @return TableAlias - * + * */ private TableAlias createTableAlias(ClassDescriptor aCld, String aPath, String aUserAlias, String anOriginalPath,List hints) { if (aUserAlias == null || !anOriginalPath.equals(aPath)) { - return createTableAlias(aCld, hints, aPath); + return createTableAlias(aCld, hints, aPath); } else { @@ -1116,12 +1113,12 @@ { TableAlias alias; boolean lookForExtents = false; - + if (!cld.getExtentClasses().isEmpty() && path.length() > 0) { lookForExtents = true; - } - + } + String aliasName = String.valueOf(getAliasChar()) + m_aliasCount++; // m_pathToAlias.size(); alias = new TableAlias(cld, aliasName, lookForExtents,hints); @@ -1141,7 +1138,7 @@ { if (aUserAlias == null || !anOriginalPath.equals(aPath)) { - return createTableAlias(aTable, aPath); + return createTableAlias(aTable, aPath); } else { @@ -1171,7 +1168,7 @@ } /** - * Answer the TableAlias for aPath + * Answer the TableAlias for aPath * @param aPath * @return TableAlias, null if none */ @@ -1183,14 +1180,14 @@ /** * Answer the TableAlias for aPath or aUserAlias * @param aPath - * @param aUserAlias + * @param aUserAlias * @return TableAlias, null if none */ private TableAlias getTableAliasForPath(String aPath, String aUserAlias) { if (aUserAlias == null) { - return getTableAliasForPath(aPath); + return getTableAliasForPath(aPath); } else { @@ -1201,7 +1198,7 @@ /** * Answer the TableAlias for aPath or aUserAlias * @param aPath - * @param aUserAlias + * @param aUserAlias * @param anOriginalPath * @return TableAlias, null if none */ @@ -1209,7 +1206,7 @@ { if (aUserAlias == null || !anOriginalPath.equals(aPath)) { - return getTableAliasForPath(aPath); + return getTableAliasForPath(aPath); } else { @@ -1229,7 +1226,7 @@ if (q instanceof QueryByCriteria) { - itemClasses = ((QueryByCriteria) q).getClassesForPath(attr); + itemClasses = ((QueryByCriteria) q).getClassesForPath(attr); } if (itemClasses == null) @@ -1237,16 +1234,16 @@ itemClasses = new ArrayList(); itemClasses.add(ord.getItemClass()); } - + List classDescriptors = new ArrayList(itemClasses.size()); DescriptorRepository repo = ord.getClassDescriptor().getRepository(); - + for (Iterator iter = itemClasses.iterator(); iter.hasNext();) { Class clazz = (Class) iter.next(); classDescriptors.add(repo.getDescriptorFor(clazz)); } - return (ClassDescriptor) classDescriptors.get(0); + return (ClassDescriptor) classDescriptors.get(0); } @@ -1304,7 +1301,7 @@ /** * Appends to the statement table and all tables joined to it. - * @param table the table + * @param alias the table alias * @param where append conditions for WHERE clause here */ protected void appendTableWithJoins(TableAlias alias, StringBuffer where, StringBuffer buf) @@ -1412,13 +1409,13 @@ { buf.append(" INNER JOIN "); } - + buf.append(join.right.getTableAndAlias()); buf.append(" ON "); join.appendJoinEqualities(buf); - + appendTableWithJoins(join.right, where, buf); - } + } /** * Appends to the statement columns if they are not found among the existingColumns. @@ -1465,8 +1462,8 @@ { SelectionCriteria c = (SelectionCriteria) o; // BRJ : Outer join for OR - boolean useOuterJoin = (crit.getType() == Criteria.OR); - + boolean useOuterJoin = (crit.getType() == Criteria.OR); + if (c.getAttribute() != null) { buildJoinTreeForColumn(c.getAttribute(), useOuterJoin, c.getAlias()); @@ -1477,7 +1474,7 @@ buildJoinTreeForColumn((String) cc.getValue(), useOuterJoin, c.getAlias()); } } - } + } } /** @@ -1644,7 +1641,7 @@ TableAlias tableAlias; PathInfo pathInfo; } - + /** * This class represents one table (possibly with alias) in the SQL query */ @@ -1671,7 +1668,7 @@ } TableAlias(ClassDescriptor aCld, String anAlias, boolean lookForExtents,List hints) - { + { this.cld = aCld; this.table = aCld.getFullTableName(); this.alias = anAlias; @@ -1708,7 +1705,7 @@ extTable = extCd.getFullTableName(); // BRJ : Use the first non abstract extent - // if the main cld is abstract + // if the main cld is abstract //logger.debug("cld abstract["+aCld.isAbstract()+"] i["+i+"] index ["+firtsNonAbstractExtentIndex+"]"); if (aCld.isAbstract() && i == firtsNonAbstractExtentIndex) { @@ -1727,7 +1724,7 @@ } extents.addAll(extMap.values()); } - + if (cld == null) { throw new PersistenceBrokerSQLException("Table is NULL for alias: " + alias); @@ -1741,9 +1738,9 @@ String getTableAndAlias() { - return table + " " + alias; + return table + " " + alias; } - + boolean hasExtents() { return (!extents.isEmpty()); @@ -1764,7 +1761,7 @@ { TableAlias result, temp; Iterator iter = iterateExtents(); - + if (cld == null) { result = new TableAlias(table, alias + aPostfix); @@ -1773,13 +1770,13 @@ { result = new TableAlias(cld, alias + aPostfix); } - + while (iter.hasNext()) { temp = (TableAlias)iter.next(); result.extents.add(temp.copy(aPostfix)); } - + return result; } @@ -1940,7 +1937,7 @@ { return name.hashCode(); } - + public String toString() { return left.alias + " -> " + right.alias; --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org