use of org.hibernate.SessionFactory in project ignite by apache.
the class HibernateL2CacheConfigurationSelfTest method testCacheUsage.
/**
* @param expCache1 Expected size of cache with name 'cache1'.
* @param expCache2 Expected size of cache with name 'cache2'.
* @param expCache3 Expected size of cache with name 'cache3'.
* @param expCacheE3 Expected size of cache with name {@link #ENTITY3_NAME}.
* @param expCacheE4 Expected size of cache with name {@link #ENTITY4_NAME}.
*/
@SuppressWarnings("unchecked")
private void testCacheUsage(int expCache1, int expCache2, int expCache3, int expCacheE3, int expCacheE4) {
SessionFactory sesFactory = startHibernate(getTestIgniteInstanceName(0));
try {
Session ses = sesFactory.openSession();
try {
Transaction tx = ses.beginTransaction();
ses.save(new Entity1());
ses.save(new Entity2());
ses.save(new Entity3());
ses.save(new Entity4());
tx.commit();
} finally {
ses.close();
}
ses = sesFactory.openSession();
try {
List<Entity1> list1 = ses.createCriteria(ENTITY1_NAME).list();
assertEquals(1, list1.size());
for (Entity1 e : list1) {
ses.load(ENTITY1_NAME, e.getId());
assertNotNull(e.getId());
}
List<Entity2> list2 = ses.createCriteria(ENTITY2_NAME).list();
assertEquals(1, list2.size());
for (Entity2 e : list2) assertNotNull(e.getId());
List<Entity3> list3 = ses.createCriteria(ENTITY3_NAME).list();
assertEquals(1, list3.size());
for (Entity3 e : list3) assertNotNull(e.getId());
List<Entity4> list4 = ses.createCriteria(ENTITY4_NAME).list();
assertEquals(1, list4.size());
for (Entity4 e : list4) assertNotNull(e.getId());
} finally {
ses.close();
}
IgniteCache<Object, Object> cache1 = grid(0).cache("cache1");
IgniteCache<Object, Object> cache2 = grid(0).cache("cache2");
IgniteCache<Object, Object> cache3 = grid(0).cache("cache3");
IgniteCache<Object, Object> cacheE3 = grid(0).cache(ENTITY3_NAME);
IgniteCache<Object, Object> cacheE4 = grid(0).cache(ENTITY4_NAME);
assertEquals("Unexpected entries: " + toSet(cache1.iterator()), expCache1, cache1.size());
assertEquals("Unexpected entries: " + toSet(cache2.iterator()), expCache2, cache2.size());
assertEquals("Unexpected entries: " + toSet(cache3.iterator()), expCache3, cache3.size());
assertEquals("Unexpected entries: " + toSet(cacheE3.iterator()), expCacheE3, cacheE3.size());
assertEquals("Unexpected entries: " + toSet(cacheE4.iterator()), expCacheE4, cacheE4.size());
} finally {
sesFactory.close();
}
}
use of org.hibernate.SessionFactory in project scheduling by ow2-proactive.
the class TransactionHelperTest method setUp.
@Before
public void setUp() {
sessionFactory = mock(SessionFactory.class);
session = mock(Session.class);
transaction = mock(Transaction.class);
when(sessionFactory.openSession()).thenReturn(session);
when(session.beginTransaction()).thenReturn(transaction);
when(session.getTransaction()).thenReturn(transaction);
transactionHelper = new TransactionHelper(sessionFactory);
sessionWork = mock(SessionWork.class);
}
use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class OsgiIntegrationTest method testNativeEnvers.
@Test
public void testNativeEnvers() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
final SessionFactory sf = (SessionFactory) bundleContext.getService(sr);
final Integer adpId;
Session s = sf.openSession();
s.getTransaction().begin();
AuditedDataPoint adp = new AuditedDataPoint("Chris");
s.persist(adp);
s.getTransaction().commit();
adpId = adp.getId();
s.close();
s = sf.openSession();
s.getTransaction().begin();
adp = s.get(AuditedDataPoint.class, adpId);
adp.setName("Chris2");
s.getTransaction().commit();
s.close();
s = sf.openSession();
AuditReader ar = AuditReaderFactory.get(s);
assertEquals(2, ar.getRevisions(AuditedDataPoint.class, adpId).size());
AuditedDataPoint rev1 = ar.find(AuditedDataPoint.class, adpId, 1);
AuditedDataPoint rev2 = ar.find(AuditedDataPoint.class, adpId, 2);
assertEquals(new AuditedDataPoint(adpId, "Chris"), rev1);
assertEquals(new AuditedDataPoint(adpId, "Chris2"), rev2);
s.close();
}
use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class OsgiIntegrationTest method testNative.
@Test
public void testNative() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference(SessionFactory.class.getName());
final SessionFactory sf = (SessionFactory) bundleContext.getService(sr);
Session s = sf.openSession();
s.getTransaction().begin();
s.persist(new DataPoint("Brett"));
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
DataPoint dp = (DataPoint) s.get(DataPoint.class, 1);
assertNotNull(dp);
assertEquals("Brett", dp.getName());
s.getTransaction().commit();
s.close();
dp.setName("Brett2");
s = sf.openSession();
s.getTransaction().begin();
s.update(dp);
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
dp = (DataPoint) s.get(DataPoint.class, 1);
assertNotNull(dp);
assertEquals("Brett2", dp.getName());
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
s.createQuery("delete from DataPoint").executeUpdate();
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
dp = (DataPoint) s.get(DataPoint.class, 1);
assertNull(dp);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.SessionFactory in project dropwizard by dropwizard.
the class SessionFactoryFactory method build.
public SessionFactory build(HibernateBundle<?> bundle, Environment environment, PooledDataSourceFactory dbConfig, ManagedDataSource dataSource, List<Class<?>> entities) {
final ConnectionProvider provider = buildConnectionProvider(dataSource, dbConfig.getProperties());
final SessionFactory factory = buildSessionFactory(bundle, dbConfig, provider, dbConfig.getProperties(), entities);
final SessionFactoryManager managedFactory = new SessionFactoryManager(factory, dataSource);
environment.lifecycle().manage(managedFactory);
return factory;
}
Aggregations