openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1031710 - in /openjpa/branches/2.0.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/
Date Fri, 05 Nov 2010 18:50:08 GMT
Author: mikedd
Date: Fri Nov  5 18:50:08 2010
New Revision: 1031710

URL: http://svn.apache.org/viewvc?rev=1031710&view=rev
Log:
OPENJPA-1874: Handle Oracle XMLType columns with @Lob annotation

Added:
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
  (with props)
    openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
  (with props)
Modified:
    openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java

Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java?rev=1031710&r1=1031709&r2=1031710&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
(original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
Fri Nov  5 18:50:08 2010
@@ -714,10 +714,13 @@ public class Column
                     case Types.CHAR:
                     case Types.LONGVARCHAR:
                     case Types.VARCHAR:
+                    case Types.CLOB:
+                    case Types.BLOB:
                         return true;
                      default:
                          return false;
                 }
+                
             default:
                 return type == getType();
         }

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java?rev=1031710&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
Fri Nov  5 18:50:08 2010
@@ -0,0 +1,149 @@
+/*
+ * 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.openjpa.jdbc.oracle;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.sql.DataSource;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.OracleDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
+
+public class TestOracleXmlColumn extends PersistenceTestCase {
+
+    private static String xmlData =
+        "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+            + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" " +
+            		"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
+            		"xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 " +
+            		"http://maven.apache.org/maven-v4_0_0.xsd\">"
+            + "</project>";
+
+    private boolean skipTest(DBDictionary dict) {
+        return !(dict instanceof OracleDictionary);
+    }
+
+    public void setUp() throws SQLException {
+        OpenJPAEntityManagerFactorySPI emf = createEMF();
+
+        JDBCConfiguration conf = ((JDBCConfiguration) emf.getConfiguration());
+        DBDictionary dict = conf.getDBDictionaryInstance();
+
+        if (skipTest(dict)) {
+            emf.close();
+            return;
+        }
+
+        // the mapping tool doesn't handle creating XML columns that map to strings
+        // build table manually
+        Connection con = ((DataSource) conf.getConnectionFactory()).getConnection();
+        Statement stmt = con.createStatement();
+        String ddl = "DROP TABLE XmlColEntity";
+        try { 
+            stmt.execute(ddl);
+            con.commit();
+        } catch (SQLException se) {
+            // assume the table did not exist.
+            con.rollback();
+        }
+
+        ddl =
+            "CREATE TABLE XmlColEntity (ID NUMBER NOT NULL, XMLCOLUMN " + dict.xmlTypeName
+                + ", VERSION NUMBER, PRIMARY KEY (ID))";
+        stmt.execute(ddl);
+        String insertSql = "INSERT into XmlColEntity (ID, XMLCOLUMN, VERSION) VALUES (42,
'" + xmlData + "', 1)";
+        stmt.execute(insertSql);
+        con.commit();
+
+        stmt.close();
+        con.close();
+        emf.close();
+    }
+
+    public void testCrudXmlColumn() throws SQLException {
+        // This test will fail with Oracle JDBC driver version 11.2.0.1.0.
+        // It passes with 10.2.0.1.0 (maybe others).
+        OpenJPAEntityManagerFactorySPI emf =
+            createEMF(XmlColEntity.class,
+                "openjpa.jdbc.SchemaFactory", "native", 
+                "openjpa.jdbc.SynchronizeMappings",  "");
+
+        JDBCConfiguration conf = ((JDBCConfiguration) emf.getConfiguration());
+        DBDictionary dict = conf.getDBDictionaryInstance();
+
+        if (skipTest(dict)) {
+            emf.close();
+            return;
+        }
+
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+
+        XmlColEntity xce = new XmlColEntity();
+        xce.setId(1);
+        xce.setXmlColumn(xmlData);
+
+        tran.begin();
+        em.persist(xce);
+        tran.commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        xce = em.find(XmlColEntity.class, 1);
+        assertNotNull(xce);
+        assertEquals(xmlData, xce.getXmlColumn());
+
+        em.close();
+        emf.close();
+    }
+    
+    public void testExistingColumn() throws SQLException {
+        // This test will fail with Oracle JDBC driver version 11.2.0.1.0.
+        // It passes with 10.2.0.1.0 (maybe others).
+        OpenJPAEntityManagerFactorySPI emf =
+            createEMF(XmlColEntity.class,
+                "openjpa.jdbc.SchemaFactory", "native", 
+                "openjpa.jdbc.SynchronizeMappings",  "");
+
+        JDBCConfiguration conf = ((JDBCConfiguration) emf.getConfiguration());
+        DBDictionary dict = conf.getDBDictionaryInstance();
+
+        if (skipTest(dict)) {
+            emf.close();
+            return;
+        }
+
+        EntityManager em = emf.createEntityManager();
+        EntityTransaction tran = em.getTransaction();
+
+        XmlColEntity xce = em.find(XmlColEntity.class, 42); 
+        assertNotNull(xce);
+        assertNotNull(xce.getXmlColumn());
+        assertEquals(xmlData, xce.getXmlColumn());
+        em.close();
+        emf.close();
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java?rev=1031710&view=auto
==============================================================================
--- openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
(added)
+++ openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
Fri Nov  5 18:50:08 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.openjpa.jdbc.oracle;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Version;
+
+@Entity
+public class XmlColEntity {
+
+    @Id
+    @Column(name = "ID")
+    private int id;
+
+    @Version
+    @Column(name = "VERSION")
+    private int version;
+
+    @Lob @Basic
+    @Column(name = "XMLCOLUMN")
+    private String xmlColumn;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }  
+    
+    public void setVersion(int version) {
+        this.version = version;
+    }
+
+    public String getXmlColumn() {
+        return xmlColumn;
+    }
+
+    public void setXmlColumn(String xmlColumn) {
+        this.xmlColumn = xmlColumn;
+    }
+}

Propchange: openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message