Java Code Examples for org.hibernate.internal.util.collections.ArrayHelper#countTrue()

The following examples show how to use org.hibernate.internal.util.collections.ArrayHelper#countTrue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheableResultTransformer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 )
	);
}
 
Example 2
Source File: CacheableResultTransformer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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++;
			}
		}
	}
}
 
Example 3
Source File: CriteriaLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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();

}
 
Example 4
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write the element to a JDBC <tt>PreparedStatement</tt>
 */
protected int writeElement(PreparedStatement st, Object elt, int i, SharedSessionContractImplementor session)
		throws HibernateException, SQLException {
	getElementType().nullSafeSet( st, elt, i, elementColumnIsSettable, session );
	return i + ArrayHelper.countTrue( elementColumnIsSettable );

}
 
Example 5
Source File: ComponentType.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void nullSafeSet(
		PreparedStatement st,
		Object value,
		int begin,
		boolean[] settable,
		SharedSessionContractImplementor session)
		throws HibernateException, SQLException {

	Object[] subvalues = nullSafeGetValues( value, entityMode );

	int loc = 0;
	for ( int i = 0; i < propertySpan; i++ ) {
		int len = propertyTypes[i].getColumnSpan( session.getFactory() );
		//noinspection StatementWithEmptyBody
		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;
	}
}
 
Example 6
Source File: AbstractCollectionPersister.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Write the index to a JDBC <tt>PreparedStatement</tt>
 */
protected int writeIndex(PreparedStatement st, Object index, int i, SharedSessionContractImplementor session)
		throws HibernateException, SQLException {
	getIndexType().nullSafeSet( st, incrementIndexByBase( index ), i, indexColumnIsSettable, session );
	return i + ArrayHelper.countTrue( indexColumnIsSettable );
}
 
Example 7
Source File: IdentifierHelperBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void applyIdentifierCasing(DatabaseMetaData metaData) throws SQLException {
	if ( metaData == null ) {
		return;
	}

	final int unquotedAffirmatives = ArrayHelper.countTrue(
			metaData.storesLowerCaseIdentifiers(),
			metaData.storesUpperCaseIdentifiers(),
			metaData.storesMixedCaseIdentifiers()
	);

	if ( unquotedAffirmatives == 0 ) {
		log.debug( "JDBC driver metadata reported database stores unquoted identifiers in neither upper, lower nor mixed case" );
	}
	else {
		// NOTE : still "dodgy" if more than one is true
		if ( unquotedAffirmatives > 1 ) {
			log.debug( "JDBC driver metadata reported database stores unquoted identifiers in more than one case" );
		}

		if ( metaData.storesUpperCaseIdentifiers() ) {
			this.unquotedCaseStrategy = IdentifierCaseStrategy.UPPER;
		}
		else if ( metaData.storesLowerCaseIdentifiers() ) {
			this.unquotedCaseStrategy = IdentifierCaseStrategy.LOWER;
		}
		else {
			this.unquotedCaseStrategy = IdentifierCaseStrategy.MIXED;
		}
	}


	final int quotedAffirmatives = ArrayHelper.countTrue(
			metaData.storesLowerCaseQuotedIdentifiers(),
			metaData.storesUpperCaseQuotedIdentifiers(),
			metaData.storesMixedCaseQuotedIdentifiers()
	);

	if ( quotedAffirmatives == 0 ) {
		log.debug( "JDBC driver metadata reported database stores quoted identifiers in neither upper, lower nor mixed case" );
	}
	else {
		// NOTE : still "dodgy" if more than one is true
		if ( quotedAffirmatives > 1 ) {
			log.debug( "JDBC driver metadata reported database stores quoted identifiers in more than one case" );
		}

		if ( metaData.storesMixedCaseQuotedIdentifiers() ) {
			this.quotedCaseStrategy = IdentifierCaseStrategy.MIXED;
		}
		else if ( metaData.storesLowerCaseQuotedIdentifiers() ) {
			this.quotedCaseStrategy = IdentifierCaseStrategy.LOWER;
		}
		else {
			this.quotedCaseStrategy = IdentifierCaseStrategy.UPPER;
		}
	}
}