Search in sources :

Example 6 with ServiceRegistryBuilder

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

the class EntityMetamodelFacadeTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
    org.hibernate.engine.spi.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);
    entityMetamodel = new EntityMetamodel(rc, sfi) {

        @Override
        public EntityTuplizer getTuplizer() {
            return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
        }

        @Override
        public Integer getPropertyIndexOrNull(String id) {
            methodName = "getPropertyIndexOrNull";
            arguments = new Object[] { id };
            return INDEX;
        }
    };
    entityMetamodelFacade = new AbstractEntityMetamodelFacade(FACADE_FACTORY, entityMetamodel) {
    };
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) AbstractEntityMetamodelFacade(org.jboss.tools.hibernate.runtime.common.AbstractEntityMetamodelFacade) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) ServiceRegistry(org.hibernate.service.ServiceRegistry) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Example 7 with ServiceRegistryBuilder

use of org.hibernate.service.ServiceRegistryBuilder in project ignite by apache.

the class HibernateL2CacheSelfTest method startHibernate.

/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(accessType, igniteInstanceName);
    ServiceRegistryBuilder builder = registryBuilder();
    builder.applySetting("hibernate.show_sql", false);
    return cfg.buildSessionFactory(builder.buildServiceRegistry());
}
Also used : Configuration(org.hibernate.cfg.Configuration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Example 8 with ServiceRegistryBuilder

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

the class ConfigurationFacadeImpl method buildServiceRegistry.

private ServiceRegistry buildServiceRegistry() {
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(((Configuration) getTarget()).getProperties());
    return builder.buildServiceRegistry();
}
Also used : ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Example 9 with ServiceRegistryBuilder

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

the class ServiceImpl method buildServiceRegistry.

private ServiceRegistry buildServiceRegistry(IConfiguration configuration) {
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    return builder.buildServiceRegistry();
}
Also used : ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Example 10 with ServiceRegistryBuilder

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

the class FacadeFactoryTest method testCreateEntityMetamodel.

@Test
public void testCreateEntityMetamodel() {
    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();
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    rc.setIdentifier(sv);
    EntityMetamodel entityMetamodel = new EntityMetamodel(rc, sfi);
    IEntityMetamodel facade = facadeFactory.createEntityMetamodel(entityMetamodel);
    Assert.assertSame(entityMetamodel, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Mappings(org.hibernate.cfg.Mappings) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) SimpleValue(org.hibernate.mapping.SimpleValue) 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