/** * Returns a CacheableResultTransformer that is used to transform * tuples to a value(s) that can be cached. * * @param transformer - a tuple subset result transformer; * must be non-null; * @param aliases - the aliases that correspond to the tuple; * if it is non-null, its length must equal the number * of true elements in includeInTuple[] * @param includeInTuple - array with the i-th element indicating * whether the i-th expression returned by a query is * included in the tuple; the number of true values equals * the length of the tuple that will be transformed; * must be non-null * * @return a CacheableResultTransformer that is used to transform * tuples to a value(s) that can be cached. */ private static CacheableResultTransformer create( TupleSubsetResultTransformer transformer, String[] aliases, boolean[] includeInTuple) { if ( transformer == null ) { throw new IllegalArgumentException( "transformer cannot be null" ); } int tupleLength = ArrayHelper.countTrue( includeInTuple ); if ( aliases != null && aliases.length != tupleLength ) { throw new IllegalArgumentException( "if aliases is not null, then the length of aliases[] must equal the number of true elements in includeInTuple; " + "aliases.length=" + aliases.length + "tupleLength=" + tupleLength ); } return new CacheableResultTransformer( includeInTuple, transformer.includeInTransform( aliases, tupleLength ) ); }
private CacheableResultTransformer(boolean[] includeInTuple, boolean[] includeInTransform) { if ( includeInTuple == null ) { throw new IllegalArgumentException( "includeInTuple cannot be null" ); } this.includeInTuple = includeInTuple; tupleLength = ArrayHelper.countTrue( includeInTuple ); tupleSubsetLength = ( includeInTransform == null ? tupleLength : ArrayHelper.countTrue( includeInTransform ) ); if ( tupleSubsetLength == tupleLength ) { includeInTransformIndex = null; } else { includeInTransformIndex = new int[tupleSubsetLength]; for ( int i = 0, j = 0 ; i < includeInTransform.length ; i++ ) { if ( includeInTransform[ i ] ) { includeInTransformIndex[ j ] = i; j++; } } } }
@Override public Object load( Serializable id, Object optionalObject, SessionImplementor session, LockOptions lockOptions) { final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getEntityBatch( persister(), id, maxBatchSize, persister().getEntityMode() ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { return singleKeyLoader.load( id, optionalObject, session ); } final Serializable[] idsToLoad = new Serializable[numberOfIds]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); if ( log.isDebugEnabled() ) { log.debugf( "Batch loading entity: %s", MessageHelper.infoString( persister(), idsToLoad, session.getFactory() ) ); } QueryParameters qp = buildQueryParameters( id, idsToLoad, optionalObject, lockOptions ); List results = dynamicLoader.doEntityBatchFetch( session, qp, idsToLoad ); return getObjectFromList( results, id, session ); }
public LegacyBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockMode lockMode, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new EntityLoader[ batchSizes.length ]; final EntityLoader.Builder entityLoaderBuilder = EntityLoader.forEntity( persister ) .withInfluencers( loadQueryInfluencers ) .withLockMode( lockMode ); for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = entityLoaderBuilder.withBatchSize( batchSizes[i] ).byPrimaryKey(); } }
public LegacyBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockOptions lockOptions, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new EntityLoader[ batchSizes.length ]; final EntityLoader.Builder entityLoaderBuilder = EntityLoader.forEntity( persister ) .withInfluencers( loadQueryInfluencers ) .withLockOptions( lockOptions ); for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = entityLoaderBuilder.withBatchSize( batchSizes[i] ).byPrimaryKey(); } }
@Override protected Object[] getResultRow(Object[] row, ResultSet rs, SessionImplementor session) throws SQLException, HibernateException { final Object[] result; if ( translator.hasProjection() ) { Type[] types = translator.getProjectedTypes(); result = new Object[types.length]; String[] columnAliases = translator.getProjectedColumnAliases(); for ( int i=0, pos=0; i<result.length; i++ ) { int numColumns = types[i].getColumnSpan( session.getFactory() ); if ( numColumns > 1 ) { String[] typeColumnAliases = ArrayHelper.slice( columnAliases, pos, numColumns ); result[i] = types[i].nullSafeGet(rs, typeColumnAliases, session, null); } else { result[i] = types[i].nullSafeGet(rs, columnAliases[pos], session, null); } pos += numColumns; } } else { result = toResultRow( row ); } return result; }
@Override public int[] getNamedParameterLocs(String name) throws QueryException { Object loc = namedParameterBindPoints.get( name ); if ( loc == null ) { throw new QueryException( "Named parameter does not appear in Query: " + name, sql ); } if ( loc instanceof Integer ) { return new int[] { (Integer) loc }; } else { return ArrayHelper.toIntArray( ( List ) loc ); } }
@Override protected void autoDiscoverTypes(ResultSet rs) { try { JdbcResultMetadata metadata = new JdbcResultMetadata( getFactory(), rs ); rowProcessor.prepareForAutoDiscovery( metadata ); List<String> aliases = new ArrayList<String>(); List<Type> types = new ArrayList<Type>(); for ( ResultColumnProcessor resultProcessor : rowProcessor.getColumnProcessors() ) { resultProcessor.performDiscovery( metadata, types, aliases ); } validateAliases( aliases ); resultTypes = ArrayHelper.toTypeArray( types ); transformerAliases = ArrayHelper.toStringArray( aliases ); } catch ( SQLException e ) { throw new HibernateException( "Exception while trying to autodiscover types.", e ); } }
@Override public void initialize(Serializable id, SessionImplementor session) throws HibernateException { // first, figure out how many batchable ids we have... final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, maxBatchSize ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { singleKeyLoader.loadCollection( session, id, collectionPersister().getKeyType() ); return; } final Serializable[] idsToLoad = new Serializable[numberOfIds]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); batchLoader.doBatchedCollectionLoad( session, idsToLoad, collectionPersister().getKeyType() ); }
/** * Warning: * When there are duplicated property names in the subclasses * of the class, this method may return the wrong table * number for the duplicated subclass property (note that * SingleTableEntityPersister defines an overloaded form * which takes the entity name. */ public int getSubclassPropertyTableNumber(String propertyPath) { String rootPropertyName = StringHelper.root(propertyPath); Type type = propertyMapping.toType(rootPropertyName); if ( type.isAssociationType() ) { AssociationType assocType = ( AssociationType ) type; if ( assocType.useLHSPrimaryKey() ) { // performance op to avoid the array search return 0; } else if ( type.isCollectionType() ) { // properly handle property-ref-based associations rootPropertyName = assocType.getLHSPropertyName(); } } //Enable for HHH-440, which we don't like: /*if ( type.isComponentType() && !propertyName.equals(rootPropertyName) ) { String unrooted = StringHelper.unroot(propertyName); int idx = ArrayHelper.indexOf( getSubclassColumnClosure(), unrooted ); if ( idx != -1 ) { return getSubclassColumnTableNumberClosure()[idx]; } }*/ int index = ArrayHelper.indexOf( getSubclassPropertyNameClosure(), rootPropertyName); //TODO: optimize this better! return index==-1 ? 0 : getSubclassPropertyTableNumber(index); }
private String determinePkByNaturalIdQuery(boolean[] valueNullness) { if ( ! hasNaturalIdentifier() ) { throw new HibernateException( "Attempt to build natural-id -> PK resolution query for entity that does not define natural id" ); } // performance shortcut for cases where the natural-id is defined as completely non-nullable if ( isNaturalIdNonNullable() ) { if ( valueNullness != null && ! ArrayHelper.isAllFalse( valueNullness ) ) { throw new HibernateException( "Null value(s) passed to lookup by non-nullable natural-id" ); } if ( cachedPkByNonNullableNaturalIdQuery == null ) { cachedPkByNonNullableNaturalIdQuery = generateEntityIdByNaturalIdSql( null ); } return cachedPkByNonNullableNaturalIdQuery; } // Otherwise, regenerate it each time return generateEntityIdByNaturalIdSql( valueNullness ); }
/** * Generate the SQL DELETE that deletes a particular row */ @Override protected String generateDeleteRowString() { Delete delete = new Delete() .setTableName( qualifiedTableName ); if ( hasIdentifier ) { delete.addPrimaryKeyColumns( new String[]{ identifierColumnName } ); } else if ( hasIndex && !indexContainsFormula ) { delete.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { delete.addPrimaryKeyColumns( keyColumnNames ); delete.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); } if ( getFactory().getSettings().isCommentsEnabled() ) { delete.setComment( "delete collection row " + getRole() ); } return delete.toStatementString(); }
/** * Generate the SQL UPDATE that updates a particular row's foreign * key to null */ @Override protected String generateDeleteRowString() { Update update = new Update( getDialect() ) .setTableName( qualifiedTableName ) .addColumns( keyColumnNames, "null" ); if ( hasIndex && !indexContainsFormula ) update.addColumns( indexColumnNames, "null" ); if ( getFactory().getSettings().isCommentsEnabled() ) { update.setComment( "delete one-to-many row " + getRole() ); } //use a combination of foreign key columns and pk columns, since //the ordering of removal and addition is not guaranteed when //a child moves from one parent to another String[] rowSelectColumnNames = ArrayHelper.join( keyColumnNames, elementColumnNames ); return update.addPrimaryKeyColumns( rowSelectColumnNames ) .toStatementString(); }
public NativeSQLQuerySpecification( String queryString, NativeSQLQueryReturn[] queryReturns, Collection querySpaces) { this.queryString = queryString; this.queryReturns = queryReturns; if ( querySpaces == null ) { this.querySpaces = Collections.EMPTY_SET; } else { Set tmp = new HashSet(); tmp.addAll( querySpaces ); this.querySpaces = Collections.unmodifiableSet( tmp ); } // pre-determine and cache the hashcode int hashCode = queryString.hashCode(); hashCode = 29 * hashCode + this.querySpaces.hashCode(); if ( this.queryReturns != null ) { hashCode = 29 * hashCode + ArrayHelper.toList( this.queryReturns ).hashCode(); } this.hashCode = hashCode; }
/** * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join * * @param associationType The association type for the association that represents the join * @param columnQualifier The left-hand side table alias * @param propertyIndex The index of the property that represents the association/join * @param begin The index for any nested (composites) attributes * @param lhsPersister The persister for the left-hand side of the association/join * @param mapping The mapping (typically the SessionFactory). * * @return The qualified column names. */ public static String[] getAliasedLHSColumnNames( AssociationType associationType, String columnQualifier, int propertyIndex, int begin, OuterJoinLoadable lhsPersister, Mapping mapping) { if ( associationType.useLHSPrimaryKey() ) { return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() ); } else { final String propertyName = associationType.getLHSPropertyName(); if ( propertyName == null ) { return ArrayHelper.slice( toColumns( lhsPersister, columnQualifier, propertyIndex ), begin, associationType.getColumnSpan( mapping ) ); } else { //bad cast return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName ); } } }
/** * Returns the locations of all occurrences of the named parameter. */ public int[] getNamedParameterLocations(String name) throws QueryException { Object o = namedParameters.get( name ); if ( o == null ) { throw new QueryException( QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name, queryTranslatorImpl.getQueryString() ); } if ( o instanceof Integer ) { return new int[] {(Integer) o}; } else { return ArrayHelper.toIntArray( (ArrayList) o ); } }
public boolean isInsertable() { // if the property mapping consists of all formulas, // make it non-insertable final boolean[] columnInsertability = value.getColumnInsertability(); return insertable && ( columnInsertability.length==0 || !ArrayHelper.isAllFalse( columnInsertability ) ); }
public LegacyBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockMode lockMode, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockMode, factory, loadQueryInfluencers); } }
public LegacyBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockOptions lockOptions, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockOptions, factory, loadQueryInfluencers); } }
public PaddedBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockMode lockMode, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockMode, factory, loadQueryInfluencers); } validate( maxBatchSize ); }
public PaddedBatchingEntityLoader( OuterJoinLoadable persister, int maxBatchSize, LockOptions lockOptions, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) { super( persister ); this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); this.loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockOptions, factory, loadQueryInfluencers); } validate( maxBatchSize ); }
@Override public Object load(Serializable id, Object optionalObject, SessionImplementor session, LockOptions lockOptions) { final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { return ( (UniqueEntityLoader) loaders[batchSizes.length-1] ).load( id, optionalObject, session ); } // Uses the first batch-size bigger than the number of actual ids in the batch int indexToUse = batchSizes.length-1; for ( int i = 0; i < batchSizes.length-1; i++ ) { if ( batchSizes[i] >= numberOfIds ) { indexToUse = i; } else { break; } } final Serializable[] idsToLoad = new Serializable[ batchSizes[indexToUse] ]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); for ( int i = numberOfIds; i < batchSizes[indexToUse]; i++ ) { idsToLoad[i] = id; } return doBatchLoad( id, loaders[indexToUse], session, idsToLoad, optionalObject, lockOptions ); }
public CollectionElementLoader( QueryableCollection collectionPersister, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { super( factory, loadQueryInfluencers ); this.keyType = collectionPersister.getKeyType(); this.indexType = collectionPersister.getIndexType(); this.persister = (OuterJoinLoadable) collectionPersister.getElementPersister(); this.entityName = persister.getEntityName(); JoinWalker walker = new EntityJoinWalker( persister, ArrayHelper.join( collectionPersister.getKeyColumnNames(), collectionPersister.toColumns("index") ), 1, LockMode.NONE, factory, loadQueryInfluencers ); initFromWalker( walker ); postInstantiate(); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Static select for entity %s: %s", entityName, getSQLString() ); } }
public CriteriaJoinWalker( final OuterJoinLoadable persister, final CriteriaQueryTranslator translator, final SessionFactoryImplementor factory, final CriteriaImpl criteria, final String rootEntityName, final LoadQueryInfluencers loadQueryInfluencers, final String alias) { super( persister, factory, loadQueryInfluencers, alias ); this.translator = translator; querySpaces = translator.getQuerySpaces(); if ( translator.hasProjection() ) { initProjection( translator.getSelect(), translator.getWhereCondition(), translator.getOrderBy(), translator.getGroupBy(), LockOptions.NONE ); resultTypes = translator.getProjectedTypes(); userAliases = translator.getProjectedAliases(); includeInResultRow = new boolean[ resultTypes.length ]; Arrays.fill( includeInResultRow, true ); } else { initAll( translator.getWhereCondition(), translator.getOrderBy(), LockOptions.NONE ); // root entity comes last userAliasList.add( criteria.getAlias() ); //root entity comes *last* resultTypeList.add( translator.getResultType( criteria ) ); includeInResultRowList.add( true ); userAliases = ArrayHelper.toStringArray( userAliasList ); resultTypes = ArrayHelper.toTypeArray( resultTypeList ); includeInResultRow = ArrayHelper.toBooleanArray( includeInResultRowList ); } }
public CriteriaLoader( final OuterJoinLoadable persister, final SessionFactoryImplementor factory, final CriteriaImpl criteria, final String rootEntityName, final LoadQueryInfluencers loadQueryInfluencers) throws HibernateException { super( factory, loadQueryInfluencers ); translator = new CriteriaQueryTranslator( factory, criteria, rootEntityName, CriteriaQueryTranslator.ROOT_SQL_ALIAS ); querySpaces = translator.getQuerySpaces(); CriteriaJoinWalker walker = new CriteriaJoinWalker( persister, translator, factory, criteria, rootEntityName, loadQueryInfluencers ); initFromWalker(walker); userAliases = walker.getUserAliases(); resultTypes = walker.getResultTypes(); includeInResultRow = walker.includeInResultRow(); resultRowLength = ArrayHelper.countTrue( includeInResultRow ); postInstantiate(); }
@Override protected CollectionInitializer createRealBatchingCollectionInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override protected CollectionInitializer createRealBatchingOneToManyInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); final Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override public CollectionInitializer createRealBatchingCollectionInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new PaddedBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override public CollectionInitializer createRealBatchingOneToManyInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); final Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new PaddedBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override public void initialize(Serializable id, SessionImplementor session) throws HibernateException { final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, batchSizes[0] ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { loaders[batchSizes.length-1].loadCollection( session, id, collectionPersister().getKeyType() ); return; } // Uses the first batch-size bigger than the number of actual ids in the batch int indexToUse = batchSizes.length-1; for ( int i = 0; i < batchSizes.length-1; i++ ) { if ( batchSizes[i] >= numberOfIds ) { indexToUse = i; } else { break; } } final Serializable[] idsToLoad = new Serializable[ batchSizes[indexToUse] ]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); for ( int i = numberOfIds; i < batchSizes[indexToUse]; i++ ) { idsToLoad[i] = id; } loaders[indexToUse].loadCollectionBatch( session, idsToLoad, collectionPersister().getKeyType() ); }
@Override public CollectionInitializer createRealBatchingCollectionInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override public CollectionInitializer createRealBatchingOneToManyInitializer( QueryableCollection persister, int maxBatchSize, SessionFactoryImplementor factory, LoadQueryInfluencers loadQueryInfluencers) throws MappingException { final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize ); final Loader[] loaders = new Loader[ batchSizes.length ]; for ( int i = 0; i < batchSizes.length; i++ ) { loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers ); } return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders ); }
@Override public int determineTableNumberForColumn(String columnName) { // HHH-7630: In case the naturalOrder/identifier column is explicitly given in the ordering, check here. for ( int i = 0, max = naturalOrderTableKeyColumns.length; i < max; i++ ) { final String[] keyColumns = naturalOrderTableKeyColumns[i]; if ( ArrayHelper.contains( keyColumns, columnName ) ) { return naturalOrderPropertyTableNumbers[i]; } } final String[] subclassColumnNameClosure = getSubclassColumnClosure(); for ( int i = 0, max = subclassColumnNameClosure.length; i < max; i++ ) { final boolean quoted = subclassColumnNameClosure[i].startsWith( "\"" ) && subclassColumnNameClosure[i].endsWith( "\"" ); if ( quoted ) { if ( subclassColumnNameClosure[i].equals( columnName ) ) { return getSubclassColumnTableNumberClosure()[i]; } } else { if ( subclassColumnNameClosure[i].equalsIgnoreCase( columnName ) ) { return getSubclassColumnTableNumberClosure()[i]; } } } throw new HibernateException( "Could not locate table which owns column [" + columnName + "] referenced in order-by mapping" ); }
/** * Generate the SQL UPDATE that updates a row */ @Override protected String generateUpdateRowString() { Update update = new Update( getDialect() ) .setTableName( qualifiedTableName ); //if ( !elementIsFormula ) { update.addColumns( elementColumnNames, elementColumnIsSettable, elementColumnWriters ); //} if ( hasIdentifier ) { update.addPrimaryKeyColumns( new String[]{ identifierColumnName } ); } else if ( hasIndex && !indexContainsFormula ) { update.addPrimaryKeyColumns( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { update.addPrimaryKeyColumns( keyColumnNames ); update.addPrimaryKeyColumns( elementColumnNames, elementColumnIsInPrimaryKey, elementColumnWriters ); } if ( getFactory().getSettings().isCommentsEnabled() ) { update.setComment( "update collection row " + getRole() ); } return update.toStatementString(); }
/** * Write the element to a JDBC <tt>PreparedStatement</tt> */ protected int writeElement(PreparedStatement st, Object elt, int i, SessionImplementor session) throws HibernateException, SQLException { getElementType().nullSafeSet( st, elt, i, elementColumnIsSettable, session ); return i + ArrayHelper.countTrue( elementColumnIsSettable ); }
private int[] getNamedParameterLocs(String name) throws QueryException { final Object loc = customQuery.getNamedParameterBindPoints().get( name ); if ( loc == null ) { throw new QueryException( "Named parameter does not appear in Query: " + name, customQuery.getSQL() ); } if ( loc instanceof Integer ) { return new int[] { (Integer) loc }; } else { return ArrayHelper.toIntArray( (List) loc ); } }
/** * Get the columns of the owning entity which are to be used in the join * * @param type The type representing the join * @param property The property index for the association type * @param begin ? * @param lhsPersister The persister for the left-hand-side of the join * @param mapping The mapping object (typically the SessionFactory) * * @return The columns for the left-hand-side of the join */ public static String[] getLHSColumnNames( AssociationType type, int property, int begin, OuterJoinLoadable lhsPersister, Mapping mapping) { if ( type.useLHSPrimaryKey() ) { //return lhsPersister.getSubclassPropertyColumnNames(property); return lhsPersister.getIdentifierColumnNames(); } else { final String propertyName = type.getLHSPropertyName(); if ( propertyName == null ) { //slice, to get the columns for this component //property return ArrayHelper.slice( property < 0 ? lhsPersister.getIdentifierColumnNames() : lhsPersister.getSubclassPropertyColumnNames( property ), begin, type.getColumnSpan( mapping ) ); } else { //property-refs for associations defined on a //component are not supported, so no need to slice return lhsPersister.getPropertyColumnNames( propertyName ); } } }
/** * Get the names of all entities */ @Override public String[] getEntityNames() { if ( sessionFactory == null ) { return ArrayHelper.toStringArray( entityStatistics.keySet() ); } else { return ArrayHelper.toStringArray( sessionFactory.getAllClassMetadata().keySet() ); } }
/** * Get the names of all collection roles */ @Override public String[] getCollectionRoleNames() { if ( sessionFactory == null ) { return ArrayHelper.toStringArray( collectionStatistics.keySet() ); } else { return ArrayHelper.toStringArray( sessionFactory.getAllCollectionMetadata().keySet() ); } }
/** * Get all second-level cache region names */ @Override public String[] getSecondLevelCacheRegionNames() { if ( sessionFactory == null ) { return ArrayHelper.toStringArray( secondLevelCacheStatistics.keySet() ); } else { return ArrayHelper.toStringArray( sessionFactory.getAllSecondLevelCacheRegions().keySet() ); } }