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

The following examples show how to use org.hibernate.internal.util.collections.ArrayHelper#slice() . 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: CriteriaLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Object[] getResultRow(Object[] row, ResultSet rs, SharedSessionContractImplementor session)
		throws SQLException, HibernateException {
	final Object[] result;
	if ( translator.hasProjection() ) {
		Type[] types = translator.getProjectedTypes();
		result = new Object[types.length];
		String[] columnAliases = translator.getProjectedColumnAliases();
		for ( int i=0, pos=0; i<result.length; i++ ) {
			int numColumns = types[i].getColumnSpan( session.getFactory() );
			if ( numColumns > 1 ) {
				String[] typeColumnAliases = ArrayHelper.slice( columnAliases, pos, numColumns );
				result[i] = types[i].nullSafeGet(rs, typeColumnAliases, session, null);
			}
			else {
				result[i] = types[i].nullSafeGet(rs, columnAliases[pos], session, null);
			}
			pos += numColumns;
		}
	}
	else {
		result = toResultRow( row );
	}
	return result;
}
 
Example 2
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join
 *
 * @param associationType The association type for the association that represents the join
 * @param columnQualifier The left-hand side table alias
 * @param propertyIndex The index of the property that represents the association/join
 * @param begin The index for any nested (composites) attributes
 * @param lhsPersister The persister for the left-hand side of the association/join
 * @param mapping The mapping (typically the SessionFactory).
 *
 * @return The qualified column names.
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType associationType,
		String columnQualifier,
		int propertyIndex,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( associationType.useLHSPrimaryKey() ) {
		return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		final String propertyName = associationType.getLHSPropertyName();
		if ( propertyName == null ) {
			return ArrayHelper.slice(
					toColumns( lhsPersister, columnQualifier, propertyIndex ),
					begin,
					associationType.getColumnSpan( mapping )
			);
		}
		else {
			//bad cast
			return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName );
		}
	}
}
 
Example 3
Source File: JoinHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the columns of the owning entity which are to be used in the join
 *
 * @param type The type representing the join
 * @param property The property index for the association type
 * @param begin ?
 * @param lhsPersister The persister for the left-hand-side of the join
 * @param mapping The mapping object (typically the SessionFactory)
 *
 * @return The columns for the left-hand-side of 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 {
		final String propertyName = type.getLHSPropertyName();
		if ( propertyName == null ) {
			//slice, to get the columns for this component
			//property
			return ArrayHelper.slice(
					property < 0
							? lhsPersister.getIdentifierColumnNames()
							: 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 );
		}
	}
}
 
Example 4
Source File: ComponentType.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object hydrate(
		final ResultSet rs,
		final String[] names,
		final SharedSessionContractImplementor 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;
}