Example usage for org.hibernate.internal SessionImpl getSessionFactory

List of usage examples for org.hibernate.internal SessionImpl getSessionFactory

Introduction

In this page you can find the example usage for org.hibernate.internal SessionImpl getSessionFactory.

Prototype

@Override
    public SessionFactoryImplementor getSessionFactory() 

Source Link

Usage

From source file:com.evolveum.midpoint.repo.sql.util.HibernateToSqlTranslator.java

License:Apache License

/**
 * 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//  ww  w . j  av a2  s  .  c  o  m
 * @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);
    }
}

From source file:net.e6tech.elements.persist.hibernate.HibernateEntityManagerProvider.java

License:Apache License

@Override
public void onOpen(Resources resources) {
    super.onOpen(resources);
    EntityManager em = resources.getInstance(EntityManager.class);
    SessionImpl session = (SessionImpl) em.getDelegate();
    SessionFactoryImplementor factory = session.getSessionFactory();
    resources.bind(SessionImpl.class, session);
    resources.bind(SessionFactoryImplementor.class, factory);
    resources.bind(SessionFactory.class, factory);

    // cannot call resources.inject(interceptor), resources is not fully open yet
    if (session.getInterceptor() instanceof PersistenceInterceptor) {
        PersistenceInterceptor interceptor = (PersistenceInterceptor) session.getInterceptor();
        interceptor.setResources(resources);
    }//from  ww  w  .  j  a v  a2 s .  c o  m
}

From source file:org.jbpm.services.task.query.DistincVsJoinPerformanceTest.java

License:Apache License

private void copyCollectionPersisterKeys(Attribute embeddedAttr, PluralAttribute listAttr, EntityManager em) {
    String[] keys = createOriginalAndExpectedKeys(embeddedAttr, listAttr);
    try {/*from  w  ww  .j a  va 2  s.c  om*/
        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);
    }
}