cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1129909 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/dbsync/ main/java/org/apache/cayenne/log/ test/java/org/apache/cayenne/unit/di/server/
Date Tue, 31 May 2011 20:46:04 GMT
Author: aadamchik
Date: Tue May 31 20:46:03 2011
New Revision: 1129909

URL: http://svn.apache.org/viewvc?rev=1129909&view=rev
Log:
CAY-1573 QueryLogger to DI JdbcEventLogger migration

patch by Dzmitry Kazimirchyk (partial) with edits by aadamchik

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ConnectionLogger.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ExternalTransaction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/InternalTransaction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/Transaction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ThrowOnPartialOrCreateSchemaStrategy.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ConnectionLogger.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ConnectionLogger.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ConnectionLogger.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ConnectionLogger.java
Tue May 31 20:46:03 2011
@@ -28,6 +28,7 @@ import org.apache.cayenne.conn.DataSourc
  * connection pools.
  * 
  * @since 1.2
+ * @deprecated since 3.1
  */
 public class ConnectionLogger implements ConnectionEventLoggingDelegate {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
Tue May 31 20:46:03 2011
@@ -579,9 +579,18 @@ public class DataDomain implements Query
      * @since 1.1
      */
     public Transaction createTransaction() {
-        return (isUsingExternalTransactions()) ? Transaction
-                .externalTransaction(getTransactionDelegate()) : Transaction
-                .internalTransaction(getTransactionDelegate());
+        if (isUsingExternalTransactions()) {
+            Transaction transaction = Transaction
+                    .externalTransaction(getTransactionDelegate());
+            transaction.setJdbcEventLogger(jdbcEventLogger);
+            return transaction;
+        }
+        else {
+            Transaction transaction = Transaction
+                    .internalTransaction(getTransactionDelegate());
+            transaction.setJdbcEventLogger(jdbcEventLogger);
+            return transaction;
+        }
     }
 
     /**
@@ -885,6 +894,13 @@ public class DataDomain implements Query
         return queryBuilderFactory;
     }
 
+    /**
+     * @since 3.1
+     */
+    JdbcEventLogger getJdbcEventLogger() {
+        return jdbcEventLogger;
+    }
+
     void refreshEntitySorter() {
         if (entitySorter != null) {
             entitySorter.setEntityResolver(getEntityResolver());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushAction.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushAction.java
Tue May 31 20:46:03 2011
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.access;
 
 import java.util.ArrayList;
@@ -74,7 +73,7 @@ class DataDomainFlushAction {
     DataDomain getDomain() {
         return domain;
     }
-    
+
     DataContext getContext() {
         return context;
     }
@@ -120,7 +119,7 @@ class DataDomainFlushAction {
         }
 
         this.context = context;
-        
+
         // ObjectStoreGraphDiff contains changes already categorized by objectId...
         this.changesByObjectId = ((ObjectStoreGraphDiff) changes).getChangesByObjectId();
         this.insertBucket = new DataDomainInsertBucket(this);
@@ -187,7 +186,8 @@ class DataDomainFlushAction {
     }
 
     private void runQueries() {
-        DataDomainFlushObserver observer = new DataDomainFlushObserver();
+        DataDomainFlushObserver observer = new DataDomainFlushObserver(domain
+                .getJdbcEventLogger());
 
         // split query list by spanned nodes and run each single node range individually.
         // Since connections are reused per node within an open transaction, there should
@@ -253,7 +253,7 @@ class DataDomainFlushAction {
                     Collections.EMPTY_LIST,
                     resultIndirectlyModifiedIds);
         }
-        
+
         context.getObjectStore().postprocessAfterCommit(resultDiff);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainFlushObserver.java
Tue May 31 20:46:03 2011
@@ -25,6 +25,7 @@ import org.apache.cayenne.CayenneExcepti
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQuery;
 import org.apache.cayenne.query.InsertBatchQuery;
@@ -38,6 +39,15 @@ import org.apache.cayenne.util.Util;
  */
 class DataDomainFlushObserver implements OperationObserver {
 
+    /**
+     * @since 3.1
+     */
+    private JdbcEventLogger logger;
+
+    DataDomainFlushObserver(JdbcEventLogger logger) {
+        this.logger = logger;
+    }
+
     public void nextQueryException(Query query, Exception ex) {
         throw new CayenneRuntimeException("Raising from query exception.", Util
                 .unwindException(ex));
@@ -123,7 +133,7 @@ class DataDomainFlushObserver implements
                 Object value = key.values().iterator().next();
 
                 // Log the generated PK
-                QueryLogger.logGeneratedKey(attribute, value);
+                logger.logGeneratedKey(attribute, value);
 
                 // I guess we should override any existing value,
                 // as generated key is the latest thing that exists in the DB.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
Tue May 31 20:46:03 2011
@@ -33,6 +33,8 @@ import org.apache.cayenne.CayenneRuntime
 import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
@@ -53,9 +55,31 @@ public class DataNode implements QueryEn
     protected SchemaUpdateStrategy schemaUpdateStrategy;
     protected Map<String, DataMap> dataMaps;
 
+    private JdbcEventLogger jdbcEventLogger;
+
     TransactionDataSource readThroughDataSource;
 
     /**
+     * Creates a new unnamed DataNode.
+     */
+    public DataNode() {
+        this(null);
+    }
+
+    /**
+     * Creates a new DataNode, assigning it a name.
+     */
+    public DataNode(String name) {
+
+        this.name = name;
+        this.dataMaps = new HashMap<String, DataMap>();
+        this.readThroughDataSource = new TransactionDataSource();
+
+        // make sure logger is not null
+        this.jdbcEventLogger = NoopJdbcEventLogger.getInstance();
+    }
+
+    /**
      * @since 3.0
      */
     public String getSchemaUpdateStrategyName() {
@@ -87,19 +111,17 @@ public class DataNode implements QueryEn
     }
 
     /**
-     * Creates a new unnamed DataNode.
+     * @since 3.1
      */
-    public DataNode() {
-        this(null);
+    public JdbcEventLogger getJdbcEventLogger() {
+        return jdbcEventLogger;
     }
 
     /**
-     * Creates a new DataNode, assigning it a name.
+     * @since 3.1
      */
-    public DataNode(String name) {
-        this.name = name;
-        this.dataMaps = new HashMap<String, DataMap>();
-        this.readThroughDataSource = new TransactionDataSource();
+    public void setJdbcEventLogger(JdbcEventLogger logger) {
+        this.jdbcEventLogger = logger;
     }
 
     /**
@@ -235,7 +257,7 @@ public class DataNode implements QueryEn
             connection = this.getDataSource().getConnection();
         }
         catch (Exception globalEx) {
-            QueryLogger.logQueryError(globalEx);
+            jdbcEventLogger.logQueryError(globalEx);
 
             Transaction transaction = Transaction.getThreadTransaction();
             if (transaction != null) {
@@ -256,7 +278,7 @@ public class DataNode implements QueryEn
                     queryRunner.runQuery(connection, nextQuery);
                 }
                 catch (Exception queryEx) {
-                    QueryLogger.logQueryError(queryEx);
+                    jdbcEventLogger.logQueryError(queryEx);
 
                     // notify consumer of the exception,
                     // stop running further queries

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
Tue May 31 20:46:03 2011
@@ -40,6 +40,8 @@ import org.apache.cayenne.conn.DriverDat
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -66,6 +68,8 @@ public class DbGenerator {
     // optional DataDomain needed for correct FK generation in cross-db situations
     protected DataDomain domain;
 
+    protected JdbcEventLogger jdbcEventLogger;
+
     // stores generated SQL statements
     protected Map<String, Collection<String>> dropTables;
     protected Map<String, String> createTables;
@@ -90,7 +94,10 @@ public class DbGenerator {
 
     /**
      * Creates and initializes new DbGenerator.
+     * 
+     * @deprecated since 3.1 use {@link #DbGenerator(DbAdapter, DataMap, JdbcEventLogger)}
      */
+    @Deprecated
     public DbGenerator(DbAdapter adapter, DataMap map) {
         this(adapter, map, Collections.<DbEntity> emptyList());
     }
@@ -101,10 +108,28 @@ public class DbGenerator {
      * @param adapter DbAdapter corresponding to the database
      * @param map DataMap whose entities will be used in schema generation
      * @param excludedEntities entities that should be ignored during schema generation
+     * @deprecated since 3.1 use
+     *             {@link #DbGenerator(DbAdapter, DataMap, Collection, DataDomain, JdbcEventLogger)}
      */
+    @Deprecated
     public DbGenerator(DbAdapter adapter, DataMap map,
             Collection<DbEntity> excludedEntities) {
-        this(adapter, map, excludedEntities, null);
+        this(adapter, map, excludedEntities, null, NoopJdbcEventLogger.getInstance());
+    }
+
+    /**
+     * @since 3.1
+     */
+    public DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger) {
+        this(adapter, map, logger, Collections.<DbEntity> emptyList());
+    }
+
+    /**
+     * @since 3.1
+     */
+    public DbGenerator(DbAdapter adapter, DataMap map, JdbcEventLogger logger,
+            Collection<DbEntity> excludedEntities) {
+        this(adapter, map, excludedEntities, null, logger);
     }
 
     /**
@@ -114,10 +139,11 @@ public class DbGenerator {
      * @param map DataMap whose entities will be used in schema generation
      * @param excludedEntities entities that should be ignored during schema generation
      * @param domain optional DataDomain used to detect cross-database relationships.
-     * @since 1.2
+     * @since 3.1
      */
     public DbGenerator(DbAdapter adapter, DataMap map,
-            Collection<DbEntity> excludedEntities, DataDomain domain) {
+            Collection<DbEntity> excludedEntities, DataDomain domain,
+            JdbcEventLogger logger) {
         // sanity check
         if (adapter == null) {
             throw new IllegalArgumentException("Adapter must not be null.");
@@ -130,6 +156,7 @@ public class DbGenerator {
         this.domain = domain;
         this.map = map;
         this.adapter = adapter;
+        this.jdbcEventLogger = logger;
 
         prepareDbEntities(excludedEntities);
         resetToDefaults();
@@ -346,7 +373,7 @@ public class DbGenerator {
         Statement statement = connection.createStatement();
 
         try {
-            QueryLogger.logQuery(sql, null);
+            jdbcEventLogger.logQuery(sql, null);
             statement.execute(sql);
             return true;
         }
@@ -356,7 +383,7 @@ public class DbGenerator {
             }
 
             failures.addFailure(new SimpleValidationFailure(sql, ex.getMessage()));
-            QueryLogger.logQueryError(ex);
+            jdbcEventLogger.logQueryError(ex);
             return false;
         }
         finally {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ExternalTransaction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ExternalTransaction.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ExternalTransaction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ExternalTransaction.java
Tue May 31 20:46:03 2011
@@ -144,13 +144,11 @@ class ExternalTransaction extends Transa
     }
 
     void processCommit() throws SQLException, CayenneException {
-        QueryLogger
-                .logCommitTransaction("no commit - transaction controlled externally.");
+        jdbcEventLogger.logCommitTransaction("no commit - transaction controlled externally.");
     }
 
     void processRollback() throws SQLException, CayenneException {
-        QueryLogger
-                .logRollbackTransaction("no rollback - transaction controlled externally.");
+        jdbcEventLogger.logRollbackTransaction("no rollback - transaction controlled externally.");
     }
 
     /**
@@ -161,7 +159,7 @@ class ExternalTransaction extends Transa
             return;
         }
 
-        Iterator it = connections.values().iterator();
+        Iterator<?> it = connections.values().iterator();
         while (it.hasNext()) {
             try {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
Tue May 31 20:46:03 2011
@@ -160,10 +160,6 @@ public class IncrementalFaultList<E> imp
                 while (it.hasNextRow()) {
                     elementsList.add(it.nextRow());
                 }
-
-                QueryLogger.logSelectCount(elementsList.size(), System
-                        .currentTimeMillis()
-                        - t1);
             }
             finally {
                 it.close();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/InternalTransaction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/InternalTransaction.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/InternalTransaction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/InternalTransaction.java
Tue May 31 20:46:03 2011
@@ -39,7 +39,7 @@ class InternalTransaction extends Extern
     @Override
     public void begin() {
         super.begin();
-        QueryLogger.logBeginTransaction("transaction started.");
+        jdbcEventLogger.logBeginTransaction("transaction started.");
     }
 
     @Override
@@ -64,7 +64,7 @@ class InternalTransaction extends Extern
 
         if (connections != null && connections.size() > 0) {
             Throwable deferredException = null;
-            Iterator it = connections.values().iterator();
+            Iterator<?> it = connections.values().iterator();
             while (it.hasNext()) {
                 Connection connection = (Connection) it.next();
                 try {
@@ -93,7 +93,7 @@ class InternalTransaction extends Extern
             }
 
             if (deferredException != null) {
-                QueryLogger.logRollbackTransaction("transaction rolledback.");
+                jdbcEventLogger.logRollbackTransaction("transaction rolledback.");
                 if (deferredException instanceof SQLException) {
                     throw (SQLException) deferredException;
                 }
@@ -102,7 +102,7 @@ class InternalTransaction extends Extern
                 }
             }
             else {
-                QueryLogger.logCommitTransaction("transaction committed.");
+                jdbcEventLogger.logCommitTransaction("transaction committed.");
             }
         }
     }
@@ -114,7 +114,7 @@ class InternalTransaction extends Extern
         if (connections != null && connections.size() > 0) {
             Throwable deferredException = null;
 
-            Iterator it = connections.values().iterator();
+            Iterator<?> it = connections.values().iterator();
             while (it.hasNext()) {
                 Connection connection = (Connection) it.next();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/Transaction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/Transaction.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/Transaction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/Transaction.java
Tue May 31 20:46:03 2011
@@ -25,6 +25,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneException;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
 
 /**
  * A Cayenne transaction. Currently supports managing JDBC connections.
@@ -69,6 +71,8 @@ public abstract class Transaction {
     protected Map<String, Connection> connections;
     protected int status;
     protected TransactionDelegate delegate;
+    
+    protected JdbcEventLogger jdbcEventLogger;
 
     static String decodeStatus(int status) {
         switch (status) {
@@ -142,6 +146,7 @@ public abstract class Transaction {
      */
     protected Transaction() {
         status = STATUS_NO_TRANSACTION;
+        jdbcEventLogger = NoopJdbcEventLogger.getInstance();
     }
 
     public TransactionDelegate getDelegate() {
@@ -155,6 +160,20 @@ public abstract class Transaction {
     public int getStatus() {
         return status;
     }
+    
+    /**
+     * @since 3.1
+     */
+    public void setJdbcEventLogger(JdbcEventLogger jdbcEventLogger) {
+        this.jdbcEventLogger = jdbcEventLogger;
+    }
+    
+    /**
+     * @since 3.1
+     */
+    public JdbcEventLogger getJdbcEventLogger() {
+        return this.jdbcEventLogger;
+    }
 
     public synchronized void setRollbackOnly() {
         setStatus(STATUS_MARKED_ROLLEDBACK);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
Tue May 31 20:46:03 2011
@@ -68,7 +68,8 @@ public class CreateIfNoSchemaStrategy ex
         Collection<DataMap> map = dataNode.getDataMaps();
         Iterator<DataMap> iterator = map.iterator();
         while (iterator.hasNext()) {
-            DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next());
+            DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next(), 
+                    dataNode.getJdbcEventLogger());
             gen.setShouldCreateTables(true);
             gen.setShouldDropTables(false);
             gen.setShouldCreateFKConstraints(true);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ThrowOnPartialOrCreateSchemaStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ThrowOnPartialOrCreateSchemaStrategy.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ThrowOnPartialOrCreateSchemaStrategy.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ThrowOnPartialOrCreateSchemaStrategy.java
Tue May 31 20:46:03 2011
@@ -76,7 +76,8 @@ public class ThrowOnPartialOrCreateSchem
         Collection<DataMap> map = dataNode.getDataMaps();
         Iterator<DataMap> iterator = map.iterator();
         while (iterator.hasNext()) {
-            DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next());
+            DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next(), 
+                    dataNode.getJdbcEventLogger());
             gen.setShouldCreateTables(true);
             gen.setShouldDropTables(false);
             gen.setShouldCreateFKConstraints(false);

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java?rev=1129909&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
Tue May 31 20:46:03 2011
@@ -0,0 +1,96 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.log;
+
+import java.util.List;
+
+import org.apache.cayenne.conn.DataSourceInfo;
+import org.apache.cayenne.map.DbAttribute;
+
+/**
+ * @since 3.1
+ */
+public class NoopJdbcEventLogger implements JdbcEventLogger {
+
+    private static final NoopJdbcEventLogger instance = new NoopJdbcEventLogger();
+
+    public static NoopJdbcEventLogger getInstance() {
+        return instance;
+    }
+
+    private NoopJdbcEventLogger() {
+
+    }
+
+    public void log(String message) {
+    }
+
+    public void logConnect(String dataSource) {
+    }
+
+    public void logConnect(String url, String userName, String password) {
+    }
+
+    public void logPoolCreated(DataSourceInfo dsi) {
+    }
+
+    public void logConnectSuccess() {
+    }
+
+    public void logConnectFailure(Throwable th) {
+    }
+
+    public void logGeneratedKey(DbAttribute attribute, Object value) {
+    }
+
+    public void logQuery(String sql, List<?> params) {
+    }
+
+    public void logQuery(String sql, List<DbAttribute> attrs, List<?> params,
long time) {
+    }
+
+    public void logQueryParameters(
+            String label,
+            List<DbAttribute> attrs,
+            List<Object> parameters,
+            boolean isInserting) {
+    }
+
+    public void logSelectCount(int count, long time) {
+    }
+
+    public void logUpdateCount(int count) {
+    }
+
+    public void logBeginTransaction(String transactionLabel) {
+    }
+
+    public void logCommitTransaction(String transactionLabel) {
+    }
+
+    public void logRollbackTransaction(String transactionLabel) {
+    }
+
+    public void logQueryError(Throwable th) {
+    }
+
+    public boolean isLoggable() {
+        return false;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java?rev=1129909&r1=1129908&r2=1129909&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
Tue May 31 20:46:03 2011
@@ -43,6 +43,7 @@ import org.apache.cayenne.cache.MapQuery
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
@@ -83,14 +84,16 @@ public class SchemaBuilder {
     private DataSource dataSource;
     private UnitDbAdapter unitDbAdapter;
     private DbAdapter dbAdapter;
-
     private DataDomain domain;
+    private JdbcEventLogger jdbcEventLogger;
 
     public SchemaBuilder(@Inject DataSource dataSource,
-            @Inject UnitDbAdapter unitDbAdapter, @Inject DbAdapter dbAdapter) {
+            @Inject UnitDbAdapter unitDbAdapter, @Inject DbAdapter dbAdapter,
+            @Inject JdbcEventLogger jdbcEventLogger) {
         this.dataSource = dataSource;
         this.unitDbAdapter = unitDbAdapter;
         this.dbAdapter = dbAdapter;
+        this.jdbcEventLogger = jdbcEventLogger;
     }
 
     /**
@@ -345,7 +348,7 @@ public class SchemaBuilder {
     private Collection<String> tableCreateQueries(DataNode node, DataMap map)
             throws Exception {
         DbAdapter adapter = node.getAdapter();
-        DbGenerator gen = new DbGenerator(adapter, map, null, domain);
+        DbGenerator gen = new DbGenerator(adapter, map, null, domain, jdbcEventLogger);
 
         List<DbEntity> orderedEnts = dbEntitiesInInsertOrder(node, map);
         List<String> queries = new ArrayList<String>();



Mime
View raw message