org.hibernate.tool.hbm2ddl.DatabaseMetadata#org.hibernate.util.ArrayHelper源码实例Demo

下面列出了org.hibernate.tool.hbm2ddl.DatabaseMetadata#org.hibernate.util.ArrayHelper 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cacheonix-core   文件: BatchingEntityLoader.java
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);
	}
}
 
源代码2 项目: cacheonix-core   文件: CustomLoader.java
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);
	}
}
 
源代码5 项目: cacheonix-core   文件: AbstractEntityPersister.java
/**
 * 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);
}
 
源代码6 项目: cacheonix-core   文件: BasicCollectionPersister.java
/**
 * 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();
}
 
源代码7 项目: cacheonix-core   文件: BasicCollectionPersister.java
/**
 * 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();
}
 
源代码8 项目: cacheonix-core   文件: OneToManyPersister.java
/**
 * 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();
}
 
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;
}
 
源代码10 项目: cacheonix-core   文件: JoinHelper.java
/**
 * 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
		}
	}
}
 
源代码11 项目: cacheonix-core   文件: Property.java
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)
		);
}
 
源代码12 项目: cacheonix-core   文件: Property.java
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)
		);
}
 
源代码13 项目: cacheonix-core   文件: ProjectionList.java
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);
}
 
源代码14 项目: cacheonix-core   文件: ProjectionList.java
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);
}
 
源代码15 项目: cacheonix-core   文件: ProjectionList.java
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);

}
 
源代码16 项目: cacheonix-core   文件: CollectionElementLoader.java
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() );

}
 
源代码17 项目: cacheonix-core   文件: CriteriaJoinWalker.java
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);

}
 
源代码18 项目: cacheonix-core   文件: CustomLoader.java
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 );
	}
}
 
源代码19 项目: cacheonix-core   文件: AbstractEntityPersister.java
/**
 * 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);

}
 
源代码21 项目: cacheonix-core   文件: NativeSQLQueryPlan.java
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 );
	}
}
 
源代码22 项目: cacheonix-core   文件: JoinHelper.java
/**
 * 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);
		}
	}
}
 
源代码23 项目: cacheonix-core   文件: ExceptionUtils.java
/**
 * <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] );
}
 
源代码24 项目: cacheonix-core   文件: StatisticsImpl.java
/**
 * Get the names of all entities
 */
public String[] getEntityNames() {
	if (sessionFactory==null) {
		return ArrayHelper.toStringArray( entityStatistics.keySet() );
	}
	else {
		return ArrayHelper.toStringArray( sessionFactory.getAllClassMetadata().keySet() );
	}
}
 
源代码25 项目: cacheonix-core   文件: StatisticsImpl.java
/**
 * 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() );
	}
}
 
源代码26 项目: cacheonix-core   文件: StatisticsImpl.java
/**
 * 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() );
	}
}
 
源代码27 项目: cacheonix-core   文件: IntoClause.java
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 );
}
 
源代码28 项目: cacheonix-core   文件: HqlSqlWalker.java
/**
 * 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 );
	}
}
 
源代码29 项目: cacheonix-core   文件: QueryTranslatorImpl.java
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 );
	}
}
 
源代码30 项目: cacheonix-core   文件: ComponentType.java
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;
	}
}