@Test public void testMaxSize() { doInJPA( this::entityManagerFactory, entityManager -> { EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class ); assertEquals( expectedQueryStatisticsMaxSize(), sessionFactory.getSessionFactoryOptions().getQueryStatisticsMaxSize() ); StatisticsImplementor statistics = (StatisticsImplementor) sessionFactory.getStatistics(); for ( int i = 0; i < 10; i++ ) { statistics.queryExecuted( String.valueOf( i ), 100, i * 1000 ); } assertEquals( 1000, statistics.getQueryStatistics( "1" ).getExecutionTotalTime() ); for ( int i = 100; i < 300; i++ ) { statistics.queryExecuted( String.valueOf( i ), 100, i * 1000 ); } assertEquals( 0, statistics.getQueryStatistics( "1" ).getExecutionTotalTime() ); } ); } }
@Override public SessionFactoryOptions getSessionFactoryOptions() { return delegate.getSessionFactoryOptions(); }
@Override public SessionFactoryOptions getSessionFactoryOptions() { return impl.getSessionFactoryOptions(); }
@Override public SessionFactoryOptions getSessionFactoryOptions() { return impl.getSessionFactoryOptions(); }
@Override public SessionFactoryOptions getSessionFactoryOptions() { return delegate.getSessionFactoryOptions(); }
public SessionFactoryOptions getSessionFactoryOptions() { return delegate.getSessionFactoryOptions(); }
/** * Method to extract from the given Hibernate SessionFactory a working instance of StandardServiceRegistry * * IMPORTANT : As much as possible, prefer using the * {@link #getSessionFactoryServiceRegistry(org.hibernate.SessionFactory)} mthod instead of the current one because * the SessionFactoryServiceRegistry is a child of the StandardServiceRegistry * * NB: This method is static to make sure it does not depend on the current instance * * @param sessionFactory the Hibernate's SessionFactory instance * @return the StandardServiceRegistry instance used by the given SessionFactory */ public static StandardServiceRegistry getStandardServiceRegistry(SessionFactory sessionFactory) { // AThimel 03/04/14 The next two lines are the good way to get the StandardServiceRegistry in Hibernate 4.3 SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions(); StandardServiceRegistry result = sessionFactoryOptions.getServiceRegistry(); return result; }
/** * Schema validation */ // TODO private void validateSchema() { try { SessionFactory factory = this.localSessionFactory.unwrap(SessionFactory.class); StandardServiceRegistry registry = factory.getSessionFactoryOptions().getServiceRegistry(); MetadataSources sources = new MetadataSources(registry); sources.addPackage("org.unitedinternet.cosmo.model.hibernate"); Metadata metadata = sources.buildMetadata(registry); new SchemaValidator().validate(metadata); LOG.info("schema validation passed"); } catch (HibernateException e) { LOG.error("error validating schema", e); throw e; } } }
sessionService.getSessionFactory().getSessionFactoryOptions().getMultiTenancyStrategy(); this.multitenancyEnabled = !MultiTenancyStrategy.NONE.equals( multitenancyStrategy );
/** * Schema validation */ // TODO private void validateSchema() { try { SessionFactory factory = this.localSessionFactory.unwrap(SessionFactory.class); StandardServiceRegistry registry = factory.getSessionFactoryOptions().getServiceRegistry(); MetadataSources sources = new MetadataSources(registry); sources.addPackage("org.unitedinternet.cosmo.model.hibernate"); Metadata metadata = sources.buildMetadata(registry); new SchemaValidator().validate(metadata); LOG.info("schema validation passed"); } catch (HibernateException e) { LOG.error("error validating schema", e); throw e; } } }
public static void withTxSession(boolean useJta, SessionFactory sessionFactory, ThrowingConsumer<Session, Exception> consumer) throws Exception { JtaPlatform jtaPlatform = useJta ? sessionFactory.getSessionFactoryOptions().getServiceRegistry().getService(JtaPlatform.class) : null; withTxSession(jtaPlatform, sessionFactory.withOptions(), consumer); }
public static <T> T withTxSessionApply(boolean useJta, SessionFactory sessionFactory, ThrowingFunction<Session, T, Exception> function) throws Exception { JtaPlatform jtaPlatform = useJta ? sessionFactory.getSessionFactoryOptions().getServiceRegistry().getService(JtaPlatform.class) : null; return withTxSessionApply(jtaPlatform, sessionFactory.withOptions(), function); }
public static void markRollbackOnly(boolean useJta, Session s) { if (useJta) { JtaPlatform jtaPlatform = s.getSessionFactory().getSessionFactoryOptions().getServiceRegistry().getService(JtaPlatform.class); TransactionManager tm = jtaPlatform.retrieveTransactionManager(); try { tm.setRollbackOnly(); } catch (SystemException e) { throw new RuntimeException(e); } } else { s.getTransaction().markRollbackOnly(); } }