下面列出了org.hibernate.internal.util.collections.ArrayHelper#countTrue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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++;
}
}
}
}
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();
}
/**
* 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 );
}
@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;
}
}
/**
* 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 );
}
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;
}
}
}