From: <hib...@li...> - 2006-03-19 03:13:07
|
Author: ste...@jb... Date: 2006-03-18 22:13:00 -0500 (Sat, 18 Mar 2006) New Revision: 9655 Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java Log: initial join related classes Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java 2006-03-17 22:08:11 UTC (rev 9654) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinNode.java 2006-03-19 03:13:00 UTC (rev 9655) @@ -0,0 +1,54 @@ +package org.hibernate.hql.ast.tree; + +import antlr.Token; + +/** + * Represents an HQL join. The coneptualization here is strictly that of + * the join in terms of the context of the HQL query which may or may not have + * direct correlation to any SQL join. + * + * @author Steve Ebersole + */ +public class JoinNode extends Node { + + private JoinType joinType; + private JoinSource source; + private boolean fetch; + + public JoinNode() { + } + + public JoinNode(Token tok) { + super( tok ); + } + + public JoinNode(JoinType joinType, JoinSource source, boolean fetch) { + this.joinType = joinType; + this.source = source; + this.fetch = fetch; + } + + public JoinType getJoinType() { + return joinType; + } + + public void setJoinType(JoinType joinType) { + this.joinType = joinType; + } + + public JoinSource getSource() { + return source; + } + + public void setSource(JoinSource source) { + this.source = source; + } + + public boolean isFetch() { + return fetch; + } + + public void setFetch(boolean fetch) { + this.fetch = fetch; + } +} Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java 2006-03-17 22:08:11 UTC (rev 9654) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinSource.java 2006-03-19 03:13:00 UTC (rev 9655) @@ -0,0 +1,50 @@ +package org.hibernate.hql.ast.tree; + +import java.util.HashMap; +import java.io.Serializable; + +/** + * Represents the source of a join, in the context of the HQL query. + */ +public class JoinSource implements Serializable { + + /** + * Indicates a join using the HQL explicit join syntax (i.e. the join keyword). + */ + public static final JoinSource EXPLICIT = new JoinSource( "explicit" ); + /** + * Indicates a join defined by implicit syntax (i.e. a path expression). + */ + public static final JoinSource IMPLICIT = new JoinSource( "implicit" ); + /** + * Indicates a join that is the result of an indexed operation (i.e. []) + * on an indexed or keyed collection (list or map). + */ + public static final JoinSource INDEXED = new JoinSource( "indexed" ); + /** + * Indicates a theta-style join (i.e. from A a, B b where a.id = b.id...) + */ + public static final JoinSource THETA = new JoinSource( "theta" ); + + private static final HashMap INSTANCES = new HashMap(); + static { + INSTANCES.put( EXPLICIT.name, EXPLICIT ); + INSTANCES.put( IMPLICIT.name, IMPLICIT ); + INSTANCES.put( INDEXED.name, INDEXED ); + INSTANCES.put( THETA.name, THETA ); + } + + private final String name; + + private JoinSource(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + private Object readResolve() { + return INSTANCES.get( name ); + } +} Added: branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java =================================================================== --- branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java 2006-03-17 22:08:11 UTC (rev 9654) +++ branches/HQL_ANTLR_2/Hibernate3/src/org/hibernate/hql/ast/tree/JoinType.java 2006-03-19 03:13:00 UTC (rev 9655) @@ -0,0 +1,60 @@ +package org.hibernate.hql.ast.tree; + +import java.io.Serializable; +import java.util.HashMap; + +/** + * Represents a canonical join type. + * <p/> + * Note that currently HQL really only supports inner and left outer joins + * (though cross joins can also be achieved). This is because joins in HQL + * are always defined in relation to a mapped association. However, when we + * start allowing users to specify ad-hoc joins this may need to change to + * allow the full spectrum of join types. Thus the others are provided here + * currently just for completeness and for future expansion. + */ +public class JoinType implements Serializable { + /** + * Represents an inner join. + */ + public static final JoinType INNER = new JoinType( "inner" ); + /** + * Represents a left outer join. + */ + public static final JoinType LEFT = new JoinType( "left outer" ); + /** + * Represents a right outer join. + */ + public static final JoinType RIGHT = new JoinType( "right outer" ); + /** + * Represents a cross join (aka a cartesian product). + */ + public static final JoinType CROSS = new JoinType( "cross" ); + /** + * Represents a full join. + */ + public static final JoinType FULL = new JoinType( "full" ); + + private static final HashMap INSTANCES = new HashMap(); + static { + INSTANCES.put( INNER.name, INNER ); + INSTANCES.put( LEFT.name, LEFT ); + INSTANCES.put( RIGHT.name, RIGHT ); + INSTANCES.put( CROSS.name, CROSS ); + INSTANCES.put( FULL.name, FULL ); + } + + private final String name; + + private JoinType(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + private Object readResolve() { + return INSTANCES.get( name ); + } +} |