You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/04/17 03:53:51 UTC

svn commit: r394599 [1/2] - in /incubator/servicemix/trunk/servicemix-core: ./ src/main/java/org/apache/servicemix/jbi/audit/ src/main/java/org/apache/servicemix/jbi/audit/jdbc/ src/main/java/org/apache/servicemix/jdbc/ src/main/java/org/apache/service...

Author: gnodet
Date: Sun Apr 16 18:53:47 2006
New Revision: 394599

URL: http://svn.apache.org/viewcvs?rev=394599&view=rev
Log:
Abstract JDBC operations so that they can be reused in JDBC auditor.
Get rid of ddlutils dependency.
The implementation is borrowed from ActiveMQ, thus all major databases are supported.

Added:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/Statements.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jtds_type_4_jdbc_driver_for_ms_sql_server_and_sybase
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/mysql-ab_jdbc_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/oracle_jdbc_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/postgresql_native_driver
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/sap_db
    incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/sqlserver
Removed:
    incubator/servicemix/trunk/servicemix-core/src/main/resources/org/
Modified:
    incubator/servicemix/trunk/servicemix-core/project.xml
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/AbstractAuditor.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java

Modified: incubator/servicemix/trunk/servicemix-core/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/project.xml?rev=394599&r1=394598&r2=394599&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-core/project.xml Sun Apr 16 18:53:47 2006
@@ -329,11 +329,6 @@
         </dependency>
         
         <dependency>
-            <groupId>org.apache.db.ddlutils</groupId>
-            <artifactId>ddlutils</artifactId>
-            <version>${ddlutils_version}</version>
-        </dependency>
-        <dependency>
             <groupId>commons-lang</groupId>
             <artifactId>commons-lang</artifactId>
             <version>${commons_lang_version}</version>

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/AbstractAuditor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/AbstractAuditor.java?rev=394599&r1=394598&r2=394599&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/AbstractAuditor.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/AbstractAuditor.java Sun Apr 16 18:53:47 2006
@@ -195,7 +195,9 @@
     /* (non-Javadoc)
      * @see org.apache.servicemix.jbi.audit.AuditorMBean#deleteExchanges(int, int)
      */
-    public abstract int deleteExchanges(int fromIndex, int toIndex) throws AuditorException;
+    public int deleteExchanges(int fromIndex, int toIndex) throws AuditorException {
+        return deleteExchanges(getExchangeIds(fromIndex, toIndex));
+    }
     
     /* (non-Javadoc)
      * @see org.apache.servicemix.jbi.audit.AuditorMBean#deleteExchanges(java.lang.String[])

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java?rev=394599&r1=394598&r2=394599&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/audit/jdbc/JdbcAuditor.java Sun Apr 16 18:53:47 2006
@@ -15,21 +15,14 @@
  */
 package org.apache.servicemix.jbi.audit.jdbc;
 
+import java.io.IOException;
 import java.net.URI;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Statement;
 
 import javax.jbi.messaging.MessageExchange;
 import javax.sql.DataSource;
 
-import org.apache.ddlutils.Platform;
-import org.apache.ddlutils.PlatformFactory;
-import org.apache.ddlutils.model.Column;
-import org.apache.ddlutils.model.Database;
-import org.apache.ddlutils.model.Table;
 import org.apache.servicemix.jbi.audit.AbstractAuditor;
 import org.apache.servicemix.jbi.audit.AuditorException;
 import org.apache.servicemix.jbi.event.ExchangeEvent;
@@ -40,6 +33,9 @@
 import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
 import org.apache.servicemix.jbi.messaging.RobustInOnlyImpl;
+import org.apache.servicemix.jdbc.JDBCAdapter;
+import org.apache.servicemix.jdbc.JDBCAdapterFactory;
+import org.apache.servicemix.jdbc.Statements;
 import org.springframework.beans.factory.InitializingBean;
 
 /**
@@ -61,12 +57,12 @@
  */
 public class JdbcAuditor extends AbstractAuditor implements InitializingBean {
 
-    public static String DATABASE_MODEL = "database.xml";
-    
     private DataSource dataSource;
-    private Platform platform;
-    private Database database;
     private boolean autoStart = true;
+    private Statements statements;
+    private String tableName = "SM_AUDIT";
+    private JDBCAdapter adapter;
+    private boolean createDataBase = true;
     
     public String getDescription() {
         return "JDBC Auditing Service";
@@ -79,9 +75,33 @@
         if (this.dataSource == null) {
             throw new IllegalArgumentException("dataSource should not be null");
         }
-        platform = PlatformFactory.createNewPlatformInstance(dataSource);
-        database = createDatabase();
-        platform.createTables(database, false, true);
+        if (statements == null) {
+            statements = new Statements();
+            statements.setStoreTableName(tableName);
+        }
+        Connection connection = null;
+        try {
+            connection = getDataSource().getConnection();
+            adapter = JDBCAdapterFactory.getAdapter(connection);
+            if (statements == null) {
+                statements = new Statements();
+                statements.setStoreTableName(tableName);
+            }
+            adapter.setStatements(statements);
+            if (createDataBase) {
+                adapter.doCreateTables(connection);
+            }
+            connection.commit();
+        } catch (SQLException e) {
+            throw (IOException) new IOException("Exception while creating database").initCause(e); 
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (Exception e) {
+                }
+            }
+        }
         init(getContainer());
         if (autoStart) {
             start();
@@ -90,25 +110,6 @@
         }
     }
     
-    protected Database createDatabase() {
-        Database db = new Database();
-        db.setName("JDBCAudit");
-        Table table = new Table();
-        table.setName("SM_AUDIT");
-        Column id = new Column();
-        id.setName("ID");
-        id.setType("VARCHAR");
-        id.setPrimaryKey(true);
-        id.setRequired(true);
-        table.addColumn(id);
-        Column exchange = new Column();
-        exchange.setName("EXCHANGE");
-        exchange.setType("BLOB");
-        table.addColumn(exchange);
-        db.addTable(table);
-        return db;
-    }
-
     public void exchangeSent(ExchangeEvent event) {
         MessageExchange exchange = event.getExchange();
         if (exchange instanceof MessageExchangeImpl == false) {
@@ -118,39 +119,33 @@
             ExchangePacket packet = ((MessageExchangeImpl) exchange).getPacket();
             String id = packet.getExchangeId();
             byte[] data = packet.getData();
-            Connection connection = platform.borrowConnection();
+            Connection connection = dataSource.getConnection();
             try {
                 store(connection, id, data);
+                connection.commit();
             } finally {
-                platform.returnConnection(connection);
+                close(connection);
             }
         } catch (Exception e) {
             log.error("Could not persist exchange", e);
         }
     }
     
