Helper for performing common and/or complex operations with the
during translation of an HQL query.
| Method from org.hibernate.hql.ast.util.SessionFactoryHelper Detail: |
public JoinSequence createCollectionJoinSequence(QueryableCollection collPersister,
String collectionName) {
JoinSequence joinSequence = createJoinSequence();
joinSequence.setRoot( collPersister, collectionName );
joinSequence.setUseThetaStyle( true ); // TODO: figure out how this should be set.
///////////////////////////////////////////////////////////////////////////////
// This was the reason for failures regarding INDEX_OP and subclass joins on
// theta-join dialects; not sure what behaviour we were trying to emulate ;)
// joinSequence = joinSequence.getFromPart(); // Emulate the old addFromOnly behavior.
return joinSequence;
}
Create a join sequence rooted at the given collection. |
public JoinSequence createJoinSequence() {
return new JoinSequence( sfi );
}
Generate an empty join sequence instance. |
public JoinSequence createJoinSequence(boolean implicit,
AssociationType associationType,
String tableAlias,
int joinType,
String[] columns) {
JoinSequence joinSequence = createJoinSequence();
joinSequence.setUseThetaStyle( implicit ); // Implicit joins use theta style (WHERE pk = fk), explicit joins use JOIN (after from)
joinSequence.addJoin( associationType, tableAlias, joinType, columns );
return joinSequence;
}
Generate a join sequence representing the given association type. |
public Type findFunctionReturnType(String functionName,
AST first) {
// locate the registered function by the given name
SQLFunction sqlFunction = requireSQLFunction( functionName );
// determine the type of the first argument...
Type argumentType = null;
if ( first != null ) {
if ( "cast".equals(functionName) ) {
argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() );
}
else if ( first instanceof SqlNode ) {
argumentType = ( (SqlNode) first ).getDataType();
}
}
return sqlFunction.getReturnType( argumentType, sfi );
}
Find the function return type given the function name and the first argument expression node. |
public Queryable findQueryableUsingImports(String className) {
return findQueryableUsingImports( sfi, className );
}
Given a (potentially unqualified) class name, locate its persister. |
public static Queryable findQueryableUsingImports(SessionFactoryImplementor sfi,
String className) {
final String importedClassName = sfi.getImportedClassName( className );
if ( importedClassName == null ) {
return null;
}
try {
return ( Queryable ) sfi.getEntityPersister( importedClassName );
}
catch ( MappingException me ) {
return null;
}
}
Given a (potentially unqualified) class name, locate its persister. |
public SQLFunction findSQLFunction(String functionName) {
return sfi.getSqlFunctionRegistry().findSQLFunction( functionName.toLowerCase() );
}
Locate a registered sql function by name. |
public String[][] generateColumnNames(Type[] sqlResultTypes) {
return NameGenerator.generateColumnNames( sqlResultTypes, sfi );
}
|
public String getAssociatedEntityName(CollectionType collectionType) {
return collectionType.getAssociatedEntityName( sfi );
}
Given a collection type, determine the entity name of the elements
contained within instance of that collection. |
public String[] getCollectionElementColumns(String role,
String roleAlias) {
return getCollectionPropertyMapping( role ).toColumns( roleAlias, CollectionPropertyNames.COLLECTION_ELEMENTS );
}
Retrieves the column names corresponding to the collection elements for the given
collection role. |
public QueryableCollection getCollectionPersister(String role) {
try {
return ( QueryableCollection ) sfi.getCollectionPersister( role );
}
catch ( ClassCastException cce ) {
throw new QueryException( "collection is not queryable: " + role );
}
catch ( Exception e ) {
throw new QueryException( "collection not found: " + role );
}
}
Locate the collection persister by the collection role. |
public int getColumnSpan(Type type) {
return type.getColumnSpan( sfi );
}
Retreive the number of columns represented by this type. |
public AssociationType getElementAssociationType(CollectionType collectionType) {
return ( AssociationType ) getElementType( collectionType );
}
Essentially the same as #getElementType , but requiring that the
element type be an association type. |
public SessionFactoryImplementor getFactory() {
return sfi;
}
Get a handle to the encapsulated SessionFactory. |
public String getIdentifierOrUniqueKeyPropertyName(EntityType entityType) {
try {
return entityType.getIdentifierOrUniqueKeyPropertyName( sfi );
}
catch ( MappingException me ) {
throw new QueryException( me );
}
}
Determine the name of the property for the entity encapsulated by the
given type which represents the id or unique-key. |
public String getImportedClassName(String className) {
return sfi.getImportedClassName( className );
}
Given a (potentially unqualified) class name, locate its imported qualified name. |
public boolean hasPhysicalDiscriminatorColumn(Queryable persister) {
if ( persister.getDiscriminatorType() != null ) {
String discrimColumnName = persister.getDiscriminatorColumnName();
// Needed the "clazz_" check to work around union-subclasses
// TODO : is there a way to tell whether a persister is truly discrim-column based inheritence?
if ( discrimColumnName != null && !"clazz_".equals( discrimColumnName ) ) {
return true;
}
}
return false;
}
Does the given persister define a physical discriminator column
for the purpose of inheritence discrimination? |
public boolean isStrictJPAQLComplianceEnabled() {
return sfi.getSettings().isStrictJPAQLCompliance();
}
|
public EntityPersister requireClassPersister(String name) throws SemanticException {
EntityPersister cp;
try {
cp = findEntityPersisterByName( name );
if ( cp == null ) {
throw new QuerySyntaxException( name + " is not mapped" );
}
}
catch ( MappingException e ) {
throw new DetailedSemanticException( e.getMessage(), e );
}
return cp;
}
Locate the persister by class or entity name, requiring that such a persister
exist. |
public QueryableCollection requireQueryableCollection(String role) throws QueryException {
try {
QueryableCollection queryableCollection = ( QueryableCollection ) sfi.getCollectionPersister( role );
if ( queryableCollection != null ) {
collectionPropertyMappingByRole.put( role, new CollectionPropertyMapping( queryableCollection ) );
}
return queryableCollection;
}
catch ( ClassCastException cce ) {
throw new QueryException( "collection role is not queryable: " + role );
}
catch ( Exception e ) {
throw new QueryException( "collection role not found: " + role );
}
}
Locate the collection persister by the collection role, requiring that
such a persister exist. |