public CriteriaQueryTranslator( final SessionFactoryImplementor factory, final CriteriaImpl criteria, final String rootEntityName, final String rootSQLAlias) throws HibernateException { this.rootCriteria = criteria; this.rootEntityName = rootEntityName; this.sessionFactory = factory; this.rootSQLAlias = rootSQLAlias; this.helper = new SessionFactoryHelper(factory); createAliasCriteriaMap(); createAssociationPathCriteriaMap(); createCriteriaEntityNameMap(); createCriteriaSQLAliasMap(); }
FromElement createCollectionElementsJoin( QueryableCollection queryableCollection, String collectionName) throws SemanticException { JoinSequence collectionJoinSequence = fromClause.getSessionFactoryHelper() .createCollectionJoinSequence( queryableCollection, collectionName ); this.queryableCollection = queryableCollection; return createCollectionJoin( collectionJoinSequence, null ); }
tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() ); String associatedEntityName = entityPersister.getEntityName(); EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName ); String roleAlias = origin.getTableAlias(); String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias ); AssociationType elementAssociationType = sfh.getElementAssociationType( type ); JoinSequence joinSequence = sfh.createJoinSequence( implied, elementAssociationType,
/** * Find the function return type given the function name and the first argument expression node. * * @param functionName The function name. * @param first The first argument expression. * * @return the function return type given the function name and the first argument expression node. */ public Type findFunctionReturnType(String functionName, AST first) { SQLFunction sqlFunction = requireSQLFunction( functionName ); return findFunctionReturnType( functionName, sqlFunction, first ); }
private void dialectFunction(AST exprList) { function = getSessionFactoryHelper().findSQLFunction( methodName ); if ( function != null ) { AST firstChild = exprList != null ? exprList.getFirstChild() : null; Type functionReturnType = getSessionFactoryHelper() .findFunctionReturnType( methodName, function, firstChild ); setDataType( functionReturnType ); } }
@Override public Type getDataType() { Type type = super.getDataType(); if ( type != null ) { return type; } FromElement fe = getFromElement(); if ( fe != null ) { return fe.getDataType(); } SQLFunction sf = getWalker().getSessionFactoryHelper().findSQLFunction( getText() ); if ( sf != null ) { return sf.getReturnType( null, getWalker().getSessionFactoryHelper().getFactory() ); } return null; }
private JoinSequence createJoinSequence(String roleAlias, JoinType joinType) { SessionFactoryHelper sessionFactoryHelper = fromClause.getSessionFactoryHelper(); String[] joinColumns = getColumns(); if ( collectionType == null ) { throw new IllegalStateException( "collectionType is null!" ); } return sessionFactoryHelper.createJoinSequence( implied, collectionType, roleAlias, joinType, joinColumns ); }
@Override protected AST createFromFilterElement(AST filterEntity, AST alias) throws SemanticException { FromElement fromElement = currentFromClause.addFromElement( filterEntity.getText(), alias ); FromClause fromClause = fromElement.getFromClause(); QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole ); // Get the names of the columns used to link between the collection // owner and the collection elements. String[] keyColumnNames = persister.getKeyColumnNames(); String fkTableAlias = persister.isOneToMany() ? fromElement.getTableAlias() : fromClause.getAliasGenerator().createName( collectionFilterRole ); JoinSequence join = sessionFactoryHelper.createJoinSequence(); join.setRoot( persister, fkTableAlias ); if ( !persister.isOneToMany() ) { join.addJoin( (AssociationType) persister.getElementType(), fromElement.getTableAlias(), JoinType.INNER_JOIN, persister.getElementColumnNames( fkTableAlias ) ); } join.addCondition( fkTableAlias, keyColumnNames, " = ?" ); fromElement.setJoinSequence( join ); fromElement.setFilter( true ); LOG.debug( "createFromFilterElement() : processed filter FROM element." ); return fromElement; }
String[] secondJoinColumns = sfh.getCollectionElementColumns( role, roleAlias ); sfh.getElementAssociationType( collectionType ), tableAlias, joinType,
QueryableCollection persister = sessionFactoryHelper.getCollectionPersister( collectionFilterRole ); Type collectionElementType = persister.getElementType(); if ( !collectionElementType.isEntityType() ) { final Type collectionFilterKeyType = sessionFactoryHelper.requireQueryableCollection( collectionFilterRole ) .getKeyType(); final ParameterNode collectionFilterKeyParameter = (ParameterNode) astFactory.create( PARAM, "?" );
/** * Given a (potentially unqualified) class name, locate its persister. * * @param className The (potentially unqualified) class name. * * @return The defined persister for this class, or null if none found. */ public Queryable findQueryableUsingImports(String className) { return findQueryableUsingImports( sfi, className ); }
public void lookupConstant(DotNode node) throws SemanticException { String text = ASTUtil.getPathText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); node.setDataType( persister.getDiscriminatorType() ); if ( InFragment.NULL.equals( discrim ) || InFragment.NOT_NULL.equals( discrim ) ) { throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'" ); } // the class discriminator value setSQLValue( node, text, discrim ); } else { Object value = ReflectHelper.getConstantValue( text, walker.getSessionFactoryHelper().getFactory() ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } setConstantValue( node, text, value ); } }
public Type getDataType() { return getSessionFactoryHelper().findFunctionReturnType( getText(), null ); }
/** * Locate a registered sql function by name, requiring that such a registered function exist. * * @param functionName The name of the function to locate * * @return The sql function. * * @throws QueryException Indicates no matching sql functions could be found. */ private SQLFunction requireSQLFunction(String functionName) { SQLFunction f = findSQLFunction( functionName ); if ( f == null ) { throw new QueryException( "Unable to find SQL function: " + functionName ); } return f; }
attributeName, classAlias, columns, false ); final JoinSequence joinSequence = walker.getSessionFactoryHelper().createJoinSequence( false, entityType, tableAlias, JoinType.LEFT_OUTER_JOIN, columns ); ); final QueryableCollection queryableCollection = walker.getSessionFactoryHelper() .requireQueryableCollection( collectionType.getRole() ); fromElement = fromElementFactory.createCollection( queryableCollection, collectionType.getRole(), JoinType.LEFT_OUTER_JOIN, true, false
public static MapKeyEntityFromElement buildKeyJoin(FromElement collectionFromElement) { final HqlSqlWalker walker = collectionFromElement.getWalker(); final SessionFactoryHelper sfh = walker.getSessionFactoryHelper(); final SessionFactoryImplementor sf = sfh.getFactory(); JoinSequence joinSequence = sfh.createJoinSequence( useThetaJoin, indexEntityType,
private EntityPersister resolveEntityJoinReferencedPersister(AST path) { if ( path.getType() == IDENT ) { final IdentNode pathIdentNode = (IdentNode) path; String name = path.getText(); if ( name == null ) { name = pathIdentNode.getOriginalText(); } return sessionFactoryHelper.findEntityPersisterByName( name ); } else if ( path.getType() == DOT ) { final String pathText = ASTUtil.getPathText( path ); return sessionFactoryHelper.findEntityPersisterByName( pathText ); } return null; }
private void initializeColumnNames() { // Generate a 2d array of column names, the first dimension is parallel with the // return types array. The second dimension is the list of column names for each // type. // todo: we should really just collect these from the various SelectExpressions, rather than regenerating here columnNames = getSessionFactoryHelper().generateColumnNames( queryReturnTypes ); columnNamesStartPositions = new int[columnNames.length]; int startPosition = 1; for ( int i = 0; i < columnNames.length; i++ ) { columnNamesStartPositions[i] = startPosition; startPosition += columnNames[i].length; } }
provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) );
/** * Generate a join sequence representing the given association type. * * @param implicit Should implicit joins (theta-style) or explicit joins (ANSI-style) be rendered * @param associationType The type representing the thing to be joined into. * @param tableAlias The table alias to use in qualifying the join conditions * @param joinType The type of join to render (inner, outer, etc); see {@link org.hibernate.sql.JoinFragment} * @param columns The columns making up the condition of the join. * * @return The generated join sequence. */ public JoinSequence createJoinSequence(boolean implicit, AssociationType associationType, String tableAlias, JoinType joinType, String[][] columns) { JoinSequence joinSequence = createJoinSequence(); joinSequence.setUseThetaStyle( implicit ); // Implicit joins use theta style (WHERE pk = fk), explicit joins use JOIN (afterQuery from) joinSequence.addJoin( associationType, tableAlias, joinType, columns ); return joinSequence; }