Search in sources :

Example 1 with SessionFactoryImplementor

use of org.hibernate.engine.SessionFactoryImplementor in project xwiki-platform by xwiki.

the class HibernateStore method shutdownHibernate.

/**
 * Allows to shut down the hibernate configuration Closing all pools and connections.
 */
public void shutdownHibernate() {
    Session session = getCurrentSession();
    closeSession(session);
    // Close all connections
    if (getSessionFactory() != null) {
        // Note that we need to do the cast because this is how Hibernate suggests to get the Connection Provider.
        // See http://bit.ly/QAJXlr
        ConnectionProvider connectionProvider = ((SessionFactoryImplementor) getSessionFactory()).getConnectionProvider();
        connectionProvider.close();
    }
}
Also used : SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) Session(org.hibernate.Session) ConnectionProvider(org.hibernate.connection.ConnectionProvider)

Example 2 with SessionFactoryImplementor

use of org.hibernate.engine.SessionFactoryImplementor in project xwiki-platform by xwiki.

the class XWikiHibernateStoreTest method createHibernateSequenceIfRequiredWhenInUpdateCommands.

/**
 * We verify that the sequence is not created if it's already in the update script.
 */
@Test
public void createHibernateSequenceIfRequiredWhenInUpdateCommands() throws Exception {
    Session session = mock(Session.class);
    SessionFactoryImplementor sessionFactory = mock(SessionFactoryImplementor.class);
    Dialect dialect = mock(Dialect.class);
    when(session.getSessionFactory()).thenReturn(sessionFactory);
    when(sessionFactory.getDialect()).thenReturn(dialect);
    when(dialect.getNativeIdentifierGeneratorClass()).thenReturn(SequenceGenerator.class);
    SQLQuery sqlQuery = mock(SQLQuery.class);
    when(session.createSQLQuery("create sequence schema.hibernate_sequence")).thenReturn(sqlQuery);
    when(sqlQuery.executeUpdate()).thenReturn(0);
    this.store.createHibernateSequenceIfRequired(new String[] { "whatever", "create sequence schema.hibernate_sequence" }, "schema", session);
    verify(session, never()).createSQLQuery("create sequence schema.hibernate_sequence");
    verify(sqlQuery, never()).executeUpdate();
}
Also used : SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) Dialect(org.hibernate.dialect.Dialect) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with SessionFactoryImplementor

use of org.hibernate.engine.SessionFactoryImplementor 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");
    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();
    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(EntityMode entityMode) {
            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 EntityMetamodelFacadeImpl(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) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) ArrayList(java.util.ArrayList) SimpleValue(org.hibernate.mapping.SimpleValue) EntityMode(org.hibernate.EntityMode) Column(org.hibernate.mapping.Column) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Example 4 with SessionFactoryImplementor

use of org.hibernate.engine.SessionFactoryImplementor 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);
    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)

Example 5 with SessionFactoryImplementor

use of org.hibernate.engine.SessionFactoryImplementor 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();
    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)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.SessionFactoryImplementor)13 Configuration (org.hibernate.cfg.Configuration)8 SessionFactoryImpl (org.hibernate.impl.SessionFactoryImpl)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 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)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 Session (org.hibernate.Session)3 Mappings (org.hibernate.cfg.Mappings)3 Dialect (org.hibernate.dialect.Dialect)3 EntityMode (org.hibernate.EntityMode)2 SQLQuery (org.hibernate.SQLQuery)2 ConnectionProvider (org.hibernate.connection.ConnectionProvider)2 HQLQueryPlan (org.hibernate.engine.query.HQLQueryPlan)2 PrimaryKey (org.hibernate.mapping.PrimaryKey)2