Search in sources :

Example 6 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl in project xwiki-platform by xwiki.

the class XWikiHibernateStore method injectInSessionFactory.

private SessionFactory injectInSessionFactory(Configuration config) throws XWikiException {
    SessionFactoryImpl sfactory = (SessionFactoryImpl) config.buildSessionFactory();
    Settings settings = sfactory.getSettings();
    ConnectionProvider provider = ((SessionFactoryImpl) getSessionFactory()).getSettings().getConnectionProvider();
    Field field = null;
    try {
        field = settings.getClass().getDeclaredField("connectionProvider");
        field.setAccessible(true);
        field.set(settings, provider);
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED, "Mapping injection failed", e);
    }
    return sfactory;
}
Also used : Field(java.lang.reflect.Field) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) Settings(org.hibernate.cfg.Settings) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) XWikiException(com.xpn.xwiki.XWikiException) ConnectionProvider(org.hibernate.connection.ConnectionProvider)

Example 7 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl in project xwiki-platform by xwiki.

the class XWikiHibernateStore method injectCustomMappingsInSessionFactory.

private SessionFactory injectCustomMappingsInSessionFactory(XWikiDocument doc, XWikiContext context) throws XWikiException {
    // If we haven't turned of dynamic custom mappings we should not inject them
    if (!context.getWiki().hasDynamicCustomMappings()) {
        return getSessionFactory();
    }
    boolean result = injectCustomMappings(doc, context);
    if (!result) {
        return getSessionFactory();
    }
    Configuration config = getConfiguration();
    SessionFactoryImpl sfactory = (SessionFactoryImpl) config.buildSessionFactory();
    Settings settings = sfactory.getSettings();
    ConnectionProvider provider = ((SessionFactoryImpl) getSessionFactory()).getSettings().getConnectionProvider();
    Field field = null;
    try {
        field = settings.getClass().getDeclaredField("connectionProvider");
        field.setAccessible(true);
        field.set(settings, provider);
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_MAPPING_INJECTION_FAILED, "Mapping injection failed", e);
    }
    return sfactory;
}
Also used : Field(java.lang.reflect.Field) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) Settings(org.hibernate.cfg.Settings) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) XWikiException(com.xpn.xwiki.XWikiException) ConnectionProvider(org.hibernate.connection.ConnectionProvider)

Example 8 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    assert sessionFactory instanceof IFacade;
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl)

Example 9 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl 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");
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    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.SessionFactoryImplementor) ArrayList(java.util.ArrayList) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 10 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl 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);
    SimpleValue sv = new SimpleValue();
    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);
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    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) HQLQueryPlan(org.hibernate.engine.query.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) 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) Mappings(org.hibernate.cfg.Mappings) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

SessionFactoryImpl (org.hibernate.impl.SessionFactoryImpl)13 Configuration (org.hibernate.cfg.Configuration)9 SessionFactoryImplementor (org.hibernate.engine.SessionFactoryImplementor)8 RootClass (org.hibernate.mapping.RootClass)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 Column (org.hibernate.mapping.Column)6 Table (org.hibernate.mapping.Table)6 ArrayList (java.util.ArrayList)4 HQLQueryPlan (org.hibernate.engine.query.HQLQueryPlan)4 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)4 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)4 IEntityMetamodel (org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel)4 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)4 Test (org.junit.Test)4 Mappings (org.hibernate.cfg.Mappings)3 XWikiException (com.xpn.xwiki.XWikiException)2 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)2 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 EntityMode (org.hibernate.EntityMode)2