servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ioca...@apache.org
Subject svn commit: r1056236 - in /servicemix/smx4/nmr/trunk/nmr/audit/src: main/java/org/apache/servicemix/nmr/audit/jdbc/ test/java/org/apache/servicemix/nmr/audit/jdbc/ test/java/org/apache/servicemix/nmr/audit/lucene/
Date Fri, 07 Jan 2011 10:12:31 GMT
Author: iocanel
Date: Fri Jan  7 10:12:31 2011
New Revision: 1056236

URL: http://svn.apache.org/viewvc?rev=1056236&view=rev
Log:
[SMX4NMR-232] JdbcAudior checks if JDBCAdapter is null before use. Method afterProperties
set was renamed to createAdapter to avoid confusion with InitializingBean.

Modified:
    servicemix/smx4/nmr/trunk/nmr/audit/src/main/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditor.java
    servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditorTest.java
    servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/lucene/LuceneAuditorTest.java

Modified: servicemix/smx4/nmr/trunk/nmr/audit/src/main/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditor.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/audit/src/main/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditor.java?rev=1056236&r1=1056235&r2=1056236&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/audit/src/main/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditor.java
(original)
+++ servicemix/smx4/nmr/trunk/nmr/audit/src/main/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditor.java
Fri Jan  7 10:12:31 2011
@@ -71,7 +71,8 @@ public class JdbcAuditor extends Abstrac
         return "JDBC Auditing Service";
     }
     
-    public void afterPropertiesSet() throws Exception {
+    public JDBCAdapter createAdapter() throws AuditorException {
+        JDBCAdapter jdbcAdapter;
         if (this.dataSource == null) {
             throw new IllegalArgumentException("dataSource should not be null");
         }
@@ -87,22 +88,25 @@ public class JdbcAuditor extends Abstrac
                 connection.setAutoCommit(false);
                 restoreAutoCommit = true;
             }
-            adapter = JDBCAdapterFactory.getAdapter(connection);
+            jdbcAdapter = JDBCAdapterFactory.getAdapter(connection);
             if (statements == null) {
                 statements = new Statements();
                 statements.setStoreTableName(tableName);
             }
-            adapter.setStatements(statements);
+            jdbcAdapter.setStatements(statements);
             if (createDataBase) {
-                adapter.doCreateTables(connection);
+                jdbcAdapter.doCreateTables(connection);
             }
             connection.commit();
         } catch (SQLException e) {
-            throw (IOException) new IOException("Exception while creating database").initCause(e);

+            throw (AuditorException) new AuditorException("Exception while creating database").initCause(e);
+        } catch (IOException e) {
+           throw (AuditorException) new AuditorException("Exception while creating database").initCause(e);
         } finally {
             close(connection, restoreAutoCommit);
         }
         this.tccl = Thread.currentThread().getContextClassLoader();
+        return jdbcAdapter;
     }
     
     public void exchangeSent(Exchange exchange) {
@@ -193,6 +197,9 @@ public class JdbcAuditor extends Abstrac
     }
 
     protected void store(Connection connection, String id, byte[] data) throws Exception
{
+        if(adapter == null)
+           adapter = createAdapter();
+
         if (adapter.doLoadData(connection, id) != null) {
             adapter.doUpdateData(connection, id, data);
         } else {
@@ -213,6 +220,8 @@ public class JdbcAuditor extends Abstrac
      */
     public int getExchangeCount() throws AuditorException {
         Connection connection = null;
+        if(adapter == null)
+           adapter=createAdapter();
         try {
             connection = dataSource.getConnection();
             return adapter.doGetCount(connection);
@@ -227,6 +236,8 @@ public class JdbcAuditor extends Abstrac
      * @see org.apache.servicemix.nmr.audit.AuditorMBean#getExchangeIds(int, int)
      */
     public String[] getExchangeIdsByRange(int fromIndex, int toIndex) throws AuditorException
{
+        if(adapter == null)
+           adapter=createAdapter();
         if (fromIndex < 0) {
             throw new IllegalArgumentException("fromIndex should be greater or equal to zero");
         }
@@ -253,6 +264,9 @@ public class JdbcAuditor extends Abstrac
      */
     public Exchange[] getExchangesByIds(String[] ids) throws AuditorException {
         Exchange[] exchanges = new Exchange[ids.length];
+        if(adapter == null)
+           adapter=createAdapter();
+
         Connection connection = null;
         try {
             connection = dataSource.getConnection();
@@ -272,6 +286,8 @@ public class JdbcAuditor extends Abstrac
      */
     public int deleteExchangesByIds(String[] ids) throws AuditorException {
         Connection connection = null;
+        if(adapter == null)
+           adapter=createAdapter();
         boolean restoreAutoCommit = false;
         try {
             connection = dataSource.getConnection();
@@ -324,5 +340,4 @@ public class JdbcAuditor extends Abstrac
             }
         }
     }
-
 }

Modified: servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditorTest.java?rev=1056236&r1=1056235&r2=1056236&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditorTest.java
(original)
+++ servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/jdbc/JdbcAuditorTest.java
Fri Jan  7 10:12:31 2011
@@ -53,7 +53,6 @@ public class JdbcAuditorTest extends Abs
         
         JdbcAuditor auditor = new JdbcAuditor();
         auditor.setDataSource(dataSource);
-        auditor.afterPropertiesSet();
         nmr.getListenerRegistry().register(auditor, null);
 
         auditor.deleteAllExchanges();

Modified: servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/lucene/LuceneAuditorTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/lucene/LuceneAuditorTest.java?rev=1056236&r1=1056235&r2=1056236&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/lucene/LuceneAuditorTest.java
(original)
+++ servicemix/smx4/nmr/trunk/nmr/audit/src/test/java/org/apache/servicemix/nmr/audit/lucene/LuceneAuditorTest.java
Fri Jan  7 10:12:31 2011
@@ -61,7 +61,6 @@ public class LuceneAuditorTest extends A
 
         JdbcAuditor jdbcAuditor = new JdbcAuditor();
         jdbcAuditor.setDataSource(dataSource);
-        jdbcAuditor.afterPropertiesSet();
         LuceneAuditor auditor = new LuceneAuditor();
         auditor.setDelegatedAuditor(jdbcAuditor);
         LuceneIndexer indexer = new LuceneIndexer();



Mime
View raw message