-    protected void store(Connection connection, String id, byte[] data) throws Exception {
-        PreparedStatement selectStatement = null;
-        PreparedStatement storeStatement = null;
-        try {
-            selectStatement = connection.prepareStatement("SELECT ID FROM SM_AUDIT WHERE ID = ?");
-            selectStatement.setString(1, id);
-            // Update
-            if (selectStatement.executeQuery().next()) {
-                storeStatement = connection.prepareStatement("UPDATE SM_AUDIT SET EXCHANGE = ? WHERE ID = ?");
-                storeStatement.setString(2, id);
-                storeStatement.setBytes(1, data);
-                storeStatement.execute();
-            // Insert
-            } else {
-                storeStatement = connection.prepareStatement("INSERT INTO SM_AUDIT (ID, EXCHANGE) VALUES (?, ?)");
-                storeStatement.setString(1, id);
-                storeStatement.setBytes(2, data);
-                storeStatement.execute();
+    private static void close(Connection connection) {
+        if (connection != null) {
+            try {
+                connection.close();
+            } catch (SQLException e) {
             }
-        } finally {
-            closeStatement(selectStatement);
-            closeStatement(storeStatement);
+        }
+        
+    }
+
+    protected void store(Connection connection, String id, byte[] data) throws Exception {
+        if (adapter.doLoadData(connection, id) != null) {
+            adapter.doUpdateData(connection, id, data);
+        } else {
+            adapter.doStoreData(connection, id, data);
         }
     }
     
@@ -165,60 +160,19 @@
     /* (non-Javadoc)
      * @see org.apache.servicemix.jbi.audit.AuditorMBean#getExchangeCount()
      */
-    public int getExchangeCount()throws AuditorException {
-        Connection con = platform.borrowConnection();
-        Statement statement = null;
+    public int getExchangeCount() throws AuditorException {
+        Connection connection = null;
         try {
-            statement = con.createStatement();
-            ResultSet rs = statement.executeQuery("SELECT COUNT(ID) FROM SM_AUDIT");
-            rs.next();
-            return rs.getInt(1);
-        } catch (SQLException e) {
+            connection = dataSource.getConnection();
+            return adapter.doGetCount(connection);
+        } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchange count", e);
         } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
+            close(connection);
         }
     }
 
     /* (non-Javadoc)
-     * @see org.apache.servicemix.jbi.audit.AuditorMBean#getExchanges(int, int)
-     */
-    public MessageExchange[] getExchanges(int fromIndex, int toIndex) throws AuditorException {
-        if (fromIndex < 0) {
-            throw new IllegalArgumentException("fromIndex should be greater or equal to zero");
-        }
-        if (toIndex < fromIndex) {
-            throw new IllegalArgumentException("toIndex should be greater or equal to fromIndex");
-        }
-        // Do not hit the database if no exchanges are requested
-        if (fromIndex == toIndex) {
-            return new MessageExchange[0];
-        }
-        Connection con = platform.borrowConnection();
-        Statement statement = null;
-        try {
-            statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
-            statement.setFetchSize(toIndex - fromIndex);
-            ResultSet rs = statement.executeQuery("SELECT EXCHANGE FROM SM_AUDIT");
-            rs.absolute(fromIndex + 1);
-            MessageExchange[] exchanges = new MessageExchange[toIndex - fromIndex];
-            for (int row = 0; row < toIndex - fromIndex; row++) {
-                exchanges[row] = getExchange(rs.getBytes(1));
-                if (!rs.next()) {
-                    break;
-                }
-            }
-            return exchanges;
-        } catch (SQLException e) {
-            throw new AuditorException("Could not retrieve exchanges", e);
-        } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
-        }
-    }
-    
-    /* (non-Javadoc)
      * @see org.apache.servicemix.jbi.audit.AuditorMBean#getExchangeIds(int, int)
      */
     public String[] getExchangeIds(int fromIndex, int toIndex) throws AuditorException {
@@ -232,26 +186,15 @@
         if (fromIndex == toIndex) {
             return new String[0];
         }
-        Connection con = platform.borrowConnection();
-        Statement statement = null;
+        Connection connection = null;
         try {
-            statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
-            statement.setFetchSize(toIndex - fromIndex);
-            ResultSet rs = statement.executeQuery("SELECT ID FROM SM_AUDIT");
-            rs.absolute(fromIndex + 1);
-            String[] ids = new String[toIndex - fromIndex];
-            for (int row = 0; row < toIndex - fromIndex; row++) {
-                ids[row] = rs.getString(1);
-                if (!rs.next()) {
-                    break;
-                }
-            }
+            connection = dataSource.getConnection();
+            String[] ids = adapter.doGetIds(connection, fromIndex, toIndex);
             return ids;
-        } catch (SQLException e) {
+        } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchange ids", e);
         } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
+            close(connection);
         }
     }
 
