Search in sources :

Example 1 with EntityCache

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;
}
Also used : TransactionListener(io.requery.TransactionListener) EntityCache(io.requery.EntityCache)

Example 2 with EntityCache

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());
}
Also used : EntityCache(io.requery.EntityCache) Address(io.requery.test.model.Address) CacheManager(javax.cache.CacheManager) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) Person(io.requery.test.model.Person) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Aggregations

EntityCache (io.requery.EntityCache)2 TransactionListener (io.requery.TransactionListener)1 EntityCacheBuilder (io.requery.cache.EntityCacheBuilder)1 Address (io.requery.test.model.Address)1 Person (io.requery.test.model.Person)1 CacheManager (javax.cache.CacheManager)1 CachingProvider (javax.cache.spi.CachingProvider)1 Test (org.junit.Test)1