Java Code Examples for org.hibernate.param.ParameterSpecification#bind()

The following examples show how to use org.hibernate.param.ParameterSpecification#bind() . 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: AbstractIdsBulkIdHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected List<Object[]> selectIds(
		SharedSessionContractImplementor session,
		QueryParameters queryParameters) {
	List<Object[]> ids = new ArrayList<>();
	try {
		try (PreparedStatement ps = session.getJdbcCoordinator()
				.getStatementPreparer()
				.prepareStatement( idSelect, false )) {
			int position = 1;
			for ( ParameterSpecification parameterSpecification : idSelectParameterSpecifications ) {
				position += parameterSpecification.bind( ps, queryParameters, session, position );
			}

			Dialect dialect = session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getDialect();

			ResultSet rs = session
					.getJdbcCoordinator()
					.getResultSetReturn()
					.extract( ps );
			while ( rs.next() ) {
				Object[] result = new Object[targetedPersister.getIdentifierColumnNames().length];
				for ( String columnName : targetedPersister.getIdentifierColumnNames() ) {
					int columnIndex = rs.findColumn( StringHelper.unquote( columnName, dialect ) );
					Object column = rs.getObject(columnIndex);
					result[columnIndex - 1] = column;
				}
				ids.add( result );
			}
		}
	}
	catch ( SQLException e ) {
		throw convert( e, "could not select ids for bulk operation", idSelect );
	}

	return ids;
}
 
Example 2
Source File: IndexNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int bind(PreparedStatement statement, QueryParameters qp, SharedSessionContractImplementor session, int position)
		throws SQLException {
	int bindCount = 0;
	for ( ParameterSpecification paramSpec : paramSpecs ) {
		bindCount += paramSpec.bind( statement, qp, session, position + bindCount );
	}
	return bindCount;
}
 
Example 3
Source File: QueryLoader.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * We specifically override this method here, because in general we know much more
 * about the parameters and their appropriate bind positions here then we do in
 * our super because we track them explciitly here through the ParameterSpecification
 * interface.
 *
 * @param queryParameters The encapsulation of the parameter values to be bound.
 * @param startIndex The position from which to start binding parameter values.
 * @param session The originating session.
 * @return The number of JDBC bind positions actually bound during this method execution.
 * @throws SQLException Indicates problems performing the binding.
 */
protected int bindParameterValues(
		final PreparedStatement statement,
		final QueryParameters queryParameters,
		final int startIndex,
		final SessionImplementor session) throws SQLException {
	int position = bindFilterParameterValues( statement, queryParameters, startIndex, session );
	List parameterSpecs = queryTranslator.getSqlAST().getWalker().getParameters();
	Iterator itr = parameterSpecs.iterator();
	while ( itr.hasNext() ) {
		ParameterSpecification spec = ( ParameterSpecification ) itr.next();
		position += spec.bind( statement, queryParameters, session, position );
	}
	return position - startIndex;
}
 
Example 4
Source File: BasicExecutor.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int execute(QueryParameters parameters, SessionImplementor session) throws HibernateException {

		coordinateSharedCacheCleanup( session );

		PreparedStatement st = null;
		RowSelection selection = parameters.getRowSelection();

		try {
			try {
				st = session.getBatcher().prepareStatement( sql );
				Iterator paramSpecifications = getWalker().getParameters().iterator();
				int pos = 1;
				while ( paramSpecifications.hasNext() ) {
					final ParameterSpecification paramSpec = ( ParameterSpecification ) paramSpecifications.next();
					pos += paramSpec.bind( st, parameters, session, pos );
				}
				if ( selection != null ) {
					if ( selection.getTimeout() != null ) {
						st.setQueryTimeout( selection.getTimeout().intValue() );
					}
				}

				return st.executeUpdate();
			}
			finally {
				if ( st != null ) {
					session.getBatcher().closeStatement( st );
				}
			}
		}
		catch( SQLException sqle ) {
			throw JDBCExceptionHelper.convert(
					getFactory().getSQLExceptionConverter(),
			        sqle,
			        "could not execute update query",
			        sql
				);
		}
	}
 
Example 5
Source File: BasicExecutor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected int doExecute(QueryParameters parameters, SharedSessionContractImplementor session, String sql,
		List parameterSpecifications) throws HibernateException {
	BulkOperationCleanupAction action = new BulkOperationCleanupAction( session, persister );
	if ( session.isEventSource() ) {
		( (EventSource) session ).getActionQueue().addAction( action );
	}
	else {
		action.getAfterTransactionCompletionProcess().doAfterTransactionCompletion( true, session );
	}

	PreparedStatement st = null;
	RowSelection selection = parameters.getRowSelection();

	try {
		try {
			st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false );
			Iterator paramSpecItr = parameterSpecifications.iterator();
			int pos = 1;
			while ( paramSpecItr.hasNext() ) {
				final ParameterSpecification paramSpec = (ParameterSpecification) paramSpecItr.next();
				pos += paramSpec.bind( st, parameters, session, pos );
			}
			if ( selection != null ) {
				if ( selection.getTimeout() != null ) {
					st.setQueryTimeout( selection.getTimeout() );
				}
			}

			return session.getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
		}
		finally {
			if ( st != null ) {
				session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st );
				session.getJdbcCoordinator().afterStatementExecution();
			}
		}
	}
	catch( SQLException sqle ) {
		throw session.getJdbcServices().getSqlExceptionHelper().convert( sqle, "could not execute update query", sql );
	}
}
 
Example 6
Source File: QueryLoader.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * We specifically override this method here, because in general we know much more
 * about the parameters and their appropriate bind positions here then we do in
 * our super because we track them explicitly here through the ParameterSpecification
 * interface.
 *
 * @param queryParameters The encapsulation of the parameter values to be bound.
 * @param startIndex The position from which to start binding parameter values.
 * @param session The originating session.
 *
 * @return The number of JDBC bind positions actually bound during this method execution.
 *
 * @throws SQLException Indicates problems performing the binding.
 */
@Override
protected int bindParameterValues(
		final PreparedStatement statement,
		final QueryParameters queryParameters,
		final int startIndex,
		final SharedSessionContractImplementor session) throws SQLException {
	int position = startIndex;
	List<ParameterSpecification> parameterSpecs = queryTranslator.getCollectedParameterSpecifications();
	for ( ParameterSpecification spec : parameterSpecs ) {
		position += spec.bind( statement, queryParameters, session, position );
	}
	return position - startIndex;
}