protected void createTempTable(Queryable persister, SessionImplementor session) { // Don't really know all the codes required to adequately decipher returned jdbc exceptions here. // simply allow the failure to be eaten and the subsequent insert-selects/deletes should fail TemporaryTableCreationWork work = new TemporaryTableCreationWork( persister ); if ( shouldIsolateTemporaryTableDDL( session ) ) { session.getTransactionCoordinator() .getTransaction() .createIsolationDelegate() .delegateWork( work, shouldTransactIsolatedTemporaryTableDDL( session ) ); } else { final Connection connection = session.getTransactionCoordinator() .getJdbcCoordinator() .getLogicalConnection() .getConnection(); work.execute( connection ); session.getTransactionCoordinator() .getJdbcCoordinator() .afterStatementExecution(); } }
FromElement addFromElement() throws SemanticException { final FromClause parentFromClause = fromClause.getParentFromClause(); if ( parentFromClause != null ) { // Look up class name using the first identifier in the path. final String pathAlias = PathHelper.getAlias( path ); final FromElement parentFromElement = parentFromClause.getFromElement( pathAlias ); if ( parentFromElement != null ) { return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias ); } } final EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path ); final FromElement elem = createAndAddFromElement( path, classAlias, entityPersister, (EntityType) ( (Queryable) entityPersister ).getType(), null ); // Add to the query spaces. fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() ); return elem; }
private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) { AliasGenerator aliasGenerator = new LocalAliasGenerator( 0 ); appendSelectExpressions( collectionPersister.getIndexColumnNames(), selections, aliasGenerator ); Type keyType = collectionPersister.getIndexType(); if ( keyType.isAssociationType() ) { EntityType entityType = (EntityType) keyType; Queryable keyEntityPersister = (Queryable) sfi().getEntityPersister( entityType.getAssociatedEntityName( sfi() ) ); SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment( collectionTableAlias(), null, false ); appendSelectExpressions( fragment, selections, aliasGenerator ); } }
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) { AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 ); appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator ); Type valueType = collectionPersister.getElementType(); if ( valueType.isAssociationType() ) { EntityType valueEntityType = (EntityType) valueType; Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister( valueEntityType.getAssociatedEntityName( sfi() ) ); SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment( elementTableAlias(), null, false ); appendSelectExpressions( fragment, selections, aliasGenerator ); } }
public void processConstant(AST constant, boolean resolveIdent) throws SemanticException { // If the constant is an IDENT, figure out what it means... boolean isIdent = ( constant.getType() == IDENT || constant.getType() == WEIRD_IDENT ); if ( resolveIdent && isIdent && isAlias( constant.getText() ) ) { // IDENT is a class alias in the FROM. IdentNode ident = (IdentNode) constant; // Resolve to an identity column. ident.resolve( false, true ); } else { // IDENT might be the name of a class. Queryable queryable = walker.getSessionFactoryHelper().findQueryableUsingImports( constant.getText() ); if ( isIdent && queryable != null ) { constant.setText( queryable.getDiscriminatorSQLValue() ); } // Otherwise, it's a literal. else { processLiteral( constant ); } } }
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 ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } setConstantValue( node, text, value ); } }
PropertyMapping getPropertyMapping(String name) throws QueryException { PropertyMapping decorator = getDecoratedPropertyMapping( name ); if ( decorator != null ) return decorator; String type = getType( name ); if ( type == null ) { String role = getRole( name ); if ( role == null ) { throw new QueryException( "alias not found: " + name ); } return getCollectionPersister( role ); //.getElementPropertyMapping(); } else { Queryable persister = getEntityPersister( type ); if ( persister == null ) throw new QueryException( "persistent class not found: " + type ); return persister; } }
private void cleanUpRows(SharedSessionContractImplementor session, Queryable persister) { final String sql = "delete from " + fullyQualifiedTableName + " where " + discriminatorColumn + "=?"; PreparedStatement ps = null; try { ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql, false); ps.setString(1, generateDiscriminatorValue(persister)); StringType.INSTANCE.set(ps, generateDiscriminatorValue(persister), 1, session); session.getJdbcCoordinator().getResultSetReturn().executeUpdate(ps); } catch (SQLException e) { throw session.getJdbcServices().getSqlExceptionHelper().convert(e, "Unable to clean up id table [" + fullyQualifiedTableName + "]", sql); } finally { if (ps != null) { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(ps); } } }
FromElement addFromElement() throws SemanticException { FromClause parentFromClause = fromClause.getParentFromClause(); if ( parentFromClause != null ) { // Look up class name using the first identifier in the path. String pathAlias = PathHelper.getAlias( path ); FromElement parentFromElement = parentFromClause.getFromElement( pathAlias ); if ( parentFromElement != null ) { return createFromElementInSubselect( path, pathAlias, parentFromElement, classAlias ); } } EntityPersister entityPersister = fromClause.getSessionFactoryHelper().requireClassPersister( path ); FromElement elem = createAndAddFromElement( path, classAlias, entityPersister, ( EntityType ) ( ( Queryable ) entityPersister ).getType(), null ); // Add to the query spaces. fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() ); return elem; }
/** * Returns the identifier select SQL fragment. * * @param size The total number of returned types. * @param k The sequence of the current returned type. * @return the identifier select SQL fragment. */ String renderIdentifierSelect(int size, int k) { checkInitialized(); // Render the identifier select fragment using the table alias. if ( fromElement.getFromClause().isSubQuery() ) { // TODO: Replace this with a more elegant solution. String[] idColumnNames = ( persister != null ) ? ( ( Queryable ) persister ).getIdentifierColumnNames() : new String[0]; StringBuffer buf = new StringBuffer(); for ( int i = 0; i < idColumnNames.length; i++ ) { buf.append( fromElement.getTableAlias() ).append( '.' ).append( idColumnNames[i] ); if ( i != idColumnNames.length - 1 ) buf.append( ", " ); } return buf.toString(); } else { if (persister==null) { throw new QueryException( "not an entity" ); } String fragment = ( ( Queryable ) persister ).identifierSelectFragment( getTableAlias(), getSuffix( size, k ) ); return trimLeadingCommaAndSpaces( fragment ); } }
public void processConstant(AST constant, boolean resolveIdent) throws SemanticException { // If the constant is an IDENT, figure out what it means... boolean isIdent = ( constant.getType() == IDENT || constant.getType() == WEIRD_IDENT ); if ( resolveIdent && isIdent && isAlias( constant.getText() ) ) { // IDENT is a class alias in the FROM. IdentNode ident = ( IdentNode ) constant; // Resolve to an identity column. ident.resolve(false, true); } else { // IDENT might be the name of a class. Queryable queryable = walker.getSessionFactoryHelper().findQueryableUsingImports( constant.getText() ); if ( isIdent && queryable != null ) { constant.setText( queryable.getDiscriminatorSQLValue() ); } // Otherwise, it's a literal. else { processLiteral( constant ); } } }
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 + "'" ); } else { setSQLValue( node, text, discrim ); //the class discriminator value } } else { Object value = ReflectHelper.getConstantValue( text ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } else { setConstantValue( node, text, value ); } } }
protected void postProcessDML(RestrictableStatement statement) throws SemanticException { statement.getFromClause().resolve(); FromElement fromElement = ( FromElement ) statement.getFromClause().getFromElements().get( 0 ); Queryable persister = fromElement.getQueryable(); // Make #@%$^#^&# sure no alias is applied to the table name fromElement.setText( persister.getTableName() ); // append any filter fragments; the EMPTY_MAP is used under the assumption that // currently enabled filters should not affect this process if ( persister.getDiscriminatorType() != null ) { new SyntheticAndFactory( getASTFactory() ).addDiscriminatorWhereFragment( statement, persister, java.util.Collections.EMPTY_MAP, fromElement.getTableAlias() ); } }
public BulkOperationCleanupAction(SessionImplementor session, Queryable[] affectedQueryables) { this.session = session; // TODO : probably better to calculate these and pass them in, as it'll be more performant ArrayList tmpSpaces = new ArrayList(); for ( int i = 0; i < affectedQueryables.length; i++ ) { if ( affectedQueryables[i].hasCache() ) { affectedEntityNames.add( affectedQueryables[i].getEntityName() ); } Set roles = session.getFactory().getCollectionRolesByEntityParticipant( affectedQueryables[i].getEntityName() ); if ( roles != null ) { affectedCollectionRoles.addAll( roles ); } for ( int y = 0; y < affectedQueryables[i].getQuerySpaces().length; y++ ) { tmpSpaces.add( affectedQueryables[i].getQuerySpaces()[y] ); } } this.spaces = new Serializable[ tmpSpaces.size() ]; for ( int i = 0; i < tmpSpaces.size(); i++ ) { this.spaces[i] = ( Serializable ) tmpSpaces.get( i ); } }
private void createCriteriaEntityNameMap() { // initialize the rootProvider first final CriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider( (Queryable) sessionFactory.getEntityPersister( rootEntityName ) ); criteriaInfoMap.put( rootCriteria, rootProvider); nameCriteriaInfoMap.put( rootProvider.getName(), rootProvider ); for ( final String key : associationPathCriteriaMap.keySet() ) { final Criteria value = associationPathCriteriaMap.get( key ); final CriteriaInfoProvider info = getPathInfo( key ); criteriaInfoMap.put( value, info ); nameCriteriaInfoMap.put( info.getName(), info ); } }
/** * Get the a typed value for the given property value. */ @Override public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value) throws HibernateException { // Detect discriminator values... if ( value instanceof Class ) { final Class entityClass = (Class) value; final Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() ); if ( q != null ) { final Type type = q.getDiscriminatorType(); String stringValue = q.getDiscriminatorSQLValue(); if ( stringValue != null && stringValue.length() > 2 && stringValue.startsWith( "'" ) && stringValue.endsWith( "'" ) ) { // remove the single quotes stringValue = stringValue.substring( 1, stringValue.length() - 1 ); } // Convert the string value into the proper type. if ( type instanceof StringRepresentableType ) { final StringRepresentableType nullableType = (StringRepresentableType) type; value = nullableType.fromStringValue( stringValue ); } else { throw new QueryException( "Unsupported discriminator type " + type ); } return new TypedValue( type, value ); } } // Otherwise, this is an ordinary value. return new TypedValue( getTypeUsingProjection( subcriteria, propertyName ), value ); }
protected void applyRootReturnFilterRestrictions(SelectStatementBuilder selectStatementBuilder) { final Queryable rootQueryable = (Queryable) getRootEntityReturn().getEntityPersister(); selectStatementBuilder.appendRestrictions( rootQueryable.filterFragment( entityReferenceAliases.getTableAlias(), Collections.emptyMap() ) ); }
/** * Returns a EntityLoadQueryDetails object from the given inputs. * * @param loadPlan The load plan * @param keyColumnNames The columns to load the entity by (the PK columns or some other unique set of columns) * @param buildingParameters And influencers that would affect the generated SQL (mostly we are concerned with those * that add additional joins here) * @param factory The SessionFactory * * @return The EntityLoadQueryDetails */ public static LoadQueryDetails makeEntityLoadQueryDetails( LoadPlan loadPlan, String[] keyColumnNames, QueryBuildingParameters buildingParameters, SessionFactoryImplementor factory) { // TODO: how should shouldUseOptionalEntityInformation be used? // final int batchSize = buildingParameters.getBatchSize(); // final boolean shouldUseOptionalEntityInformation = batchSize == 1; final EntityReturn rootReturn = RootHelper.INSTANCE.extractRootReturn( loadPlan, EntityReturn.class ); final String[] keyColumnNamesToUse = keyColumnNames != null ? keyColumnNames : ( (Queryable) rootReturn.getEntityPersister() ).getIdentifierColumnNames(); // Should be just one querySpace (of type EntityQuerySpace) in querySpaces. Should we validate that? // Should we make it a util method on Helper like we do for extractRootReturn ? final AliasResolutionContextImpl aliasResolutionContext = new AliasResolutionContextImpl( factory ); return new EntityLoadQueryDetails( loadPlan, keyColumnNamesToUse, aliasResolutionContext, rootReturn, buildingParameters, factory ); }
public ExpandingEntityQuerySpace makeEntityQuerySpace( ExpandingQuerySpace lhsQuerySpace, AssociationAttributeDefinition attribute, String querySpaceUid, FetchStrategy fetchStrategy) { final EntityType fetchedType = (EntityType) attribute.getType(); final EntityPersister fetchedPersister = attribute.toEntityDefinition().getEntityPersister(); if ( fetchedPersister == null ) { throw new WalkingException( String.format( "Unable to locate EntityPersister [%s] for fetch [%s]", fetchedType.getAssociatedEntityName(), attribute.getName() ) ); } // TODO: Queryable.isMultiTable() may be more broad than it needs to be... final boolean isMultiTable = Queryable.class.cast( fetchedPersister ).isMultiTable(); final boolean required = lhsQuerySpace.canJoinsBeRequired() && !isMultiTable && !attribute.isNullable(); return makeEntityQuerySpace( lhsQuerySpace, fetchedPersister, attribute.getName(), (EntityType) attribute.getType(), querySpaceUid, required, shouldIncludeJoin( fetchStrategy ) ); }
private String[] formulaTemplates(String reference, int expectedSize) { try { final int propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndex( reference ); return ( (Queryable) elementPersister ).getSubclassPropertyFormulaTemplateClosure()[propertyIndex]; } catch (Exception e) { return new String[expectedSize]; } }
protected String generateIdInsertSelect(Queryable persister, String tableAlias, ProcessedWhereClause whereClause) { Select select = new Select( sessionFactory.getDialect() ); SelectValues selectClause = new SelectValues( sessionFactory.getDialect() ) .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() ); addAnyExtraIdSelectValues( selectClause ); select.setSelectClause( selectClause.render() ); String rootTableName = persister.getTableName(); String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false ); String whereJoinFragment = persister.whereJoinFragment( tableAlias, true, false ); select.setFromClause( rootTableName + ' ' + tableAlias + fromJoinFragment ); if ( whereJoinFragment == null ) { whereJoinFragment = ""; } else { whereJoinFragment = whereJoinFragment.trim(); if ( whereJoinFragment.startsWith( "and" ) ) { whereJoinFragment = whereJoinFragment.substring( 4 ); } } if ( whereClause.getUserWhereClauseFragment().length() > 0 ) { if ( whereJoinFragment.length() > 0 ) { whereJoinFragment += " and "; } } select.setWhereClause( whereJoinFragment + whereClause.getUserWhereClauseFragment() ); InsertSelect insert = new InsertSelect( sessionFactory.getDialect() ); if ( sessionFactory.getSettings().isCommentsEnabled() ) { insert.setComment( "insert-select for " + persister.getEntityName() + " ids" ); } insert.setTableName( determineIdTableName( persister ) ); insert.setSelect( select ); return insert.toStatementString(); }
private FromElement createFromElementInSubselect( String path, String pathAlias, FromElement parentFromElement, String classAlias) throws SemanticException { LOG.debugf( "createFromElementInSubselect() : path = %s", path ); // Create an DotNode AST for the path and resolve it. FromElement fromElement = evaluateFromElementPath( path, classAlias ); EntityPersister entityPersister = fromElement.getEntityPersister(); // If the first identifier in the path refers to the class alias (not the class name), then this // is a correlated subselect. If it's a correlated sub-select, use the existing table alias. Otherwise // generate a new one. String tableAlias = null; boolean correlatedSubselect = pathAlias.equals( parentFromElement.getClassAlias() ); if ( correlatedSubselect ) { tableAlias = fromElement.getTableAlias(); } else { tableAlias = null; } // If the from element isn't in the same clause, create a new from element. if ( fromElement.getFromClause() != fromClause ) { LOG.debug( "createFromElementInSubselect() : creating a new FROM element..." ); fromElement = createFromElement( entityPersister ); initializeAndAddFromElement( fromElement, path, classAlias, entityPersister, (EntityType) ( (Queryable) entityPersister ).getType(), tableAlias ); } LOG.debugf( "createFromElementInSubselect() : %s -> %s", path, fromElement ); return fromElement; }
public void initialize(Queryable persister) { if ( persister.isAbstract() ) { throw new QueryException( "cannot insert into abstract class (no table)" ); } this.persister = persister; initializeColumns(); if ( getWalker().getSessionFactoryHelper().hasPhysicalDiscriminatorColumn( persister ) ) { discriminated = true; columnSpec += ", " + persister.getDiscriminatorColumnName(); } resetText(); }
public void handlePropertyBeingDereferenced(Type propertySource, String propertyName) { if ( getQueryableCollection() != null && CollectionProperties.isCollectionProperty( propertyName ) ) { // propertyName refers to something like collection.size... return; } if ( propertySource.isComponentType() ) { // property name is a sub-path of a component... return; } Queryable persister = getQueryable(); if ( persister != null ) { try { Queryable.Declarer propertyDeclarer = persister.getSubclassPropertyDeclarer( propertyName ); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Handling property dereference [{0} ({1}) -> {2} ({3})]", persister.getEntityName(), getClassAlias(), propertyName, propertyDeclarer ); } if ( propertyDeclarer == Queryable.Declarer.SUBCLASS ) { dereferencedBySubclassProperty = true; includeSubclasses = true; } else if ( propertyDeclarer == Queryable.Declarer.SUPERCLASS ) { dereferencedBySuperclassProperty = true; } } catch( QueryException ignore ) { // ignore it; the incoming property could not be found so we // cannot be sure what to do here. At the very least, the // safest is to simply not apply any dereference toggling... } } }
public FromElementType(FromElement fromElement, EntityPersister persister, EntityType entityType) { this.fromElement = fromElement; this.persister = persister; this.entityType = entityType; if ( persister != null ) { fromElement.setText( ( (Queryable) persister ).getTableName() + " " + getTableAlias() ); } }
/** * Returns the identifier select SQL fragment. * * @param size The total number of returned types. * @param k The sequence of the current returned type. * * @return the identifier select SQL fragment. */ String renderIdentifierSelect(int size, int k) { checkInitialized(); // Render the identifier select fragment using the table alias. if ( fromElement.getFromClause().isSubQuery() ) { // TODO: Replace this with a more elegant solution. String[] idColumnNames = ( persister != null ) ? ( (Queryable) persister ).getIdentifierColumnNames() : new String[0]; StringBuilder buf = new StringBuilder(); for ( int i = 0; i < idColumnNames.length; i++ ) { buf.append( fromElement.getTableAlias() ).append( '.' ).append( idColumnNames[i] ); if ( i != idColumnNames.length - 1 ) { buf.append( ", " ); } } return buf.toString(); } else { if ( persister == null ) { throw new QueryException( "not an entity" ); } String fragment = ( (Queryable) persister ).identifierSelectFragment( getTableAlias(), getSuffix( size, k ) ); return trimLeadingCommaAndSpaces( fragment ); } }
/** * Returns the property select SQL fragment. * * @param size The total number of returned types. * @param k The sequence of the current returned type. * * @return the property select SQL fragment. */ String renderPropertySelect(int size, int k, boolean allProperties) { checkInitialized(); if ( persister == null ) { return ""; } else { String fragment = ( (Queryable) persister ).propertySelectFragment( getTableAlias(), getSuffix( size, k ), allProperties ); return trimLeadingCommaAndSpaces( fragment ); } }
private DereferenceType resolveAsNakedPropertyRef() { FromElement fromElement = locateSingleFromElement(); if (fromElement == null) { return DereferenceType.UNKNOWN; } Queryable persister = fromElement.getQueryable(); if (persister == null) { return DereferenceType.UNKNOWN; } Type propertyType = getNakedPropertyType(fromElement); if (propertyType == null) { // assume this ident's text does *not* refer to a property on the given persister return DereferenceType.UNKNOWN; } if ((propertyType.isComponentType() || propertyType.isAssociationType() )) { return DereferenceType.COMPONENT_REF; } setFromElement(fromElement); String property = getText(); String[] columns = getWalker().isSelectStatement() ? persister.toColumns(fromElement.getTableAlias(), property) : persister.toColumns(property); String text = StringHelper.join(", ", columns); setText(columns.length == 1 ? text : "(" + text + ")"); setType(SqlTokenTypes.SQL_TOKEN); // these pieces are needed for usage in select clause super.setDataType(propertyType); nakedPropertyRef = true; return DereferenceType.PROPERTY_REF; }
public BasicExecutor(HqlSqlWalker walker, Queryable persister) { this.factory = walker.getSessionFactoryHelper().getFactory(); this.persister = persister; try { SqlGenerator gen = new SqlGenerator( factory ); gen.statement( walker.getAST() ); sql = gen.getSQL(); gen.getParseErrorHandler().throwQueryException(); parameterSpecifications = gen.getCollectedParameters(); } catch ( RecognitionException e ) { throw QuerySyntaxException.convert( e ); } }
/** * Does the given persister define a physical discriminator column * for the purpose of inheritance discrimination? * * @param persister The persister to be checked. * * @return True if the persister does define an actual discriminator column. */ 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; }
/** * Given a (potentially unqualified) class name, locate its persister. * * @param sfi The session factory implementor. * @param className The (potentially unqualified) class name. * * @return The defined persister for this class, or null if none found. */ 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; } }
protected void postProcessDML(RestrictableStatement statement) throws SemanticException { statement.getFromClause().resolve(); FromElement fromElement = (FromElement) statement.getFromClause().getFromElements().get( 0 ); Queryable persister = fromElement.getQueryable(); // Make #@%$^#^&# sure no alias is applied to the table name fromElement.setText( persister.getTableName() ); // // append any filter fragments; the EMPTY_MAP is used under the assumption that // // currently enabled filters should not affect this process // if ( persister.getDiscriminatorType() != null ) { // new SyntheticAndFactory( getASTFactory() ).addDiscriminatorWhereFragment( // statement, // persister, // java.util.Collections.EMPTY_MAP, // fromElement.getTableAlias() // ); // } if ( persister.getDiscriminatorType() != null || !queryTranslatorImpl.getEnabledFilters().isEmpty() ) { new SyntheticAndFactory( this ).addDiscriminatorWhereFragment( statement, persister, queryTranslatorImpl.getEnabledFilters(), fromElement.getTableAlias() ); } }
private void evaluateAssignment(AST eq, Queryable persister, int targetIndex) { if ( persister.isMultiTable() ) { // no need to even collect this information if the persister is considered multi-table AssignmentSpecification specification = new AssignmentSpecification( eq, persister ); if ( targetIndex >= 0 ) { assignmentSpecifications.add( targetIndex, specification ); } else { assignmentSpecifications.add( specification ); } numberOfParametersInSetClause += specification.getParameters().length; } }
@Override protected AST createIntoClause(String path, AST propertySpec) throws SemanticException { Queryable persister = (Queryable) getSessionFactoryHelper().requireClassPersister( path ); IntoClause intoClause = (IntoClause) getASTFactory().create( INTO, persister.getEntityName() ); intoClause.setFirstChild( propertySpec ); intoClause.initialize( persister ); addQuerySpaces( persister.getQuerySpaces() ); return intoClause; }
private AST generateVersionPropertyNode(Queryable persister) throws SemanticException { String versionPropertyName = persister.getPropertyNames()[persister.getVersionProperty()]; AST versionPropertyRef = getASTFactory().create( HqlSqlTokenTypes.IDENT, versionPropertyName ); AST versionPropertyNode = lookupNonQualifiedProperty( versionPropertyRef ); resolve( versionPropertyNode ); return versionPropertyNode; }
String continueFromManyToMany(String entityName, String[] joinColumns, QueryTranslatorImpl q) throws QueryException { start( q ); continuation = true; currentName = q.createNameFor( entityName ); q.addType( currentName, entityName ); Queryable classPersister = q.getEntityPersister( entityName ); //QueryJoinFragment join = q.createJoinFragment(useThetaStyleJoin); addJoin( currentName, q.getFactory().getTypeResolver().getTypeFactory().manyToOne( entityName ), joinColumns ); currentPropertyMapping = classPersister; return currentName; }
public String addFromCollection(QueryTranslatorImpl q) throws QueryException { Type collectionElementType = getPropertyType(); if ( collectionElementType == null ) { throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path ); } if ( collectionElementType.isEntityType() ) { // an association QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole ); Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister(); String clazz = entityPersister.getEntityName(); final String elementName; if ( collectionPersister.isOneToMany() ) { elementName = collectionName; //allow index() function: q.decoratePropertyMapping( elementName, collectionPersister ); } else { //many-to-many q.addCollection( collectionName, collectionRole ); elementName = q.createNameFor( clazz ); addJoin( elementName, ( AssociationType ) collectionElementType ); } q.addFrom( elementName, clazz, joinSequence ); currentPropertyMapping = new CollectionPropertyMapping( collectionPersister ); return elementName; } else { // collections of values q.addFromCollection( collectionName, collectionRole, joinSequence ); return collectionName; } }
Queryable getEntityPersisterUsingImports(String className) { final String importedClassName = getFactory().getImportedClassName( className ); if ( importedClassName == null ) { return null; } try { return ( Queryable ) getFactory().getEntityPersister( importedClassName ); } catch ( MappingException me ) { return null; } }