Search in sources :

Example 16 with SessionImpl

use of org.hibernate.internal.SessionImpl in project jbpm by kiegroup.

the class DistincVsJoinPerformanceTest method copyCollectionPersisterKeys.

private void copyCollectionPersisterKeys(Attribute embeddedAttr, PluralAttribute listAttr, EntityManager em) {
    String[] keys = createOriginalAndExpectedKeys(embeddedAttr, listAttr);
    try {
        SessionImpl session = (SessionImpl) em.getDelegate();
        SessionFactoryImplementor sessionFactory = session.getSessionFactory();
        CollectionPersister persister = sessionFactory.getCollectionPersister(keys[0]);
        sessionFactory.getCollectionPersisters().put(keys[1], persister);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SessionImpl(org.hibernate.internal.SessionImpl)

Example 17 with SessionImpl

use of org.hibernate.internal.SessionImpl in project midpoint by Evolveum.

the class HibernateToSqlTranslator method toSql.

/**
 * Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade.
 * Method provides translation from hibernate {@link Criteria} to plain SQL string query.
 *
 * @param criteria
 * @return SQL string, null if criteria parameter was null.
 */
public static String toSql(Criteria criteria) {
    if (criteria == null) {
        return null;
    }
    try {
        CriteriaImpl c;
        if (criteria instanceof CriteriaImpl) {
            c = (CriteriaImpl) criteria;
        } else {
            CriteriaImpl.Subcriteria subcriteria = (CriteriaImpl.Subcriteria) criteria;
            c = (CriteriaImpl) subcriteria.getParent();
        }
        SessionImpl s = (SessionImpl) c.getSession();
        SessionFactoryImplementor factory = s.getSessionFactory();
        String[] implementors = factory.getImplementors(c.getEntityOrClassName());
        CriteriaLoader loader = new CriteriaLoader((OuterJoinLoadable) factory.getEntityPersister(implementors[0]), factory, c, implementors[0], s.getLoadQueryInfluencers());
        Field f = OuterJoinLoader.class.getDeclaredField("sql");
        f.setAccessible(true);
        return (String) f.get(loader);
    } catch (Exception ex) {
        throw new SystemException(ex.getMessage(), ex);
    }
}
Also used : Field(java.lang.reflect.Field) CriteriaImpl(org.hibernate.internal.CriteriaImpl) SystemException(com.evolveum.midpoint.util.exception.SystemException) CriteriaLoader(org.hibernate.loader.criteria.CriteriaLoader) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SessionImpl(org.hibernate.internal.SessionImpl) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Aggregations

SessionImpl (org.hibernate.internal.SessionImpl)17 Test (org.junit.Test)9 List (java.util.List)5 Session (org.hibernate.Session)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 Statement (java.sql.Statement)4 EntityManager (javax.persistence.EntityManager)4 PersistenceContext (org.hibernate.engine.spi.PersistenceContext)4 ClassMetadata (org.hibernate.metadata.ClassMetadata)4 Serializable (java.io.Serializable)3 Transaction (org.hibernate.Transaction)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 ActionQueue (org.hibernate.engine.spi.ActionQueue)2 EntityKey (org.hibernate.engine.spi.EntityKey)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2