//
// Beanshell script to run the aop tree cache demo
//
import org.jboss.cache.PropertyConfigurator;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.aop.*;
import org.jboss.cache.aop.test.*;
// Tx imports
import javax.transaction.UserTransaction;
import javax.naming.*;
import org.jboss.cache.transaction.DummyTransactionManager;

show();  // verbose mode

// Set up transaction manager
//System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
  //  "org.jboss.cache.transaction.DummyContextFactory");
DummyTransactionManager.getInstance();

prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
    "org.jboss.cache.transaction.DummyContextFactory");
tx = (UserTransaction)new InitialContext(prop).lookup("UserTransaction");

tree = new PojoCache();
config = new PropertyConfigurator();
// configure tree cache. 
config.configure(tree, "META-INF/oodb-service.xml");
tree.startService();  // kick start tree cache

if(!tree.exists("/aop/joe")) {
  System.out.println("creating new instance of Person");
  joe = new Person();
  joe.setName("Joe Black");
  joe.setAge(31);

  addr = new Address();
  addr.setCity("Sunnyvale");
  addr.setStreet("123 Albert Ave");
  addr.setZip(94086);
  joe.setAddress(addr);
  tree.putObject("/aop/joe", joe); // add aop sanctioned object
}
else {
  System.out.println("Joe already exists - retrieving it from JBossCache");
  joe=tree.getObject("/aop/joe");
  System.out.println("Joe is " + joe);
}






// tree.stopService(); // will stop the cache
