cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r614031 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/
Date Mon, 21 Jan 2008 22:12:09 GMT
Author: aadamchik
Date: Mon Jan 21 14:12:08 2008
New Revision: 614031

URL: http://svn.apache.org/viewvc?rev=614031&view=rev
Log:
CAY-970 Allow application to add DbAdatperFactory to AutoAdapter

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=614031&r1=614030&r2=614031&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Mon Jan 21 14:12:08 2008
@@ -8,6 +8,15 @@
 http://issues.apache.org/cayenne/
 
 ----------------------------------
+Release: 3.0M4
+Date: 
+----------------------------------
+
+Changes/New Features Since M3:
+
+CAY-970 Allow application to add DbAdatperFactory to AutoAdapter
+
+----------------------------------
 Release: 3.0M3
 Date: 
 ----------------------------------

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=614031&r1=614030&r2=614031&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
Mon Jan 21 14:12:08 2008
@@ -22,8 +22,10 @@
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 
 import javax.sql.DataSource;
 
@@ -63,21 +65,42 @@
  */
 public class AutoAdapter implements DbAdapter {
 
-    // hardcoded factories for adapters that we know how to auto-detect
-    static final DbAdapterFactory[] DEFAULT_FACTORIES = new DbAdapterFactory[] {
-            new MySQLSniffer(), new PostgresSniffer(), new OracleSniffer(),
-            new SQLServerSniffer(), new HSQLDBSniffer(), new DB2Sniffer(),
-            new SybaseSniffer(), new DerbySniffer(), new OpenBaseSniffer(),
-            new FrontBaseSniffer(), new IngresSniffer(), new SQLiteSniffer(),
-            new H2Sniffer()
-    };
+    static final List<DbAdapterFactory> defaultFactories;
+    static {
+        defaultFactories = new ArrayList<DbAdapterFactory>();
+
+        // hardcoded factories for adapters that we know how to auto-detect
+        defaultFactories.addAll(Arrays.asList(
+                new MySQLSniffer(),
+                new PostgresSniffer(),
+                new OracleSniffer(),
+                new SQLServerSniffer(),
+                new HSQLDBSniffer(),
+                new DB2Sniffer(),
+                new SybaseSniffer(),
+                new DerbySniffer(),
+                new OpenBaseSniffer(),
+                new FrontBaseSniffer(),
+                new IngresSniffer(),
+                new SQLiteSniffer(),
+                new H2Sniffer()));
+    }
+
+    /**
+     * Allows application code to add a sniffer to detect a custom adapter.
+     * 
+     * @since 3.0
+     */
+    public static void addFactory(DbAdapterFactory factory) {
+        defaultFactories.add(factory);
+    }
 
     /**
      * Returns a DbAdapterFactory configured to detect all databases officially supported
      * by Cayenne.
      */
     public static DbAdapterFactory getDefaultFactory() {
-        return new DbAdapterFactoryChain(Arrays.asList(DEFAULT_FACTORIES));
+        return new DbAdapterFactoryChain(defaultFactories);
     }
 
     protected DbAdapterFactory adapterFactory;
@@ -208,7 +231,7 @@
     }
 
     /**
-     * @deprecated since 3.0 as the deocarated method is deprecated.
+     * @deprecated since 3.0 as the decorated method is deprecated.
      */
     public String dropTable(DbEntity entity) {
         return getAdapter().dropTable(entity);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java?rev=614031&r1=614030&r2=614031&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/AutoAdapterTest.java
Mon Jan 21 14:12:08 2008
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.dba;
 
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
 import org.apache.art.Artist;
 import org.apache.cayenne.access.jdbc.SQLTemplateAction;
 import org.apache.cayenne.query.SQLTemplate;
@@ -28,6 +31,19 @@
 import com.mockrunner.mock.jdbc.MockDataSource;
 
 public class AutoAdapterTest extends CayenneCase {
+
+    public void testAddFactory() {
+
+        DbAdapterFactory mockFactory = new DbAdapterFactory() {
+
+            public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
+                return null;
+            }
+        };
+        AutoAdapter.addFactory(mockFactory);
+        assertTrue(AutoAdapter.defaultFactories.contains(mockFactory));
+        AutoAdapter.defaultFactories.remove(mockFactory);
+    }
 
     public void testGetAdapter() {
         MockDbAdapter realAdapter = new MockDbAdapter();



Mime
View raw message