use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class SimpleResultSetProcessorTest method testSimpleEntityProcessing.
@Test
public void testSimpleEntityProcessing() throws Exception {
final EntityPersister entityPersister = sessionFactory().getEntityPersister(SimpleEntity.class.getName());
// create some test data
Session session = openSession();
session.beginTransaction();
session.save(new SimpleEntity(1, "the only"));
session.getTransaction().commit();
session.close();
{
final LoadPlan plan = Helper.INSTANCE.buildLoadPlan(sessionFactory(), entityPersister);
final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails(plan, sessionFactory());
final String sql = queryDetails.getSqlStatement();
final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor();
final List results = new ArrayList();
final Session workSession = openSession();
workSession.beginTransaction();
workSession.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
((SessionImplementor) workSession).getFactory().getServiceRegistry().getService(JdbcServices.class).getSqlStatementLogger().logStatement(sql);
PreparedStatement ps = connection.prepareStatement(sql);
ps.setInt(1, 1);
ResultSet resultSet = ps.executeQuery();
results.addAll(resultSetProcessor.extractResults(resultSet, (SessionImplementor) workSession, new QueryParameters(), new NamedParameterContext() {
@Override
public int[] getNamedParameterLocations(String name) {
return new int[0];
}
}, true, false, null, null));
resultSet.close();
ps.close();
}
});
assertEquals(1, results.size());
Object result = results.get(0);
assertNotNull(result);
SimpleEntity workEntity = ExtraAssertions.assertTyping(SimpleEntity.class, result);
assertEquals(1, workEntity.id.intValue());
assertEquals("the only", workEntity.name);
workSession.getTransaction().commit();
workSession.close();
}
// clean up test data
session = openSession();
session.beginTransaction();
session.createQuery("delete SimpleEntity").executeUpdate();
session.getTransaction().commit();
session.close();
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class AbstractProducedQuery method doScroll.
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
if (getMaxResults() == 0) {
return EmptyScrollableResults.INSTANCE;
}
final String query = queryParameterBindings.expandListValuedParameters(getQueryString(), getProducer());
QueryParameters queryParameters = getQueryParameters();
queryParameters.setScrollMode(scrollMode);
return getProducer().scroll(query, queryParameters);
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class NativeQueryImpl method doScroll.
@Override
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
final NativeSQLQuerySpecification nativeSQLQuerySpecification = generateQuerySpecification();
final QueryParameters queryParameters = getQueryParameters();
queryParameters.setScrollMode(scrollMode);
return getProducer().scroll(nativeSQLQuerySpecification, queryParameters);
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class NativeQueryImpl method getQueryParameters.
@Override
public QueryParameters getQueryParameters() {
final QueryParameters queryParameters = super.getQueryParameters();
queryParameters.setCallable(callable);
queryParameters.setAutoDiscoverScalarTypes(autoDiscoverTypes);
if (collectionKey != null) {
queryParameters.setCollectionKeys(new Serializable[] { collectionKey });
}
return queryParameters;
}
use of org.hibernate.engine.spi.QueryParameters in project hibernate-orm by hibernate.
the class ProcedureCallImpl method getQueryParameters.
@Override
public QueryParameters getQueryParameters() {
final QueryParameters qp = super.getQueryParameters();
// both of these are for documentation purposes, they are actually handled directly...
qp.setAutoDiscoverScalarTypes(true);
qp.setCallable(true);
return qp;
}
Aggregations