[jboss-cvs] JBossCache/src/org/jboss/cache/pojo/demo ...

Galder Zamarreno galder.zamarreno at jboss.com
Wed May 16 08:33:59 EDT 2007


  User: gzamarreno
  Date: 07/05/16 08:33:58

  Added:       src/org/jboss/cache/pojo/demo    PojoCacheModelDelegate.java
                        PojoCacheGUI.java PojoCacheView.java
  Log:
  [JBCACHE-1000] JBossCache tutorial demo has been refactored to accomodate PojoCache one so that it uses the same embedded beanshell. PojoCache tutorial has been rewritten to have more similarities with JBossCache one, and has been extended with a section on Collections. Person and Address fields have been made private to promote encapsulation. Person no has a setLanguages(List<String>) to be consistent with get operation. This required fixing the ReplicatedPutWithBulkRemoveTest.
  
  Revision  Changes    Path
  1.1      date: 2007/05/16 12:33:58;  author: gzamarreno;  state: Exp;JBossCache/src/org/jboss/cache/pojo/demo/PojoCacheModelDelegate.java
  
  Index: PojoCacheModelDelegate.java
  ===================================================================
  package org.jboss.cache.pojo.demo;
  
  import org.jboss.cache.Cache;
  import org.jboss.cache.demo.CacheModelDelegate;
  import org.jboss.cache.pojo.PojoCache;
  
  /**
   * Model delegate implementation for JBossCache demo
   *
   * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
   */
  public class PojoCacheModelDelegate implements CacheModelDelegate
  {
     private PojoCache pojoCache;
  
     public void setCacheShellVariable(Object cache)
     {
        pojoCache = (PojoCache)cache;
     }
  
     public Object getCacheShellVariable()
     {
        return pojoCache;
     }
  
     public Cache getGenericCache()
     {
        return pojoCache.getCache();
     }
  }
  
  
  
  1.1      date: 2007/05/16 12:33:58;  author: gzamarreno;  state: Exp;JBossCache/src/org/jboss/cache/pojo/demo/PojoCacheGUI.java
  
  Index: PojoCacheGUI.java
  ===================================================================
  package org.jboss.cache.pojo.demo;
  
  import bsh.Interpreter;
  import bsh.EvalError;
  
  import java.util.Map;
  import java.util.TreeMap;
  
  import org.jboss.cache.demo.JBossCacheGUI;
  import org.jboss.cache.demo.CacheModelDelegate;
  
  /**
   * View for PojoCache demo.
   *
   * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
   */
  public class PojoCacheGUI extends JBossCacheGUI
  {
     public PojoCacheGUI(CacheModelDelegate cacheDelegate, boolean useConsole)
             throws Exception
     {
        super(cacheDelegate, useConsole);
     }
  
     @Override
     protected String getWelcomeMessage()
     {
        return "Welcome to the BeanShell console.\n\n" +
           "This console gives you a direct shell interface to the GUI above and allows you to manipulate the pojo cache directly. " +
           "Some of the variables initialised in this shell session are:\n\n" +
           "// an instance of org.jboss.cache.pojo\n" +
           "    PojoCache cache;\n" +
           "// the transaction manager registered with the cache\n" +
           "    TransactionManager transactionManager;\n";      
     }
  
     @Override
     protected void configureInterpreter(Interpreter interpreter, CacheModelDelegate cacheDelegate) throws EvalError
     {
        interpreter.getNameSpace().importPackage("org.jboss.cache");
        interpreter.getNameSpace().importPackage("org.jboss.cache.pojo");
        interpreter.getNameSpace().importPackage("org.jboss.cache.transaction");
        interpreter.getNameSpace().importPackage("org.jboss.cache.pojo.test");
        interpreter.set("cache", cacheDelegate.getCacheShellVariable());
        interpreter.set("transactionManager", cacheDelegate.getGenericCache().getConfiguration().getRuntimeConfig().getTransactionManager());      
     }
  
     @Override
     protected void populateTable(Map data)
     {
        Object key;
        Object val;
        int num_rows;
        clearTable();
        if (data == null) return;
        num_rows = data.size();
  
        if (num_rows > 0)
        {
           // sort this according to the natural sort order of keys
           TreeMap<Object, Object> sortedMap = new TreeMap<Object, Object>(data);
  
           for (Map.Entry<Object, Object> entry : sortedMap.entrySet())
           {
              key = entry.getKey();
              val = entry.getValue();
              getTableModel().addRow(new Object[]{key, val});
           }
           getTableModel().fireTableRowsInserted(0, num_rows - 1);
           validate();
        }
     }
  }
  
  
  
  1.1      date: 2007/05/16 12:33:58;  author: gzamarreno;  state: Exp;JBossCache/src/org/jboss/cache/pojo/demo/PojoCacheView.java
  
  Index: PojoCacheView.java
  ===================================================================
  package org.jboss.cache.pojo.demo;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.demo.JBossCacheView;
  import org.jboss.cache.demo.JBossCacheGUI;
  import org.jboss.cache.demo.CacheModelDelegate;
  
  /**
   * PojoCac
   *
   * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
   */
  public class PojoCacheView extends JBossCacheView
  {
     private static Log log = LogFactory.getLog(PojoCacheView.class.getName());
  
     @Override
     protected JBossCacheGUI createCacheGUI(CacheModelDelegate cacheDelegate, boolean useConsole) throws Exception
     {
        return new PojoCacheGUI(cacheDelegate, useConsole);
     }
  
     @Override
     protected CacheModelDelegate createCacheDelegate() throws Exception
     {
        PojoCache pojoCache = PojoCacheFactory.createCache(getConfigurationFile(), false);
        pojoCache.getCache().getConfiguration().setFetchInMemoryState(false);
  
        CacheModelDelegate delegate = new PojoCacheModelDelegate();
        delegate.setCacheShellVariable(pojoCache);
  
        return delegate;
     }
  
     public static void main(String args[])
     {
        try
        {
           JBossCacheView view = new PojoCacheView();
           view.doMain(args);
        }
        catch (Exception ex)
        {
           log.error("Cannot start up!!", ex);
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list