Search in sources :

Example 66 with SessionFactoryImplementor

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());
}
Also used : EntityManager(javax.persistence.EntityManager) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ProcedureCallMementoImpl(org.hibernate.procedure.internal.ProcedureCallMementoImpl) Test(org.junit.Test)

Example 67 with SessionFactoryImplementor

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();
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 68 with SessionFactoryImplementor

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);
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) InputStream(java.io.InputStream) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 69 with SessionFactoryImplementor

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();
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 70 with SessionFactoryImplementor

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();
        }
    });
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) Integrator(org.hibernate.integrator.spi.Integrator) SessionFactoryServiceRegistry(org.hibernate.service.spi.SessionFactoryServiceRegistry)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)129 Test (org.junit.Test)46 Configuration (org.hibernate.cfg.Configuration)27 SQLException (java.sql.SQLException)18 Type (org.hibernate.type.Type)16 EntityPersister (org.hibernate.persister.entity.EntityPersister)13 Connection (java.sql.Connection)12 HibernateException (org.hibernate.HibernateException)12 PreparedStatement (java.sql.PreparedStatement)11 Metadata (org.hibernate.boot.Metadata)11 Statement (java.sql.Statement)10 ArrayList (java.util.ArrayList)10 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)10 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)10 Serializable (java.io.Serializable)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HashMap (java.util.HashMap)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 Map (java.util.Map)6