use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class PooledHiLoSequenceIdentifierTest method insertNewRow.
private void insertNewRow(Session session) {
final SessionImplementor si = (SessionImplementor) session;
final SessionFactoryImplementor sfi = si.getFactory();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("INSERT INTO sequenceIdentifier VALUES (?)");
statement.setObject(1, sfi.getIdentifierGenerator(SequenceIdentifier.class.getName()).generate(si, null));
statement.executeUpdate();
} finally {
if (statement != null) {
statement.close();
}
}
}
});
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class QueryTranslatorTestCase method assertTranslation.
protected void assertTranslation(String hql, Map replacements, boolean scalar, String sql) {
SessionFactoryImplementor factory = sessionFactory();
// Create an empty replacements map if we don't have one.
if (replacements == null) {
replacements = new HashMap();
}
// steve -> note that the empty maps here represent the currently enabled filters...
QueryTranslator oldQueryTranslator = null;
Exception oldException = null;
try {
System.out.println("Compiling with classic QueryTranslator...");
QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory();
oldQueryTranslator = classic.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
oldQueryTranslator.compile(replacements, scalar);
} catch (QueryException e) {
oldException = e;
} catch (MappingException e) {
oldException = e;
}
QueryTranslator newQueryTranslator = null;
Exception newException = null;
try {
System.out.println("Compiling with AST QueryTranslator...");
newQueryTranslator = createNewQueryTranslator(hql, replacements, scalar);
} catch (QueryException e) {
newException = e;
} catch (MappingException e) {
newException = e;
}
// If the old QT threw an exception, the new one should too.
if (oldException != null) {
assertNotNull("New query translator did *NOT* throw an exception, the old one did : " + oldException, newException);
assertEquals(oldException.getMessage(), newException.getMessage());
// Don't bother with the rest of the assertions.
return;
} else if (newException != null) {
newException.printStackTrace();
assertNull("Old query translator did not throw an exception, the new one did", newException);
}
// -- check all of the outputs --
checkSql(oldQueryTranslator, newQueryTranslator, hql, scalar, sql);
checkQuerySpaces(oldQueryTranslator, newQueryTranslator);
checkReturnedTypes(oldQueryTranslator, newQueryTranslator);
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class QueryTranslatorTestCase method compileBadHql.
protected Exception compileBadHql(String hql, boolean scalar) {
QueryTranslator newQueryTranslator;
Map replacements = null;
Exception newException = null;
SessionFactoryImplementor factory = sessionFactory();
try {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
newQueryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
newQueryTranslator.compile(replacements, scalar);
} catch (QueryException e) {
newException = e;
} catch (MappingException e) {
newException = e;
}
assertNotNull("Expected exception from compilation of '" + hql + "'!", newException);
return newException;
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class LoadPlanStructureAssertionTest method testEncapsulatedCompositeIdNoFetches2.
@Test
public void testEncapsulatedCompositeIdNoFetches2() {
// Parent is an entity with a composite identifier mapped via a @EmbeddedId class (ParentPK) which is defined
// using just basic types (strings, ints, etc)
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(EncapsulatedCompositeIdResultSetProcessorTest.Parent.class);
SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
try {
doCompare(sf, (OuterJoinLoadable) sf.getClassMetadata(EncapsulatedCompositeIdResultSetProcessorTest.Parent.class));
} finally {
sf.close();
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class LoadPlanStructureAssertionTest method testEncapsulatedCompositeIdWithFetches1.
@Test
public void testEncapsulatedCompositeIdWithFetches1() {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Card.class);
cfg.addAnnotatedClass(CardField.class);
cfg.addAnnotatedClass(Key.class);
cfg.addAnnotatedClass(PrimaryKey.class);
SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
try {
final OuterJoinLoadable cardFieldPersister = (OuterJoinLoadable) sf.getClassMetadata(CardField.class);
doCompare(sf, cardFieldPersister);
final LoadPlan loadPlan = LoadPlanStructureAssertionHelper.INSTANCE.buildLoadPlan(sf, cardFieldPersister);
assertEquals(LoadPlan.Disposition.ENTITY_LOADER, loadPlan.getDisposition());
assertEquals(1, loadPlan.getReturns().size());
final EntityReturn cardFieldReturn = assertTyping(EntityReturn.class, loadPlan.getReturns().get(0));
assertEquals(0, cardFieldReturn.getFetches().length);
// CardField defines a composite pk with 2 many-to-ones : Card and Key (the id description acts as the composite);
// because it is an @EmbeddedId, the ID provided by the application is used "as is"
// and fetches are not included in the load plan.
assertFalse(cardFieldReturn.getIdentifierDescription().hasFetches());
// we need the readers ordered in a certain manner. Here specifically: Fetch(Card), Fetch(Key), Return(CardField)
//
// additionally, we need Fetch(Card) and Fetch(Key) to be hydrated/semi-resolved beforeQuery attempting to
// resolve the EntityKey for Return(CardField)
//
// together those sound like argument enough to continue keeping readers for "identifier fetches" as part of
// a special "identifier reader". generated aliases could help here too to remove cyclic-ness from the graph.
// but at any rate, we need to know still when this becomes circularity
} finally {
sf.close();
}
}
Aggregations