-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: if you want tangosol REALLY work with hibernate
PostPosted: Mon Jun 13, 2005 7:00 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
The code suggested by Tangosol and hibernate forums (http://www.hibernate.org/132.html )
does not work and must be changed:

I. the package structure from "package net.sf.hibernate.cache;"
to
"package org.hibernate.cache;" in both classes: public class
CoherenceCache and public class CoherenceCacheProvider.

II. The implementation of method
"public void destroy()" of public class CoherenceCache
must be changed as it is wrapping wrong method of
com.tangosol.net.NamedCache - NamedCache.destroy() -
the cache destroyed when the node is shut down,
and hence:
1)All cached data will be lost and all other nodes of the cluster will be affected
2)Session replication would not work.

The appropriate method to use is NamedCache.release() which releases
local resources associated
with this instance of NamedCache without interference with the
whole cache shared across the cluster.
The correct code is:

***********************************************************
***********************************************************
package org.hibernate.cache;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.io.Serializable;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;


public class CoherenceCache implements Cache {
private NamedCache cache;

public CoherenceCache(NamedCache cache) {

this.cache = cache;
}

public Object get(Object key) throws CacheException {

return cache.get(key);
}

public void put(Object key, Object value) throws CacheException {

cache.put(key, value);
}

public void remove(Object key) throws CacheException {

cache.remove(key);

}

public void clear() throws CacheException {

cache.clear();
}

public void destroy() throws CacheException {

cache.release();
}

public long nextTimestamp() {

return CacheFactory.getCluster().getTimeMillis();
}

public void lock(Object key) throws CacheException {

cache.lock(key);
}

public void unlock(Object key) throws CacheException {

cache.unlock(key);
}

public int getTimeout() {

return 10000;
}

public void update(Object key, Object value) throws CacheException {

cache.put(key, value);

}


public String getRegionName() {

return cache.getCacheName();
}


public long getSizeInMemory() {

return 0;
}


public long getElementCountInMemory() {

try {
return cache.size();
}
catch (org.hibernate.cache.CacheException ce) {
throw new CacheException(ce);
}
}


public long getElementCountOnDisk() {

return 0;
}

public Map toMap() {

try {
Map result = new HashMap();
Iterator iter = cache.keySet().iterator();
while ( iter.hasNext() ) {
Object key = iter.next();
result.put( key, cache.get( (Serializable) key ) );
}
return result;
}
catch (Exception e) {
throw new CacheException(e);
}
}



}

***********************************************************
***********************************************************

package org.hibernate.cache;

import java.util.Properties;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;


public class CoherenceCacheProvider implements CacheProvider {
NamedCache cache;
public CoherenceCacheProvider(){

}
public Cache buildCache(String regionName, Properties properties)
throws CacheException {
cache = CacheFactory.getCache(regionName);

return new CoherenceCache(cache);
}

public long nextTimestamp() {

return CacheFactory.getCluster().getTimeMillis();
}


public void start(Properties properties) throws CacheException {

CacheFactory.ensureCluster();

}

public void stop() {

CacheFactory.shutdown();

}

public boolean isMinimalPutsEnabledByDefault() {

return false;
}

}

Enjoy

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 7:03 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's a wiki, you know.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 7:01 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
Christian, thanks for reminding me .
I have modified the page: http://www.hibernate.org/132.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 7:10 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't forget to get your check from Tangosol for maintaining their product :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.