use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class AccountDAO method getTotalBalance.
public int getTotalBalance(AccountHolder holder, boolean useRegion) throws Exception {
List results = (List) withTxSessionApply(useJta, sessionFactory, session -> {
Query query = session.createQuery("select account.balance from Account as account where account.accountHolder = ?");
query.setParameter(0, holder);
if (useRegion) {
query.setCacheRegion("AccountRegion");
}
query.setCacheable(true);
return query.list();
});
int total = 0;
if (results != null) {
for (Iterator it = results.iterator(); it.hasNext(); ) {
total += ((Integer) it.next()).intValue();
System.out.println("Total = " + total);
}
}
return total;
}
use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class CacheKeysFactoryTest method test.
private void test(String cacheKeysFactory, String keyClassName) throws Exception {
SessionFactory sessionFactory = getSessionFactory(cacheKeysFactory);
withTxSession(false, sessionFactory, s -> {
Person person = new Person("John", "Black", 39);
s.persist(person);
});
TestInfinispanRegionFactory regionFactory = (TestInfinispanRegionFactory) ((CacheImplementor) sessionFactory.getCache()).getRegionFactory();
Cache<Object, Object> cache = regionFactory.getCacheManager().getCache(Person.class.getName());
Iterator<Object> iterator = cache.getAdvancedCache().getDataContainer().keySet().iterator();
assertTrue(iterator.hasNext());
Object key = iterator.next();
assertEquals(keyClassName, key.getClass().getSimpleName());
withTxSession(false, sessionFactory, s -> {
Person person = s.load(Person.class, new Name("John", "Black"));
assertEquals(39, person.getAge());
});
}
use of org.hibernate.SessionFactory in project dropwizard by dropwizard.
the class DAOTestRuleTest method ruleCreatedSessionFactory.
@Test
public void ruleCreatedSessionFactory() {
final SessionFactory sessionFactory = daoTestRule.getSessionFactory();
assertThat(sessionFactory).isNotNull();
}
use of org.hibernate.SessionFactory in project yyl_example by Relucent.
the class HibernateTest method main.
public static void main(String[] args) {
Configuration configuration = new Configuration().configure("/yyl/example/demo/hibernate/config/hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = null;
Session session = null;
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
test1(sessionFactory);
test2(sessionFactory);
test3(sessionFactory);
} finally {
closeQuietly(session);
closeQuietly(sessionFactory);
}
}
use of org.hibernate.SessionFactory in project wildfly by wildfly.
the class HibernateCollectionStatistics method getBaseStatistics.
private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
if (entityManagerFactory == null) {
return null;
}
HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
if (sessionFactory != null) {
return sessionFactory.getStatistics();
}
return null;
}
Aggregations