org.hibernate.hql.ast.util

Class SessionFactoryHelper


public class SessionFactoryHelper
extends java.lang.Object

Helper for performing common and/or complex operations with the SessionFactoryImplementor during translation of an HQL query.
Author:
Joshua Davis

Constructor Summary

SessionFactoryHelper(SessionFactoryImplementor sfi)
Construct a new SessionFactoryHelper instance.

Method Summary

JoinSequence
createCollectionJoinSequence(QueryableCollection collPersister, String collectionName)
Create a join sequence rooted at the given collection.
JoinSequence
createJoinSequence()
Generate an empty join sequence instance.
JoinSequence
createJoinSequence(boolean implicit, AssociationType associationType, String tableAlias, int joinType, String[] columns)
Generate a join sequence representing the given association type.
Type
findFunctionReturnType(String functionName, AST first)
Find the function return type given the function name and the first argument expression node.
Queryable
findQueryableUsingImports(String className)
Given a (potentially unqualified) class name, locate its persister.
static Queryable
findQueryableUsingImports(SessionFactoryImplementor sfi, String className)
Given a (potentially unqualified) class name, locate its persister.
SQLFunction
findSQLFunction(String functionName)
Locate a registered sql function by name.
String[][]
generateColumnNames(Type[] sqlResultTypes)
String
getAssociatedEntityName(CollectionType collectionType)
Given a collection type, determine the entity name of the elements contained within instance of that collection.
String[]
getCollectionElementColumns(String role, String roleAlias)
Retrieves the column names corresponding to the collection elements for the given collection role.
QueryableCollection
getCollectionPersister(String role)
Locate the collection persister by the collection role.
int
getColumnSpan(Type type)
Retreive the number of columns represented by this type.
AssociationType
getElementAssociationType(CollectionType collectionType)
Essentially the same as SessionFactoryHelper, but requiring that the element type be an association type.
SessionFactoryImplementor
getFactory()
Get a handle to the encapsulated SessionFactory.
String
getIdentifierOrUniqueKeyPropertyName(EntityType entityType)
Determine the name of the property for the entity encapsulated by the given type which represents the id or unique-key.
String
getImportedClassName(String className)
Given a (potentially unqualified) class name, locate its imported qualified name.
boolean
hasPhysicalDiscriminatorColumn(Queryable persister)
Does the given persister define a physical discriminator column for the purpose of inheritence discrimination?
boolean
isStrictJPAQLComplianceEnabled()
EntityPersister
requireClassPersister(String name)
Locate the persister by class or entity name, requiring that such a persister exist.
QueryableCollection
requireQueryableCollection(String role)
Locate the collection persister by the collection role, requiring that such a persister exist.

Constructor Details

SessionFactoryHelper

public SessionFactoryHelper(SessionFactoryImplementor sfi)
Construct a new SessionFactoryHelper instance.
Parameters:
sfi - The SessionFactory impl to be encapsualted.

Method Details

createCollectionJoinSequence

public JoinSequence createCollectionJoinSequence(QueryableCollection collPersister,
                                                 String collectionName)
Create a join sequence rooted at the given collection.
Parameters:
collPersister - The persister for the collection at which the join should be rooted.
collectionName - The alias to use for qualifying column references.
Returns:
The generated join sequence.

createJoinSequence

public JoinSequence createJoinSequence()
Generate an empty join sequence instance.
Returns:
The generate join sequence.

createJoinSequence

public JoinSequence createJoinSequence(boolean implicit,
                                       AssociationType associationType,
                                       String tableAlias,
                                       int joinType,
                                       String[] columns)
Generate a join sequence representing the given association type.
Parameters:
implicit - Should implicit joins (theta-style) or explicit joins (ANSI-style) be rendered
associationType - The type representing the thing to be joined into.
tableAlias - The table alias to use in qualifing the join conditions
joinType - The type of join to render (inner, outer, etc); see JoinFragment
columns - The columns making up the condition of the join.
Returns:
The generated join sequence.

