cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r583315 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/dba/ main/java/org/apache/cayenne/dba/sqlite/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/unit/
Date Tue, 09 Oct 2007 22:36:05 GMT
Author: aadamchik
Date: Tue Oct  9 15:36:03 2007
New Revision: 583315

URL: http://svn.apache.org/viewvc?rev=583315&view=rev
Log:
CAY-875 DbAdapter for SQLite
("object type" and adapter auto detection)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteObjectType.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSniffer.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteDateType.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/SQLiteStackAdapter.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
Tue Oct  9 15:36:03 2007
@@ -42,6 +42,7 @@
 import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
 import org.apache.cayenne.dba.oracle.OracleSniffer;
 import org.apache.cayenne.dba.postgres.PostgresSniffer;
+import org.apache.cayenne.dba.sqlite.SQLiteSniffer;
 import org.apache.cayenne.dba.sqlserver.SQLServerSniffer;
 import org.apache.cayenne.dba.sybase.SybaseSniffer;
 import org.apache.cayenne.map.DbAttribute;
@@ -65,7 +66,7 @@
             new MySQLSniffer(), new PostgresSniffer(), new OracleSniffer(),
             new SQLServerSniffer(), new HSQLDBSniffer(), new DB2Sniffer(),
             new SybaseSniffer(), new DerbySniffer(), new OpenBaseSniffer(),
-            new FrontBaseSniffer(), new IngresSniffer()
+            new FrontBaseSniffer(), new IngresSniffer(), new SQLiteSniffer()
     };
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
Tue Oct  9 15:36:03 2007
@@ -50,6 +50,7 @@
         map.registerType(new SQLiteBigDecimalType());
         map.registerType(new SQLiteFloatType());
         map.registerType(new SQLiteByteArrayType());
+        map.registerType(new SQLiteObjectType());
     }
 
     public String createFkConstraint(DbRelationship rel) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteDateType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteDateType.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteDateType.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteDateType.java
Tue Oct  9 15:36:03 2007
@@ -32,6 +32,8 @@
  * @author Andrus Adamchik
  * @since 3.0
  */
+// TODO: andrus 10/10/2007 - most of this is bogus... see http://www.zentus.com/sqlitejdbc/usage.html