@@ -260,74 +203,17 @@
      */
     public MessageExchange[] getExchanges(String[] ids) throws AuditorException {
         MessageExchange[] exchanges = new MessageExchange[ids.length];
-        Connection con = platform.borrowConnection();
-        PreparedStatement statement = null;
+        Connection connection = null;
         try {
-            statement = con.prepareStatement("SELECT EXCHANGE FROM SM_AUDIT WHERE ID = ?");
-            for (int i = 0; i < exchanges.length; i++) {
-                statement.setString(1, ids[i]);
-                ResultSet rs = statement.executeQuery();
-                rs.next();
-                exchanges[i] = getExchange(rs.getBytes(1));
+            connection = dataSource.getConnection();
+            for (int row = 0; row < ids.length; row++) {
+                exchanges[row] = getExchange(adapter.doLoadData(connection, ids[row]));
             }
             return exchanges;
-        } catch (SQLException e) {
+        } catch (Exception e) {
             throw new AuditorException("Could not retrieve exchanges", e);
         } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.jbi.audit.AuditorMBean#deleteExchanges()
-     */
-    public int deleteExchanges() throws AuditorException {
-        Connection con = platform.borrowConnection();
-        Statement statement = null;
-        try {
-            statement = con.createStatement();
-            return statement.executeUpdate("DELETE FROM SM_AUDIT");
-        } catch (SQLException e) {
-            throw new AuditorException("Could not delete exchanges", e);
-        } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
-        }
-    }
-    
-    /* (non-Javadoc)
-     * @see org.apache.servicemix.jbi.audit.AuditorMBean#deleteExchanges(int, int)
-     */
-    public int deleteExchanges(int fromIndex, int toIndex) throws AuditorException {
-        if (fromIndex < 0) {
-            throw new IllegalArgumentException("fromIndex should be greater or equal to zero");
-        }
-        if (toIndex < fromIndex) {
-            throw new IllegalArgumentException("toIndex should be greater or equal to fromIndex");
-        }
-        // Do not hit the database if no removal is requested
-        if (fromIndex == toIndex) {
-            return 0;
-        }
-        Connection con = platform.borrowConnection();
-        Statement statement = null;
-        try {
-            statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
-            ResultSet rs = statement.executeQuery("SELECT ID FROM SM_AUDIT");
-            rs.absolute(fromIndex + 1);
-            for (int row = 0; row < toIndex - fromIndex; row++) {
-                rs.deleteRow();
-                if (!rs.next()) {
-                    return row + 1;
-                }
-            }
-            return toIndex - fromIndex;
-        } catch (SQLException e) {
-            throw new AuditorException("Could not delete exchanges", e);
-        } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
+            close(connection);
         }
     }
 
@@ -335,21 +221,17 @@
      * @see org.apache.servicemix.jbi.audit.AuditorMBean#deleteExchanges(java.lang.String[])
      */
     public int deleteExchanges(String[] ids) throws AuditorException {
-        Connection con = platform.borrowConnection();
-        PreparedStatement statement = null;
+        Connection connection = null;
         try {
-            int deleted = 0;
-            statement = con.prepareStatement("DELETE FROM SM_AUDIT WHERE ID = ?");
-            for (int i = 0; i < ids.length; i++) {
-                statement.setString(1, ids[i]);
-                deleted += statement.executeUpdate();
+            connection = dataSource.getConnection();
+            for (int row = 0; row < ids.length; row++) {
+                adapter.doRemoveData(connection, ids[row]);
             }
-            return deleted;
-        } catch (SQLException e) {
+            return -1;
+        } catch (Exception e) {
             throw new AuditorException("Could not delete exchanges", e);
         } finally {
-            closeStatement(statement);
-            platform.returnConnection(con);
+            close(connection);
         }
     }
     
@@ -375,23 +257,6 @@
         }
     }
     
