Search in sources :

Example 1 with AccountHolder

use of org.hibernate.test.cache.infinispan.functional.entities.AccountHolder 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;
}
Also used : AccountHolder(org.hibernate.test.cache.infinispan.functional.entities.AccountHolder) List(java.util.List) Iterator(java.util.Iterator) TxUtil.withTxSession(org.hibernate.test.cache.infinispan.util.TxUtil.withTxSession) SessionFactory(org.hibernate.SessionFactory) Query(org.hibernate.Query) Account(org.hibernate.test.cache.infinispan.functional.entities.Account) InfinispanMessageLogger(org.hibernate.cache.infinispan.util.InfinispanMessageLogger) TxUtil.withTxSessionApply(org.hibernate.test.cache.infinispan.util.TxUtil.withTxSessionApply) Query(org.hibernate.Query) Iterator(java.util.Iterator) List(java.util.List)

Example 2 with AccountHolder

use of org.hibernate.test.cache.infinispan.functional.entities.AccountHolder in project hibernate-orm by hibernate.

the class TimestampsRegionImplTest method testClearTimestampsRegionInIsolated.

public void testClearTimestampsRegionInIsolated() throws Exception {
    StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder();
    final StandardServiceRegistry registry = ssrb.build();
    final StandardServiceRegistry registry2 = ssrb.build();
    try {
        final Properties properties = CacheTestUtil.toProperties(ssrb.getSettings());
        InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(registry, getCacheTestSupport());
        InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(registry2, getCacheTestSupport());
        TimestampsRegionImpl region = (TimestampsRegionImpl) regionFactory.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
        TimestampsRegionImpl region2 = (TimestampsRegionImpl) regionFactory2.buildTimestampsRegion(getStandardRegionName(REGION_PREFIX), properties);
        Account acct = new Account();
        acct.setAccountHolder(new AccountHolder());
        region.getCache().withFlags(Flag.FORCE_SYNCHRONOUS).put(acct, "boo");
    } finally {
        StandardServiceRegistryBuilder.destroy(registry);
        StandardServiceRegistryBuilder.destroy(registry2);
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) Account(org.hibernate.test.cache.infinispan.functional.entities.Account) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Properties(java.util.Properties) AccountHolder(org.hibernate.test.cache.infinispan.functional.entities.AccountHolder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Aggregations

Account (org.hibernate.test.cache.infinispan.functional.entities.Account)2 AccountHolder (org.hibernate.test.cache.infinispan.functional.entities.AccountHolder)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Properties (java.util.Properties)1 Query (org.hibernate.Query)1 SessionFactory (org.hibernate.SessionFactory)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)1 InfinispanMessageLogger (org.hibernate.cache.infinispan.util.InfinispanMessageLogger)1 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)1 TxUtil.withTxSession (org.hibernate.test.cache.infinispan.util.TxUtil.withTxSession)1 TxUtil.withTxSessionApply (org.hibernate.test.cache.infinispan.util.TxUtil.withTxSessionApply)1