User: danch   
  Date: 01/06/21 20:24:49

  Modified:    src/main/org/jboss/ejb/plugins/jaws/jdbc JDBCCommand.java
                        JDBCCommandFactory.java
                        JDBCPreloadFinderCommand.java
  Log:
  extended Bill's earlier work to work on findAll and findBy commands as well
  
  Revision  Changes    Path
  1.34      +10 -1     jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java
  
  Index: JDBCCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- JDBCCommand.java  2001/06/18 14:34:27     1.33
  +++ JDBCCommand.java  2001/06/22 03:24:49     1.34
  @@ -57,7 +57,11 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dirk Zimmermann</a>
  - * @version $Revision: 1.33 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson</a>
  + * @version $Revision: 1.34 $ 
  + * 
  + * Revision:
  + * 20010621 danch: add getter for name
    */
   public abstract class JDBCCommand
   {
  @@ -125,6 +129,11 @@
         this.debug = factory.getDebug();
      }
   
  +   /** return the name of this command */
  +   public String getName() {
  +      return name;
  +   }
  +   
      // Protected -----------------------------------------------------
   
      /**
  
  
  
  1.12      +30 -12    
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommandFactory.java
  
  Index: JDBCCommandFactory.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommandFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JDBCCommandFactory.java   2001/06/21 21:55:01     1.11
  +++ JDBCCommandFactory.java   2001/06/22 03:24:49     1.12
  @@ -69,11 +69,13 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="[EMAIL PROTECTED]">danch (Dan Christopherson)</a>
    * @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    *
    * Revision:
    * 20010621 Bill Burke: createDefinedFinderCommand creates different objects
  - * based on the read-head flag of the FinderMetaData.
  + *    based on the read-head flag of the FinderMetaData.
  + * 20010621 danch: extended Bill's change to work on other finder types; 
  + *    removed stale todos. 
    */
   public class JDBCCommandFactory implements JPMCommandFactory
   {
  @@ -95,12 +97,10 @@
      
      /** a map of data preloaded within some transaction for some entity. This map
       *  is keyed by Transaction and the data are hashmaps with key = entityKey and
  -    *  data = Object[] containing the entity data. 
  -    *  @todo use weak references to ease memory. */
  +    *  data = Object[] containing the entity data.  */
      private Map preloadedData = new HashMap();
      /** A map of data preloaded without a transaction context. key=entityKey, 
       *  data = Object[] containing entity data
  -    *  @todo use weak references to ease memory. 
       */
      private Map nonTransactionalPreloadData = new HashMap();
      
  @@ -125,7 +125,7 @@
      {
         this.container = container;
         this.log = log;
  -       
  +     
         this.javaCtx = (Context)new InitialContext().lookup("java:comp/env");
         
         String ejbName = container.getBeanMetaData().getEjbName();
  @@ -144,10 +144,10 @@
         if (metadata == null) {
            throw new DeploymentException("No metadata found for bean " + ejbName);
         }
  -            
  +      
         tm = (TransactionManager) container.getTransactionManager();
         
  -      softRefHandler.schedule(new PreloadRefQueueHandlerTask(), 50);
  +      softRefHandler.schedule(new PreloadRefQueueHandlerTask());
      }
      
      // Public --------------------------------------------------------
  @@ -195,7 +195,14 @@
      
      public JPMFindEntitiesCommand createFindAllCommand(FinderMetaData f)
      {
  -      return new JDBCFindAllCommand(this, f);
  +      if (f.hasReadAhead())
  +      {
  +         return new JDBCPreloadFinderCommand(this, new JDBCFindAllCommand(this, f));
  +      }
  +      else 
  +      {
  +         return new JDBCFindAllCommand(this, f);
  +      }
      }
      
      public JPMFindEntitiesCommand createDefinedFinderCommand(FinderMetaData f)
  @@ -213,7 +220,14 @@
      public JPMFindEntitiesCommand createFindByCommand(Method finderMethod, 
FinderMetaData f)
         throws IllegalArgumentException
      {
  -      return new JDBCFindByCommand(this, finderMethod, f);
  +      if (f.hasReadAhead())
  +      {
  +         return new JDBCPreloadFinderCommand(this, new JDBCFindByCommand(this, 
finderMethod, f));
  +      }
  +      else 
  +      {
  +         return new JDBCFindByCommand(this, finderMethod, f);
  +      }
      }
      
      // JPMCommandFactory implementation ------------------------------
  @@ -402,11 +416,14 @@
       *  Reference.clear() 
      */
      private class PreloadRefQueueHandlerTask extends TimerTask {
  -     public void execute() throws Exception {
  +      PreloadRefQueueHandlerTask() {
  +         super(50);
  +      }
  +      
  +      public void execute() throws Exception {
            PreloadData preloadData = (PreloadData)preloadRefQueue.poll();
            int handled = 0;
            while (preloadData != null && handled < 10) {
  -            log.debug("PRELOAD: clearing "+preloadData.getKey());
               if (preloadData.getTransaction() != null) {
                  Map entitiesInTransaction = null;
                  // Do we really need this to be syncrhonized? What is the effect of 
  @@ -433,6 +450,7 @@
            }
         }
      }
  +   
      /** Inner class used in the preload Data hashmaps so that we can wrap a 
       *  SoftReference around the data and still have enough information to remove
       *  the reference from the appropriate hashMap.
  
  
  
  1.2       +36 -15    
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCPreloadFinderCommand.java
  
  Index: JDBCPreloadFinderCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCPreloadFinderCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCPreloadFinderCommand.java     2001/06/21 22:00:43     1.1
  +++ JDBCPreloadFinderCommand.java     2001/06/22 03:24:49     1.2
  @@ -39,12 +39,19 @@
    * @see <related>
    * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson)</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
  + * 
  + * Revision:
  + * 20010621 danch: abstracted the finders further so that this class can be 
  + *    used against the findAll and FindBy types of finders as well as the 
  + *    defined finders.
    */
   public class JDBCPreloadFinderCommand
      extends JDBCFinderCommand
   {
  -   protected JDBCDefinedFinderCommand defined;
  +   /** The finder we delegate to for setParameters and to get our SQL */
  +   protected JDBCFinderCommand finderDelegate;
  +   /** The load command we delegate to for our column list */
      protected JDBCLoadEntityCommand loadCommand;
   
      // Constructors --------------------------------------------------
  @@ -58,28 +65,39 @@
      {
         super(factory, "PreloadFinder " + f.getName());
         loadCommand = new JDBCLoadEntityCommand(factory);
  -      defined = new JDBCDefinedFinderCommand(factory, f);
  -      String sql = loadCommand.createSelectClause() + " "
  -         + defined.getFromClause() + " "
  -         + defined.getWhereClause() + " "
  -         + defined.getOrderByClause();
  -      if (jawsEntity.hasSelectForUpdate())
  -      {
  -         sql += " FOR UPDATE";
  -      }
  -      setSQL(sql);
  +      finderDelegate = new JDBCDefinedFinderCommand(factory, f);
  +      buildSQL();
  +   }
  +   public JDBCPreloadFinderCommand(JDBCCommandFactory factory, JDBCFinderCommand 
finder) {
  +      super(factory, "PreloadFinder "+finder.getName());
  +      loadCommand = new JDBCLoadEntityCommand(factory);
  +      finderDelegate = finder;
  +      buildSQL();
      }
   
      public String getWhereClause() {
  -      return defined.getWhereClause();
  +      return finderDelegate.getWhereClause();
      }
      public String getFromClause() {
  -      return defined.getFromClause();
  +      return finderDelegate.getFromClause();
      }
      public String getOrderByClause() {
  -      return defined.getOrderByClause();
  +      return finderDelegate.getOrderByClause();
      }
   
  +   /** Helper method called by the constructors */
  +   protected void buildSQL() {
  +      String sql = loadCommand.createSelectClause() + " "
  +         + finderDelegate.getFromClause() + " "
  +         + finderDelegate.getWhereClause() + " "
  +         + finderDelegate.getOrderByClause();
  +      if (jawsEntity.hasSelectForUpdate())
  +      {
  +         sql += " FOR UPDATE";
  +      }
  +      setSQL(sql);
  +   }
  +   
      protected Object handleResult(ResultSet rs, Object argOrArgs) throws Exception
      {
         Collection result = new ArrayList();
  @@ -162,6 +180,8 @@
      protected void setParameters(PreparedStatement stmt, Object argOrArgs)
         throws Exception
      {
  +      finderDelegate.setParameters(stmt, argOrArgs);
  +/*      
         Object[] args = (Object[])argOrArgs;
   
         TypeMappingMetaData typeMapping = 
jawsEntity.getJawsApplication().getTypeMapping();
  @@ -171,5 +191,6 @@
            int jdbcType = typeMapping.getJdbcTypeForJavaType(arg.getClass());
            setParameter(stmt,i+1,jdbcType,arg);
         }
  +*/
      }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to