User: ejort   
  Date: 02/01/05 04:08:51

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc
                        JDBCAbstractQueryCommand.java
                        JDBCCreateEntityCommand.java
                        JDBCCustomFinderQuery.java
                        JDBCDeleteRelationsCommand.java JDBCEJBQLQuery.java
                        JDBCFindByForeignKeyCommand.java
                        JDBCInsertRelationsCommand.java
                        JDBCLoadEntityCommand.java
                        JDBCLoadFieldCommand.java
                        JDBCLoadRelationCommand.java JDBCQueryManager.java
                        JDBCReadAheadCommand.java
                        JDBCRemoveEntityCommand.java JDBCStartCommand.java
                        JDBCStopCommand.java JDBCStoreEntityCommand.java
                        JDBCStoreManager.java
  Log:
  Guarded debug logging
  
  Revision  Changes    Path
  1.5       +13 -8     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCAbstractQueryCommand.java
  
  Index: JDBCAbstractQueryCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCAbstractQueryCommand.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JDBCAbstractQueryCommand.java     2001/12/19 05:50:11     1.4
  +++ JDBCAbstractQueryCommand.java     2002/01/05 12:08:50     1.5
  @@ -42,7 +42,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public abstract class JDBCAbstractQueryCommand implements JDBCQueryCommand {
      private JDBCStoreManager manager;
  @@ -74,6 +74,8 @@
            Object[] args,
            EntityEnterpriseContext ctx) throws FinderException {
   
  +      boolean debug = log.isDebugEnabled();
  +
         Collection results = new ArrayList();
   
         Connection con = null;
  @@ -81,11 +83,12 @@
         try {
            // get the connection
            con = manager.getEntityBridge().getDataSource().getConnection();
  -         
  +
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql);
  -         
  +
            // set the parameters
            for(int i=0; i<parameters.size(); i++) {
               QueryParameter parameter = (QueryParameter)parameters.get(i);
  @@ -112,9 +115,10 @@
                  selectField.loadArgumentResults(rs, 1, valueRef);
                  results.add(valueRef[0]);
               }
  -         }   
  +         }
         } catch(Exception e) {
  -         log.debug(e);
  +         if (debug)
  +            log.debug(e);
            throw new FinderException("Find failed: " + e);
         } finally {
            JDBCUtil.safeClose(ps);
  @@ -158,14 +162,15 @@
               return invoker.getEntityCollection(finderResults);
         }
      }
  -   
  +
      protected Logger getLog() {
         return log;
      }
   
      protected void setSQL(String sql) {
         this.sql = sql;
  -      log.debug("SQL: " + sql);
  +      if (log.isDebugEnabled())
  +         log.debug("SQL: " + sql);
      }
   
      protected void setParameterList(List p) {
  
  
  
  1.11      +30 -18    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCreateEntityCommand.java
  
  Index: JDBCCreateEntityCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCreateEntityCommand.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JDBCCreateEntityCommand.java      2001/12/02 01:41:46     1.10
  +++ JDBCCreateEntityCommand.java      2002/01/05 12:08:50     1.11
  @@ -31,7 +31,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class JDBCCreateEntityCommand {
      private JDBCStoreManager manager;
  @@ -41,17 +41,19 @@
      private String entityExistsSQL;
      private String insertEntitySQL;
      private boolean createAllowed;
  -   
  +
      public JDBCCreateEntityCommand(JDBCStoreManager manager) {
         this.manager = manager;
         entity = manager.getEntityBridge();
   
         // Create the Log
         log = Logger.getLogger(
  -            this.getClass().getName() + 
  -            "." + 
  +            this.getClass().getName() +
  +            "." +
               manager.getMetaData().getName());
   
  +      boolean debug = log.isDebugEnabled();
  +
         // set create allowed
         createAllowed = true;
         JDBCCMPFieldBridge[] cmpFields = entity.getJDBCCMPFields();
  @@ -61,18 +63,23 @@
               break;
            }
         }
  -      
  +
         if(createAllowed) {
            insertFields = getInsertFields();
            entityExistsSQL = createEntityExistsSQL();
            insertEntitySQL = createInsertEntitySQL();
  -         log.debug("Entity Exists SQL: " + entityExistsSQL);
  -         log.debug("Insert Entity SQL: " + entityExistsSQL);
  -      } else {
  +         if (debug)
  +         {
  +            log.debug("Entity Exists SQL: " + entityExistsSQL);
  +            log.debug("Insert Entity SQL: " + entityExistsSQL);
  +         }
  +      }
  +      else if (debug)
  +      {
            log.debug("Create will not be allowed.");
         }
      }
  -  
  +
      private JDBCCMPFieldBridge[] getInsertFields() {
         JDBCCMPFieldBridge[] cmpFields = entity.getJDBCCMPFields();
         ArrayList fields = new ArrayList(cmpFields.length);
  @@ -135,7 +142,8 @@
   
         try {
            Object pk = entity.extractPrimaryKeyFromInstance(ctx);
  -         log.debug("Create: pk="+pk);
  +         if (log.isDebugEnabled())
  +            log.debug("Create: pk="+pk);
            return pk;
         } catch(Exception e) {
            log.error(e);
  @@ -154,9 +162,10 @@
            con = dataSource.getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + entityExistsSQL);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + entityExistsSQL);
            ps = con.prepareStatement(entityExistsSQL);
  -         
  +
            // set the parameters
            entity.setPrimaryKeyParameters(ps, 1, pk);
   
  @@ -166,7 +175,7 @@
               throw new CreateException("Error checking if entity exists: " +
                     "result set contains no rows");
            }
  -      
  +
            // did any rows mathch
            return rs.getInt(1) > 0;
         } catch(CreateException e) {
  @@ -179,22 +188,24 @@
            JDBCUtil.safeClose(con);
         }
      }
  -   
  +
      private void insertEntity(EntityEnterpriseContext ctx)
            throws CreateException{
   
         Connection con = null;
         PreparedStatement ps = null;
         int rowsAffected  = 0;
  +      boolean debug = log.isDebugEnabled();
         try {
            // get the connection
            DataSource dataSource = entity.getDataSource();
            con = dataSource.getConnection();
  -         
  +
            // create the statement
  -         log.debug("Executing SQL: " + insertEntitySQL);
  +         if (debug)
  +            log.debug("Executing SQL: " + insertEntitySQL);
            ps = con.prepareStatement(insertEntitySQL);
  -         
  +
            // set the parameters
            entity.setInstanceParameters(ps, 1, ctx, insertFields);
   
  @@ -214,7 +225,8 @@
                  "affected row: rowsAffected=" + rowsAffected +
                  "id=" + ctx.getId());
         }
  -      log.debug("Create: Rows affected = " + rowsAffected);
  +      if (debug)
  +         log.debug("Create: Rows affected = " + rowsAffected);
   
         // Mark the inserted fields as clean.
         for(int i=0; i<insertFields.length; i++) {
  
  
  
  1.5       +5 -4      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCustomFinderQuery.java
  
  Index: JDBCCustomFinderQuery.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCCustomFinderQuery.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JDBCCustomFinderQuery.java        2001/12/03 14:14:18     1.4
  +++ JDBCCustomFinderQuery.java        2002/01/05 12:08:50     1.5
  @@ -30,7 +30,7 @@
    *
    * @see org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntitiesCommand
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class JDBCCustomFinderQuery implements JDBCQueryCommand {
      private Logger log;
  @@ -54,7 +54,8 @@
               "." + 
               finderMethod.getName());
   
  -      log.debug("Finder: Custom finder " + finderMethod.getName());
  +      if (log.isDebugEnabled())
  +         log.debug("Finder: Custom finder " + finderMethod.getName());
      }
   
      public Collection execute(
  @@ -87,9 +88,9 @@
            throw new FinderException("Illegal arguments for finder " +
                  "implementation: " + finderMethod.getName());
         } catch(InvocationTargetException e) {
  -         log.error("Error invoking custom finder " + finderMethod.getName(), 
  +         log.error("Error invoking custom finder " + finderMethod.getName(),
                  e.getTargetException());
  -         throw new FinderException("Errror invoking cutom finder " + 
  +         throw new FinderException("Errror invoking cutom finder " +
                  finderMethod.getName() + ": " + e.getTargetException());
         }
      }
  
  
  
  1.7       +12 -8     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDeleteRelationsCommand.java
  
  Index: JDBCDeleteRelationsCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDeleteRelationsCommand.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCDeleteRelationsCommand.java   2001/12/01 21:55:04     1.6
  +++ JDBCDeleteRelationsCommand.java   2002/01/05 12:08:50     1.7
  @@ -21,7 +21,7 @@
    * Deletes relations from a relation table.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class JDBCDeleteRelationsCommand {
      private JDBCStoreManager manager;
  @@ -48,29 +48,33 @@
            return;
         }
   
  +      boolean debug = log.isDebugEnabled();
  +
         String sql = createSQL(relationData);
  -      
  +
         Connection con = null;
         PreparedStatement ps = null;
  -      JDBCRelationMetaData relationMetaData = 
  +      JDBCRelationMetaData relationMetaData =
               relationData.getLeftCMRField().getRelationMetaData();
         try {
            // get the connection
            DataSource dataSource = relationMetaData.getDataSource();
            con = dataSource.getConnection();
  -         
  +
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql);
  -         
  +
            // set the parameters
            setParameters(ps, relationData);
   
            // execute statement
            int rowsAffected = ps.executeUpdate();
  -         log.debug("Create: Rows affected = " + rowsAffected);
  +         if (debug)
  +            log.debug("Create: Rows affected = " + rowsAffected);
         } catch(Exception e) {
  -         throw new EJBException("Could not delete relations from " + 
  +         throw new EJBException("Could not delete relations from " +
                  relationMetaData.getTableName(), e);
         } finally {
            JDBCUtil.safeClose(ps);
  
  
  
  1.2       +7 -4      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java
  
  Index: JDBCEJBQLQuery.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCEJBQLQuery.java       2001/11/28 11:32:54     1.1
  +++ JDBCEJBQLQuery.java       2002/01/05 12:08:50     1.2
  @@ -16,24 +16,27 @@
   import org.jboss.ejb.plugins.cmp.jdbc.ejbql.SQLTarget;
   import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
   import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
  +import org.jboss.logging.Logger;
   
   /**
    * This class generates a query from EJB-QL.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCEJBQLQuery extends JDBCAbstractQueryCommand {
   
      public JDBCEJBQLQuery(
  -         JDBCStoreManager manager, 
  +         JDBCStoreManager manager,
            JDBCQueryMetaData q) throws DeploymentException {
   
         super(manager, q);
   
         JDBCQlQueryMetaData metadata = (JDBCQlQueryMetaData)q;
  -      getLog().debug("EQL-QL: "+metadata.getEjbQl());
  -      
  +      Logger log = getLog();
  +      if (log.isDebugEnabled())
  +         log.debug("EQL-QL: "+metadata.getEjbQl());
  +
         // get a parser
         Parser ejbql = new EJBQLParser().ejbqlQuery();
         
  
  
  
  1.11      +3 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCFindByForeignKeyCommand.java
  
  Index: JDBCFindByForeignKeyCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCFindByForeignKeyCommand.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JDBCFindByForeignKeyCommand.java  2001/12/05 05:07:01     1.10
  +++ JDBCFindByForeignKeyCommand.java  2002/01/05 12:08:50     1.11
  @@ -25,7 +25,7 @@
    * entity's table.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class JDBCFindByForeignKeyCommand {
   
  @@ -78,7 +78,8 @@
            con = entity.getDataSource().getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
            
            // set the parameters
  
  
  
  1.9       +22 -18    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCInsertRelationsCommand.java
  
  Index: JDBCInsertRelationsCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCInsertRelationsCommand.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JDBCInsertRelationsCommand.java   2001/12/01 21:55:04     1.8
  +++ JDBCInsertRelationsCommand.java   2002/01/05 12:08:51     1.9
  @@ -22,7 +22,7 @@
    * Inserts relations into a relation table.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class JDBCInsertRelationsCommand {
      protected JDBCStoreManager manager;
  @@ -39,39 +39,43 @@
               "." + 
               manager.getMetaData().getName());
      }
  -   
  +
      public void execute(RelationData relationData) {
         if(relationData.addedRelations.size() == 0) {
            return;
         }
  -      
  +
         Connection con = null;
         PreparedStatement ps = null;
  -      
  -      JDBCRelationMetaData relationMetaData = 
  +
  +      boolean debug = log.isDebugEnabled();
  +
  +      JDBCRelationMetaData relationMetaData =
               relationData.getLeftCMRField().getRelationMetaData();
         try {
            // get the connection
            DataSource dataSource = relationMetaData.getDataSource();
            con = dataSource.getConnection();
  -         
  +
            // get the sql
            String sql = getSQL(relationData);
  -         
  +
            // get a prepared statement
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql);
  -         
  +
            Iterator pairs = relationData.addedRelations.iterator();
            while(pairs.hasNext()) {
               RelationPair pair = (RelationPair)pairs.next();
  -            
  +
               // set the parameters
               setParameters(ps, relationData, pair);
  -         
  +
               int rowsAffected = ps.executeUpdate();
  -         
  -            log.debug("Rows affected = " + rowsAffected);
  +
  +            if (debug)
  +               log.debug("Rows affected = " + rowsAffected);
            }
         } catch(Exception e) {
            throw new EJBException("Could insert relations into " +
  @@ -81,14 +85,14 @@
            JDBCUtil.safeClose(con);
         }
      }
  -   
  +
      protected String getSQL(RelationData relationData) throws Exception {
         JDBCCMRFieldBridge left = relationData.getLeftCMRField();
         JDBCCMRFieldBridge right = relationData.getRightCMRField();
  -      
  +
         StringBuffer sql = new StringBuffer();
         sql.append("INSERT INTO ").append(
  -           left.getRelationMetaData().getTableName());      
  +           left.getRelationMetaData().getTableName());
   
         sql.append(" (");
               sql.append(SQLUtil.getColumnNamesClause(left.getTableKeyFields()));
  @@ -100,10 +104,10 @@
               sql.append(SQLUtil.getValuesClause(left.getTableKeyFields()));
               sql.append(", ");
               sql.append(SQLUtil.getValuesClause(right.getTableKeyFields()));
  -      sql.append(")");      
  +      sql.append(")");
         return sql.toString();
      }
  -      
  +
      protected void setParameters(
            PreparedStatement ps,
            RelationData relationData,
  
  
  
  1.13      +3 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadEntityCommand.java
  
  Index: JDBCLoadEntityCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadEntityCommand.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JDBCLoadEntityCommand.java        2001/12/05 05:07:01     1.12
  +++ JDBCLoadEntityCommand.java        2002/01/05 12:08:51     1.13
  @@ -34,7 +34,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dirk Zimmermann</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>danch (Dan Christopherson)</a>
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    */
   public class JDBCLoadEntityCommand {
      private JDBCStoreManager manager;
  @@ -97,7 +97,8 @@
            con = entity.getDataSource().getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
            
            // set the parameters
  
  
  
  1.11      +3 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadFieldCommand.java
  
  Index: JDBCLoadFieldCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadFieldCommand.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JDBCLoadFieldCommand.java 2001/12/05 05:07:00     1.10
  +++ JDBCLoadFieldCommand.java 2002/01/05 12:08:51     1.11
  @@ -32,7 +32,7 @@
    * fields.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class JDBCLoadFieldCommand {
      private JDBCStoreManager manager;
  @@ -108,7 +108,8 @@
            con = entity.getDataSource().getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
            
            // set the parameters
  
  
  
  1.10      +3 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadRelationCommand.java
  
  Index: JDBCLoadRelationCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCLoadRelationCommand.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JDBCLoadRelationCommand.java      2001/12/05 05:07:00     1.9
  +++ JDBCLoadRelationCommand.java      2002/01/05 12:08:51     1.10
  @@ -24,7 +24,7 @@
    * Loads relations for a particular entity from a relation table.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   public class JDBCLoadRelationCommand {
      private JDBCStoreManager manager;
  @@ -79,7 +79,8 @@
            con = cmrField.getRelationMetaData().getDataSource().getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
            
            // set the parameters
  
  
  
  1.2       +30 -24    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCQueryManager.java
  
  Index: JDBCQueryManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCQueryManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCQueryManager.java     2001/11/28 11:32:54     1.1
  +++ JDBCQueryManager.java     2002/01/05 12:08:51     1.2
  @@ -30,7 +30,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCQueryManager {
      private final Map knownQueries = new HashMap();
  @@ -54,16 +54,17 @@
   
      public void start() throws DeploymentException {
         Logger log = Logger.getLogger(
  -            this.getClass().getName() + 
  -            "." + 
  +            this.getClass().getName() +
  +            "." +
               manager.getMetaData().getName());
  -      
  -      JDBCCommandFactory factory = manager.getCommandFactory();      
  -      
  +      boolean debug = log.isDebugEnabled();
  +
  +      JDBCCommandFactory factory = manager.getCommandFactory();
  +
         Class homeClass = manager.getContainer().getHomeClass();
         Class localHomeClass = manager.getContainer().getLocalHomeClass();
   
  -      // 
  +      //
         // findByPrimaryKey
         //
         JDBCEntityBridge entity = manager.getEntityBridge();
  @@ -71,50 +72,52 @@
            try {
               // try to get the finder method on the home interface
               Method method = homeClass.getMethod(
  -                  "findByPrimaryKey", 
  +                  "findByPrimaryKey",
                     new Class[] {entity.getPrimaryKeyClass()});
  -            
  +
               // got it add it to known finders
               JDBCQueryMetaData q = new JDBCAutomaticQueryMetaData(method);
               knownQueries.put(
  -                  method, 
  +                  method,
                     factory.createFindByPrimaryKeyQuery(q));
   
  -            log.debug("Added findByPrimaryKey query command for " +
  +            if (debug)
  +               log.debug("Added findByPrimaryKey query command for " +
                     "home interface");
            } catch(NoSuchMethodException e) {
               throw new DeploymentException("Home interface does not " +
                     "have a findByPrimaryKey method");
            }
         }
  -         
  +
         if(localHomeClass != null) {
            try {
               // try to get the finder method on the local home interface
               Method method = localHomeClass.getMethod(
  -                  "findByPrimaryKey", 
  +                  "findByPrimaryKey",
                     new Class[] {entity.getPrimaryKeyClass()});
  -            
  +
               // got it add it to known finders
               JDBCQueryMetaData q = new JDBCAutomaticQueryMetaData(method);
               knownQueries.put(
  -                  method, 
  +                  method,
                     factory.createFindByPrimaryKeyQuery(q));
   
  -            log.debug("Added findByPrimaryKey query command for " +
  +            if (debug)
  +               log.debug("Added findByPrimaryKey query command for " +
                     "local home interface");
            } catch(NoSuchMethodException e) {
               throw new DeploymentException("Local home interface does " +
                     "not have a findByPrimaryKey method");
            }
         }
  - 
  +
         //
         // Custom finders - Overrides defined and automatic finders.
         //
         Class ejbClass = manager.getMetaData().getEntityClass();
   
  -      Method[] customMethods = ejbClass.getMethods();         
  +      Method[] customMethods = ejbClass.getMethods();
         for (int i = 0; i < customMethods.length; i++) {
            Method m = customMethods[i];
            String  methodName = m.getName();
  @@ -125,15 +128,16 @@
                  try {
                     // try to get the finder method on the home interface
                     Method interfaceMethod = homeClass.getMethod(
  -                        interfaceName, 
  +                        interfaceName,
                           m.getParameterTypes());
  -                  
  +
                     // got it add it to known finders
                     knownQueries.put(
  -                        interfaceMethod, 
  +                        interfaceMethod,
                           new JDBCCustomFinderQuery(manager, m));
   
  -                  log.debug("Added custom finder " + methodName +
  +                  if (debug)
  +                     log.debug("Added custom finder " + methodName +
                           " on home interface");
                  } catch(NoSuchMethodException e) {
                     // this is ok method may not be defined on this interface
  @@ -152,7 +156,8 @@
                           interfaceMethod, 
                           new JDBCCustomFinderQuery(manager, m));
   
  -                  log.debug("Added custom finder " + methodName +
  +                  if (debug)
  +                     log.debug("Added custom finder " + methodName +
                           " on local home interface");
                  } catch(NoSuchMethodException e) {
                     // this is ok method may not be defined on this interface
  @@ -213,7 +218,8 @@
                     JDBCQueryMetaData q = new JDBCAutomaticQueryMetaData(m);
                     knownQueries.put(m, factory.createFindByQuery(q));
                  } catch (IllegalArgumentException e) {
  -                  log.debug("Could not create the finder " + name +
  +                  if (log.isDebugEnabled())
  +                     log.debug("Could not create the finder " + name +
                           ", because no matching CMP field was found.");
                  }
               }
  
  
  
  1.8       +3 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCReadAheadCommand.java
  
  Index: JDBCReadAheadCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCReadAheadCommand.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JDBCReadAheadCommand.java 2001/12/05 05:07:00     1.7
  +++ JDBCReadAheadCommand.java 2002/01/05 12:08:51     1.8
  @@ -26,7 +26,7 @@
    * JDBCReadAheadCommand
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Oleg Nitz</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class JDBCReadAheadCommand {
   
  @@ -76,7 +76,8 @@
            con = entity.getDataSource().getConnection();
            
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (log.isDebugEnabled())
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql);
            
            // set the parameters
  
  
  
  1.12      +12 -8     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRemoveEntityCommand.java
  
  Index: JDBCRemoveEntityCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRemoveEntityCommand.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JDBCRemoveEntityCommand.java      2001/12/02 01:41:46     1.11
  +++ JDBCRemoveEntityCommand.java      2002/01/05 12:08:51     1.12
  @@ -29,7 +29,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    */
   public class JDBCRemoveEntityCommand {
      
  @@ -55,12 +55,13 @@
                  entity.getJDBCPrimaryKeyFields()));
         
         removeEntitySQL = sql.toString();
  -      log.debug("Remove SQL: " + removeEntitySQL);
  +      if (log.isDebugEnabled())
  +         log.debug("Remove SQL: " + removeEntitySQL);
      }
  -   
  +
      public void execute(EntityEnterpriseContext context)
            throws RemoveException {
  -      
  +
         // remove entity from all relations
         HashMap oldRelations = removeFromRelations(context);
   
  @@ -69,17 +70,19 @@
            manager.getContainer().synchronizeEntitiesWithinTransaction(
                  context.getTransaction());
         }
  -      
  +
         Connection con = null;
         PreparedStatement ps = null;
         int rowsAffected = 0;
  +      boolean debug = log.isDebugEnabled();
         try {
            // get the connection
            DataSource dataSource = entity.getDataSource();
            con = dataSource.getConnection();
  -         
  +
            // create the statement
  -         log.debug("Executing SQL: " + removeEntitySQL);
  +         if (debug)
  +            log.debug("Executing SQL: " + removeEntitySQL);
            ps = con.prepareStatement(removeEntitySQL);
            
            // set the parameters
  @@ -99,7 +102,8 @@
         if(rowsAffected == 0) {
            throw new RemoveException("Could not remove entity");
         }
  -      log.debug("Remove: Rows affected = " + rowsAffected);
  +      if (debug)
  +         log.debug("Remove: Rows affected = " + rowsAffected);
   
         // cascate-delete to old relations, if relation uses cascade.
         cascadeDelete(oldRelations);
  
  
  
  1.15      +30 -16    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java
  
  Index: JDBCStartCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JDBCStartCommand.java     2001/12/30 20:34:22     1.14
  +++ JDBCStartCommand.java     2002/01/05 12:08:51     1.15
  @@ -36,7 +36,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public class JDBCStartCommand {
   
  @@ -70,6 +70,8 @@
   
      public void execute() throws Exception {
   
  +      boolean debug = log.isDebugEnabled();
  +
         // Create table if necessary
         if(!entity.getTableExists()) {
            if(entityMetaData.getCreateTable()) {
  @@ -77,17 +79,19 @@
                     entity.getDataSource(),
                     entity.getTableName(),
                     getEntityCreateTableSQL());
  -         } else {
  +         }
  +         else if (debug)
  +         {
               log.debug("Table not create as requested: " +
                     entity.getTableName());
            }
            entity.setTableExists(true);
         }
  -     
  +
         // create relation tables
         JDBCCMRFieldBridge[] cmrFields = entity.getJDBCCMRFields();
         for(int i=0; i<cmrFields.length; i++) {
  -         JDBCRelationMetaData relationMetaData = 
  +         JDBCRelationMetaData relationMetaData =
                  cmrFields[i].getRelationMetaData();
   
            // if the table for the related entity has been created
  @@ -96,13 +100,15 @@
               // create the relation table
               if(relationMetaData.isTableMappingStyle() &&
                  !relationMetaData.getTableExists()) {
  -               
  +
                  if(relationMetaData.getCreateTable()) {
                     createTable(
                           relationMetaData.getDataSource(),
                           relationMetaData.getTableName(),
                           getRelationCreateTableSQL(cmrFields[i]));
  -               } else {
  +               }
  +               else if (debug)
  +               {
                     log.debug("Relation table not create as requested: " +
                           relationMetaData.getTableName());
                  }
  @@ -131,24 +137,27 @@
   
         Connection con = null;
         Statement statement = null;
  +      boolean debug = log.isDebugEnabled();
         try {
            // since we use the pools, we have to do this within a transaction
            manager.getContainer().getTransactionManager().begin ();
   
            // get the connection
            con = dataSource.getConnection();
  -         
  +
            // create the statement
            statement = con.createStatement();
  -         
  +
            // execute sql
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            statement.executeUpdate(sql);
   
            // commit the transaction
            manager.getContainer().getTransactionManager().commit ();
         } catch (Exception e) {
  -         log.debug("Could not create table " + tableName, e);
  +         if (debug)
  +            log.debug("Could not create table " + tableName, e);
            try {
               manager.getContainer().getTransactionManager().rollback ();
            } catch (Exception _e) {
  @@ -287,8 +296,10 @@
                     cmrField.getRelatedEntity().getTableName(),
                     cmrField.getRelatedEntity().getJDBCPrimaryKeyFields());
            }
  -      } else {
  -         log.debug("Foreign key constaint not added as requested: " + 
  +      }
  +      else if (log.isDebugEnabled())
  +      {
  +         log.debug("Foreign key constaint not added as requested: " +
                  "relationshipRolename=" +
                  cmrField.getMetaData().getRelationshipRoleName());
         }
  @@ -325,18 +336,20 @@
   
         Connection con = null;
         Statement statement = null;
  +      boolean debug = log.isDebugEnabled();
         try {
            // since we use the pools, we have to do this within a transaction
            manager.getContainer().getTransactionManager().begin();
   
            // get the connection
            con = dataSource.getConnection();
  -         
  +
            // create the statement
            statement = con.createStatement();
  -         
  +
            // execute sql
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            statement.executeUpdate(sql);
   
            // commit the transaction
  @@ -345,7 +358,8 @@
            // success
            log.info("Added foreign key constriant to table '" + tableName);
         } catch (Exception e) {
  -         log.debug("Could not add foreign key constriant to table " + 
  +         if (debug)
  +            log.debug("Could not add foreign key constriant to table " +
                  tableName, e);
            try {
               manager.getContainer().getTransactionManager().rollback ();
  
  
  
  1.8       +8 -4      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStopCommand.java
  
  Index: JDBCStopCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStopCommand.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JDBCStopCommand.java      2001/12/02 01:41:46     1.7
  +++ JDBCStopCommand.java      2002/01/05 12:08:51     1.8
  @@ -27,7 +27,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class JDBCStopCommand {
   
  @@ -50,7 +50,8 @@
      
      public void execute() {
         if(entityMetaData.getRemoveTable()) {
  -         log.debug("Droping table for entity " + entity.getEntityName());
  +         if (log.isDebugEnabled())
  +            log.debug("Droping table for entity " + entity.getEntityName());
            dropTable(entity.getDataSource(), entityMetaData.getTableName());
         }
   
  @@ -76,6 +77,7 @@
      private void dropTable(DataSource dataSource, String tableName) {
         Connection con = null;
         ResultSet rs = null;
  +      boolean debug = log.isDebugEnabled();
   
         // was the table already delete?
         try {
  @@ -86,7 +88,8 @@
               return;
            }
         } catch(SQLException e) {
  -         log.debug("Error getting database metadata for DROP TABLE command. " +
  +         if (debug)
  +            log.debug("Error getting database metadata for DROP TABLE command. " +
                  " DROP TABLE will not be executed. ", e);
            return;
         } finally {
  @@ -114,7 +117,8 @@
            // success
            log.info("Dropped table '" + tableName + "' successfully.");
         } catch (Exception e) {
  -         log.debug("Could not drop table " + tableName + ": " + e.getMessage());
  +         if (debug)
  +            log.debug("Could not drop table " + tableName + ": " + e.getMessage());
            try {
               manager.getContainer().getTransactionManager().rollback ();
            } catch (Exception _e) {
  
  
  
  1.10      +12 -8     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreEntityCommand.java
  
  Index: JDBCStoreEntityCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreEntityCommand.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JDBCStoreEntityCommand.java       2001/12/02 01:41:46     1.9
  +++ JDBCStoreEntityCommand.java       2002/01/05 12:08:51     1.10
  @@ -27,7 +27,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   public class JDBCStoreEntityCommand {
      private JDBCStoreManager manager;
  @@ -48,15 +48,17 @@
      public void execute(EntityEnterpriseContext ctx) {
         JDBCCMPFieldBridge[] dirtyFields = 
               (JDBCCMPFieldBridge[])entity.getDirtyFields(ctx);
  -         
  +
  +      boolean debug = log.isDebugEnabled();
         if(dirtyFields.length == 0) {
  -         log.debug("Store command NOT executed. Entity is not dirty: pk=" + 
  +         if (debug)
  +            log.debug("Store command NOT executed. Entity is not dirty: pk=" +
                  ctx.getId());
            return;
         }
   
         // generate sql
  -      StringBuffer sql = new StringBuffer(); 
  +      StringBuffer sql = new StringBuffer();
         sql.append("UPDATE ").append(entity.getTableName());
         sql.append(" SET ").append(SQLUtil.getSetClause(dirtyFields));
         sql.append(" WHERE ").append(
  @@ -68,11 +70,12 @@
         try {
            // get the connection
            con = entity.getDataSource().getConnection();
  -         
  +
            // create the statement
  -         log.debug("Executing SQL: " + sql);
  +         if (debug)
  +            log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
  -         
  +
            // set the parameters
            int index = 1;
            index = entity.setInstanceParameters(ps, index, ctx, dirtyFields);
  @@ -93,7 +96,8 @@
                  "affected row: rowsAffected=" + rowsAffected +
                  "id=" + ctx.getId());
         }
  -      log.debug("Create: Rows affected = " + rowsAffected);
  +      if (debug)
  +         log.debug("Create: Rows affected = " + rowsAffected);
   
         // Mark the inserted fields as clean.
         for(int i=0; i<dirtyFields.length; i++) {
  
  
  
  1.24      +7 -4      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreManager.java
  
  Index: JDBCStoreManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- JDBCStoreManager.java     2001/12/28 18:46:01     1.23
  +++ JDBCStoreManager.java     2002/01/05 12:08:51     1.24
  @@ -59,7 +59,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
    * @see org.jboss.ejb.EntityPersistenceStore
  - * @version $Revision: 1.23 $
  + * @version $Revision: 1.24 $
    */
   public class JDBCStoreManager implements EntityPersistenceStore {
   
  @@ -235,7 +235,8 @@
      // Store Manager Life Cycle Commands
      //
      public void create() throws Exception {
  -      log.debug("Initializing CMP plugin for " +
  +      if (log.isDebugEnabled())
  +         log.debug("Initializing CMP plugin for " +
                   container.getBeanMetaData().getEjbName());
   
         initApplicationDataMap();
  @@ -383,7 +384,8 @@
      public void loadEntity(EntityEnterpriseContext ctx) {
         // is any on the data already in the entity valid
         if(!ctx.isValid()) {
  -         log.debug("RESET PERSISTENCE CONTEXT: id="+ctx.getId());
  +         if (log.isDebugEnabled())
  +            log.debug("RESET PERSISTENCE CONTEXT: id="+ctx.getId());
            entityBridge.resetPersistenceContext(ctx);
         }
   
  @@ -654,7 +656,8 @@
         preloadKey = new PreloadKey(
               trans, entityKey, field.getMetaData().getFieldName());
         fieldValue = preloadedData.remove(preloadKey);
  -      log.debug("Getting Preload " + preloadKey + " " + 
  +      if (log.isDebugEnabled())
  +         log.debug("Getting Preload " + preloadKey + " " +
               field.getMetaData().getFieldName() + " " + fieldValue);
         found = (fieldValue != null);
   
  
  
  

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

Reply via email to