findFunctionReturnType

public Type findFunctionReturnType(String functionName,
                                   AST first)
Find the function return type given the function name and the first argument expression node.
Parameters:
functionName - The function name.
first - The first argument expression.
Returns:
the function return type given the function name and the first argument expression node.

findQueryableUsingImports

public Queryable findQueryableUsingImports(String className)
Given a (potentially unqualified) class name, locate its persister.
Parameters:
className - The (potentially unqualified) class name.
Returns:
The defined persister for this class, or null if none found.

findQueryableUsingImports

public static Queryable findQueryableUsingImports(SessionFactoryImplementor sfi,
                                                  String className)
Given a (potentially unqualified) class name, locate its persister.
Parameters:
sfi - The session factory implementor.
className - The (potentially unqualified) class name.
Returns:
The defined persister for this class, or null if none found.

findSQLFunction

public SQLFunction findSQLFunction(String functionName)
Locate a registered sql function by name.
Parameters:
functionName - The name of the function to locate
Returns:
The sql function, or null if not found.

generateColumnNames

public String[][] generateColumnNames(Type[] sqlResultTypes)

getAssociatedEntityName

public String getAssociatedEntityName(CollectionType collectionType)
Given a collection type, determine the entity name of the elements contained within instance of that collection.
Parameters:
collectionType - The collection type to check.
Returns:
The entity name of the elements of this collection.

getCollectionElementColumns

public String[] getCollectionElementColumns(String role,
                                            String roleAlias)
Retrieves the column names corresponding to the collection elements for the given collection role.
Parameters:
role - The collection role
roleAlias - The sql column-qualification alias (i.e., the table alias)
Returns:
the collection element columns

getCollectionPersister

public QueryableCollection getCollectionPersister(String role)
Locate the collection persister by the collection role.
Parameters:
role - The collection role name.
Returns:
The defined CollectionPersister for this collection role, or null.

getColumnSpan

public int getColumnSpan(Type type)
Retreive the number of columns represented by this type.
Parameters:
type - The type.
Returns:
The number of columns.

getElementAssociationType

public AssociationType getElementAssociationType(CollectionType collectionType)
Essentially the same as SessionFactoryHelper, but requiring that the element type be an association type.
Parameters:
collectionType - The collection type to be checked.
Returns:
The AssociationType of the elements of the collection.

getFactory

public SessionFactoryImplementor getFactory()
Get a handle to the encapsulated SessionFactory.
Returns:
The encapsulated SessionFactory.

getIdentifierOrUniqueKeyPropertyName

public String getIdentifierOrUniqueKeyPropertyName(EntityType entityType)
Determine the name of the property for the entity encapsulated by the given type which represents the id or unique-key.
Parameters:
entityType - The type representing the entity.
Returns:
The corresponding property name

getImportedClassName

public String getImportedClassName(String className)
Given a (potentially unqualified) class name, locate its imported qualified name.
Parameters:
className - The potentially unqualified class name
Returns:
The qualified class name.

hasPhysicalDiscriminatorColumn

public boolean hasPhysicalDiscriminatorColumn(Queryable persister)
Does the given persister define a physical discriminator column for the purpose of inheritence discrimination?
Parameters:
persister - The persister to be checked.
Returns:
True if the persister does define an actual discriminator column.

isStrictJPAQLComplianceEnabled

public boolean isStrictJPAQLComplianceEnabled()

requireClassPersister

public EntityPersister requireClassPersister(String name)
            throws SemanticException
Locate the persister by class or entity name, requiring that such a persister exist.
Parameters:
name - The class or entity name
Returns:
The defined persister for this entity

requireQueryableCollection

public QueryableCollection requireQueryableCollection(String role)
            throws QueryException
Locate the collection persister by the collection role, requiring that such a persister exist.
Parameters:
role - The collection role name.
Returns:
The defined CollectionPersister for this collection role.
Throws:
QueryException - Indicates that the collection persister could not be found.