public static UniqueEntityLoader createBatchingEntityLoader( final OuterJoinLoadable persister, final int maxBatchSize, final LockMode lockMode, final SessionFactoryImplementor factory, final Map enabledFilters) throws MappingException { if ( maxBatchSize>1 ) { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], lockMode, factory, enabledFilters); } return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate); } else { return new EntityLoader(persister, lockMode, factory, enabledFilters); } }
protected void autoDiscoverTypes(ResultSet rs) { try { Metadata metadata = new Metadata( getFactory(), rs ); List aliases = new ArrayList(); List types = new ArrayList(); rowProcessor.prepareForAutoDiscovery( metadata ); for ( int i = 0; i < rowProcessor.columnProcessors.length; i++ ) { rowProcessor.columnProcessors[i].performDiscovery( metadata, types, aliases ); } resultTypes = ArrayHelper.toTypeArray( types ); transformerAliases = ArrayHelper.toStringArray( aliases ); } catch ( SQLException e ) { throw new HibernateException( "Exception while trying to autodiscover types.", e ); } }
public static CollectionInitializer createBatchingOneToManyInitializer( final QueryableCollection persister, final int maxBatchSize, final SessionFactoryImplementor factory, final Map enabledFilters) throws MappingException { if ( maxBatchSize>1 ) { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new OneToManyLoader(persister, batchSizesToCreate[i], factory, enabledFilters); } return new BatchingCollectionInitializer(persister, batchSizesToCreate, loadersToCreate); } else { return new OneToManyLoader(persister, factory, enabledFilters); } }
public static CollectionInitializer createBatchingCollectionInitializer( final QueryableCollection persister, final int maxBatchSize, final SessionFactoryImplementor factory, final Map enabledFilters) throws MappingException { if ( maxBatchSize>1 ) { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new BasicCollectionLoader(persister, batchSizesToCreate[i], factory, enabledFilters); } return new BatchingCollectionInitializer(persister, batchSizesToCreate, loadersToCreate); } else { return new BasicCollectionLoader(persister, factory, enabledFilters); } }
/** * 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); }
/** * Generate the SQL UPDATE that updates a row */ protected String generateUpdateRowString() { Update update = new Update( getDialect() ) .setTableName( qualifiedTableName ); //if ( !elementIsFormula ) { update.addColumns( elementColumnNames, elementColumnIsSettable ); //} if ( hasIdentifier ) { update.setPrimaryKeyColumnNames( new String[]{ identifierColumnName } ); } else if ( hasIndex && !indexContainsFormula ) { update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { update.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, elementColumnNames, elementColumnIsInPrimaryKey ) ); } if ( getFactory().getSettings().isCommentsEnabled() ) { update.setComment( "update collection row " + getRole() ); } return update.toStatementString(); }
/** * Generate the SQL DELETE that deletes a particular row */ protected String generateDeleteRowString() { Delete delete = new Delete() .setTableName( qualifiedTableName ); if ( hasIdentifier ) { delete.setPrimaryKeyColumnNames( new String[]{ identifierColumnName } ); } else if ( hasIndex && !indexContainsFormula ) { delete.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, indexColumnNames ) ); } else { delete.setPrimaryKeyColumnNames( ArrayHelper.join( keyColumnNames, elementColumnNames, elementColumnIsInPrimaryKey ) ); } 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 */ 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.setPrimaryKeyColumnNames( rowSelectColumnNames ) .toStatementString(); }
private String[] getFiles() { List files = new LinkedList(); for ( Iterator i = fileSets.iterator(); i.hasNext(); ) { FileSet fs = (FileSet) i.next(); DirectoryScanner ds = fs.getDirectoryScanner( getProject() ); String[] dsFiles = ds.getIncludedFiles(); for (int j = 0; j < dsFiles.length; j++) { File f = new File(dsFiles[j]); if ( !f.isFile() ) { f = new File( ds.getBasedir(), dsFiles[j] ); } files.add( f.getAbsolutePath() ); } } return ArrayHelper.toStringArray(files); }
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 aliased columns of the owning entity which are to * be used in the join */ public static String[] getAliasedLHSColumnNames( AssociationType type, String alias, int property, int begin, OuterJoinLoadable lhsPersister, Mapping mapping ) { if ( type.useLHSPrimaryKey() ) { return StringHelper.qualify( alias, lhsPersister.getIdentifierColumnNames() ); } else { String propertyName = type.getLHSPropertyName(); if (propertyName==null) { return ArrayHelper.slice( lhsPersister.toColumns(alias, property), begin, type.getColumnSpan(mapping) ); } else { return ( (PropertyMapping) lhsPersister ).toColumns(alias, propertyName); //bad cast } } }
public boolean isUpdateable() { // if the property mapping consists of all formulas, // make it non-updateable final boolean[] columnUpdateability = value.getColumnUpdateability(); return updateable && ( //columnUpdateability.length==0 || !ArrayHelper.isAllFalse(columnUpdateability) ); }
public boolean isInsertable() { // if the property mapping consists of all formulas, // make it insertable final boolean[] columnInsertability = value.getColumnInsertability(); return insertable && ( columnInsertability.length==0 || !ArrayHelper.isAllFalse(columnInsertability) ); }
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { List types = new ArrayList( getLength() ); for ( int i=0; i<getLength(); i++ ) { Type[] elemTypes = getProjection(i).getTypes(criteria, criteriaQuery); ArrayHelper.addAll(types, elemTypes); } return ArrayHelper.toTypeArray(types); }
public String[] getColumnAliases(int loc) { List result = new ArrayList( getLength() ); for ( int i=0; i<getLength(); i++ ) { String[] colAliases = getProjection(i).getColumnAliases(loc); ArrayHelper.addAll(result, colAliases); loc+=colAliases.length; } return ArrayHelper.toStringArray(result); }
public String[] getAliases() { List result = new ArrayList( getLength() ); for ( int i=0; i<getLength(); i++ ) { String[] aliases = getProjection(i).getAliases(); ArrayHelper.addAll(result, aliases); } return ArrayHelper.toStringArray(result); }
public CollectionElementLoader( QueryableCollection collectionPersister, SessionFactoryImplementor factory, Map enabledFilters) throws MappingException { super(factory, enabledFilters); 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.getIndexColumnNames() ), 1, LockMode.NONE, factory, enabledFilters ); initFromWalker( walker ); postInstantiate(); log.debug( "Static select for entity " + entityName + ": " + getSQLString() ); }
public CriteriaJoinWalker( final OuterJoinLoadable persister, final CriteriaQueryTranslator translator, final SessionFactoryImplementor factory, final CriteriaImpl criteria, final String rootEntityName, final Map enabledFilters) throws HibernateException { super(persister, factory, enabledFilters); this.translator = translator; querySpaces = translator.getQuerySpaces(); if ( translator.hasProjection() ) { resultTypes = translator.getProjectedTypes(); initProjection( translator.getSelect(), translator.getWhereCondition(), translator.getOrderBy(), translator.getGroupBy(), LockMode.NONE ); } else { resultTypes = new Type[] { TypeFactory.manyToOne( persister.getEntityName() ) }; initAll( translator.getWhereCondition(), translator.getOrderBy(), LockMode.NONE ); } userAliasList.add( criteria.getAlias() ); //root entity comes *last* userAliases = ArrayHelper.toStringArray(userAliasList); }
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 ).intValue() }; } else { return ArrayHelper.toIntArray( ( List ) loc ); } }
/** * Marshall the fields of a persistent instance to a prepared statement */ protected int dehydrate( final Serializable id, final Object[] fields, final Object rowId, final boolean[] includeProperty, final boolean[][] includeColumns, final int j, final PreparedStatement ps, final SessionImplementor session, int index) throws SQLException, HibernateException { if ( log.isTraceEnabled() ) { log.trace( "Dehydrating entity: " + MessageHelper.infoString( this, id, getFactory() ) ); } for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { if ( includeProperty[i] && isPropertyOfTable( i, j ) ) { getPropertyTypes()[i].nullSafeSet( ps, fields[i], index, includeColumns[i], session ); //index += getPropertyColumnSpan( i ); index += ArrayHelper.countTrue( includeColumns[i] ); //TODO: this is kinda slow... } } if ( rowId != null ) { ps.setObject( index, rowId ); index += 1; } else if ( id != null ) { getIdentifierType().nullSafeSet( ps, id, index, session ); index += getIdentifierColumnSpan(); } return index; }
/** * 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 { 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 ).intValue() }; } else { return ArrayHelper.toIntArray( (List) loc ); } }
/** * Get the columns of the owning entity which are to * be used in 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 { String propertyName = type.getLHSPropertyName(); if (propertyName==null) { //slice, to get the columns for this component //property return ArrayHelper.slice( 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); } } }
/** * <p>Creates a compact stack trace for the root cause of the supplied * <code>Throwable</code>.</p> * * @param throwable the throwable to examine, may be null * @return an array of stack trace frames, never null * @since 2.0 */ public static String[] getRootCauseStackTrace(Throwable throwable) { if ( throwable == null ) { return ArrayHelper.EMPTY_STRING_ARRAY; } Throwable throwables[] = getThrowables( throwable ); int count = throwables.length; ArrayList frames = new ArrayList(); List nextTrace = getStackFrameList( throwables[count - 1] ); for ( int i = count; --i >= 0; ) { List trace = nextTrace; if ( i != 0 ) { nextTrace = getStackFrameList( throwables[i - 1] ); removeCommonFrames( trace, nextTrace ); } if ( i == count - 1 ) { frames.add( throwables[i].toString() ); } else { frames.add( WRAPPED_MARKER + throwables[i].toString() ); } for ( int j = 0; j < trace.size(); j++ ) { frames.add( trace.get( j ) ); } } return ( String[] ) frames.toArray( new String[0] ); }
/** * Get the names of all entities */ 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 */ 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 */ public String[] getSecondLevelCacheRegionNames() { if (sessionFactory==null) { return ArrayHelper.toStringArray( secondLevelCacheStatistics.keySet() ); } else { return ArrayHelper.toStringArray( sessionFactory.getAllSecondLevelCacheRegions().keySet() ); } }
private void initializeColumns() { AST propertySpec = getFirstChild(); List types = new ArrayList(); visitPropertySpecNodes( propertySpec.getFirstChild(), types ); this.types = ArrayHelper.toTypeArray( types ); columnSpec = columnSpec.substring( 0, columnSpec.length() - 2 ); }
/** * 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 ) { QueryException qe = new QueryException( QueryTranslator.ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name ); qe.setQueryString( queryTranslatorImpl.getQueryString() ); throw qe; } if ( o instanceof Integer ) { return new int[]{( ( Integer ) o ).intValue()}; } else { return ArrayHelper.toIntArray( ( ArrayList ) o ); } }
public int[] getNamedParameterLocs(String name) throws QueryException { Object o = namedParameters.get( name ); if ( o == null ) { QueryException qe = new QueryException( ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR + name ); qe.setQueryString( queryString ); throw qe; } if ( o instanceof Integer ) { return new int[]{ ( ( Integer ) o ).intValue() }; } else { return ArrayHelper.toIntArray( ( ArrayList ) o ); } }
public void nullSafeSet( PreparedStatement st, Object value, int begin, boolean[] settable, SessionImplementor session) throws HibernateException, SQLException { Object[] subvalues = nullSafeGetValues( value, session.getEntityMode() ); int loc = 0; for ( int i = 0; i < propertySpan; i++ ) { int len = propertyTypes[i].getColumnSpan( session.getFactory() ); if ( len == 0 ) { //noop } else if ( len == 1 ) { if ( settable[loc] ) { propertyTypes[i].nullSafeSet( st, subvalues[i], begin, session ); begin++; } } else { boolean[] subsettable = new boolean[len]; System.arraycopy( settable, loc, subsettable, 0, len ); propertyTypes[i].nullSafeSet( st, subvalues[i], begin, subsettable, session ); begin += ArrayHelper.countTrue( subsettable ); } loc += len; } }
public Object hydrate( final ResultSet rs, final String[] names, final SessionImplementor session, final Object owner) throws HibernateException, SQLException { int begin = 0; boolean notNull = false; Object[] values = new Object[propertySpan]; for ( int i = 0; i < propertySpan; i++ ) { int length = propertyTypes[i].getColumnSpan( session.getFactory() ); String[] range = ArrayHelper.slice( names, begin, length ); //cache this Object val = propertyTypes[i].hydrate( rs, range, session, owner ); if ( val == null ) { if ( isKey ) { return null; //different nullability rules for pk/fk } } else { notNull = true; } values[i] = val; begin += length; } return notNull ? values : null; }
public static BatchingEntityLoader createBatchingEntityLoader( final OuterJoinLoadable persister, final SessionFactoryImplementor factory) throws MappingException { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(DEFAULT_MAX_BATCH_SIZE); //System.out.print("created loader"); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], LockMode.NONE, factory, LoadQueryInfluencers.NONE); // System.out.print(", " + batchSizesToCreate[i]); } // org.webdsl.logging.Logger.info(); return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate); }
public static BatchingCollectionInitializer createBatchingOneToManyInitializer( final QueryableCollection persister, final int maxBatchSize, final SessionFactoryImplementor factory, final LoadQueryInfluencers loadQueryInfluencers) throws MappingException { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize > DEFAULT_MAX_BATCH_SIZE ? maxBatchSize : DEFAULT_MAX_BATCH_SIZE); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new OneToManyLoader( persister, batchSizesToCreate[i], factory, loadQueryInfluencers ); } return new BatchingCollectionInitializer( persister, batchSizesToCreate, loadersToCreate, maxBatchSize ); }
public static BatchingCollectionInitializer createBatchingCollectionInitializer( final QueryableCollection persister, final int maxBatchSize, final SessionFactoryImplementor factory, final LoadQueryInfluencers loadQueryInfluencers) throws MappingException { int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize > DEFAULT_MAX_BATCH_SIZE ? maxBatchSize : DEFAULT_MAX_BATCH_SIZE); Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ]; for ( int i=0; i<batchSizesToCreate.length; i++ ) { loadersToCreate[i] = new BasicCollectionLoader( persister, batchSizesToCreate[i], factory, loadQueryInfluencers ); } return new BatchingCollectionInitializer(persister, batchSizesToCreate, loadersToCreate, maxBatchSize); }
public boolean[] getColumnInsertability() { return ArrayHelper.EMPTY_BOOLEAN_ARRAY; }
public boolean[] getColumnUpdateability() { return ArrayHelper.EMPTY_BOOLEAN_ARRAY; }
protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException { final int joins = countEntityPersisters(associations); final int collections = countCollectionPersisters(associations); collectionOwners = collections==0 ? null : new int[collections]; collectionPersisters = collections==0 ? null : new CollectionPersister[collections]; collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections ); persisters = new Loadable[joins]; aliases = new String[joins]; owners = new int[joins]; ownerAssociationTypes = new EntityType[joins]; lockModeArray = ArrayHelper.fillArray(lockMode, joins); int i=0; int j=0; Iterator iter = associations.iterator(); while ( iter.hasNext() ) { final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next(); if ( !oj.isCollection() ) { persisters[i] = (Loadable) oj.getJoinable(); aliases[i] = oj.getRHSAlias(); owners[i] = oj.getOwner(associations); ownerAssociationTypes[i] = (EntityType) oj.getJoinableType(); i++; } else { QueryableCollection collPersister = (QueryableCollection) oj.getJoinable(); if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) { //it must be a collection fetch collectionPersisters[j] = collPersister; collectionOwners[j] = oj.getOwner(associations); j++; } if ( collPersister.isOneToMany() ) { persisters[i] = (Loadable) collPersister.getElementPersister(); aliases[i] = oj.getRHSAlias(); i++; } } } if ( ArrayHelper.isAllNegative(owners) ) owners = null; if ( collectionOwners!=null && ArrayHelper.isAllNegative(collectionOwners) ) { collectionOwners = null; } }