Author: cbredesen
Date: 2009-06-16 10:35:22 -0400 (Tue, 16 Jun 2009)
New Revision: 16796
Added:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicCacheTest.java
Removed:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicEntityTest.java
Modified:
core/branches/INFINISPAN/cache-infinispan/pom.xml
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.hbm.xml
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.java
core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties
Log:
Refactoring, extra test coverage, fixes
Modified: core/branches/INFINISPAN/cache-infinispan/pom.xml
===================================================================
--- core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-06-16 14:34:28 UTC (rev 16795)
+++ core/branches/INFINISPAN/cache-infinispan/pom.xml 2009-06-16 14:35:22 UTC (rev 16796)
@@ -25,7 +25,7 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
- <version>4.0.0.ALPHA3</version>
+ <version>4.0.0.ALPHA5</version>
</dependency>
<!-- test dependencies -->
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,34 +0,0 @@
-package org.hibernate.cache.infinispan;
-
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.GeneralDataRegion;
-import org.infinispan.Cache;
-
-/**
- * Support for Infinispan {@link GeneralDataRegion} implementors.
- *
- * @author Chris Bredesen
- */
-public abstract class BaseGeneralDataRegion extends BaseRegion implements
GeneralDataRegion {
-
- public BaseGeneralDataRegion( Cache<Object, Object> cache, String name ) {
- super( cache, name );
- }
-
- public void evict( Object key ) throws CacheException {
- getCache().evict( key );
- }
-
- public void evictAll() throws CacheException {
- getCache().clear();
- }
-
- public Object get( Object key ) throws CacheException {
- return getCache().get( key );
- }
-
- public void put( Object key, Object value ) throws CacheException {
- getCache().put( key, value );
- }
-
-}
\ No newline at end of file
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,76 +0,0 @@
-package org.hibernate.cache.infinispan;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.hibernate.cache.CacheException;
-import org.hibernate.cache.Region;
-import org.infinispan.Cache;
-
-/**
- * Support for Infinispan {@link Region}s. Handles common "utility" methods
for
- * an underlying named Cache. In other words, this implementation doesn't
- * actually read or write data. Subclasses are expected to provide core cache
- * interaction appropriate to the semantics needed.
- *
- * @author Chris Bredesen
- */
-abstract class BaseRegion implements Region {
- private final Cache<Object, Object> cache;
- private final String name;
-
- public BaseRegion( Cache<Object, Object> cache, String name ) {
- this.cache = cache;
- this.name = name;
- }
-
- public Cache<Object, Object> getCache() {
- return cache;
- }
-
- public String getName() {
- return name;
- }
-
- public long getElementCountInMemory() {
- return cache.size();
- }
-
- /**
- * Not supported.
- *
- * @return -1
- */
- public long getElementCountOnDisk() {
- return -1;
- }
-
- /**
- * Not supported.
- *
- * @return -1
- */
- public long getSizeInMemory() {
- return -1;
- }
-
- public int getTimeout() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long nextTimestamp() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @SuppressWarnings("unchecked")
- public Map toMap() {
- return Collections.EMPTY_MAP;
- }
-
- public void destroy() throws CacheException {
- // TODO see if we need to do this even in spite of RF.shutdown()
- }
-
-}
\ No newline at end of file
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,28 +0,0 @@
-package org.hibernate.cache.infinispan;
-
-import org.hibernate.cache.CacheDataDescription;
-import org.hibernate.cache.TransactionalDataRegion;
-import org.infinispan.Cache;
-
-/**
- * Support for Inifinispan {@link TransactionalDataRegion} implementors.
- *
- * @author Chris Bredesen
- */
-public abstract class BaseTransactionalDataRegion extends BaseRegion implements
TransactionalDataRegion {
- private final CacheDataDescription metadata;
-
- public BaseTransactionalDataRegion( Cache<Object, Object> cache, String name,
CacheDataDescription metadata ) {
- super( cache, name );
- this.metadata = metadata;
- }
-
- public CacheDataDescription getCacheDataDescription() {
- return metadata;
- }
-
- public boolean isTransactionAware() {
- return true;
- }
-
-}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/InfinispanCollectionRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -5,7 +5,7 @@
import org.hibernate.cache.CollectionRegion;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
-import org.hibernate.cache.infinispan.BaseTransactionalDataRegion;
+import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
import org.infinispan.Cache;
public class InfinispanCollectionRegion extends BaseTransactionalDataRegion implements
CollectionRegion {
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -2,25 +2,23 @@
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion;
-import org.hibernate.cache.Region;
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.access.SoftLock;
public class ReadOnlyAccess implements CollectionRegionAccessStrategy {
- private final Region region;
+ private final InfinispanCollectionRegion region;
- public ReadOnlyAccess( Region region ) {
+ public ReadOnlyAccess( InfinispanCollectionRegion region ) {
this.region = region;
}
public void evict( Object key ) throws CacheException {
- // TODO Auto-generated method stub
-
+ region.getCache().evict( key );
}
public void evictAll() throws CacheException {
- // TODO Auto-generated method stub
-
+ // TODO ensure proper clustering semantics here
+ region.getCache().clear();
}
public Object get( Object key, long txTimestamp ) throws CacheException {
@@ -29,8 +27,7 @@
}
public CollectionRegion getRegion() {
- // TODO Auto-generated method stub
- return null;
+ return region;
}
public SoftLock lockItem( Object key, Object version ) throws CacheException {
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -2,77 +2,72 @@
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion;
-import org.hibernate.cache.Region;
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.access.SoftLock;
+/**
+ * Transactional collection region access for Infinispan.
+ *
+ * @author Chris Bredesen
+ */
public class TransactionalAccess implements CollectionRegionAccessStrategy {
- private final Region region;
+ private final InfinispanCollectionRegion region;
- public TransactionalAccess( Region region ) {
+ public TransactionalAccess( InfinispanCollectionRegion region ) {
this.region = region;
}
public void evict( Object key ) throws CacheException {
- // TODO Auto-generated method stub
-
+ region.getCache().evict( key );
}
public void evictAll() throws CacheException {
- // TODO Auto-generated method stub
-
+ // TODO ensure proper clustering semantics
+ region.getCache().clear();
}
public Object get( Object key, long txTimestamp ) throws CacheException {
- // TODO Auto-generated method stub
- return null;
+ return region.getCache().get( key );
}
- public CollectionRegion getRegion() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public SoftLock lockItem( Object key, Object version ) throws CacheException {
- // TODO Auto-generated method stub
- return null;
- }
-
- public SoftLock lockRegion() throws CacheException {
- // TODO Auto-generated method stub
- return null;
- }
-
public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version
)
throws CacheException {
- // TODO Auto-generated method stub
- return false;
+ region.getCache().putForExternalRead( key, value );
+ return true;
}
public boolean putFromLoad( Object key, Object value, long txTimestamp, Object version,
boolean minimalPutOverride ) throws CacheException {
- // TODO Auto-generated method stub
- return false;
+ region.getCache().putForExternalRead( key, value );
+ return true;
}
public void remove( Object key ) throws CacheException {
- // TODO Auto-generated method stub
-
+ region.getCache().remove( key );
}
public void removeAll() throws CacheException {
- // TODO Auto-generated method stub
+ region.getCache().clear();
+ }
+ public CollectionRegion getRegion() {
+ return region;
}
- public void unlockItem( Object key, SoftLock lock ) throws CacheException {
- // TODO Auto-generated method stub
+ // following methods copied from o.h.c.jbc2.collection.TransactionalAccess
- }
+ public SoftLock lockItem(Object key, Object version) throws CacheException {
+ return null;
+ }
- public void unlockRegion( SoftLock lock ) throws CacheException {
- // TODO Auto-generated method stub
+ public SoftLock lockRegion() throws CacheException {
+ return null;
+ }
- }
+ public void unlockItem(Object key, SoftLock lock) throws CacheException {
+ }
-}
+ public void unlockRegion(SoftLock lock) throws CacheException {
+ }
+
+}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/InfinispanEntityRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -5,7 +5,7 @@
import org.hibernate.cache.EntityRegion;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cache.access.EntityRegionAccessStrategy;
-import org.hibernate.cache.infinispan.BaseTransactionalDataRegion;
+import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
import org.infinispan.Cache;
public class InfinispanEntityRegion extends BaseTransactionalDataRegion implements
EntityRegion {
Copied:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
(from rev 16771,
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseGeneralDataRegion.java)
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -0,0 +1,34 @@
+package org.hibernate.cache.infinispan.impl;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.GeneralDataRegion;
+import org.infinispan.Cache;
+
+/**
+ * Support for Infinispan {@link GeneralDataRegion} implementors.
+ *
+ * @author Chris Bredesen
+ */
+public abstract class BaseGeneralDataRegion extends BaseRegion implements
GeneralDataRegion {
+
+ public BaseGeneralDataRegion( Cache<Object, Object> cache, String name ) {
+ super( cache, name );
+ }
+
+ public void evict( Object key ) throws CacheException {
+ getCache().evict( key );
+ }
+
+ public void evictAll() throws CacheException {
+ getCache().clear();
+ }
+
+ public Object get( Object key ) throws CacheException {
+ return getCache().get( key );
+ }
+
+ public void put( Object key, Object value ) throws CacheException {
+ getCache().put( key, value );
+ }
+
+}
\ No newline at end of file
Property changes on:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
(from rev 16778,
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseRegion.java)
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -0,0 +1,76 @@
+package org.hibernate.cache.infinispan.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.Region;
+import org.infinispan.Cache;
+
+/**
+ * Support for Infinispan {@link Region}s. Handles common "utility" methods
for
+ * an underlying named Cache. In other words, this implementation doesn't
+ * actually read or write data. Subclasses are expected to provide core cache
+ * interaction appropriate to the semantics needed.
+ *
+ * @author Chris Bredesen
+ */
+abstract class BaseRegion implements Region {
+ private final Cache<Object, Object> cache;
+ private final String name;
+
+ public BaseRegion( Cache<Object, Object> cache, String name ) {
+ this.cache = cache;
+ this.name = name;
+ }
+
+ public Cache<Object, Object> getCache() {
+ return cache;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public long getElementCountInMemory() {
+ return cache.size();
+ }
+
+ /**
+ * Not supported.
+ *
+ * @return -1
+ */
+ public long getElementCountOnDisk() {
+ return -1;
+ }
+
+ /**
+ * Not supported.
+ *
+ * @return -1
+ */
+ public long getSizeInMemory() {
+ return -1;
+ }
+
+ public int getTimeout() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long nextTimestamp() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map toMap() {
+ return Collections.EMPTY_MAP;
+ }
+
+ public void destroy() throws CacheException {
+ // TODO see if we need to do this even in spite of RF.shutdown()
+ }
+
+}
\ No newline at end of file
Property changes on:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
(from rev 16771,
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/BaseTransactionalDataRegion.java)
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -0,0 +1,28 @@
+package org.hibernate.cache.infinispan.impl;
+
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.TransactionalDataRegion;
+import org.infinispan.Cache;
+
+/**
+ * Support for Inifinispan {@link TransactionalDataRegion} implementors.
+ *
+ * @author Chris Bredesen
+ */
+public abstract class BaseTransactionalDataRegion extends BaseRegion implements
TransactionalDataRegion {
+ private final CacheDataDescription metadata;
+
+ public BaseTransactionalDataRegion( Cache<Object, Object> cache, String name,
CacheDataDescription metadata ) {
+ super( cache, name );
+ this.metadata = metadata;
+ }
+
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+
+ public boolean isTransactionAware() {
+ return true;
+ }
+
+}
\ No newline at end of file
Property changes on:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/query/InfinispanQueryResultsRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,7 +1,7 @@
package org.hibernate.cache.infinispan.query;
import org.hibernate.cache.QueryResultsRegion;
-import org.hibernate.cache.infinispan.BaseGeneralDataRegion;
+import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
import org.infinispan.Cache;
public class InfinispanQueryResultsRegion extends BaseGeneralDataRegion implements
QueryResultsRegion {
Modified:
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/InfinispanTimestampsRegion.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,7 +1,7 @@
package org.hibernate.cache.infinispan.timestamp;
import org.hibernate.cache.TimestampsRegion;
-import org.hibernate.cache.infinispan.BaseGeneralDataRegion;
+import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
import org.infinispan.Cache;
public class InfinispanTimestampsRegion extends BaseGeneralDataRegion implements
TimestampsRegion {
Copied:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicCacheTest.java
(from rev 16778,
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicEntityTest.java)
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicCacheTest.java
(rev 0)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicCacheTest.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -0,0 +1,93 @@
+package org.hibernate.test.cache.infinispan.functional;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.stat.SecondLevelCacheStatistics;
+import org.hibernate.stat.Statistics;
+
+public class BasicCacheTest extends FunctionalTestCase {
+
+ public BasicCacheTest( String string ) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "cache/infinispan/functional/Item.hbm.xml" };
+ }
+
+ @Override
+ public String getCacheConcurrencyStrategy() {
+ return "transactional";
+ }
+
+ public void testEntityCache() {
+ Item item = new Item("chris", "Chris's Item");
+
+ Session s = openSession();
+ Statistics stats = s.getSessionFactory().getStatistics();
+ s.getTransaction().begin();
+ s.persist( item );
+ s.getTransaction().commit();
+ s.close();
+
+ stats.clear();
+ s = openSession();
+ Item found = (Item) s.load( Item.class, item.getId() );
+ System.out.println( stats );
+ assertEquals( item.getDescription(), found.getDescription() );
+ assertEquals( 0, stats.getSecondLevelCacheMissCount() );
+ assertEquals( 1, stats.getSecondLevelCacheHitCount() );
+ s.delete( found );
+ s.close();
+ }
+
+ public void testQueryCache() {
+ Item item = new Item( "chris", "Chris's Item" );
+
+ Session s = openSession();
+ s.getTransaction().begin();
+ s.persist( item );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.createQuery( "from Item" ).setCacheable( true ).list();
+ s.close();
+
+ s = openSession();
+ Statistics stats = s.getSessionFactory().getStatistics();
+ stats.clear();
+ s.createQuery( "from Item" ).setCacheable( true ).list();
+ assertEquals( 1, stats.getQueryCacheHitCount() );
+ s.createQuery( "delete from Item" ).executeUpdate();
+ s.close();
+ }
+
+ public void testCollectionCache() {
+ Item item = new Item( "chris", "Chris's Item" );
+ Item another = new Item( "another", "Owned Item" );
+ item.addItem( another );
+
+ Session s = openSession();
+ s.getTransaction().begin();
+ s.persist( another );
+ s.persist( item );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ Item loaded = (Item) s.load( Item.class, item.getId() );
+ assertEquals( 1, loaded.getItems().size() );
+ s.close();
+
+ s = openSession();
+ Statistics stats = s.getSessionFactory().getStatistics();
+ stats.clear();
+ SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(
Item.class.getName() + ".items" );
+ Item loadedWithCachedCollection = (Item) s.load( Item.class, item.getId() );
+ assertEquals( 1, loadedWithCachedCollection.getItems().size() );
+ assertEquals( 1, cStats.getHitCount() );
+ s.close();
+ }
+
+}
\ No newline at end of file
Property changes on:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicCacheTest.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicEntityTest.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicEntityTest.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicEntityTest.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -1,45 +0,0 @@
-package org.hibernate.test.cache.infinispan.functional;
-
-import org.hibernate.Session;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.stat.Statistics;
-
-public class BasicEntityTest extends FunctionalTestCase {
-
- public BasicEntityTest( String string ) {
- super( string );
- }
-
- public String[] getMappings() {
- return new String[] { "cache/infinispan/functional/Item.hbm.xml" };
- }
-
- @Override
- public String getCacheConcurrencyStrategy() {
- return "transactional";
- }
-
- public void testEntityCache() {
- Item item = new Item();
- item.setName( "chris" );
- item.setDescription( "Chris's Item" );
-
- Session s = openSession();
- Statistics stats = s.getSessionFactory().getStatistics();
- s.getTransaction().begin();
- s.persist( item );
- s.getTransaction().commit();
- s.close();
-
- stats.clear();
- s = openSession();
- Item found = (Item) s.load( Item.class, item.getId() );
- System.out.println( stats );
- assertEquals( item.getDescription(), found.getDescription() );
- assertEquals( 0, stats.getSecondLevelCacheMissCount() );
- assertEquals( 1, stats.getSecondLevelCacheHitCount() );
- s.delete( found );
- s.close();
- }
-
-}
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.hbm.xml
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.hbm.xml 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.hbm.xml 2009-06-16
14:35:22 UTC (rev 16796)
@@ -35,6 +35,11 @@
</id>
<property name="name" not-null="true"/>
<property name="description" not-null="true"/>
+ <many-to-one name="owner" column="owner_id"
class="Item" />
+ <set name="items" inverse="true">
+ <key column="owner_id" />
+ <one-to-many class="Item"/>
+ </set>
</class>
<class name="VersionedItem" table="VersionedItems">
@@ -46,4 +51,4 @@
<property name="description" not-null="true"/>
</class>
-</hibernate-mapping>
+</hibernate-mapping>
\ No newline at end of file
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.java
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.java 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/Item.java 2009-06-16
14:35:22 UTC (rev 16796)
@@ -23,6 +23,9 @@
*/
package org.hibernate.test.cache.infinispan.functional;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* @author Gavin King
*/
@@ -30,8 +33,17 @@
private Long id;
private String name;
private String description;
+ private Item owner;
+ private Set<Item> items = new HashSet<Item>();
- public String getDescription() {
+ public Item() {}
+
+ public Item( String name, String description ) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public String getDescription() {
return description;
}
@@ -54,4 +66,25 @@
public void setName(String name) {
this.name = name;
}
+
+ public Item getOwner() {
+ return owner;
+ }
+
+ public void setOwner( Item owner ) {
+ this.owner = owner;
+ }
+
+ public Set<Item> getItems() {
+ return items;
+ }
+
+ public void setItems( Set<Item> items ) {
+ this.items = items;
+ }
+
+ public void addItem( Item item ) {
+ item.setOwner( this );
+ getItems().add( item );
+ }
}
Modified:
core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties
===================================================================
---
core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties 2009-06-16
14:34:28 UTC (rev 16795)
+++
core/branches/INFINISPAN/cache-infinispan/src/test/resources/hibernate.properties 2009-06-16
14:35:22 UTC (rev 16796)
@@ -36,4 +36,5 @@
hibernate.generate_statistics true
hibernate.cache.use_second_level_cache true
+hibernate.cache.use_query_cache true
hibernate.cache.region.factory_class
org.hibernate.cache.infinispan.InfinispanRegionFactory
\ No newline at end of file