use of io.requery.EntityCache in project requery by requery.
the class ThreadLocalTransaction method begin.
@Override
public Transaction begin(TransactionIsolation isolation) {
EntityTransaction transaction = threadLocal.get();
if (transaction == null) {
EntityCache cache = configuration.getCache();
TransactionMode mode = configuration.getTransactionMode();
TransactionListener listener = new CompositeTransactionListener(configuration.getTransactionListenerFactories());
transaction = mode == TransactionMode.MANAGED ? new ManagedTransaction(listener, configuration, cache) : new ConnectionTransaction(listener, configuration, cache, mode != TransactionMode.NONE);
threadLocal.set(transaction);
}
transaction.begin(isolation);
return this;
}
use of io.requery.EntityCache in project requery by requery.
the class EntityCacheTest method testSerializeGetPut.
@Test
public void testSerializeGetPut() {
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
EntityCache cache = new EntityCacheBuilder(Models.DEFAULT).useReferenceCache(false).useSerializableCache(true).useCacheManager(cacheManager).build();
Person p = new Person();
p.setName("Alice");
p.setUUID(UUID.randomUUID());
p.setAddress(new Address());
p.getAddress().setType(AddressType.HOME);
int id = 100;
cache.put(Person.class, id, p);
Person d = cache.get(Person.class, id);
Assert.assertNotNull(d);
Assert.assertNotSame(p, d);
Assert.assertEquals(p.getName(), d.getName());
Assert.assertEquals(p.getUUID(), d.getUUID());
}
Aggregations