Author: mikedd
Date: Mon Sep 20 15:45:06 2010
New Revision: 998961
URL: http://svn.apache.org/viewvc?rev=998961&view=rev
Log:
OPENJPA-1289: Added Oracle specific type to compatibility checking method,
merged from Jeremy's changes to trunk
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
(with props)
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
(with props)
Modified:
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
Modified:
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java?rev=998961&r1=998960&r2=998961&view=diff
==============================================================================
---
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
(original)
+++
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java
Mon Sep 20 15:45:06 2010
@@ -640,6 +640,15 @@ public class Column
default:
return false;
}
+ case 2007: // Oracle-defined opaque type code for XMLType
+ switch (type) {
+ case Types.CHAR:
+ case Types.LONGVARCHAR:
+ case Types.VARCHAR:
+ return true;
+ default:
+ return false;
+ }
default:
return type == getType();
}
Modified:
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=998961&r1=998960&r2=998961&view=diff
==============================================================================
---
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
(original)
+++
openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
Mon Sep 20 15:45:06 2010
@@ -40,6 +40,7 @@ import java.util.Map;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.ForeignKey;
import org.apache.openjpa.jdbc.schema.Index;
@@ -50,6 +51,7 @@ import org.apache.openjpa.lib.jdbc.Deleg
import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.StoreException;
import org.apache.openjpa.util.UserException;
@@ -843,7 +845,7 @@ public class OracleDictionary
sql[0] += " CACHE " + seq.getAllocate();
return sql;
}
-
+
protected String getSequencesSQL(String schemaName, String sequenceName) {
StringBuffer buf = new StringBuffer();
buf.append("SELECT SEQUENCE_OWNER AS SEQUENCE_SCHEMA, ").
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java?rev=998961&view=auto
==============================================================================
---
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
(added)
+++
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
Mon Sep 20 15:45:06 2010
@@ -0,0 +1,118 @@
+/*
+ * 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);
+ 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();
+ }
+}
Propchange:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/TestOracleXmlColumn.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java?rev=998961&view=auto
==============================================================================
---
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
(added)
+++
openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
Mon Sep 20 15:45:06 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+...@entity
+public class XmlColEntity {
+
+ @Id
+ @Column(name = "ID")
+ private int id;
+
+ @Version
+ @Column(name = "VERSION")
+ private int version;
+
+ @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/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/oracle/XmlColEntity.java
------------------------------------------------------------------------------
svn:eol-style = native