use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class AbstractStoredProcedureTest method testNamedStoredProcedureBinding.
@Test
public void testNamedStoredProcedureBinding() {
EntityManager em = getOrCreateEntityManager();
SessionFactoryImplementor sf = em.getEntityManagerFactory().unwrap(SessionFactoryImplementor.class);
final ProcedureCallMementoImpl m1 = (ProcedureCallMementoImpl) sf.getNamedQueryRepository().getNamedProcedureCallMemento("s1");
assertNotNull(m1);
assertEquals("p1", m1.getProcedureName());
assertEquals(ParameterStrategy.NAMED, m1.getParameterStrategy());
List<ProcedureCallMementoImpl.ParameterMemento> list = m1.getParameterDeclarations();
assertEquals(2, list.size());
ProcedureCallMementoImpl.ParameterMemento memento = list.get(0);
assertEquals("p11", memento.getName());
assertEquals(javax.persistence.ParameterMode.IN, memento.getMode());
assertEquals(IntegerType.INSTANCE, memento.getHibernateType());
assertEquals(Integer.class, memento.getType());
memento = list.get(1);
assertEquals("p12", memento.getName());
assertEquals(javax.persistence.ParameterMode.IN, memento.getMode());
assertEquals(IntegerType.INSTANCE, memento.getHibernateType());
assertEquals(Integer.class, memento.getType());
final ProcedureCallMementoImpl m2 = (ProcedureCallMementoImpl) sf.getNamedQueryRepository().getNamedProcedureCallMemento("s2");
assertNotNull(m2);
assertEquals("p2", m2.getProcedureName());
assertEquals(ParameterStrategy.POSITIONAL, m2.getParameterStrategy());
list = m2.getParameterDeclarations();
memento = list.get(0);
assertEquals(Integer.valueOf(1), memento.getPosition());
assertEquals(javax.persistence.ParameterMode.INOUT, memento.getMode());
assertEquals(StringType.INSTANCE, memento.getHibernateType());
assertEquals(String.class, memento.getType());
memento = list.get(1);
assertEquals(Integer.valueOf(2), memento.getPosition());
assertEquals(javax.persistence.ParameterMode.INOUT, memento.getMode());
assertEquals(LongType.INSTANCE, memento.getHibernateType());
assertEquals(Long.class, memento.getType());
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class FetchProfileTest method testFetchProfileConfigured.
@Test
public void testFetchProfileConfigured() {
Configuration config = new Configuration();
config.addAnnotatedClass(Customer.class);
config.addAnnotatedClass(Order.class);
config.addAnnotatedClass(SupportTickets.class);
config.addAnnotatedClass(Country.class);
SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("customer-with-orders"));
assertFalse("package info should not be parsed", sessionImpl.containsFetchProfileDefinition("package-profile-1"));
sessionImpl.close();
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class FetchProfileTest method testXmlOverride.
@Test
public void testXmlOverride() {
Configuration config = new Configuration();
config.addAnnotatedClass(Customer5.class);
config.addAnnotatedClass(Order.class);
config.addAnnotatedClass(Country.class);
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
config.addInputStream(is);
SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
sessionImpl.close();
// now the same with no xml
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
try {
metadataSources.buildMetadata();
fail();
} catch (MappingException e) {
log.trace("success");
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class FetchProfileTest method testPackageConfiguredFetchProfile.
@Test
public void testPackageConfiguredFetchProfile() {
Configuration config = new Configuration();
config.addAnnotatedClass(Customer.class);
config.addAnnotatedClass(Order.class);
config.addAnnotatedClass(SupportTickets.class);
config.addAnnotatedClass(Country.class);
config.addPackage(Customer.class.getPackage().getName());
SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("package-profile-1"));
assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("package-profile-2"));
sessionImpl.close();
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class CallbackTest method prepareBootstrapRegistryBuilder.
@Override
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
super.prepareBootstrapRegistryBuilder(builder);
builder.applyIntegrator(new Integrator() {
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
integrate(serviceRegistry);
}
private void integrate(SessionFactoryServiceRegistry serviceRegistry) {
serviceRegistry.getService(EventListenerRegistry.class).setListeners(EventType.DELETE, listener);
listener.initialize();
}
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
listener.cleanup();
}
});
}
Aggregations