[jboss-cvs] JBossCache/migration/examples/cacheloader-migration/src/examples ...
Galder Zamarreno
galder.zamarreno at jboss.com
Wed Mar 7 18:32:06 EST 2007
User: gzamarreno
Date: 07/03/07 18:32:06
Added: migration/examples/cacheloader-migration/src/examples
TransformStore.java
Log:
[JBCACHE-964] Work committed:
- Transforming Cache Loaders implemented and unit tests provided
- migration folder structure. See JIRA.
- build.xml modified to compile, jar, create manifest for migration jar
and also added examples and migration jar to distros.
- example created and tested; it includes readme.txt with details of the
example and how to run it.
Still TODO:
- Unit tests for transforming cache loaders need to run from build.xml
- Documentation for transforming cache loaders in users guide, what are
they, when to use them,...etc.
- Fix JBCACHE-877 that occurrs when unzipping JBossCache-core-2.0.0.BETA2.zip
and running the examples. Workaround is to bring trove.jar into its lib.
- Get examples/cacheloader-migration/build.sh working
- Move JDBCCacheLoaderOld to the migration side. It's not that straightforward due to classes in
/src having dependencies on it. Needs further study.
Revision Changes Path
1.1 date: 2007/03/07 23:32:06; author: gzamarreno; state: Exp;JBossCache/migration/examples/cacheloader-migration/src/examples/TransformStore.java
Index: TransformStore.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package examples;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.Node;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Cache store transforming example
*
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
*/
public class TransformStore
{
/* Type of cache loader, either use "jdbccl" for JDBCCacheLoader or "fcl" for FileCacheLoader */
public static final String CL_TYPE = System.getProperty("cacheloader.type", "jdbccl");
private static Log log = LogFactory.getLog(TransformStore.class);
public static void main(String[] args) throws Exception
{
TransformStore ts = new TransformStore();
String transformConfigName = "transform-" + CL_TYPE + "-service.xml";
log.info("Transforming configuration file: " + transformConfigName);
Cache transformingCache = ts.createAndStartCache(transformConfigName);
ts.transformCacheStore(transformingCache);
ts.stopAndDestroyCache(transformingCache);
String originalConfigName = "original-" + CL_TYPE + "-service.xml";
log.info("Original configuration file: " + originalConfigName);
Cache checkingCache = ts.createAndStartCache(originalConfigName);
ts.checkCacheStore(checkingCache);
ts.stopAndDestroyCache(checkingCache);
}
public Cache createAndStartCache(String configFile)
{
return DefaultCacheFactory.getInstance().createCache(configFile, true);
}
public void stopAndDestroyCache(Cache cache)
{
cache.stop();
cache.destroy();
}
public void transformCacheStore(Cache cache)
{
log.info("Transforming 1.x cache store");
transformNode(cache, cache.getRoot());
log.info("Cache store transformed to 2.x format");
}
public void transformNode(Cache cache, Node node)
{
cache.put(node.getFqn(), node.getData());
log.info(node.getFqn() + " transformed");
for (Node child : node.getChildren())
{
transformNode(cache, child);
}
}
public void checkCacheStore(Cache cache)
{
checkNode(cache, cache.getRoot());
}
public void checkNode(Cache cache, Node node)
{
log.info("Node: " + node.getFqn() + " | Data: " + node.getData());
for (Node child : node.getChildren())
{
checkNode(cache, child);
}
}
}
More information about the jboss-cvs-commits
mailing list