[hibernate-commits] Hibernate SVN: r11524 - in trunk/sandbox/maven-poc/Hibernate3: cache-jbosscache2 and 7 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon May 14 17:48:31 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-14 17:48:31 -0400 (Mon, 14 May 2007)
New Revision: 11524
Added:
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java
trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java
Log:
fix deps to account for jbosscache "transitive" deps...
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/pom.xml 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core-project</artifactId>
+ <version>3.3.0.beta1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jbosscache2</artifactId>
+ <packaging>jar</packaging>
+ <name>Hibernate JBossCache2.x integration</name>
+ <description>Integration of Hibernate with JBossCache (based on JBossCache2.x APIs)</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-cache</artifactId>
+ <!-- does not work with idea plugin :(
+ <version>[2.0.0.BETA2,)</version>
+ -->
+ <version>2.0.0.BETA2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-idea-plugin</artifactId>
+ <configuration>
+ <jdkName>1.5</jdkName>
+ <jdkLevel>5.0</jdkLevel>
+ <!-- why this isnt the default I have no clue -->
+ <linkModules>true</linkModules>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TransactionManagerLookupAdaptor.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,25 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Properties;
+import javax.transaction.TransactionManager;
+
+import org.hibernate.transaction.TransactionManagerLookup;
+
+/**
+ * An adapter between JBossCache's notion of a TM lookup and Hibernate's.
+ *
+ * @author Steve Ebersole
+ */
+public class TransactionManagerLookupAdaptor implements org.jboss.cache.transaction.TransactionManagerLookup {
+ private final TransactionManagerLookup tml;
+ private final Properties props;
+
+ TransactionManagerLookupAdaptor(TransactionManagerLookup tml, Properties props) {
+ this.tml = tml;
+ this.props = props;
+ }
+
+ public TransactionManager getTransactionManager() throws Exception {
+ return tml.getTransactionManager( props );
+ }
+}
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionAdapter.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,105 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Node;
+import org.jboss.cache.config.Option;
+
+import org.hibernate.cache.Region;
+import org.hibernate.cache.CacheException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class TreeCacheRegionAdapter implements Region {
+ private static final String ITEM = "item";
+
+ protected final Node jbcNode;
+ protected final String regionName;
+
+ public TreeCacheRegionAdapter(Cache jbcCache, String regionName) {
+ this.regionName = regionName;
+ Fqn fqn = Fqn.fromString( regionName.replace( '.', '/' ) );
+ this.jbcNode = jbcCache.getRoot().addChild( fqn );
+ }
+
+ public String getName() {
+ return regionName;
+ }
+
+ public void destroy() throws CacheException {
+ try {
+ // NOTE : this is being used from the process of shutting down a
+ // SessionFactory. Specific things to consider:
+ // (1) this clearing of the region should not propogate to
+ // other nodes on the cluster (if any); this is the
+ // cache-mode-local option bit...
+ // (2) really just trying a best effort to cleanup after
+ // ourselves; lock failures, etc are not critical here;
+ // this is the fail-silently option bit...
+ Option option = new Option();
+ option.setCacheModeLocal( true );
+ option.setFailSilently( true );
+ jbcNode.
+ jbcTreeCache.remove( regionFqn, option );
+ }
+ catch( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public long getSizeInMemory() {
+ // not supported
+ return -1;
+ }
+
+ public long getElementCountInMemory() {
+ try {
+ Set children = jbcTreeCache.getChildrenNames( regionFqn );
+ return children == null ? 0 : children.size();
+ }
+ catch ( Exception e ) {
+ throw new CacheException( e );
+ }
+ }
+
+ public long getElementCountOnDisk() {
+ return -1;
+ }
+
+ public Map toMap() {
+ try {
+ Map result = new HashMap();
+ Set childrenNames = jbcTreeCache.getChildrenNames( regionFqn );
+ if (childrenNames != null) {
+ Iterator iter = childrenNames.iterator();
+ while ( iter.hasNext() ) {
+ Object key = iter.next();
+ result.put(
+ key,
+ jbcTreeCache.get( new Fqn( regionFqn, key ), ITEM )
+ );
+ }
+ }
+ return result;
+ }
+ catch (Exception e) {
+ throw new CacheException(e);
+ }
+ }
+
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
+
+ public int getTimeout() {
+ return 600; //60 seconds
+ }
+}
Added: trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java
===================================================================
--- trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/Hibernate3/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc/TreeCacheRegionFactory.java 2007-05-14 21:48:31 UTC (rev 11524)
@@ -0,0 +1,226 @@
+package org.hibernate.cache.impl.jbc;
+
+import java.util.Properties;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+
+import org.hibernate.cache.RegionFactory;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.EntityRegion;
+import org.hibernate.cache.CacheDataDescription;
+import org.hibernate.cache.CollectionRegion;
+import org.hibernate.cache.QueryResultsRegion;
+import org.hibernate.cache.TimestampsRegion;
+import org.hibernate.cache.access.EntityRegionAccessStrategy;
+import org.hibernate.cache.access.AccessType;
+import org.hibernate.cfg.Settings;
+import org.hibernate.util.PropertiesHelper;
+
+/**
+ * A factory for building regions based on a JBossCache
+ * {@link org.jboss.cache.Node}. Here we are utilizing the
+ * same underlying {@link org.jboss.cache.Node} instance for each jbcTreeCache region.
+ *
+ * @author Steve Ebersole
+ */
+public class TreeCacheRegionFactory implements RegionFactory {
+ public static final String ENTITY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.entity";
+ public static final String COLL_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.collection";
+ public static final String TS_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.ts";
+ public static final String QUERY_CACHE_RESOURCE_PROP = "hibernate.cache.region.jbc.cfg.query";
+
+ public static final String DEF_ENTITY_RESOURCE = "entity-cache.xml";
+ public static final String DEF_COLL_RESOURCE = "collection-cache.xml";
+ public static final String DEF_TS_RESOURCE = "ts-cache.xml";
+ public static final String DEF_QUERY_RESOURCE = "query-cache.xml";
+
+ public static final String OPTIMISTIC_LOCKING_SCHEME = "OPTIMISTIC";
+
+ private static final Log log = LogFactory.getLog( TreeCacheRegionFactory.class );
+
+ private Cache jbcEntityCache;
+ private Cache jbcCollectionCache;
+ private Cache jbcTsCache;
+ private Cache jbcQueryCache;
+ private boolean useOptimisticLocking;
+
+ public void start(Settings settings, Properties properties) throws CacheException {
+ try {
+ TransactionManager tm = settings.getTransactionManagerLookup() == null
+ ? null
+ : settings.getTransactionManagerLookup().getTransactionManager( properties );
+ if ( settings.isSecondLevelCacheEnabled() ) {
+ jbcEntityCache = buildEntityRegionCacheInstance( properties );
+ jbcCollectionCache = buildCollectionRegionCacheInstance( properties );
+ if ( tm != null ) {
+ jbcEntityCache.getConfiguration().getRuntimeConfig().setTransactionManager( tm );
+ jbcCollectionCache.getConfiguration().getRuntimeConfig().setTransactionManager( tm );
+ }
+ }
+ if ( settings.isQueryCacheEnabled() ) {
+ jbcTsCache = buildTsRegionCacheInstance( properties );
+ jbcQueryCache = buildQueryRegionCacheInstance( properties );
+ }
+ }
+ catch( CacheException ce ) {
+ throw ce;
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "Unable to start region factory", t );
+ }
+// String resource = PropertiesHelper.getString( Environment.CACHE_PROVIDER_CONFIG, properties, DEFAULT_CONFIG );
+// log.debug( "Configuring basic TreeCache RegionFactory from resource [" + resource + "]" );
+// try {
+// jbcTreeCache = new TreeCache();
+// PropertyConfigurator config = new PropertyConfigurator();
+// config.configure( jbcTreeCache, resource );
+// TransactionManagerLookup transactionManagerLookup = settings.getTransactionManagerLookup();
+// if ( transactionManagerLookup != null ) {
+// jbcTreeCache.setTransactionManagerLookup(
+// new TransactionManagerLookupAdaptor( transactionManagerLookup, properties )
+// );
+// }
+// jbcTreeCache.start();
+// useOptimisticLocking = OPTIMISTIC_LOCKING_SCHEME.equalsIgnoreCase( jbcTreeCache.getNodeLockingScheme() );
+// }
+// catch ( Exception e ) {
+// throw new CacheException( e );
+// }
+ }
+
+ protected Cache buildEntityRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( ENTITY_CACHE_RESOURCE_PROP, properties, DEF_ENTITY_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build entity region cache instance", t );
+ }
+ }
+
+ protected Cache buildCollectionRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( COLL_CACHE_RESOURCE_PROP, properties, DEF_COLL_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build collection region cache instance", t );
+ }
+ }
+
+ protected Cache buildTsRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( TS_CACHE_RESOURCE_PROP, properties, DEF_TS_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build timestamps region cache instance", t );
+ }
+ }
+
+ protected Cache buildQueryRegionCacheInstance(Properties properties) {
+ try {
+ String configResource = PropertiesHelper.getString( QUERY_CACHE_RESOURCE_PROP, properties, DEF_QUERY_RESOURCE );
+ return DefaultCacheFactory.getInstance().createCache( configResource );
+ }
+ catch( Throwable t ) {
+ throw new CacheException( "unable to build query region cache instance", t );
+ }
+ }
+
+ public void stop() {
+ if ( jbcEntityCache != null ) {
+ try {
+ jbcEntityCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop entity cache instance", t );
+ }
+ }
+ if ( jbcCollectionCache != null ) {
+ try {
+ jbcCollectionCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop collection cache instance", t );
+ }
+ }
+ if ( jbcTsCache != null ) {
+ try {
+ jbcTsCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop timestamp cache instance", t );
+ }
+ }
+ if ( jbcQueryCache != null ) {
+ try {
+ jbcQueryCache.stop();
+ }
+ catch( Throwable t ) {
+ log.info( "Unable to stop query cache instance", t );
+ }
+ }
+ }
+
+ public boolean isMinimalPutsEnabledByDefault() {
+ return true;
+ }
+
+ public long nextTimestamp() {
+ return System.currentTimeMillis() / 100;
+ }
+
+ public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) {
+ if ( useOptimisticLocking && !metadata.isVersioned() ) {
+ log.warn( "JBossCache configured to use optimistic locking, but entity to be cached is not versioned [" + regionName + "]" );
+ }
+ else if ( !useOptimisticLocking && metadata.isVersioned() ) {
+ log.info( "Caching versioned entity without optimisitic locking; consider optimistic locking if all cached entities are versioned" );
+ }
+ return new EntityRegionAdapter( regionName, metadata );
+ }
+
+ public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata)
+ throws CacheException {
+ return null;
+ }
+
+ public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException {
+ return null;
+ }
+
+ public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException {
+ return null;
+ }
+
+ private class EntityRegionAdapter extends TreeCacheRegionAdapter implements EntityRegion {
+ private final CacheDataDescription metadata;
+
+ public EntityRegionAdapter(String regionName, CacheDataDescription metadata) {
+ super( TreeCacheRegionFactory.this.jbcTreeCache, regionName );
+ this.metadata = metadata;
+ }
+
+ public boolean isTransactionAware() {
+ return jbcTreeCache.getTransactionManager() != null;
+ }
+
+ public CacheDataDescription getCacheDataDescription() {
+ return metadata;
+ }
+
+ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
+ if ( ! ( AccessType.READ_ONLY.equals( accessType ) || AccessType.TRANSACTIONAL.equals( accessType ) ) ) {
+ throw new CacheException( "TreeCacheRegionFactory only supports ( " + AccessType.READ_ONLY.getName() + " | " + AccessType.TRANSACTIONAL + " ) access strategies [" + accessType.getName() + "]" );
+ }
+ // todo : implement :)
+ return null;
+ }
+ }
+}
More information about the hibernate-commits
mailing list