Search in sources :

Example 11 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project jbosstools-hibernate by jbosstools.

the class ClassMetadataFacadeTest method createSampleEntityPersister.

private TestEntityPersister createSampleEntityPersister() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    RootClass rc = new RootClass();
    Table t = new Table("foobar");
    rc.setTable(t);
    Column c = new Column("foo");
    t.addColumn(c);
    ArrayList<Column> keyList = new ArrayList<>();
    keyList.add(c);
    t.createUniqueKey(keyList);
    SimpleValue sv = new SimpleValue(configuration.createMappings());
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    return new TestEntityPersister(rc, sfi);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) Column(org.hibernate.mapping.Column) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 12 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewDatabaseCollector.

@Test
public void testNewDatabaseCollector() {
    Configuration cfg = new Configuration();
    ServiceRegistry sr = new ServiceRegistryBuilder().buildServiceRegistry();
    IJDBCReader jdbcReader = FACADE_FACTORY.createJDBCReader(JDBCReaderFactory.newJDBCReader(cfg.getProperties(), cfg.buildSettings(sr), new DefaultReverseEngineeringStrategy(), sr));
    IDatabaseCollector databaseCollectorFacade = service.newDatabaseCollector(jdbcReader);
    Assert.assertNotNull(databaseCollectorFacade);
    DatabaseCollector databaseCollector = (DatabaseCollector) ((IFacade) databaseCollectorFacade).getTarget();
    Assert.assertNotNull(databaseCollector);
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Configuration(org.hibernate.cfg.Configuration) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) ServiceRegistry(org.hibernate.service.ServiceRegistry) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) IJDBCReader(org.jboss.tools.hibernate.runtime.spi.IJDBCReader) DatabaseCollector(org.hibernate.cfg.reveng.DatabaseCollector) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) Test(org.junit.Test)

Example 13 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testGetAllClassMetadata.

@Test
public void testGetAllClassMetadata() {
    Configuration configuration = new Configuration();
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertTrue(sessionFactoryFacade.getAllClassMetadata().isEmpty());
    sessionFactory.close();
    configuration.addClass(Foo.class);
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Map<String, IClassMetadata> allClassMetaData = sessionFactoryFacade.getAllClassMetadata();
    Assert.assertNotNull(allClassMetaData.get("org.jboss.tools.hibernate.runtime.v_4_0.internal.test.Foo"));
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Test(org.junit.Test)

Example 14 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testGetAllCollectionMetadata.

@Test
public void testGetAllCollectionMetadata() {
    Configuration configuration = new Configuration();
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertTrue(sessionFactoryFacade.getAllCollectionMetadata().isEmpty());
    sessionFactory.close();
    configuration.addClass(Foo.class);
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Map<String, ICollectionMetadata> allCollectionMetaData = sessionFactoryFacade.getAllCollectionMetadata();
    Assert.assertNotNull(allCollectionMetaData.get("org.jboss.tools.hibernate.runtime.v_4_0.internal.test.Foo.bars"));
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) Configuration(org.hibernate.cfg.Configuration) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Test(org.junit.Test)

Example 15 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project jbosstools-hibernate by jbosstools.

the class SessionFactoryFacadeTest method testGetCollectionMetadata.

@Test
public void testGetCollectionMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    CollectionMetadata collectionMetadata = sessionFactory.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_4_0.internal.test.Foo.bars");
    Assert.assertSame(collectionMetadata, ((IFacade) sessionFactoryFacade.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_4_0.internal.test.Foo.bars")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) CollectionMetadata(org.hibernate.metadata.CollectionMetadata) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) Configuration(org.hibernate.cfg.Configuration) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Test(org.junit.Test)

Aggregations

ServiceRegistryBuilder (org.hibernate.service.ServiceRegistryBuilder)16 Configuration (org.hibernate.cfg.Configuration)13 ServiceRegistry (org.hibernate.service.ServiceRegistry)11 Test (org.junit.Test)9 SessionFactory (org.hibernate.SessionFactory)6 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 Column (org.hibernate.mapping.Column)4 RootClass (org.hibernate.mapping.RootClass)4 SimpleValue (org.hibernate.mapping.SimpleValue)4 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)4 Table (org.hibernate.mapping.Table)3 ArrayList (java.util.ArrayList)2 Mappings (org.hibernate.cfg.Mappings)2 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)2 IClassMetadata (org.jboss.tools.hibernate.runtime.spi.IClassMetadata)2 ICollectionMetadata (org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata)2 IEntityMetamodel (org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel)2 Properties (java.util.Properties)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1