Java Code Examples for org.hibernate.type.Type.getColumnSpan()

The following are Jave code examples for showing how to use getColumnSpan() of the org.hibernate.type.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: SimpleProjection.java   View Source Code Vote up 5 votes
/**
 * Count the number of columns this projection uses.
 *
 * @param criteria The criteria
 * @param criteriaQuery The query
 *
 * @return The number of columns
 */
public int getColumnCount(Criteria criteria, CriteriaQuery criteriaQuery) {
	final Type[] types = getTypes( criteria, criteriaQuery );
	int count = 0;
	for ( Type type : types ) {
		count += type.getColumnSpan( criteriaQuery.getFactory() );
	}
	return count;
}
 
Example 2
Project: lams   File: BinaryLogicOperatorNode.java   View Source Code Vote up 5 votes
private int getColumnSpan(Type type, SessionFactoryImplementor sfi) {
	int columnSpan = type.getColumnSpan( sfi );
	if ( columnSpan == 0 && type instanceof OneToOneType ) {
		columnSpan = ( (OneToOneType) type ).getIdentifierOrUniqueKeyType( sfi ).getColumnSpan( sfi );
	}
	return columnSpan;
}
 
Example 3
Project: lams   File: AbstractNullnessCheckNode.java   View Source Code Vote up 5 votes
@Override
public void initialize() {
	// TODO : this really needs to be delayed unitl after we definitively know the operand node type;
	// where this is currently a problem is parameters for which where we cannot unequivocally
	// resolve an expected type
	Type operandType = extractDataType( getOperand() );
	if ( operandType == null ) {
		return;
	}
	SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
	int operandColumnSpan = operandType.getColumnSpan( sessionFactory );
	if ( operandColumnSpan > 1 ) {
		mutateRowValueConstructorSyntax( operandColumnSpan );
	}
}
 
Example 4
Project: lams   File: AbstractEntityPersister.java   View Source Code Vote up 4 votes
@Override
public Serializable loadEntityIdByNaturalId(
		Object[] naturalIdValues,
		LockOptions lockOptions,
		SessionImplementor session) {
	if ( LOG.isTraceEnabled() ) {
		LOG.tracef(
				"Resolving natural-id [%s] to id : %s ",
				naturalIdValues,
				MessageHelper.infoString( this )
		);
	}

	final boolean[] valueNullness = determineValueNullness( naturalIdValues );
	final String sqlEntityIdByNaturalIdString = determinePkByNaturalIdQuery( valueNullness );

	try {
		PreparedStatement ps = session.getTransactionCoordinator()
				.getJdbcCoordinator()
				.getStatementPreparer()
				.prepareStatement( sqlEntityIdByNaturalIdString );
		try {
			int positions = 1;
			int loop = 0;
			for ( int idPosition : getNaturalIdentifierProperties() ) {
				final Object naturalIdValue = naturalIdValues[loop++];
				if ( naturalIdValue != null ) {
					final Type type = getPropertyTypes()[idPosition];
					type.nullSafeSet( ps, naturalIdValue, positions, session );
					positions += type.getColumnSpan( session.getFactory() );
				}
			}
			ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( ps );
			try {
				// if there is no resulting row, return null
				if ( !rs.next() ) {
					return null;
				}

				return (Serializable) getIdentifierType().hydrate( rs, getIdentifierAliases(), session, null );
			}
			finally {
				session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps );
			}
		}
		finally {
			session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
		}
	}
	catch ( SQLException e ) {
		throw getFactory().getSQLExceptionHelper().convert(
				e,
				String.format(
						"could not resolve natural-id [%s] to id : %s",
						naturalIdValues,
						MessageHelper.infoString( this )
				),
				sqlEntityIdByNaturalIdString
		);
	}
}
 
Example 5
Project: lams   File: PositionalParameterSpecification.java   View Source Code Vote up 3 votes
/**
 * Bind the appropriate value into the given statement at the specified position.
 *
 * @param statement The statement into which the value should be bound.
 * @param qp The defined values for the current query execution.
 * @param session The session against which the current execution is occuring.
 * @param position The position from which to start binding value(s).
 *
 * @return The number of sql bind positions "eaten" by this bind operation.
 */
@Override
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position) throws SQLException {
	Type type = qp.getPositionalParameterTypes()[hqlPosition];
	Object value = qp.getPositionalParameterValues()[hqlPosition];

	type.nullSafeSet( statement, value, position, session );
	return type.getColumnSpan( session.getFactory() );
}
 
Example 6
Project: lams   File: SessionFactoryHelper.java   View Source Code Vote up 2 votes
/**
 * Retrieve the number of columns represented by this type.
 *
 * @param type The type.
 *
 * @return The number of columns.
 */
public int getColumnSpan(Type type) {
	return type.getColumnSpan( sfi );
}