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

The following examples show how to use org.hibernate.util.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: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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;

}
 
Example 2
Source File: AbstractCollectionPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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);

}
 
Example 3
Source File: ComponentType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
	}
}
 
Example 4
Source File: AbstractCollectionPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write the index to a JDBC <tt>PreparedStatement</tt>
 */
protected int writeIndex(PreparedStatement st, Object index, int i, SessionImplementor session)
		throws HibernateException, SQLException {
	getIndexType().nullSafeSet( st, incrementIndexByBase(index), i, indexColumnIsSettable, session );
	return i + ArrayHelper.countTrue(indexColumnIsSettable);
}