Search in sources :

Example 1 with ServiceRegistryBuilder

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

the class SchemaExport method createServiceRegistry.

private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
    Environment.verifyProperties(properties);
    ConfigurationHelper.resolvePlaceHolders(properties);
    return (StandardServiceRegistryImpl) new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry();
}
Also used : StandardServiceRegistryImpl(org.hibernate.service.internal.StandardServiceRegistryImpl) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Example 2 with ServiceRegistryBuilder

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

the class ColumnFacadeImpl method getSqlType.

@Override
public String getSqlType(IConfiguration configuration) {
    Column targetColumn = (Column) getTarget();
    Configuration configurationTarget = (Configuration) ((IFacade) configuration).getTarget();
    Properties properties = configurationTarget.getProperties();
    ServiceRegistryBuilder ssrb = new ServiceRegistryBuilder();
    ssrb.applySettings(properties);
    ServiceRegistry ssr = ssrb.buildServiceRegistry();
    DialectFactory df = ssr.getService(DialectFactory.class);
    Dialect dialectTarget = df.buildDialect(properties, null);
    return targetColumn.getSqlType(dialectTarget, configurationTarget.buildMapping());
}
Also used : IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Configuration(org.hibernate.cfg.Configuration) Column(org.hibernate.mapping.Column) Dialect(org.hibernate.dialect.Dialect) DialectFactory(org.hibernate.service.jdbc.dialect.spi.DialectFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) Properties(java.util.Properties) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder)

Example 3 with ServiceRegistryBuilder

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

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    Mappings mappings = configuration.createMappings();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey();
    key.addColumn(c);
    t.setPrimaryKey(key);
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    RootClass rc = new RootClass();
    rc.setEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    mappings.addClass(rc);
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, Collections.emptyMap(), sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) SimpleValue(org.hibernate.mapping.SimpleValue) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Mappings(org.hibernate.cfg.Mappings) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) ServiceRegistry(org.hibernate.service.ServiceRegistry) Test(org.junit.Test)

Example 4 with ServiceRegistryBuilder

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

the class SessionFactoryFacadeTest method testOpenSession.

@Test
public void testOpenSession() {
    Configuration configuration = new Configuration();
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    ISession sessionFacade = sessionFactoryFacade.openSession();
    Session session = (Session) ((IFacade) sessionFacade).getTarget();
    Assert.assertSame(sessionFactory, session.getSessionFactory());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Configuration(org.hibernate.cfg.Configuration) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) ServiceRegistry(org.hibernate.service.ServiceRegistry) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) Session(org.hibernate.Session) ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Test(org.junit.Test)

Example 5 with ServiceRegistryBuilder

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

the class SessionFactoryFacadeTest method testGetClassMetadata.

@Test
public void testGetClassMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    ClassMetadata classMetadata = sessionFactory.getClassMetadata(Foo.class);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata(Foo.class)).getTarget());
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata("org.jboss.tools.hibernate.runtime.v_4_0.internal.test.Foo")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ClassMetadata(org.hibernate.metadata.ClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) 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