-    /**
-     * Close the given statement, logging any exception.
-     * @param statement the statement to close
-     */
-    protected void closeStatement(Statement statement) {
-        if (statement != null) {
-            try {
-                Connection conn = statement.getConnection();
-                if ((conn != null) && !conn.isClosed()) {
-                    statement.close();
-                }
-            } catch (Exception e) {
-                log.warn("Error closing statement", e);
-            }
-        }
-    }
-
     public boolean isAutoStart() {
         return autoStart;
     }

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public interface JDBCAdapter {
+
+    public void doCreateTables(Connection connection) throws SQLException, IOException;
+    
+    public void doDropTables(Connection connection) throws SQLException, IOException;
+    
+    public byte[] doLoadData(Connection connection, String id) throws SQLException, IOException;
+    
+    public byte[][] doLoadData(Connection connection, String[] ids) throws SQLException, IOException;
+    
+    public void doStoreData(Connection connection, String id, byte[] data) throws SQLException, IOException;
+    
+    public void doUpdateData(Connection connection, String id, byte[] data) throws SQLException, IOException;
+    
+    public void doRemoveData(Connection connection, String id) throws SQLException, IOException;
+    
+    public void doRemoveData(Connection connection, String[] ids) throws SQLException, IOException;
+    
+    public int doGetCount(Connection connection) throws SQLException, IOException;
+    
+    public String[] doGetIds(Connection connection) throws SQLException, IOException;
+    
+    public String[] doGetIds(Connection connection, int fromIndex, int toIndex) throws SQLException, IOException;
+    
+    public Statements getStatements();
+    
+    public void setStatements(Statements statements);
+    
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.activeio.util.FactoryFinder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jdbc.adapter.DefaultJDBCAdapter;
+
+public class JDBCAdapterFactory {
+
+    private static final Log log = LogFactory.getLog(JDBCAdapterFactory.class);
+    private static FactoryFinder factoryFinder = new FactoryFinder("META-INF/services/org/apache/servicemix/jdbc/");
+
+    public static JDBCAdapter getAdapter(Connection connection) {
+        JDBCAdapter adapter = null;
+        try {
+
+            // Make the filename file system safe.
+            String driverName = connection.getMetaData().getDriverName();
+            driverName = driverName.replaceAll("[^a-zA-Z0-9\\-]", "_").toLowerCase();
+
+            try {
+                adapter = (JDBCAdapter) factoryFinder.newInstance(driverName);
+                log.info("Database driver recognized: [" + driverName + "]");
+            } catch (Throwable e) {
+                log.warn("Database driver NOT recognized: [" + driverName
+                        + "].  Will use default JDBC implementation.");
+            }
+
+        } catch (SQLException e) {
+            log.warn("JDBC error occurred while trying to detect database type.  Will use default JDBC implementation: "
+                            + e.getMessage());
+            log("Failure details: ", e);
+        }
+
+        // Use the default JDBC adapter if the
+        // Database type is not recognized.
+        if (adapter == null) {
+            adapter = new DefaultJDBCAdapter();
+        }
+        
+        return adapter;
+    }
+    
+    public static void log(String msg, SQLException e) {
+        if (log.isDebugEnabled()) {
+            if (log.isDebugEnabled()) {
+                String s = msg + e.getMessage();
+                while (e.getNextException() != null) {
+                    e = e.getNextException();
+                    s += ", due to: " + e.getMessage();
+                }
+                log.debug(s, e);
+            }
+        }
+    }
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/Statements.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/Statements.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/Statements.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/Statements.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc;
+
+/**
+ * @version $Revision: 1.4 $
+ * 
+ * @org.apache.xbean.XBean element="statements"
+ * 
+ */
+public class Statements {
+
+    private String tablePrefix = "";
+    protected String storeTableName = "SM_STORE";
+
+    protected String binaryDataType = "BLOB";
+    protected String idDataType = "VARCHAR(32)";
+    private String storeDataStatement;
+    private String updateDataStatement;
+    private String removeDataStatement;
+    private String findDataStatement;
+    private String findAllIdsStatement;
+    private String findAllDataStatement;
+    private String countStatement;
+    private String[] createSchemaStatements;
+    private String[] dropSchemaStatements;
+
+    public String[] getCreateSchemaStatements() {
+        if (createSchemaStatements == null) {
+            createSchemaStatements = new String[] {
+                    "CREATE TABLE " + getFullStoreTableName() + "(" + "ID " + idDataType + " NOT NULL"
+                            + ", DATA " + binaryDataType
+                            + ", PRIMARY KEY ( ID ) )",
+            };
+        }
+        return createSchemaStatements;
+    }
+
+    public String[] getDropSchemaStatements() {
+        if (dropSchemaStatements == null) {
+            dropSchemaStatements = new String[] { 
+                    "DROP TABLE " + getFullStoreTableName() + "", 
+            };
+        }
+        return dropSchemaStatements;
+    }
+
+    public String getStoreDataStatement() {
+        if (storeDataStatement == null) {
+            storeDataStatement = "INSERT INTO " + getFullStoreTableName()
+                    + "(ID, DATA) VALUES (?, ?)";
+        }
+        return storeDataStatement;
+    }
+
+    public String getUpdateDataStatement() {
+        if (updateDataStatement == null) {
+            updateDataStatement = "UPDATE " + getFullStoreTableName() + " SET DATA=? WHERE ID=?";
+        }
+        return updateDataStatement;
+    }
+
+    public String getRemoveDataStatement() {
+        if (removeDataStatement == null) {
+            removeDataStatement = "DELETE FROM " + getFullStoreTableName() + " WHERE ID=?";
+        }
+        return removeDataStatement;
+    }
+
+    public String getFindDataStatement() {
+        if (findDataStatement == null) {
+            findDataStatement = "SELECT DATA FROM " + getFullStoreTableName() + " WHERE ID=?";
+        }
+        return findDataStatement;
+    }
+
+    public String getFindAllIdsStatement() {
+        if (findAllIdsStatement == null) {
+            findAllIdsStatement = "SELECT ID FROM " + getFullStoreTableName() 
+                    + " ORDER BY ID"; 
+        }
+        return findAllIdsStatement;
+    }
+
+    public String getFindAllDataStatement() {
+        if (findAllDataStatement == null) {
+            findAllDataStatement = "SELECT ID, DATA FROM " + getFullStoreTableName()
+                    + " WHERE ORDER BY ID";
+        }
+        return findAllDataStatement;
+    }
+
+    public String getCountStatement() {
+        if (countStatement == null) {
+            countStatement = "SELECT COUNT(ID) FROM " + getFullStoreTableName();
+        }
+        return countStatement;
+    }
+
+    public String getFullStoreTableName() {
+        return getTablePrefix() + getStoreTableName();
+    }
+
+    /**
+     * @return Returns the messageDataType.
+     */
+    public String getBinaryDataType() {
+        return binaryDataType;
+    }
+
+    /**
+     * @param messageDataType
+     *            The messageDataType to set.
+     */
+    public void setBinaryDataType(String messageDataType) {
+        this.binaryDataType = messageDataType;
+    }
+
+    /**
+     * @return Returns the storeTableName.
+     */
+    public String getStoreTableName() {
+        return storeTableName;
+    }
+
+    /**
+     * @param storeTableName
+     *            The storeTableName to set.
+     */
+    public void setStoreTableName(String storeTableName) {
+        this.storeTableName = storeTableName;
+    }
+
+    /**
+     * @return Returns the idDataType.
+     */
+    public String getIdDataType() {
+        return idDataType;
+    }
+
+    /**
+     * @param idDataType
+     *            The idDataType to set.
+     */
+    public void setIdDataType(String msgIdDataType) {
+        this.idDataType = msgIdDataType;
+    }
+
+    /**
+     * @return Returns the tablePrefix.
+     */
+    public String getTablePrefix() {
+        return tablePrefix;
+    }
+
+    /**
+     * @param tablePrefix
+     *            The tablePrefix to set.
+     */
+    public void setTablePrefix(String tablePrefix) {
+        this.tablePrefix = tablePrefix;
+    }
+
+    public void setStoreDataStatement(String addMessageStatment) {
+        this.storeDataStatement = addMessageStatment;
+    }
+
+    public void setCreateSchemaStatements(String[] createSchemaStatments) {
+        this.createSchemaStatements = createSchemaStatments;
+    }
+
+    public void setDropSchemaStatements(String[] dropSchemaStatments) {
+        this.dropSchemaStatements = dropSchemaStatments;
+    }
+
+    public void setFindAllDataStatement(String findAllMessagesStatment) {
+        this.findAllDataStatement = findAllMessagesStatment;
+    }
+
+    public void setFindDataStatement(String findMessageStatment) {
+        this.findDataStatement = findMessageStatment;
+    }
+
+    public void setRemoveDataStatement(String removeMessageStatment) {
+        this.removeDataStatement = removeMessageStatment;
+    }
+
+    public void setUpdateDataStatement(String updateMessageStatment) {
+        this.updateDataStatement = updateMessageStatment;
+    }
+
+    public void setFindAllIdsStatement(String findAllIdsStatement) {
+        this.findAllIdsStatement = findAllIdsStatement;
+    }
+
+    public void setCountStatement(String getCountStatement) {
+        this.countStatement = getCountStatement;
+    }
+
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+
+
+/**
+ * Axion specific Adapter.
+ * 
+ * @org.apache.xbean.XBean element="axionJDBCAdapter"
+ * @version $Revision: 1.4 $
+ */
+public class AxionJDBCAdapter extends StreamJDBCAdapter {
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.jms.JMSException;
+
+import org.apache.activeio.util.ByteArrayOutputStream;
+import org.apache.activemq.store.jdbc.TransactionContext;
+
+
+/**
+ * This JDBCAdapter inserts and extracts BLOB data using the 
+ * getBlob()/setBlob() operations.  This is a little more involved
+ * since to insert a blob you have to:
+ * 
+ *  1: insert empty blob.
+ *  2: select the blob 
+ *  3: finally update the blob with data value. 
+ * 
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li></li> 
+ * </ul>
+ * 
+ * @org.apache.xbean.XBean element="blobJDBCAdapter"
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class BlobJDBCAdapter extends DefaultJDBCAdapter {
+    
+    public void doAddMessage(Connection c, long seq, String messageID, String destinationName, byte[] data) throws SQLException,
+            JMSException {
+        PreparedStatement s = null;
+        ResultSet rs = null;
+        try {
+            
+            // Add the Blob record.
+            s = c.prepareStatement(statements.getStoreDataStatement());
+            s.setLong(1, seq);
+            s.setString(2, destinationName);
+            s.setString(3, messageID);
+            s.setString(4, " ");
+            
+            if (s.executeUpdate() != 1)
+                throw new JMSException("Failed to broker message: " + messageID
+                        + " in container.");
+            s.close();
+
+            // Select the blob record so that we can update it.
+            s = c.prepareStatement(statements.getFindDataStatement());
+            s.setLong(1, seq);
+            rs = s.executeQuery();
+            if (!rs.next())
+                throw new JMSException("Failed to broker message: " + messageID
+                        + " in container.");
+
+            // Update the blob
+            Blob blob = rs.getBlob(1);
+            OutputStream stream = blob.setBinaryStream(data.length);
+            stream.write(data);
+            stream.close();
+            s.close();
+
+            // Update the row with the updated blob
+            s = c.prepareStatement(statements.getUpdateDataStatement());
+            s.setBlob(1, blob);
+            s.setLong(2, seq);
+
+        } catch (IOException e) {
+            throw (SQLException) new SQLException("BLOB could not be updated: "
+                    + e).initCause(e);
+        } finally {
+            try {
+                rs.close();
+            } catch (Throwable e) {
+            }
+            try {
+                s.close();
+            } catch (Throwable e) {
+            }
+        }
+    }
+    
+    public byte[] doGetMessage(TransactionContext c, long seq) throws SQLException {
+	    PreparedStatement s=null; ResultSet rs=null;
+	    try {
+	        
+	        s = c.getConnection().prepareStatement(statements.getFindDataStatement());
+	        s.setLong(1, seq); 
+	        rs = s.executeQuery();
+	        
+	        if( !rs.next() )
+	            return null;
+	        Blob blob = rs.getBlob(1);
+	        InputStream is = blob.getBinaryStream();
+	        
+	        ByteArrayOutputStream os = new ByteArrayOutputStream((int)blob.length());	        
+	        int ch;
+	        while( (ch=is.read())>= 0 ) {
+	            os.write(ch);
+	        }
+	        is.close();
+	        os.close();
+	        
+	        return os.toByteArray();
+	        
+	    } catch (IOException e) {
+            throw (SQLException) new SQLException("BLOB could not be updated: "
+                    + e).initCause(e);
+        } finally {
+	        try { rs.close(); } catch (Throwable e) {}
+	        try { s.close(); } catch (Throwable e) {}
+	    }
+    }
+
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * This JDBCAdapter inserts and extracts BLOB data using the 
+ * setBytes()/getBytes() operations.
+ * 
+ * The databases/JDBC drivers that use this adapter are:
+ * 
+ * @org.apache.xbean.XBean element="bytesJDBCAdapter"
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class BytesJDBCAdapter extends DefaultJDBCAdapter {
+
+	    
+    /**
+     * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#getBinaryData(java.sql.ResultSet, int)
+     */
+    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
+        return rs.getBytes(index);
+    }
+    
+    /**
+     * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#setBinaryData(java.sql.PreparedStatement, int, byte[])
+     */
+    protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException {
+        s.setBytes(index, data);
+    }
+    
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ *
+ * @org.apache.xbean.XBean element="db2JDBCAdapter"
+ *
+ * @version $Revision: 1.2 $
+ */
+public class DB2JDBCAdapter extends DefaultJDBCAdapter {
+
+    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
+        // Get as a BLOB
+        Blob aBlob = rs.getBlob(index);
+        return aBlob.getBytes(1, (int) aBlob.length());
+    }
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,313 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jdbc.JDBCAdapter;
+import org.apache.servicemix.jdbc.JDBCAdapterFactory;
+import org.apache.servicemix.jdbc.Statements;
+
+/**
+ * Implements all the default JDBC operations that are used
+ * by the JDBCPersistenceAdapter.
+ * <p/>
+ * sub-classing is encouraged to override the default
+ * implementation of methods to account for differences
+ * in JDBC Driver implementations.
+ * <p/>
+ * The JDBCAdapter inserts and extracts BLOB data using the
+ * getBytes()/setBytes() operations.
+ * <p/>
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li></li>
+ * </ul>
+ *
+ * @org.apache.xbean.XBean element="defaultJDBCAdapter"
+ * 
+ * @version $Revision: 1.10 $
+ */
+public class DefaultJDBCAdapter implements JDBCAdapter {
+
+    private static final Log log = LogFactory.getLog(DefaultJDBCAdapter.class);
+
+    protected Statements statements;
+
+    protected void setBinaryData(PreparedStatement s, int index, byte data[]) throws SQLException {
+        s.setBytes(index, data);
+    }
+
+    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
+        return rs.getBytes(index);
+    }
+
+    public void doCreateTables(Connection connection) throws SQLException, IOException {
+        Statement s = null;
+        try {
+            
+            // Check to see if the table already exists.  If it does, then don't log warnings during startup.
+            // Need to run the scripts anyways since they may contain ALTER statements that upgrade a previous version of the table
+            boolean alreadyExists = false;
+            ResultSet rs=null;
+            try {
+                rs= connection.getMetaData().getTables(null,null, statements.getFullStoreTableName(), new String[] {"TABLE"});
+                alreadyExists = rs.next();                
+            } catch (Throwable ignore) {
+            } finally {
+                close(rs);
+            }
+            
+            s = connection.createStatement();
+            String[] createStatments = statements.getCreateSchemaStatements();
+            for (int i = 0; i < createStatments.length; i++) {
+                // This will fail usually since the tables will be
+                // created already.
+                try {
+                    log.debug("Executing SQL: " + createStatments[i]);
+                    s.execute(createStatments[i]);
+                }
+                catch (SQLException e) {
+                    if( alreadyExists )  {
+                        log.debug("Could not create JDBC tables; The message table already existed." +
+                                " Failure was: " + createStatments[i] + " Message: " + e.getMessage() +
+                                " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() );
+                    } else {
+                        log.warn("Could not create JDBC tables; they could already exist." +
+                            " Failure was: " + createStatments[i] + " Message: " + e.getMessage() +
+                            " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() );
+                        JDBCAdapterFactory.log("Failure details: ", e);
+                    }
+                }
+            }
+            connection.commit();
+            
+        }
+        finally {
+            close(s);
+        }
+    }
+
+    public void doDropTables(Connection connection) throws SQLException, IOException {
+        Statement s = null;
+        try {
+            s = connection.createStatement();
+            String[] dropStatments = statements.getDropSchemaStatements();
+            for (int i = 0; i < dropStatments.length; i++) {
+                // This will fail usually since the tables will be
+                // created already.
+                try {
+                    s.execute(dropStatments[i]);
+                }
+                catch (SQLException e) {
+                    log.warn("Could not drop JDBC tables; they may not exist." +
+                        " Failure was: " + dropStatments[i] + " Message: " + e.getMessage() +
+                        " SQLState: " + e.getSQLState() + " Vendor code: " + e.getErrorCode() );
+                    JDBCAdapterFactory.log("Failure details: ", e);
+                }
+            }
+            connection.commit();
+        }
+        finally {
+            close(s);
+        }
+    }
+
+    public void doStoreData(Connection connection, String id, byte[] data) throws SQLException, IOException {
+        PreparedStatement s = null;
+        try {
+            if (s == null) {
+                s = connection.prepareStatement(statements.getStoreDataStatement());
+            }
+            s.setString(1, id);
+            setBinaryData(s, 2, data);
+            if ( s.executeUpdate() != 1 ) {
+                throw new SQLException("Failed to insert data");
+            }
+        } finally {
+            close(s);
+        }
+    }
+    
+    public byte[] doLoadData(Connection connection, String id) throws SQLException, IOException {
+        PreparedStatement s = null;
+        ResultSet rs = null;
+        try {
+            s = connection.prepareStatement(statements.getFindDataStatement());
+            s.setString(1, id);
+            rs = s.executeQuery();
+            if (!rs.next()) {
+                return null;
+            }
+            return getBinaryData(rs, 1);
+        }
+        finally {
+            close(rs);
+            close(s);
+        }
+    }
+    
+    public void doUpdateData(Connection connection, String id, byte[] data) throws SQLException, IOException {
+        PreparedStatement s = null;
+        try {
+            if( s == null ) {
+                s = connection.prepareStatement(statements.getUpdateDataStatement());
+            }
+            s.setString(2, id);
+            setBinaryData(s, 1, data);
+            if ( s.executeUpdate() != 1 ) {
+                throw new SQLException("Failed to update data");
+            }
+        } finally {
+            close(s);
+        }
+    }
+    
+    public void doRemoveData(Connection connection, String id) throws SQLException, IOException {
+        PreparedStatement s = null;
+        try {
+            s = connection.prepareStatement(statements.getRemoveDataStatement());
+            s.setString(1, id);
+            if (s.executeUpdate() != 1) {
+                throw new SQLException("Failed to remove data");
+            }
+        } finally {
+            close(s);
+        }        
+    }
+    
+    static private void close(Statement s) {
+        try {
+            s.close();
+        } catch (Throwable e) {
+        }
+    }
+
+    static private void close(ResultSet rs) {
+        try {
+            rs.close();
+        } catch (Throwable e) {
+        }
+    }
+
+    public Statements getStatements() {
+        return statements;
+    }
+
+    public void setStatements(Statements statements) {
+        this.statements = statements;
+    }
+
+    public byte[][] doLoadData(Connection connection, String[] ids) throws SQLException, IOException {
+        PreparedStatement s = null;
+        byte[][] datas = new byte[ids.length][];
+        try {
+            s = connection.prepareStatement(statements.getFindDataStatement());
+            for (int i = 0; i < ids.length; i++) {
+                s.setString(1, ids[i]);
+                ResultSet rs = s.executeQuery();
+                if (rs.next()) {
+                    datas[i] = getBinaryData(rs, 1);
+                }
+                close(rs);
+            }
+            return datas;
+        }
+        finally {
+            close(s);
+        }
+    }
+
+    public void doRemoveData(Connection connection, String[] ids) throws SQLException, IOException {
+        PreparedStatement s = null;
+        try {
+            s = connection.prepareStatement(statements.getRemoveDataStatement());
+            for (int i = 0; i < ids.length; i++) {
+                s.setString(1, ids[i]);
+                s.executeUpdate();
+            }
+        }
+        finally {
+            close(s);
+        }
+    }
+
+    public int doGetCount(Connection connection) throws SQLException, IOException {
+        PreparedStatement s = null;
+        ResultSet rs = null;
+        try {
+            s = connection.prepareStatement(statements.getCountStatement());
+            rs = s.executeQuery();
+            rs.next();
+            return rs.getInt(1);
+        }
+        finally {
+            close(rs);
+            close(s);
+        }
+    }
+
+    public String[] doGetIds(Connection connection) throws SQLException, IOException {
+        PreparedStatement s = null;
+        ResultSet rs = null;
+        try {
+            List ids = new ArrayList();
+            s = connection.prepareStatement(statements.getFindAllIdsStatement());
+            rs = s.executeQuery();
+            while (!rs.next()) {
+                ids.add(rs.getString(1));
+            }
+            return (String[]) ids.toArray(new String[ids.size()]);
+        }
+        finally {
+            close(rs);
+            close(s);
+        }
+    }
+
+    public String[] doGetIds(Connection connection, int fromIndex, int toIndex) throws SQLException, IOException {
+        Statement s = null;
+        ResultSet rs = null;
+        try {
+            s = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+            s.setFetchSize(toIndex - fromIndex);
+            rs = s.executeQuery(statements.getFindAllIdsStatement());
+            rs.absolute(fromIndex + 1);
+            String[] ids = new String[toIndex - fromIndex];
+            for (int row = 0; row < toIndex - fromIndex; row++) {
+                ids[row] = rs.getString(1);
+                if (!rs.next()) {
+                    break;
+                }
+            }
+            return ids;
+        }
+        finally {
+            close(rs);
+            close(s);
+        }
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import org.apache.servicemix.jdbc.Statements;
+
+/**
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class HsqldbJDBCAdapter extends BytesJDBCAdapter {
+	   
+    public void setStatements(Statements statements) {
+        statements.setBinaryDataType("OTHER");
+        super.setStatements(statements);
+    }
+    
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import org.apache.servicemix.jdbc.Statements;
+
+/**
+ * Provides JDBCAdapter since that uses
+ * IMAGE datatype to hold binary data.
+ * 
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li>Sybase</li>
+ * <li>MS SQL</li>
+ * </ul>
+ * 
+ * @org.apache.xbean.XBean element="imageBasedJDBCAdaptor"
+ */
+public class ImageBasedJDBCAdaptor extends DefaultJDBCAdapter {
+
+    public void setStatements(Statements statements) {
+        statements.setBinaryDataType("IMAGE");
+        super.setStatements(statements);
+    }
+    
+}
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+
+/**
+ * JDBC Adapter for Informix database.
+ * Informix database restricts length of composite keys.
+ *  
+ * @org.apache.xbean.XBean element="informixJDBCAdapter"
+ */
+public class InformixJDBCAdapter extends BlobJDBCAdapter {
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import org.apache.servicemix.jdbc.Statements;
+
+/**
+ * JDBC Adapter for the MaxDB database.
+ */
+public class MaxDBJDBCAdapter extends DefaultJDBCAdapter {
+
+    public void setStatements(Statements statements) {
+        statements.setBinaryDataType("LONG BYTE");
+        statements.setIdDataType("VARCHAR(250) ASCII");
+        super.setStatements(statements);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Implements all the default JDBC operations that are used
+ * by the JDBCPersistenceAdapter.
+ * <p/>
+ * Subclassing is encouraged to override the default
+ * implementation of methods to account for differences
+ * in JDBC Driver implementations.
+ * <p/>
+ * The JDBCAdapter inserts and extracts BLOB data using the
+ * getBytes()/setBytes() operations.
+ * <p/>
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li></li>
+ * </ul>
+ *
+ * @org.apache.xbean.XBean element="oracleJDBCAdapter"
+ *
+ * @version $Revision: 1.2 $
+ */
+public class OracleJDBCAdapter extends DefaultJDBCAdapter {
+
+    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
+        // Get as a BLOB
+        Blob aBlob = rs.getBlob(index);
+        return aBlob.getBytes(1, (int) aBlob.length());
+    }
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import org.apache.servicemix.jdbc.Statements;
+
+
+/**
+ * Implements all the default JDBC operations that are used
+ * by the JDBCPersistenceAdapter.
+ * <p/>
+ * Subclassing is encouraged to override the default
+ * implementation of methods to account for differences
+ * in JDBC Driver implementations.
+ * <p/>
+ * The JDBCAdapter inserts and extracts BLOB data using the
+ * getBytes()/setBytes() operations.
+ * <p/>
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li></li>
+ * </ul>
+ *
+ * @version $Revision: 1.1 $
+ */
+public class PostgresqlJDBCAdapter extends BytesJDBCAdapter {
+
+    public void setStatements(Statements statements) {
+        statements.setBinaryDataType("BYTEA");
+        super.setStatements(statements);
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java Sun Apr 16 18:53:47 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.jdbc.adapter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.activeio.util.ByteArrayInputStream;
+
+/**
+ * This JDBCAdapter inserts and extracts BLOB data using the 
+ * setBinaryStream()/getBinaryStream() operations.
+ * 
+ * The databases/JDBC drivers that use this adapter are:
+ * <ul>
+ * <li>Axion</li> 
+ * </ul>
+ * 
+ * @org.apache.xbean.XBean element="streamJDBCAdapter"
+ * 
+ * @version $Revision: 1.2 $
+ */
+public class StreamJDBCAdapter extends DefaultJDBCAdapter {
+    
+    /**
+     * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#getBinaryData(java.sql.ResultSet, int)
+     */
+    protected byte[] getBinaryData(ResultSet rs, int index) throws SQLException {
+        
+        try {
+            InputStream is = rs.getBinaryStream(index);
+            ByteArrayOutputStream os = new ByteArrayOutputStream(1024 * 4);
+
+            int ch;
+            while ((ch = is.read()) >= 0) {
+                os.write(ch);
+            }
+            is.close();
+            os.close();
+
+            return os.toByteArray();
+        } catch (IOException e) {
+            throw (SQLException)new SQLException("Error reading binary parameter: "+index).initCause(e);
+        }
+    }
+    
+    /**
+     * @see org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter#setBinaryData(java.sql.PreparedStatement, int, byte[])
+     */
+    protected void setBinaryData(PreparedStatement s, int index, byte[] data) throws SQLException {
+        s.setBinaryStream(index, new ByteArrayInputStream(data), data.length);
+    }
+    
+}
\ No newline at end of file

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java?rev=394599&r1=394598&r2=394599&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java Sun Apr 16 18:53:47 2006
@@ -1,14 +1,27 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.store.jdbc;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 
+import org.apache.activeio.util.ByteArrayInputStream;
+import org.apache.activeio.util.ByteArrayOutputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.store.Store;
@@ -40,10 +53,8 @@
             out.writeObject(data);
             out.close();
             connection = factory.getDataSource().getConnection();
-            PreparedStatement ps = connection.prepareStatement("INSERT INTO " + factory.getTableName() + " (ID, DATA) VALUES (?, ?)");
-            ps.setString(1, name + ":" + id);
-            ps.setBytes(2, buffer.toByteArray());
-            ps.execute();
+            factory.getAdapter().doStoreData(connection, name + ":" + id, buffer.toByteArray());
+            connection.commit();
         } catch (Exception e) {
             throw (IOException) new IOException("Error storing object").initCause(e);
         } finally {
@@ -68,20 +79,15 @@
         Connection connection = null;
         try {
             connection = factory.getDataSource().getConnection();
-            PreparedStatement ps = connection.prepareStatement("SELECT DATA FROM " + factory.getTableName() + " WHERE ID = ?");
-            ps.setString(1, name + ":" + id);
-            ResultSet rs = ps.executeQuery();
-            if (rs.next()) {
-                byte[] data = rs.getBytes(1);
+            byte[] data = factory.getAdapter().doLoadData(connection, name + ":" + id);
+            Object result = null;
+            if (data != null) {
                 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
-                Object result = ois.readObject();
-                ps = connection.prepareStatement("DELETE FROM " + factory.getTableName() + " WHERE ID = ?");
-                ps.setString(1, name + ":" + id);
-                ps.execute();
-                return result;
-            } else {
-                return null;
+                result = ois.readObject();
+                factory.getAdapter().doRemoveData(connection, name + ":" + id);
             }
+            connection.commit();
+            return result;
         } catch (Exception e) {
             throw (IOException) new IOException("Error storing object").initCause(e);
         } finally {

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java?rev=394599&r1=394598&r2=394599&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java Sun Apr 16 18:53:47 2006
@@ -1,6 +1,22 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.servicemix.store.jdbc;
 
 import java.io.IOException;
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.Map;
@@ -8,11 +24,9 @@
 import javax.sql.DataSource;
 
 import org.apache.activemq.util.IdGenerator;
-import org.apache.ddlutils.Platform;
-import org.apache.ddlutils.PlatformFactory;
-import org.apache.ddlutils.model.Column;
-import org.apache.ddlutils.model.Database;
-import org.apache.ddlutils.model.Table;
+import org.apache.servicemix.jdbc.JDBCAdapter;
+import org.apache.servicemix.jdbc.JDBCAdapterFactory;
+import org.apache.servicemix.jdbc.Statements;
 import org.apache.servicemix.store.Store;
 import org.apache.servicemix.store.StoreFactory;
 
@@ -25,18 +39,36 @@
     private Map stores = new HashMap();
     private String tableName = "SM_STORE";
     private boolean createDataBase = true;
-    private boolean firstStore = true;
+    private JDBCAdapter adapter;
+    private Statements statements;
     
     /* (non-Javadoc)
      * @see org.apache.servicemix.store.ExchangeStoreFactory#get(java.lang.String)
      */
     public synchronized Store open(String name) throws IOException {
-        if (firstStore && createDataBase) {
-            firstStore = false;
+        if (adapter == null) {
+            Connection connection = null;
             try {
-                createDataBase();
-            } catch (Exception e) {
+                connection = getDataSource().getConnection();
+                adapter = JDBCAdapterFactory.getAdapter(connection);
+                if (statements == null) {
+                    statements = new Statements();
+                    statements.setStoreTableName(tableName);
+                }
+                adapter.setStatements(statements);
+                if (createDataBase) {
+                    adapter.doCreateTables(connection);
+                }
+                connection.commit();
+            } catch (SQLException e) {
                 throw (IOException) new IOException("Exception while creating database").initCause(e); 
+            } finally {
+                if (connection != null) {
+                    try {
+                        connection.close();
+                    } catch (Exception e) {
+                    }
+                }
             }
         }
         JdbcStore store = (JdbcStore) stores.get(name);
@@ -55,6 +87,13 @@
     }
     
     /**
+     * @return Returns the adapter.
+     */
+    public JDBCAdapter getAdapter() {
+        return adapter;
+    }
+    
+    /**
      * @return Returns the dataSource.
      */
     public DataSource getDataSource() {
@@ -138,25 +177,4 @@
         this.createDataBase = createDataBase;
     }
     
-    public void createDataBase() throws SQLException {
-        Database db = new Database();
-        db.setName("JdbcStore");
-        Table table = new Table();
-        table.setName(tableName);
-        Column id = new Column();
-        id.setName("ID");
-        id.setType("VARCHAR");
-        id.setPrimaryKey(true);
-        id.setRequired(true);
-        table.addColumn(id);
-        Column exchange = new Column();
-        exchange.setName("DATA");
-        exchange.setType("BLOB");
-        table.addColumn(exchange);
-        db.addTable(table);
-
-        Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
-        platform.createTables(db, false, true);
-    }
-
 }

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.DefaultJDBCAdapter
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.AxionJDBCAdapter
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.HsqldbJDBCAdapter
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000 (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000 Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.ImageBasedJDBCAdaptor
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.DB2JDBCAdapter
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.InformixJDBCAdapter
\ No newline at end of file

Added: incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_?rev=394599&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_ (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_ Sun Apr 16 18:53:47 2006
@@ -0,0 +1 @@
+class=org.apache.servicemix.jdbc.adapter.ImageBasedJDBCAdaptor
\ No newline at end of file