From 3e8def8eb2e2a7fb7b21791943b1958e1b4603b7 Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Mon, 27 Aug 2018 21:40:25 +0700 Subject: [PATCH 1/4] [OPENJPA-2567] various MySql text types support is added --- .../openjpa/jdbc/sql/MySQLDictionary.java | 58 ++++++----- .../blob/mysql/ClobColumnEntity.java | 85 +++++++++++++++++ .../blob/mysql/TestClobColumnType.java | 95 +++++++++++++++++++ 3 files changed, 216 insertions(+), 22 deletions(-) create mode 100644 openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java create mode 100644 openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java index 415c4ca938..84d160c67c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java @@ -14,7 +14,7 @@ * "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. + * under the License. */ package org.apache.openjpa.jdbc.sql; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; -import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; @@ -41,6 +40,7 @@ import org.apache.openjpa.jdbc.schema.Index; import org.apache.openjpa.jdbc.schema.PrimaryKey; import org.apache.openjpa.jdbc.schema.Table; +import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.util.StoreException; /** @@ -52,7 +52,7 @@ public class MySQLDictionary public static final String SELECT_HINT = "openjpa.hint.MySQLSelectHint"; public static final String DELIMITER_BACK_TICK = "`"; - + /** * The MySQL table type to use when creating tables; defaults to innodb. */ @@ -70,8 +70,8 @@ public class MySQLDictionary public boolean driverDeserializesBlobs = false; /** - * Whether to inline multi-table bulk-delete operations into MySQL's - * combined DELETE FROM foo, bar, baz syntax. + * Whether to inline multi-table bulk-delete operations into MySQL's + * combined DELETE FROM foo, bar, baz syntax. * Defaults to false, since this may fail in the presence of InnoDB tables * with foreign keys. * @see http://dev.mysql.com/doc/refman/5.0/en/delete.html @@ -81,6 +81,9 @@ public class MySQLDictionary public static final String tinyBlobTypeName = "TINYBLOB"; public static final String mediumBlobTypeName = "MEDIUMBLOB"; public static final String longBlobTypeName = "LONGBLOB"; + public static final String tinyTextTypeName = "TINYTEXT"; + public static final String mediumTextTypeName = "MEDIUMTEXT"; + public static final String longTextTypeName = "LONGTEXT"; public MySQLDictionary() { platform = "MySQL"; @@ -121,15 +124,15 @@ public MySQLDictionary() { reservedWordSet.addAll(Arrays.asList(new String[]{ "AUTO_INCREMENT", "BINARY", "BLOB", "CHANGE", "ENUM", "INFILE", "INT1", "INT2", "INT4", "FLOAT1", "FLOAT2", "FLOAT4", "LOAD", - "MEDIUMINT", "OUTFILE", "REPLACE", "STARTING", "TEXT", "UNSIGNED", - "ZEROFILL", "INDEX", + "MEDIUMINT", "OUTFILE", "REPLACE", "STARTING", "TEXT", "UNSIGNED", + "ZEROFILL", "INDEX", })); // reservedWordSet subset that CANNOT be used as valid column names // (i.e., without surrounding them with double-quotes) invalidColumnWordSet.addAll(Arrays.asList(new String[]{ "ADD", "ALL", "ALTER", "AND", "AS", "ASC", "BETWEEN", "BINARY", - "BLOB", "BOTH", "BY", "CASCADE", "CASE", "CHANGE", "CHAR", + "BLOB", "BOTH", "BY", "CASCADE", "CASE", "CHANGE", "CHAR", "CHARACTER", "CHECK", "COLLATE", "COLUMN", "CONSTRAINT", "CONTINUE", "CONVERT", "CREATE", "CROSS", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR", "DEC", "DECIMAL", @@ -146,7 +149,7 @@ public MySQLDictionary() { "STARTING", "TABLE", "THEN", "TO", "TRAILING", "TRUE", "UNION", "UNIQUE", "UNSIGNED", "UPDATE", "USAGE", "USING", "VALUES", "VARCHAR", "VARYING", "WHEN", "WHERE", "WITH", "WRITE", "ZEROFILL", - "INDEX", + "INDEX", })); requiresSearchStringEscapeForLike = true; @@ -158,7 +161,7 @@ public MySQLDictionary() { setLeadingDelimiter(DELIMITER_BACK_TICK); setTrailingDelimiter(DELIMITER_BACK_TICK); - + fixedSizeTypeNameSet.remove("NUMERIC"); } @@ -206,7 +209,7 @@ public Connection decorate(Connection conn) throws SQLException { conn.setReadOnly(true); return conn; } - + private static int[] getMajorMinorVersions(String versionStr) throws IllegalArgumentException { int beginIndex = 0; @@ -275,7 +278,7 @@ public String[] getDropForeignKeySQL(ForeignKey fk, Connection conn) { new String[]{ "ALTER TABLE " + getFullName(fk.getTable(), false) + " DROP FOREIGN KEY " + toDBName(fkName) }; - return retVal; + return retVal; } return new String[]{ "ALTER TABLE " + getFullName(fk.getTable(), false) @@ -300,7 +303,7 @@ public String[] getAddPrimaryKeySQL(PrimaryKey pk) { System.arraycopy(sql, 0, ret, cols.length, sql.length); return ret; } - + @Override public String[] getDeleteTableContentsSQL(Table[] tables,Connection conn) { // mysql >= 4 supports more-optimal delete syntax @@ -356,10 +359,10 @@ public int getPreferredType(int type) { return Types.LONGVARCHAR; return super.getPreferredType(type); } - + /** * Append XML comparison. - * + * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison @@ -381,10 +384,10 @@ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, else rhs.appendTo(buf); } - + /** * Append XML column value so that it can be used in comparisons. - * + * * @param buf the SQL buffer to write the value * @param val the value to be written */ @@ -395,7 +398,7 @@ private void appendXmlValue(SQLBuffer buf, FilterValue val) { val.appendTo(buf); buf.append("')"); } - + @Override public int getBatchFetchSize(int batchFetchSize) { return Integer.MIN_VALUE; @@ -414,10 +417,10 @@ public String getSelectOperation(JDBCFetchConfiguration fetch) { select += " " + hint; return select; } - + @Override protected Collection getSelectTableAliases(Select sel) { - Set result = new HashSet(); + Set result = new HashSet<>(); List selects = sel.getIdentifierAliases(); for (String s : selects) { String tableAlias = s.substring(0, s.indexOf('.')); @@ -425,7 +428,7 @@ protected Collection getSelectTableAliases(Select sel) { } return result; } - + @Override protected int matchErrorState(Map> errorStates, SQLException ex) { int state = super.matchErrorState(errorStates, ex); @@ -462,7 +465,7 @@ public boolean isFatalException(int subtype, SQLException ex) { */ @Override public String getTypeName(Column col) { - // handle blobs differently, if the DBItentifierType is NULL (e.g. no column definition is set). + // handle blobs differently, if the DBItentifierType is NULL (e.g. no column definition is set). if (col.getType() == Types.BLOB && col.getTypeIdentifier().getType() == DBIdentifierType.NULL) { if (col.getSize() <= 0) // unknown size return blobTypeName; // return old default of 64KB @@ -474,6 +477,17 @@ else if (col.getSize() <= 16777215) return mediumBlobTypeName; else return longBlobTypeName; + } else if (col.getType() == Types.CLOB && col.getTypeIdentifier().getType() == DBIdentifierType.NULL) { + if (col.getSize() <= 0) // unknown size + return clobTypeName; // return old default of 64KB + else if (col.getSize() <= 255) + return tinyTextTypeName; + else if (col.getSize() <= 65535) + return clobTypeName; // old default of 64KB + else if (col.getSize() <= 16777215) + return mediumTextTypeName; + else + return longTextTypeName; } else { return super.getTypeName(col); } diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java new file mode 100644 index 0000000000..d8d4b114fe --- /dev/null +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java @@ -0,0 +1,85 @@ +/* + * 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.persistence.blob.mysql; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; + +@Entity +public class ClobColumnEntity { + @Id + private int id; + + @Lob + @Column(length = 20) + protected String smallLob; + + @Lob + @Column(length = 66000) + protected String medLob; + + @Lob + @Column(length = 16777216) + protected String longLob; + + @Lob + protected String defaultLob; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSmallLob() { + return smallLob; + } + + public void setSmallLob(String smallLob) { + this.smallLob = smallLob; + } + + public String getMedLob() { + return medLob; + } + + public void setMedLob(String medLob) { + this.medLob = medLob; + } + + public String getLongLob() { + return longLob; + } + + public void setLongLob(String longLob) { + this.longLob = longLob; + } + + public String getDefaultLob() { + return defaultLob; + } + + public void setDefaultLob(String defaultLob) { + this.defaultLob = defaultLob; + } +} diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java new file mode 100644 index 0000000000..8b1b1d2919 --- /dev/null +++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java @@ -0,0 +1,95 @@ +/* + * 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.persistence.blob.mysql; + +import org.apache.openjpa.jdbc.identifier.DBIdentifier; +import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; +import org.apache.openjpa.jdbc.meta.ClassMapping; +import org.apache.openjpa.jdbc.schema.Column; +import org.apache.openjpa.jdbc.schema.Table; +import org.apache.openjpa.jdbc.sql.MariaDBDictionary; +import org.apache.openjpa.jdbc.sql.MySQLDictionary; +import org.apache.openjpa.persistence.test.SingleEMFTestCase; + +/** + * Testcase for MySQL Blob types. OPENJPA-740 introduced intelligent column type for BLOBs, OPENJPA-1870 refined it a + * bit. + */ +public class TestClobColumnType extends SingleEMFTestCase { + + private static boolean _firstRun=true; + private boolean _runTest = false; // only test with MySQL + + @Override + public void setUp() throws Exception { + + // create EMF solely to obtain a DBDictionary. + // need to do this without ClobColumnEntity.class since it contains a column definition which might + // not work with all databases. + super.setUp((Object) null); + if (!(getDBDictionary() instanceof MySQLDictionary || getDBDictionary() instanceof MariaDBDictionary)) { + // normal teardown will take care of the EMF. + return; + } + + // remove the EMF + tearDown(); + + _runTest = true; + super.setUp(ClobColumnEntity.class, DROP_TABLES, "openjpa.jdbc.SchemaFactory", "native"); + + if(_firstRun) { + emf.createEntityManager().close(); // trigger table creation. + _firstRun = false; + } + } + + private Column getCol(String name) { + ClassMapping mapping = getMapping(ClobColumnEntity.class); + + Table t = mapping.getTable(); + Column col = t.getColumn(DBIdentifier.newIdentifier(name, DBIdentifierType.COLUMN, true)); + assertNotNull(col); + return col; + } + + public void testSmallLob() { + if (_runTest) { + assertEquals(MySQLDictionary.tinyTextTypeName, getCol("smallLob").getTypeIdentifier().getName()); + } + } + + public void testMedLob() { + if (_runTest) { + assertEquals(MySQLDictionary.mediumTextTypeName, getCol("medLob").getTypeIdentifier().getName()); + } + } + + public void testLongBlob() { + if (_runTest) { + assertEquals(MySQLDictionary.longTextTypeName, getCol("longLob").getTypeIdentifier().getName()); + } + } + + public void testDefaultLob() { + if (_runTest) { + assertEquals(getDBDictionary().blobTypeName, getCol("defaultLob").getTypeIdentifier().getName()); + } + } +} From 92e1dc8e666cb9996812a9dd0491e3fbc79a479b Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Mon, 3 Sep 2018 18:15:57 +0700 Subject: [PATCH 2/4] [OPENJPA-2567] mysql files were moved to correct location, MariaDB dictionary was updated --- .../openjpa/jdbc/sql/MariaDBDictionary.java | 69 +++++++++++-------- .../blob/mysql/ClobColumnEntity.java | 0 .../blob/mysql/TestClobColumnType.java | 0 3 files changed, 42 insertions(+), 27 deletions(-) rename {openjpa-jdbc => openjpa-persistence-jdbc}/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java (100%) rename {openjpa-jdbc => openjpa-persistence-jdbc}/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java (100%) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java index 23901ab841..081bc2db23 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java @@ -14,7 +14,7 @@ * "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. + * under the License. */ package org.apache.openjpa.jdbc.sql; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; -import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; @@ -41,17 +40,18 @@ import org.apache.openjpa.jdbc.schema.Index; import org.apache.openjpa.jdbc.schema.PrimaryKey; import org.apache.openjpa.jdbc.schema.Table; +import org.apache.openjpa.lib.util.StringUtil; import org.apache.openjpa.util.StoreException; /* * Dictionary for MariaDB, based off the MySQLDictionary. - * + * */ public class MariaDBDictionary extends DBDictionary { public static final String SELECT_HINT = "openjpa.hint.MariaDBSelectHint"; public static final String DELIMITER_BACK_TICK = "`"; - + /** * The MySQL table type to use when creating tables; defaults to innodb. */ @@ -69,8 +69,8 @@ public class MariaDBDictionary extends DBDictionary { public boolean driverDeserializesBlobs = false; /** - * Whether to inline multi-table bulk-delete operations into MySQL's - * combined DELETE FROM foo, bar, baz syntax. + * Whether to inline multi-table bulk-delete operations into MySQL's + * combined DELETE FROM foo, bar, baz syntax. * Defaults to false, since this may fail in the presence of InnoDB tables * with foreign keys. * @see http://dev.mysql.com/doc/refman/5.0/en/delete.html @@ -80,6 +80,9 @@ public class MariaDBDictionary extends DBDictionary { public static final String tinyBlobTypeName = "TINYBLOB"; public static final String mediumBlobTypeName = "MEDIUMBLOB"; public static final String longBlobTypeName = "LONGBLOB"; + public static final String tinyTextTypeName = "TINYTEXT"; + public static final String mediumTextTypeName = "MEDIUMTEXT"; + public static final String longTextTypeName = "LONGTEXT"; public MariaDBDictionary() { platform = "MariaDB"; @@ -120,15 +123,15 @@ public MariaDBDictionary() { reservedWordSet.addAll(Arrays.asList(new String[]{ "AUTO_INCREMENT", "BINARY", "BLOB", "CHANGE", "ENUM", "INFILE", "INT1", "INT2", "INT4", "FLOAT1", "FLOAT2", "FLOAT4", "LOAD", - "MEDIUMINT", "OUTFILE", "REPLACE", "STARTING", "TEXT", "UNSIGNED", - "ZEROFILL", "INDEX", + "MEDIUMINT", "OUTFILE", "REPLACE", "STARTING", "TEXT", "UNSIGNED", + "ZEROFILL", "INDEX", })); // reservedWordSet subset that CANNOT be used as valid column names // (i.e., without surrounding them with double-quotes) invalidColumnWordSet.addAll(Arrays.asList(new String[]{ "ADD", "ALL", "ALTER", "AND", "AS", "ASC", "BETWEEN", "BINARY", - "BLOB", "BOTH", "BY", "CASCADE", "CASE", "CHANGE", "CHAR", + "BLOB", "BOTH", "BY", "CASCADE", "CASE", "CHANGE", "CHAR", "CHARACTER", "CHECK", "COLLATE", "COLUMN", "CONSTRAINT", "CONTINUE", "CONVERT", "CREATE", "CROSS", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR", "DEC", "DECIMAL", @@ -145,7 +148,7 @@ public MariaDBDictionary() { "STARTING", "TABLE", "THEN", "TO", "TRAILING", "TRUE", "UNION", "UNIQUE", "UNSIGNED", "UPDATE", "USAGE", "USING", "VALUES", "VARCHAR", "VARYING", "WHEN", "WHERE", "WITH", "WRITE", "ZEROFILL", - "INDEX", + "INDEX", })); requiresSearchStringEscapeForLike = true; @@ -157,7 +160,7 @@ public MariaDBDictionary() { setLeadingDelimiter(DELIMITER_BACK_TICK); setTrailingDelimiter(DELIMITER_BACK_TICK); - + fixedSizeTypeNameSet.remove("NUMERIC"); } @@ -180,10 +183,11 @@ public void connectedConfiguration(Connection conn) throws SQLException { if (log.isWarnEnabled()) log.warn(e.toString(), e); } - + supportsXMLColumn = true; } - + + @Override protected void setDelimitedCase(DatabaseMetaData metaData) { // Determination of case sensitivity is not accurate; MariaDB JIRA CONJ-55 delimitedCase = SCHEMA_CASE_PRESERVE; @@ -194,7 +198,7 @@ public Connection decorate(Connection conn) throws SQLException { conn = super.decorate(conn); return conn; } - + private static int[] getMajorMinorVersions(String versionStr) throws IllegalArgumentException { int beginIndex = 0; @@ -263,7 +267,7 @@ public String[] getDropForeignKeySQL(ForeignKey fk, Connection conn) { new String[]{ "ALTER TABLE " + getFullName(fk.getTable(), false) + " DROP FOREIGN KEY " + toDBName(fkName) }; - return retVal; + return retVal; } return new String[]{ "ALTER TABLE " + getFullName(fk.getTable(), false) @@ -288,7 +292,7 @@ public String[] getAddPrimaryKeySQL(PrimaryKey pk) { System.arraycopy(sql, 0, ret, cols.length, sql.length); return ret; } - + @Override public String[] getDeleteTableContentsSQL(Table[] tables,Connection conn) { // mysql >= 4 supports more-optimal delete syntax @@ -343,10 +347,10 @@ public int getPreferredType(int type) { return Types.LONGVARCHAR; return super.getPreferredType(type); } - + /** * Append XML comparison. - * + * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison @@ -368,10 +372,10 @@ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, else rhs.appendTo(buf); } - + /** * Append XML column value so that it can be used in comparisons. - * + * * @param buf the SQL buffer to write the value * @param val the value to be written */ @@ -382,7 +386,7 @@ private void appendXmlValue(SQLBuffer buf, FilterValue val) { val.appendTo(buf); buf.append("')"); } - + @Override public int getBatchFetchSize(int batchFetchSize) { return Integer.MIN_VALUE; @@ -401,10 +405,10 @@ public String getSelectOperation(JDBCFetchConfiguration fetch) { select += " " + hint; return select; } - + @Override protected Collection getSelectTableAliases(Select sel) { - Set result = new HashSet(); + Set result = new HashSet<>(); List selects = sel.getIdentifierAliases(); for (String s : selects) { String tableAlias = s.substring(0, s.indexOf('.')); @@ -412,12 +416,12 @@ protected Collection getSelectTableAliases(Select sel) { } return result; } - + @Override protected int matchErrorState(Map> errorStates, SQLException ex) { int state = super.matchErrorState(errorStates, ex); - - if (state == StoreException.GENERAL && + + if (state == StoreException.GENERAL && ex.getNextException() != null && "JZ0002".equalsIgnoreCase(ex.getNextException().getSQLState())) { if (conf != null && conf.getLockTimeout() != -1) { @@ -449,7 +453,7 @@ public boolean isFatalException(int subtype, SQLException ex) { */ @Override public String getTypeName(Column col) { - // handle blobs differently, if the DBItentifierType is NULL (e.g. no column definition is set). + // handle blobs differently, if the DBItentifierType is NULL (e.g. no column definition is set). if (col.getType() == Types.BLOB && col.getTypeIdentifier().getType() == DBIdentifierType.NULL) { if (col.getSize() <= 0) // unknown size return blobTypeName; // return old default of 64KB @@ -461,6 +465,17 @@ else if (col.getSize() <= 16777215) return mediumBlobTypeName; else return longBlobTypeName; + } else if (col.getType() == Types.CLOB && col.getTypeIdentifier().getType() == DBIdentifierType.NULL) { + if (col.getSize() <= 0) // unknown size + return clobTypeName; // return old default of 64KB + else if (col.getSize() <= 255) + return tinyTextTypeName; + else if (col.getSize() <= 65535) + return clobTypeName; // old default of 64KB + else if (col.getSize() <= 16777215) + return mediumTextTypeName; + else + return longTextTypeName; } else { return super.getTypeName(col); } diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java similarity index 100% rename from openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java rename to openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/ClobColumnEntity.java diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java similarity index 100% rename from openjpa-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java rename to openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/blob/mysql/TestClobColumnType.java From e75b4cbfc6e0226c8b0f8e6ac87104638bb15c7c Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Thu, 20 Sep 2018 20:02:48 +0700 Subject: [PATCH 3/4] [OPENJPA-2750] commons-dbcp is updated --- openjpa-all/pom.xml | 4 ++-- openjpa-features/src/main/feature/feature.xml | 2 +- openjpa-jdbc/pom.xml | 4 ++-- .../openjpa/jdbc/schema/DBCPDriverDataSource.java | 10 +++++----- .../apache/openjpa/jdbc/sql/PostgresDictionary.java | 6 +++--- openjpa-persistence-jdbc/pom.xml | 2 +- .../java/org/apache/openjpa/conf/TestBadJdbcUrl.java | 2 +- openjpa-persistence-locking/pom.xml | 2 +- openjpa-project/assembly.xml | 2 +- openjpa-project/bin-assembly.xml | 2 +- openjpa-project/pom.xml | 4 ++-- openjpa-project/src/doc/manual/ref_guide_dbsetup.xml | 2 +- pom.xml | 12 ++++++------ 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/openjpa-all/pom.xml b/openjpa-all/pom.xml index 4875c5e988..0f58e1e9e5 100644 --- a/openjpa-all/pom.xml +++ b/openjpa-all/pom.xml @@ -134,8 +134,8 @@ commons-logging - commons-dbcp - commons-dbcp + org.apache.commons + commons-dbcp2 diff --git a/openjpa-features/src/main/feature/feature.xml b/openjpa-features/src/main/feature/feature.xml index b1f0bdf1b7..96f771f2a2 100644 --- a/openjpa-features/src/main/feature/feature.xml +++ b/openjpa-features/src/main/feature/feature.xml @@ -25,7 +25,7 @@ mvn:org.apache.geronimo.specs/geronimo-annotation_1.0_spec/1.1.1 mvn:org.apache.geronimo.specs/geronimo-el_1.0_spec/1.0.1 mvn:org.apache.commons/commons-pool2/2.6.0 - mvn:commons-dbcp/commons-dbcp/1.4 + mvn:org.apache.commons/commons-dbcp2/2.5.0 mvn:commons-collections/commons-collections/3.2.2 mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1 mvn:org.apache.xbean/xbean-asm6-shaded/4.9 diff --git a/openjpa-jdbc/pom.xml b/openjpa-jdbc/pom.xml index 3f36d7ed61..6b7837e3af 100644 --- a/openjpa-jdbc/pom.xml +++ b/openjpa-jdbc/pom.xml @@ -65,8 +65,8 @@ provided - commons-dbcp - commons-dbcp + org.apache.commons + commons-dbcp2 provided diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java index 36aa46fe2f..cf3915c90a 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DBCPDriverDataSource.java @@ -41,8 +41,8 @@ public class DBCPDriverDataSource extends SimpleDriverDataSource implements Configurable, Closeable { - private static String DBCPPACKAGENAME = "org.apache.commons.dbcp"; - private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp.BasicDataSource"; + private static String DBCPPACKAGENAME = "org.apache.commons.dbcp2"; + private static String DBCPBASICDATASOURCENAME = "org.apache.commons.dbcp2.BasicDataSource"; private static Class _dbcpClass; private static Boolean _dbcpAvail; private static RuntimeException _dbcpEx; @@ -59,7 +59,7 @@ public void close() throws SQLException { try { if (_ds != null) { if (isDBCPLoaded(getClassLoader())) { - ((org.apache.commons.dbcp.BasicDataSource)_dbcpClass.cast(_ds)).close(); + ((org.apache.commons.dbcp2.BasicDataSource)_dbcpClass.cast(_ds)).close(); } } } catch (Exception e) { @@ -106,7 +106,7 @@ protected DataSource getDBCPDataSource(Properties props) { * This method should not throw an exception, as it is called by * AutoDriverDataSource to determine if user already specified * to use Commons DBCP. - * @return true if ConnectionDriverName contains org.apache.commons.dbcp, + * @return true if ConnectionDriverName contains org.apache.commons.dbcp2, * otherwise false */ protected boolean isDBCPDataSource() { @@ -117,7 +117,7 @@ protected boolean isDBCPDataSource() { /** * This method should not throw an exception, as it is called by * AutoDriverDataSource to determine if it should use DBCP or not - * based on if org.apache.commons.dbcp.BasicDataSource can be loaded. + * based on if org.apache.commons.dbcp2.BasicDataSource can be loaded. * @return true if Commons DBCP was found on the classpath, otherwise false */ static protected boolean isDBCPLoaded(ClassLoader cl) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java index febbf74b31..d3750fe9a0 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java @@ -876,7 +876,7 @@ protected PGConnection getPGConnection(DelegatingConnection conn) { if (innerConn instanceof PGConnection) { return (PGConnection) innerConn; } - if (innerConn.getClass().getName().startsWith("org.apache.commons.dbcp")) { + if (innerConn.getClass().getName().startsWith("org.apache.commons.dbcp2")) { return (PGConnection) getDbcpDelegate(innerConn); } return (PGConnection) unwrapConnection(conn, PGConnection.class); @@ -893,10 +893,10 @@ protected Connection getDbcpDelegate(Connection conn) { try { if (dbcpGetDelegate == null) { Class dbcpConnectionClass = - Class.forName("org.apache.commons.dbcp.DelegatingConnection", true, AccessController + Class.forName("org.apache.commons.dbcp2.DelegatingConnection", true, AccessController .doPrivileged(J2DoPrivHelper.getContextClassLoaderAction())); Class poolingDataSource = Class.forName( - "org.apache.commons.dbcp.PoolingDataSource", true, + "org.apache.commons.dbcp2.PoolingDataSource", true, AccessController.doPrivileged(J2DoPrivHelper .getContextClassLoaderAction())); Method setAccessToUnderlyingConnectionAllowed = poolingDataSource diff --git a/openjpa-persistence-jdbc/pom.xml b/openjpa-persistence-jdbc/pom.xml index 1537bb225a..c58ff86fba 100644 --- a/openjpa-persistence-jdbc/pom.xml +++ b/openjpa-persistence-jdbc/pom.xml @@ -557,7 +557,7 @@ mvn test -Dtest= -Ptest-derbynet --> jdbc:db2://localhost:1527/openjpa20 - + uid pwd com.ibm.db2.jcc.DB2Driver diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java index c9f3e92cb1..db6d1588c0 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestBadJdbcUrl.java @@ -49,7 +49,7 @@ public class TestBadJdbcUrl extends TestCase { public static final String GOOD_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; public static final String GOOD_DATASOURCE = - "org.apache.commons.dbcp.BasicDataSource"; + "org.apache.commons.dbcp2.BasicDataSource"; public static final String BAD_DRIVER = "bad.driver"; public static final String BAD_URL_PROTOCOL = "bad.url.protocol"; diff --git a/openjpa-persistence-locking/pom.xml b/openjpa-persistence-locking/pom.xml index 1299883679..69fbf6759b 100644 --- a/openjpa-persistence-locking/pom.xml +++ b/openjpa-persistence-locking/pom.xml @@ -534,7 +534,7 @@ mvn test -Dtest= -Ptest-derbynet --> jdbc:db2://localhost:1527/openjpa20 - + uid pwd com.ibm.db2.jcc.DB2Driver diff --git a/openjpa-project/assembly.xml b/openjpa-project/assembly.xml index 8e7afe9f46..e76713e309 100644 --- a/openjpa-project/assembly.xml +++ b/openjpa-project/assembly.xml @@ -137,7 +137,7 @@ commons-collections:commons-collections org.apache.commons:commons-pool2 commons-logging:commons-logging - commons-dbcp:commons-dbcp + org.apache.commons:commons-dbcp2 org.apache.geronimo.specs:geronimo-jta_1.1_spec org.apache.geronimo.specs:geronimo-jpa_2.1_spec diff --git a/openjpa-project/bin-assembly.xml b/openjpa-project/bin-assembly.xml index 9c1fc179ea..5c6f7348f0 100644 --- a/openjpa-project/bin-assembly.xml +++ b/openjpa-project/bin-assembly.xml @@ -76,7 +76,7 @@ commons-collections:commons-collections org.apache.commons:commons-pool2 commons-logging:commons-logging - commons-dbcp:commons-dbcp + org.apache.commons:commons-dbcp2 org.apache.geronimo.specs:geronimo-jta_1.1_spec org.apache.geronimo.specs:geronimo-jpa_2.1_spec diff --git a/openjpa-project/pom.xml b/openjpa-project/pom.xml index 747135bdd4..1197e986fa 100644 --- a/openjpa-project/pom.xml +++ b/openjpa-project/pom.xml @@ -411,8 +411,8 @@ commons-logging - commons-dbcp - commons-dbcp + org.apache.commons + commons-dbcp2 diff --git a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml index caeb3f5a8f..1925109631 100644 --- a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml +++ b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml @@ -86,7 +86,7 @@ select between the old SimpleDriverDataSource and a new has been provided on the classpath and OpenJPA is not running in a container managed mode or with managed transactions. Note, that only the openjpa-all.jar includes Commons DBCP, so you will need to -include the commons-dbcp.jar from the OpenJPA binary +include the commons-dbcp2.jar from the OpenJPA binary distribution if you are using the normal openjpa.jar. diff --git a/pom.xml b/pom.xml index 07245565d2..d0b223e711 100644 --- a/pom.xml +++ b/pom.xml @@ -482,7 +482,7 @@ jdbc:derby://localhost:1527/openjpa20;create=true;traceDirectory=target;traceFile=derby.log org.apache.derby.jdbc.ClientDriver - + uid pwd ${openjpa.derbynet.driver} @@ -554,9 +554,9 @@ ${derby.version} - commons-dbcp - commons-dbcp - 1.4 + org.apache.commons + commons-dbcp2 + 2.5.0 javax.xml.bind @@ -629,8 +629,8 @@ test - commons-dbcp - commons-dbcp + org.apache.commons + commons-dbcp2 test From 9a6715d9c2914fc9054d1de954b4bbe75c5a62db Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Thu, 20 Sep 2018 23:08:22 +0700 Subject: [PATCH 4/4] [OPENJPA-2750] tests are fixed --- openjpa-jdbc/pom.xml | 2 +- openjpa-persistence-jdbc/pom.xml | 2 +- openjpa-persistence-locking/pom.xml | 2 +- .../openjpa-maven-plugin/src/it/default_settings/pom.xml | 2 +- .../src/it/dependingArtifact/prjB/pom.xml | 2 +- .../src/it/enhanceIncludesExcludes/pom.xml | 2 +- .../src/it/nonDefaultPersistenceXml/pom.xml | 2 +- openjpa-tools/openjpa-maven-plugin/src/it/settings.xml | 2 +- .../openjpa-maven-plugin/src/it/sqlActionDropSchema/pom.xml | 4 ++-- .../openjpa-maven-plugin/src/it/testDependencies/prjB/pom.xml | 2 +- pom.xml | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/openjpa-jdbc/pom.xml b/openjpa-jdbc/pom.xml index 6b7837e3af..0752a3652b 100644 --- a/openjpa-jdbc/pom.xml +++ b/openjpa-jdbc/pom.xml @@ -55,7 +55,7 @@ true - hsqldb + org.hsqldb hsqldb provided diff --git a/openjpa-persistence-jdbc/pom.xml b/openjpa-persistence-jdbc/pom.xml index c58ff86fba..d5eb836134 100644 --- a/openjpa-persistence-jdbc/pom.xml +++ b/openjpa-persistence-jdbc/pom.xml @@ -74,7 +74,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} test diff --git a/openjpa-persistence-locking/pom.xml b/openjpa-persistence-locking/pom.xml index 69fbf6759b..3e0be2b5ec 100644 --- a/openjpa-persistence-locking/pom.xml +++ b/openjpa-persistence-locking/pom.xml @@ -84,7 +84,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} test diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/default_settings/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/default_settings/pom.xml index 094133d670..c9847e85af 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/default_settings/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/default_settings/pom.xml @@ -62,7 +62,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/dependingArtifact/prjB/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/dependingArtifact/prjB/pom.xml index d808cf9ae8..f8c491c43b 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/dependingArtifact/prjB/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/dependingArtifact/prjB/pom.xml @@ -58,7 +58,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/enhanceIncludesExcludes/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/enhanceIncludesExcludes/pom.xml index 6ffe184299..d5f6d08094 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/enhanceIncludesExcludes/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/enhanceIncludesExcludes/pom.xml @@ -61,7 +61,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/nonDefaultPersistenceXml/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/nonDefaultPersistenceXml/pom.xml index b8967f1817..a4fc45b75a 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/nonDefaultPersistenceXml/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/nonDefaultPersistenceXml/pom.xml @@ -50,7 +50,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/settings.xml b/openjpa-tools/openjpa-maven-plugin/src/it/settings.xml index b8a82c1064..47f559e374 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/settings.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/settings.xml @@ -45,7 +45,7 @@ - 1.8.0.10 + 2.4.1 diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionDropSchema/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionDropSchema/pom.xml index 66ad1fa9bb..cce1721aed 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionDropSchema/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionDropSchema/pom.xml @@ -61,7 +61,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} @@ -137,7 +137,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/testDependencies/prjB/pom.xml b/openjpa-tools/openjpa-maven-plugin/src/it/testDependencies/prjB/pom.xml index 8c1f34a236..42342ebde8 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/it/testDependencies/prjB/pom.xml +++ b/openjpa-tools/openjpa-maven-plugin/src/it/testDependencies/prjB/pom.xml @@ -50,7 +50,7 @@ - hsqldb + org.hsqldb hsqldb ${hsqldb.version} diff --git a/pom.xml b/pom.xml index d0b223e711..1dda00a4a6 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ false 10.12.1.1 - 1.8.0.10 + 2.4.1 5.1.12 9.1-901-1.jdbc4 @@ -569,7 +569,7 @@ 2.2.1 - hsqldb + org.hsqldb hsqldb ${hsqldb.version}