Author: mikedd
Date: Fri Nov 5 15:57:26 2010
New Revision: 1031648
URL: http://svn.apache.org/viewvc?rev=1031648&view=rev
Log:
OPENJPA-1874: handle Oracle XMLType columns with @Lob annotation
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
(with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java?rev=1031648&r1=1031647&r2=1031648&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
Fri Nov 5 15:57:26 2010
@@ -717,10 +717,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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java?rev=1031648&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
Fri Nov 5 15:57:26 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java?rev=1031648&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
Fri Nov 5 15:57:26 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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
------------------------------------------------------------------------------
svn:eol-style = native