Search in sources :

Example 1 with Family

use of org.hibernate.test.cache.infinispan.stress.entities.Family in project hibernate-orm by hibernate.

the class CorrectnessTestCase method createFamily.

private static Family createFamily() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    String familyName = randomString(random);
    Family f = new Family(familyName);
    HashSet<Person> members = new HashSet<>();
    members.add(createPerson(random, f));
    f.setMembers(members);
    return f;
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Person(org.hibernate.test.cache.infinispan.stress.entities.Person) HashSet(java.util.HashSet)

Example 2 with Family

use of org.hibernate.test.cache.infinispan.stress.entities.Family in project hibernate-orm by hibernate.

the class SecondLevelCacheStressTestCase method insertOperation.

Operation insertOperation() {
    return new Operation("INSERT") {

        @Override
        boolean call(final int run) throws Exception {
            return captureThrowables(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return withTx(tm, new Callable<Boolean>() {

                        @Override
                        public Boolean call() throws Exception {
                            Session s = sessionFactory.openSession();
                            s.getTransaction().begin();
                            String name = "Zamarreño-" + run;
                            Family family = new Family(name);
                            s.persist(family);
                            s.getTransaction().commit();
                            s.close();
                            return true;
                        }
                    });
                }
            });
        }
    };
}
Also used : Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Callable(java.util.concurrent.Callable) Session(org.hibernate.Session)

Example 3 with Family

use of org.hibernate.test.cache.infinispan.stress.entities.Family in project hibernate-orm by hibernate.

the class SecondLevelCacheStressTestCase method deleteOperation.

private Operation deleteOperation() {
    return new Operation("DELETE") {

        @Override
        boolean call(final int run) throws Exception {
            return captureThrowables(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return withTx(tm, new Callable<Boolean>() {

                        @Override
                        public Boolean call() throws Exception {
                            Session s = sessionFactory.openSession();
                            s.getTransaction().begin();
                            // Get each id and remove it
                            int id = removeIds.poll();
                            Family family = (Family) s.load(Family.class, id);
                            String familyName = family.getName();
                            // Skip ñ check in order to avoid issues...
                            assertTrue("Unexpected family: " + familyName, familyName.startsWith("Zamarre"));
                            s.delete(family);
                            s.getTransaction().commit();
                            s.close();
                            return true;
                        }
                    });
                }
            });
        }
    };
}
Also used : Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Callable(java.util.concurrent.Callable) Session(org.hibernate.Session)

Example 4 with Family

use of org.hibernate.test.cache.infinispan.stress.entities.Family in project hibernate-orm by hibernate.

the class SecondLevelCacheStressTestCase method updateOperation.

Operation updateOperation() {
    return new Operation("UPDATE") {

        @Override
        boolean call(final int run) throws Exception {
            return captureThrowables(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return withTx(tm, new Callable<Boolean>() {

                        @Override
                        public Boolean call() throws Exception {
                            Session s = sessionFactory.openSession();
                            s.getTransaction().begin();
                            // Update random entity that has been inserted
                            int id = RANDOM.nextInt(numEntities) + 1;
                            Family family = (Family) s.load(Family.class, id);
                            String newSecondName = "Arrizabalaga-" + run;
                            family.setSecondName(newSecondName);
                            s.getTransaction().commit();
                            s.close();
                            // Cache updated entities for later read
                            updatedIds.add(id);
                            return true;
                        }
                    });
                }
            });
        }
    };
}
Also used : Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Callable(java.util.concurrent.Callable) Session(org.hibernate.Session)

Aggregations

Family (org.hibernate.test.cache.infinispan.stress.entities.Family)4 Callable (java.util.concurrent.Callable)3 Session (org.hibernate.Session)3 HashSet (java.util.HashSet)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Person (org.hibernate.test.cache.infinispan.stress.entities.Person)1