Example usage for org.hibernate Cache containsCollection

List of usage examples for org.hibernate Cache containsCollection

Introduction

In this page you can find the example usage for org.hibernate Cache containsCollection.

Prototype

@SuppressWarnings({ "UnusedDeclaration" })
boolean containsCollection(String role, Serializable ownerIdentifier);

Source Link

Document

Determine whether the cache contains data for the given collection.

Usage

From source file:com.github.shyiko.rook.target.hibernate.cache.SecondLevelCacheSynchronizerTest.java

License:Apache License

@Test
public void testEvictionOfEntityCollection() throws Exception {
    final Cache cache = synchronizationContext.getSessionFactory().getCache();
    final AtomicLong idHolder = new AtomicLong();

    executeInTransaction(new Callback<Session>() {

        @Override/*from   w w w. j a v a  2 s  .c  om*/
        public void execute(Session session) {
            Entity entity = new Entity();
            entity.setName("Name");

            EntityProperty entityProperty = new EntityProperty();
            entityProperty.setName("name");
            entityProperty.setValue("value");
            entityProperty.setEnclosingEntity(entity);
            entity.getProperties().add(entityProperty);

            idHolder.set((Long) session.save(entity));
        }
    });
    final long ENTITY_ID = idHolder.get();

    executeInTransaction(new Callback<Session>() {

        @Override
        public void execute(Session session) {
            assertNotNull(session.get(Entity.class, ENTITY_ID));
        }
    });

    executeInTransaction(new Callback<Session>() {

        @Override
        public void execute(Session obj) {
            assertTrue(cache.containsEntity(Entity.class, ENTITY_ID));
            SecondLevelCacheSynchronizer secondLevelCacheSynchronizer = new SecondLevelCacheSynchronizer(
                    synchronizationContext);
            secondLevelCacheSynchronizer.onEvent(
                    new DeleteRowsReplicationEvent(0, "rook", "entity", new Serializable[] { ENTITY_ID }));
            assertFalse(cache.containsEntity(Entity.class, ENTITY_ID));

            assertTrue(cache.containsCollection(Entity.class.getName() + ".properties", ENTITY_ID));

            // entity_property table structure [id, name, value, entity_id]
            secondLevelCacheSynchronizer.onEvent(new DeleteRowsReplicationEvent(0, "rook", "entity_property",
                    new Serializable[] { null, null, null, ENTITY_ID }));

            assertFalse(cache.containsCollection(Entity.class.getName() + ".properties", ENTITY_ID));
        }
    });
}