Author: gnodet
Date: Wed May 10 08:23:03 2006
New Revision: 405775
URL: http://svn.apache.org/viewcvs?rev=405775&view=rev
Log:
Add a servicemix-services module that contains services used by both the container and components.
This includes timers, locks, store, jdbc, etc...
Added:
incubator/servicemix/trunk/servicemix-services/ (with props)
incubator/servicemix/trunk/servicemix-services/pom.xml
incubator/servicemix/trunk/servicemix-services/src/
incubator/servicemix/trunk/servicemix-services/src/main/
incubator/servicemix/trunk/servicemix-services/src/main/java/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/IdGenerator.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/Statements.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/LockManager.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/SimpleLockManager.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/Store.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/StoreFactory.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStore.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStoreFactory.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/timers/
incubator/servicemix/trunk/servicemix-services/src/main/resources/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/DISCLAIMER
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/LICENSE
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/NOTICE
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/apache_derby_embedded_jdbc_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/axion_jdbc_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/hsql_database_engine_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/i-net_sprinta_2000
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_db2_jdbc_universal_driver_architecture
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/ibm_informix_jdbc_driver_for_ibm_informix_dynamic_server
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/jconnect__tm__for_jdbc__tm_
incubator/servicemix/trunk/servicemix-services/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-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/mysql-ab_jdbc_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/oracle_jdbc_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/postgresql_native_driver
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/sap_db
incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/services/org/apache/servicemix/jdbc/sqlserver
incubator/servicemix/trunk/servicemix-services/src/test/
incubator/servicemix/trunk/servicemix-services/src/test/java/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/apache/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/apache/servicemix/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/apache/servicemix/store/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/apache/servicemix/store/jdbc/
incubator/servicemix/trunk/servicemix-services/src/test/java/org/apache/servicemix/store/jdbc/JdbcStoreTest.java
incubator/servicemix/trunk/servicemix-services/src/test/resources/
Propchange: incubator/servicemix/trunk/servicemix-services/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed May 10 08:23:03 2006
@@ -0,0 +1,3 @@
+target
+.classpath
+.project
Added: incubator/servicemix/trunk/servicemix-services/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/pom.xml?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/pom.xml (added)
+++ incubator/servicemix/trunk/servicemix-services/pom.xml Wed May 10 08:23:03 2006
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2005 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.
+-->
+<!-- $Rev: 356052 $ $Date: 2005-12-11 14:41:20 -0800 (dim., 11 déc. 2005) $ -->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servicemix-services</artifactId>
+ <packaging>jar</packaging>
+ <name>ServiceMix :: Services</name>
+ <description>Various services that can be used by the container or components</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-commonj_1.1_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activeio-core</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>backport-util-concurrent</groupId>
+ <artifactId>backport-util-concurrent</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/IdGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/IdGenerator.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/IdGenerator.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/id/IdGenerator.java Wed May 10 08:23:03 2006
@@ -0,0 +1,117 @@
+/**
+ *
+ * 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.
+ */
+
+/*
+ * Copied from http://svn.apache.org/repos/asf/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
+ */
+
+package org.apache.servicemix.id;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Generator for Globally unique Strings.
+ */
+
+public class IdGenerator{
+
+ private static final Logger log = Logger.getLogger(IdGenerator.class.getName());
+ private static final String UNIQUE_STUB;
+ private static int instanceCount;
+ private static String hostName;
+ private String seed;
+ private long sequence;
+
+ static {
+ String stub = "";
+ boolean canAccessSystemProps = true;
+ try{
+ SecurityManager sm = System.getSecurityManager();
+ if(sm != null){
+ sm.checkPropertiesAccess();
+ }
+ }catch(SecurityException se){
+ canAccessSystemProps = false;
+ }
+
+ if ( canAccessSystemProps) {
+ try {
+ hostName = InetAddress.getLocalHost().getHostName();
+ ServerSocket ss = new ServerSocket(0);
+ stub=hostName + "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
+ Thread.sleep(100);
+ ss.close();
+ }catch(Exception ioe){
+ log.log(Level.WARNING, "could not generate unique stub",ioe);
+ }
+ }else{
+ hostName="localhost";
+ stub = hostName + "-1-" +System.currentTimeMillis() +"-";
+ }
+ UNIQUE_STUB = stub;
+ }
+
+ /**
+ * As we have to find the hostname as a side-affect of generating
+ * a unique stub, we allow it's easy retrevial here
+ * @return the local host name
+ */
+
+ public static String getHostName(){
+ return hostName;
+ }
+
+ /**
+ * Construct an IdGenerator
+ *
+ */
+
+ public IdGenerator(String prefix){
+ synchronized(UNIQUE_STUB){
+ this.seed = prefix + UNIQUE_STUB +(instanceCount++) +":";
+ }
+ }
+
+ public IdGenerator(){
+ this("ID:");
+ }
+
+ /**
+ * Generate a unqiue id
+ * @return a unique id
+ */
+
+ public synchronized String generateId(){
+ return this.seed + (this.sequence++);
+ }
+
+ /**
+ * Generate a unique ID - that is friendly for a URL or file system
+ * @return a unique id
+ */
+ public String generateSanitizedId(){
+ String result = generateId();
+ result = result.replace(':', '-');
+ result = result.replace('_', '-');
+ result = result.replace('.', '-');
+ return result;
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/Statements.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/Statements.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/Statements.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/Statements.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/AxionJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BlobJDBCAdapter.java Wed May 10 08:23:03 2006
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+
+
+/**
+ * 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 {
+
+}
\ No newline at end of file
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/BytesJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DB2JDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/HsqldbJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/ImageBasedJDBCAdaptor.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/InformixJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/MaxDBJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/OracleJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/PostgresqlJDBCAdapter.java Wed May 10 08:23:03 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-services/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/adapter/StreamJDBCAdapter.java Wed May 10 08:23:03 2006
@@ -0,0 +1,70 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * 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
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/LockManager.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/LockManager.java?rev=405775&view=auto
==============================================================================
(empty)
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/SimpleLockManager.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/SimpleLockManager.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/SimpleLockManager.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/locks/impl/SimpleLockManager.java Wed May 10 08:23:03 2006
@@ -0,0 +1,41 @@
+/*
+ * 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.locks.impl;
+
+import org.apache.servicemix.locks.LockManager;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentMap;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
+
+public class SimpleLockManager implements LockManager {
+
+ private ConcurrentMap locks = new ConcurrentHashMap();
+
+ public Lock getLock(String id) {
+ Lock lock = (Lock) locks.get(id);
+ if (lock == null) {
+ lock = new ReentrantLock();
+ Lock oldLock = (Lock) locks.putIfAbsent(id, lock);
+ if (oldLock != null) {
+ lock = oldLock;
+ }
+ }
+ return lock;
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/Store.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/Store.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/Store.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/Store.java Wed May 10 08:23:03 2006
@@ -0,0 +1,76 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+/**
+ * A Store is an interface representing a storage where objects can be
+ * put and retrieved. A store can support different features, mainly
+ * persistence, clustered or transactional.
+ *
+ * A store is not designed to be a thread-safe map. If a user tries to
+ * store an object with an existing id, the behavior is undefined.
+ *
+ * @author gnodet
+ */
+public interface Store {
+
+ String PERSISTENT = "Persistent";
+
+ String CLUSTERED = "Clustered";
+
+ String TRANSACTIONAL = "Transactional";
+
+ /**
+ * Returns true if the store implementation supports the given feature.
+ * @param name the feature to check
+ * @return <code>true</code> if the feature is supported
+ */
+ public boolean hasFeature(String name);
+
+ /**
+ * Put an object in the store under the given id.
+ * This method must be used with caution and the behavior is
+ * unspecified if an object already exist for the same id.
+ *
+ * @param id the id of the object to store
+ * @param data the object to store
+ * @throws IOException if an error occurs
+ */
+ public void store(String id, Object data) throws IOException;
+
+ /**
+ * Put an object into the store and return the unique id that
+ * may be used at a later time to retrieve the object.
+ *
+ * @param data the object to store
+ * @return the id of the object stored
+ * @throws IOException if an error occurs
+ */
+ public String store(Object data) throws IOException;
+
+ /**
+ * Loads an object that has been previously stored under the specified key.
+ * The object is removed from the store.
+ *
+ * @param id the id of the object
+ * @return the object, or <code>null></code> if the object could not be found
+ * @throws IOException if an error occurs
+ */
+ public Object load(String id) throws IOException;
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/StoreFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/StoreFactory.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/StoreFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/StoreFactory.java Wed May 10 08:23:03 2006
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+public interface StoreFactory {
+
+ public Store open(String name) throws IOException;
+
+ public void close(Store store) throws IOException;
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java Wed May 10 08:23:03 2006
@@ -0,0 +1,104 @@
+/*
+ * 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.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.sql.Connection;
+
+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;
+
+public class JdbcStore implements Store {
+
+ private static final Log log = LogFactory.getLog(JdbcStore.class);
+
+ private JdbcStoreFactory factory;
+ private String name;
+
+ public JdbcStore(JdbcStoreFactory factory, String name) {
+ this.factory = factory;
+ this.name = name;
+ }
+
+ public boolean hasFeature(String name) {
+ return PERSISTENT.equals(name) ||
+ (CLUSTERED.equals(name) && factory.isClustered()) ||
+ (TRANSACTIONAL.equals(name) && factory.isTransactional());
+ }
+
+ public void store(String id, Object data) throws IOException {
+ log.debug("Storing object with id: " + id);
+ Connection connection = null;
+ try {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(buffer);
+ out.writeObject(data);
+ out.close();
+ connection = factory.getDataSource().getConnection();
+ factory.getAdapter().doStoreData(connection, name + ":" + id, buffer.toByteArray());
+ connection.commit();
+ } catch (Exception e) {
+ throw (IOException) new IOException("Error storing object").initCause(e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (Exception e) {
+ throw (IOException) new IOException("Error closing connection").initCause(e);
+ }
+ }
+ }
+ }
+
+ public String store(Object data) throws IOException {
+ String id = factory.getIdGenerator().generateId();
+ store(id, data);
+ return id;
+ }
+
+ public Object load(String id) throws IOException {
+ log.debug("Loading object with id: " + id);
+ Connection connection = null;
+ try {
+ connection = factory.getDataSource().getConnection();
+ byte[] data = factory.getAdapter().doLoadData(connection, name + ":" + id);
+ Object result = null;
+ if (data != null) {
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
+ 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 {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (Exception e) {
+ throw (IOException) new IOException("Error closing connection").initCause(e);
+ }
+ }
+ }
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStoreFactory.java Wed May 10 08:23:03 2006
@@ -0,0 +1,180 @@
+/*
+ * 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;
+
+import javax.sql.DataSource;
+
+import org.apache.servicemix.id.IdGenerator;
+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;
+
+public class JdbcStoreFactory implements StoreFactory {
+
+ private boolean transactional;
+ private boolean clustered;
+ private DataSource dataSource;
+ private IdGenerator idGenerator = new IdGenerator();
+ private Map stores = new HashMap();
+ private String tableName = "SM_STORE";
+ private boolean createDataBase = 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 (adapter == null) {
+ 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) {
+ }
+ }
+ }
+ }
+ JdbcStore store = (JdbcStore) stores.get(name);
+ if (store == null) {
+ store = new JdbcStore(this, name);
+ stores.put(name, store);
+ }
+ return store;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.store.ExchangeStoreFactory#release(org.apache.servicemix.store.ExchangeStore)
+ */
+ public synchronized void close(Store store) throws IOException {
+ stores.remove(store);
+ }
+
+ /**
+ * @return Returns the adapter.
+ */
+ public JDBCAdapter getAdapter() {
+ return adapter;
+ }
+
+ /**
+ * @return Returns the dataSource.
+ */
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ /**
+ * @param dataSource The dataSource to set.
+ */
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ /**
+ * @return Returns the clustered.
+ */
+ public boolean isClustered() {
+ return clustered;
+ }
+
+ /**
+ * @param clustered The clustered to set.
+ */
+ public void setClustered(boolean clustered) {
+ this.clustered = clustered;
+ }
+
+ /**
+ * @return Returns the transactional.
+ */
+ public boolean isTransactional() {
+ return transactional;
+ }
+
+ /**
+ * @param transactional The transactional to set.
+ */
+ public void setTransactional(boolean transactional) {
+ this.transactional = transactional;
+ }
+
+ /**
+ * @return Returns the idGenerator.
+ */
+ public IdGenerator getIdGenerator() {
+ return idGenerator;
+ }
+
+ /**
+ * @param idGenerator The idGenerator to set.
+ */
+ public void setIdGenerator(IdGenerator idGenerator) {
+ this.idGenerator = idGenerator;
+ }
+
+ /**
+ * @return Returns the tableName.
+ */
+ public String getTableName() {
+ return tableName;
+ }
+
+ /**
+ * @param tableName The tableName to set.
+ */
+ public void setTableName(String tableName) {
+ this.tableName = tableName;
+ }
+
+ /**
+ * @return Returns the createDataBase.
+ */
+ public boolean isCreateDataBase() {
+ return createDataBase;
+ }
+
+ /**
+ * @param createDataBase The createDataBase to set.
+ */
+ public void setCreateDataBase(boolean createDataBase) {
+ this.createDataBase = createDataBase;
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStore.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStore.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStore.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStore.java Wed May 10 08:23:03 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.memory;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.servicemix.id.IdGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.store.Store;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A simple memory store implementation based on a simple map.
+ * This store is neither clusterable, nor persistent, nor transactional.
+ *
+ * @author gnodet
+ */
+public class MemoryStore implements Store {
+
+ private static final Log log = LogFactory.getLog(MemoryStore.class);
+
+ private Map datas = new ConcurrentHashMap();
+ private IdGenerator idGenerator;
+
+ public MemoryStore(IdGenerator idGenerator) {
+ this.idGenerator = idGenerator;
+ }
+
+ public boolean hasFeature(String name) {
+ return false;
+ }
+
+ public void store(String id, Object data) throws IOException {
+ log.debug("Storing object with id: " + id);
+ datas.put(id, data);
+ }
+
+ public String store(Object data) throws IOException {
+ String id = idGenerator.generateId();
+ store(id, data);
+ return id;
+ }
+
+ public Object load(String id) throws IOException {
+ log.debug("Loading object with id: " + id);
+ return datas.get(id);
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStoreFactory.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStoreFactory.java?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStoreFactory.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/memory/MemoryStoreFactory.java Wed May 10 08:23:03 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.store.memory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicemix.id.IdGenerator;
+import org.apache.servicemix.store.Store;
+import org.apache.servicemix.store.StoreFactory;
+
+public class MemoryStoreFactory implements StoreFactory {
+
+ private IdGenerator idGenerator = new IdGenerator();
+ private Map stores = new HashMap();
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.store.ExchangeStoreFactory#get(java.lang.String)
+ */
+ public synchronized Store open(String name) throws IOException {
+ MemoryStore store = (MemoryStore) stores.get(name);
+ if (store == null) {
+ store = new MemoryStore(idGenerator);
+ stores.put(name, store);
+ }
+ return store;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.store.ExchangeStoreFactory#release(org.apache.servicemix.store.ExchangeStore)
+ */
+ public synchronized void close(Store store) throws IOException {
+ stores.remove(store);
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/DISCLAIMER
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/DISCLAIMER?rev=405775&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/DISCLAIMER (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/resources/META-INF/DISCLAIMER Wed May 10 08:23:03 2006
@@ -0,0 +1,6 @@
+Apache ServiceMix is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Geronimo PMC.
+Incubation is required of all newly accepted projects until a further review indicates that the infrastructure,
+communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
+
+While incubation status is not necessarily a reflection of the completeness or stability of the code, it does
+indicate that the project has yet to be fully endorsed by the ASF.
|