Author: steve.ebersole(a)jboss.com
Date: 2009-04-22 15:06:00 -0400 (Wed, 22 Apr 2009)
New Revision: 16405
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/alias/TableAliasGenerator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolution.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/domain/Mappings.hbm.xml
Log:
minor changes to path resolution
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/alias/TableAliasGenerator.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/alias/TableAliasGenerator.java 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/alias/TableAliasGenerator.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -43,6 +43,10 @@
this.base = base;
}
+ public String getBase() {
+ return base;
+ }
+
/**
* Generate the sql alias based on the given suffix which is the <i>subclass
table number</i>.
*
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolution.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolution.java 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/HQLResolution.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.sql.ast.phase.hql.resolve;
import org.antlr.runtime.RecognizerSharedState;
@@ -51,15 +72,12 @@
.push( new BasicPathResolutionStrategySupport( this ) );
}
- protected void registerPersisterSpace( CommonTree entityName,
- CommonTree alias ) {
- String entityPersisterName = sessionFactory
- .getImportedClassName( entityName.getText() );
- EntityPersister entityPersister = sessionFactory
- .getEntityPersister( entityPersisterName );
+ protected void registerPersisterSpace( CommonTree entityName, CommonTree alias ) {
+ String entityPersisterName = sessionFactory.getImportedClassName( entityName.getText()
);
+ Queryable entityPersister = ( Queryable ) sessionFactory.getEntityPersister(
entityPersisterName );
- EntityTableSpace tableSpace = new Table.EntityTableSpace(
- ( Queryable ) entityPersister, alias.getText() );
+ TableAliasGenerator.TableAliasRoot tableAliasRoot =
getTableAliasGenerator().generateSqlAliasRoot( entityPersister, alias.getText() );
+ EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister,
tableAliasRoot );
registerPersisterSpace( tableSpace.getPersisterSpace() );
}
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterSpace.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -61,7 +61,7 @@
public Table.TableSpace getTableSpace();
- public boolean contansProperty(String propertyName);
+ public boolean containsProperty(String propertyName);
public Type getPropertyType(String propertyName);
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/PersisterTableExpressionGenerator.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -29,6 +29,9 @@
package org.hibernate.sql.ast.phase.hql.resolve;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.persister.MappedTableMetadata;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Queryable;
@@ -36,6 +39,7 @@
import org.hibernate.sql.ast.common.HibernateTree;
import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
import org.hibernate.sql.ast.tree.Table;
+import org.hibernate.sql.ast.util.TreePrinter;
/**
* Generate table expressions for persisters.
@@ -45,6 +49,7 @@
* @author Steve Ebersole
*/
public abstract class PersisterTableExpressionGenerator {
+ private static final Logger log = LoggerFactory.getLogger(
PersisterTableExpressionGenerator.class );
public static Table generateTableExpression(
Queryable persister,
@@ -84,6 +89,11 @@
on.addChild( joinCondition );
}
+ // todo : temporary...
+ System.out.println(
+ new TreePrinter( HQLParser.class ).renderAsString( drivingTable, "Generated
table space" )
+ );
+
return drivingTable;
}
@@ -139,9 +149,7 @@
}
private static Table generateTableReference(String tableName, String tableAlias,
Table.TableSpace tableSpace) {
- Table table = new Table( HQLParser.TABLE, tableSpace );
- table.addChild( new HibernateTree( HQLParser.IDENTIFIER, tableName ) );
- table.addChild( new HibernateTree( HQLParser.ALIAS_NAME, tableAlias ) );
+ Table table = new Table( tableName, tableAlias, tableSpace );
return table;
}
Modified:
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java
===================================================================
---
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/main/java/org/hibernate/sql/ast/phase/hql/resolve/path/impl/AbstractPathResolutionStrategy.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -471,16 +471,11 @@
protected Table createJoin(PersisterSpace lhs, Queryable entityPersister, String alias)
{
EntityType entityType = entityPersister.getEntityMetamodel().getEntityType();
- Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister, alias
);
TableAliasGenerator.TableAliasRoot tableAliasRoot =
resolutionContext().getTableAliasGenerator()
.generateSqlAliasRoot( entityPersister, alias );
+ Table.EntityTableSpace tableSpace = new Table.EntityTableSpace( entityPersister,
tableAliasRoot );
+ Table joinedTableExpression = tableSpace.getDrivingTable();
- Table joinedTableExpression =
PersisterTableExpressionGenerator.generateTableExpression(
- entityPersister,
- tableAliasRoot,
- tableSpace
- );
-
HibernateTree join = new HibernateTree( HQLParser.JOIN );
join.addChild( buildJoinTypeNode() );
join.addChild( joinedTableExpression );
@@ -516,9 +511,9 @@
protected Table createJoin(PersisterSpace lhs, QueryableCollection collectionPersister,
String sourceAlias, HibernateTree extraJoinConditions) {
CollectionType collectionType = collectionPersister.getCollectionType();
- Table.CollectionTableSpace tableSpace = new Table.CollectionTableSpace(
collectionPersister, sourceAlias );
TableAliasGenerator.TableAliasRoot tableAliasRoot =
resolutionContext().getTableAliasGenerator()
.generateSqlAliasRoot( collectionPersister, sourceAlias );
+ Table.CollectionTableSpace tableSpace = new Table.CollectionTableSpace(
collectionPersister, tableAliasRoot );
Table collectionTableExpression =
PersisterTableExpressionGenerator.generateTableExpression(
collectionPersister,
Modified: core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java
===================================================================
--- core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-22
18:40:40 UTC (rev 16404)
+++ core/branches/antlr3/src/main/java/org/hibernate/sql/ast/tree/Table.java 2009-04-22
19:06:00 UTC (rev 16405)
@@ -32,18 +32,18 @@
import java.util.LinkedHashSet;
import java.util.HashMap;
-import org.antlr.runtime.Token;
-
import org.hibernate.type.Type;
-import org.hibernate.sql.ast.alias.ImplicitAliasGenerator;
+import org.hibernate.sql.ast.alias.TableAliasGenerator;
import org.hibernate.sql.ast.common.HibernateTree;
import org.hibernate.sql.ast.common.HibernateToken;
import org.hibernate.sql.ast.util.DisplayableNode;
import org.hibernate.sql.ast.phase.hql.parse.HQLParser;
import org.hibernate.sql.ast.phase.hql.resolve.PersisterSpace;
+import org.hibernate.sql.ast.phase.hql.resolve.PersisterTableExpressionGenerator;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.util.StringHelper;
+import org.hibernate.QueryException;
/**
* todo : javadocs
@@ -53,20 +53,14 @@
public class Table extends HibernateTree implements DisplayableNode {
private final TableSpace tableSpace;
- public Table(Token token, TableSpace tableSpace) {
- super( token );
+ public Table(String tableName, String tableAlias, TableSpace tableSpace) {
+ super( new HibernateToken( HQLParser.TABLE ) );
+ addChild( new HibernateTree( HQLParser.IDENTIFIER, tableName ) );
+ addChild( new HibernateTree( HQLParser.ALIAS_NAME, tableAlias ) );
this.tableSpace = tableSpace;
tableSpace.addTable( this );
}
- public Table(HibernateTree node, TableSpace tableSpace) {
- this( node.getToken(), tableSpace );
- }
-
- public Table(int tokenType, TableSpace tableSpace) {
- this( new HibernateToken( tokenType ), tableSpace );
- }
-
public TableSpace getTableSpace() {
return tableSpace;
}
@@ -144,25 +138,19 @@
}
public static abstract class AbstractTableSpace implements Table.TableSpace {
- private final String sourceAlias;
- private final boolean implicitSourceAlias;
+ private final TableAliasGenerator.TableAliasRoot aliasRoot;
protected final LinkedHashSet<Table> tables = new LinkedHashSet<Table>();
protected final HashMap<String,Table> aliasToTableMap = new
HashMap<String,Table>();
protected final HashMap<String,Table> nameToTableMap = new
HashMap<String,Table>();
- private AbstractTableSpace(String sourceAlias) {
- this.sourceAlias = sourceAlias;
- this.implicitSourceAlias = ImplicitAliasGenerator.isImplicitAlias( sourceAlias );
+ private AbstractTableSpace(TableAliasGenerator.TableAliasRoot aliasRoot) {
+ this.aliasRoot = aliasRoot;
}
public String getSourceAlias() {
- return sourceAlias;
+ return aliasRoot.getBase();
}
- public String getSqlAliasBaseRoot() {
- return implicitSourceAlias ? getPersisterSpace().getShortName() : sourceAlias;
- }
-
public void addTable(Table table) {
tables.add( table );
aliasToTableMap.put( table.getAliasText(), table );
@@ -181,8 +169,13 @@
propertyToJoinedTableMap.put( propertyName, table );
}
- public boolean contansProperty(String propertyName) {
- return getPropertyType( propertyName ) != null;
+ public boolean containsProperty(String propertyName) {
+ try {
+ return getPropertyType( propertyName ) != null;
+ }
+ catch ( QueryException qe ) {
+ return false;
+ }
}
}
@@ -190,12 +183,18 @@
private final EntityPersisterSpace persisterSpace;
private final ArrayList tables;
- public EntityTableSpace(Queryable entityPersister, String sourecAlias) {
- super( sourecAlias );
+ public EntityTableSpace(Queryable entityPersister, TableAliasGenerator.TableAliasRoot
aliasRoot) {
+ super( aliasRoot );
this.persisterSpace = new EntityPersisterSpace( this, entityPersister );
int numberOfTables = entityPersister.getMappedTableMetadata().getJoinedTables().length
+ 1;
int listSize = numberOfTables + (int) ( numberOfTables * .75 ) + 1;
this.tables = new ArrayList( listSize );
+
+ PersisterTableExpressionGenerator.generateTableExpression(
+ entityPersister,
+ aliasRoot,
+ this
+ );
}
public PersisterSpace getPersisterSpace() {
@@ -291,11 +290,11 @@
private Table collectionTable;
private EntityTableSpace entityElementTableSpace;
- public CollectionTableSpace(QueryableCollection persister, String sourceAlias) {
- super( sourceAlias );
+ public CollectionTableSpace(QueryableCollection persister,
TableAliasGenerator.TableAliasRoot aliasRoot) {
+ super( aliasRoot );
this.persisterSpace = new CollectionPersisterSpace( this, persister );
if ( persisterSpace.areElementsEntities ) {
- entityElementTableSpace = new EntityTableSpace( ( Queryable )
persister.getElementPersister(), sourceAlias );
+ entityElementTableSpace = new EntityTableSpace( ( Queryable )
persister.getElementPersister(), aliasRoot );
}
}
Modified:
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/domain/Mappings.hbm.xml
===================================================================
---
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/domain/Mappings.hbm.xml 2009-04-22
18:40:40 UTC (rev 16404)
+++
core/branches/antlr3/src/test/java/org/hibernate/sql/ast/phase/hql/domain/Mappings.hbm.xml 2009-04-22
19:06:00 UTC (rev 16405)
@@ -36,7 +36,10 @@
<many-to-one name="father" column="father_id"/>
<many-to-one name="zoo" column="zoo_id"/>
<property name="serialNumber"/>
+ <set name="offspring">
+<!--
<set name="offspring" order-by="father_id">
+-->
<key column="mother_id"/>
<one-to-many class="Animal"/>
</set>