You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2010/08/16 22:07:00 UTC
svn commit: r986120 - in /openjpa/trunk/openjpa-jdbc/src/main:
java/org/apache/openjpa/jdbc/sql/DBDictionary.java
java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java
resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
Author: faywang
Date: Mon Aug 16 20:06:59 2010
New Revision: 986120
URL: http://svn.apache.org/viewvc?rev=986120&view=rev
Log:
OPENJPA-735: OpenJPA support for SolidDB
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java
openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=986120&r1=986119&r2=986120&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Mon Aug 16 20:06:59 2010
@@ -51,7 +51,6 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -66,10 +65,10 @@ import javax.sql.DataSource;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.identifier.ColumnDefIdentifierRule;
-import org.apache.openjpa.jdbc.identifier.Normalizer;
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
import org.apache.openjpa.jdbc.identifier.DBIdentifierRule;
import org.apache.openjpa.jdbc.identifier.DBIdentifierUtil;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
@@ -88,7 +87,6 @@ import org.apache.openjpa.jdbc.schema.In
import org.apache.openjpa.jdbc.schema.NameSet;
import org.apache.openjpa.jdbc.schema.PrimaryKey;
import org.apache.openjpa.jdbc.schema.Schema;
-import org.apache.openjpa.jdbc.schema.SchemaGroup;
import org.apache.openjpa.jdbc.schema.Sequence;
import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.jdbc.schema.Unique;
@@ -3519,7 +3517,7 @@ public class DBDictionary
if (DBIdentifier.isNull(fk.getIdentifier())) {
String[] retVal;
DBIdentifier fkName = fk.loadIdentifierFromDB(this,conn);
- retVal = (fkName == null) ? new String[0] :
+ retVal = (fkName == null || fkName.getName() == null) ? new String[0] :
new String[]{ "ALTER TABLE "
+ getFullName(fk.getTable(), false)
+ " DROP CONSTRAINT " + toDBName(fkName) };
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java?rev=986120&r1=986119&r2=986120&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SolidDBDictionary.java Mon Aug 16 20:06:59 2010
@@ -18,7 +18,11 @@
*/
package org.apache.openjpa.jdbc.sql;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Arrays;
+import java.util.Collection;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
@@ -27,6 +31,8 @@ import org.apache.openjpa.jdbc.schema.Co
import org.apache.openjpa.jdbc.schema.PrimaryKey;
import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.jdbc.schema.Unique;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.ReferenceHashSet;
/**
* Dictionary for SolidDB database.
@@ -43,10 +49,20 @@ public class SolidDBDictionary
* cannot continue accessing M-tables after the transaction has committed
* or aborted. The statement must be re-executed.), the default is
* STORE DISK.
+ * The default concurrency control mechanism depends on the table type:
+ * Disk-based tables (D-tables) are by default optimistic.
+ * Main-memory tables (M-tables) are always pessimistic.
*
*/
public boolean storeIsMemory = false;
+ // weak set of connections we've already executed lock mode sql on
+ private final Collection _seenConnections = new ReferenceHashSet
+ (ReferenceHashSet.WEAK);
+
+ private static final Localizer _loc = Localizer.forPackage
+ (SolidDBDictionary.class);
+
public SolidDBDictionary() {
platform = "SolidDB";
bitTypeName = "TINYINT";
@@ -65,6 +81,10 @@ public class SolidDBDictionary
trimLeadingFunction = "LTRIM({0})";
trimTrailingFunction = "RTRIM({0})";
trimBothFunction = "TRIM({0})";
+
+ currentDateFunction = "CURDATE()";
+ currentTimeFunction = "CURTIME()";
+ currentTimestampFunction = "NOW()";
reservedWordSet.addAll(Arrays.asList(new String[]{
"BIGINT", "BINARY", "DATE", "TIME",
@@ -149,25 +169,56 @@ public class SolidDBDictionary
@Override
public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
FilterValue start) {
- buf.append("(POSITION((");
+ buf.append("(LOCATE(");
find.appendTo(buf);
- buf.append(") IN (");
-
- if (start != null)
- substring(buf, str, start, null);
- else
- str.appendTo(buf);
-
- buf.append(")) - 1");
-
+ buf.append(", ");
+ str.appendTo(buf);
if (start != null) {
- buf.append(" + ");
- start.appendTo(buf);
+ buf.append(", ");
+ if (start.getValue() instanceof Number) {
+ long startLong = toLong(start);
+ buf.append(Long.toString(startLong + 1));
+ } else {
+ buf.append("(");
+ start.appendTo(buf);
+ buf.append(" + 1)");
+ }
}
- buf.append(")");
+ buf.append(") - 1)");
}
-
- public String toUpper(String internalName, boolean force) {
- return internalName.toUpperCase();
+
+ @Override
+ public Connection decorate(Connection conn)
+ throws SQLException {
+ conn = super.decorate(conn);
+ // if we haven't already done so, initialize the lock mode of the
+ // connection
+ if (_seenConnections.add(conn)) {
+ String sql = "SET OPTIMISTIC LOCK TIMEOUT 100";
+ execute(sql, conn, true);
+ }
+ return conn;
}
+
+ private void execute(String sql, Connection conn, boolean throwExc) {
+ Statement stmnt = null;
+ try {
+ stmnt = conn.createStatement();
+ stmnt.executeUpdate(sql);
+ } catch (SQLException se) {
+ if (throwExc)
+ throw SQLExceptions.getStore(se, this);
+ else {
+ if (log.isTraceEnabled())
+ log.trace(_loc.get("can-not-execute", sql));
+ }
+ } finally {
+ if (stmnt != null)
+ try {
+ stmnt.close();
+ } catch (SQLException se) {
+ }
+ }
+ }
+
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml?rev=986120&r1=986119&r2=986120&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml Mon Aug 16 20:06:59 2010
@@ -190,4 +190,13 @@
<query>57014</query>
</dictionary>
+ <dictionary class="org.apache.openjpa.jdbc.sql.SolidDBDictionary">
+ <lock></lock>
+ <referential-integrity></referential-integrity>
+ <object-exists>23000</object-exists>
+ <object-not-found></object-not-found>
+ <optimistic></optimistic>
+ <query></query>
+ </dictionary>
+
</sql-state-codes>