+// for how dates should be handled (without relying on the driver).
 class SQLiteDateType extends UtilDateType {
 
     public Object materializeObject(ResultSet rs, int index, int type) throws Exception {

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteObjectType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteObjectType.java?rev=583315&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteObjectType.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteObjectType.java
Tue Oct  9 15:36:03 2007
@@ -0,0 +1,50 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.dba.sqlite;
+
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+
+import org.apache.cayenne.access.types.AbstractType;
+import org.apache.cayenne.access.types.DefaultType;
+
+/**
+ * This ExtendedType is used by SQLite as often the types of columns of the result sets
+ * can't be determined on the fly, and {@link DefaultType} for Object class throws on
+ * NULLs.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class SQLiteObjectType extends AbstractType {
+
+    public String getClassName() {
+        return Object.class.getName();
+    }
+
+    public Object materializeObject(CallableStatement rs, int index, int type)
+            throws Exception {
+        return rs.getObject(index);
+    }
+
+    public Object materializeObject(ResultSet rs, int index, int type) throws Exception {
+        return rs.getObject(index);
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSniffer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSniffer.java?rev=583315&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSniffer.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSniffer.java
Tue Oct  9 15:36:03 2007
@@ -0,0 +1,43 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.dba.sqlite;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.DbAdapterFactory;
+
+/**
+ * Detects SQLite database from JDBC metadata.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class SQLiteSniffer implements DbAdapterFactory {
+
+    public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
+        String dbName = md.getDatabaseProductName();
+        if (dbName == null || dbName.toUpperCase().indexOf("SQLITE") < 0) {
+            return null;
+        }
+
+        return new SQLiteAdapter();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
Tue Oct  9 15:36:03 2007
@@ -106,6 +106,7 @@
         try {
             boolean supportsUnique = getNode().getAdapter().supportsUniqueConstraints();
             boolean supportsLobs = getAccessStackAdapter().supportsLobs();
+            boolean supportsFK = getAccessStackAdapter().supportsFKConstraints();
 
             DataMap map = new DataMap();
             String tableLabel = getNode().getAdapter().tableTypeForTable();
@@ -124,34 +125,36 @@
             // *** TESTING THIS ***
             loader.loadDbRelationships(map);
 
-            Collection rels = getDbEntity(map, "ARTIST").getRelationships();
-            assertNotNull(rels);
-            assertTrue(rels.size() > 0);
-
-            // test one-to-one
-            rels = getDbEntity(map, "PAINTING").getRelationships();
-            assertNotNull(rels);
-
-            // find relationship to PAINTING_INFO
-            DbRelationship oneToOne = null;
-            Iterator it = rels.iterator();
-            while (it.hasNext()) {
-                DbRelationship rel = (DbRelationship) it.next();
-                if ("PAINTING_INFO".equalsIgnoreCase(rel.getTargetEntityName())) {
-                    oneToOne = rel;
-                    break;
+            if (supportsFK) {
+                Collection rels = getDbEntity(map, "ARTIST").getRelationships();
+                assertNotNull(rels);
+                assertTrue(rels.size() > 0);
+
+                // test one-to-one
+                rels = getDbEntity(map, "PAINTING").getRelationships();
+                assertNotNull(rels);
+
+                // find relationship to PAINTING_INFO
+                DbRelationship oneToOne = null;
+                Iterator it = rels.iterator();
+                while (it.hasNext()) {
+                    DbRelationship rel = (DbRelationship) it.next();
+                    if ("PAINTING_INFO".equalsIgnoreCase(rel.getTargetEntityName())) {
+                        oneToOne = rel;
+                        break;
+                    }
                 }
-            }
 
-            assertNotNull("No relationship to PAINTING_INFO", oneToOne);
-            assertFalse("Relationship to PAINTING_INFO must be to-one", oneToOne
-                    .isToMany());
-            assertTrue("Relationship to PAINTING_INFO must be to-one", oneToOne
-                    .isToDependentPK());
-
-            // test UNIQUE only if FK is supported...
-            if (supportsUnique) {
-                assertUniqueConstraintsInRelationships(map);
+                assertNotNull("No relationship to PAINTING_INFO", oneToOne);
+                assertFalse("Relationship to PAINTING_INFO must be to-one", oneToOne
+                        .isToMany());
+                assertTrue("Relationship to PAINTING_INFO must be to-one", oneToOne
+                        .isToDependentPK());
+
+                // test UNIQUE only if FK is supported...
+                if (supportsUnique) {
+                    assertUniqueConstraintsInRelationships(map);
+                }
             }
 
             // *** TESTING THIS ***
@@ -165,13 +168,18 @@
                 assertLobObjEntities(map);
             }
 
-            Collection rels1 = ae.getRelationships();
-            assertNotNull(rels1);
-            assertTrue(rels1.size() > 0);
+            if (supportsFK) {
+                Collection rels1 = ae.getRelationships();
+                assertNotNull(rels1);
+                assertTrue(rels1.size() > 0);
+            }
+
             // now when the map is loaded, test
             // various things
             // selectively check how different types were processed
-            checkTypes(map);
+            if (getAccessStackAdapter().supportsColumnTypeReengineering()) {
+                checkTypes(map);
+            }
         }
         finally {
             loader.getCon().close();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
Tue Oct  9 15:36:03 2007
@@ -180,6 +180,14 @@
 
         return true;
     }
+    
+    public boolean supportsFKConstraints() {
+        return true;
+    }
+    
+    public boolean supportsColumnTypeReengineering() {
+        return true;
+    }
 
     /**
      * Returns true if the target database has support for large objects (BLOB, CLOB).

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/SQLiteStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/SQLiteStackAdapter.java?rev=583315&r1=583314&r2=583315&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/SQLiteStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/SQLiteStackAdapter.java
Tue Oct  9 15:36:03 2007
@@ -25,4 +25,12 @@
     public SQLiteStackAdapter(DbAdapter adapter) {
         super(adapter);
     }
+    
+    public boolean supportsFKConstraints() {
+        return false;
+    }
+    
+    public boolean supportsColumnTypeReengineering() {
+        return false;
+    }
 }



Mime
View raw message