From dfba4dff7d9ee94a8464b5e4b8be9b2c5839bdd4 Mon Sep 17 00:00:00 2001 From: "David J. Wisneski" Date: Tue, 10 Jul 2007 02:28:11 +0000 Subject: [PATCH] OPENJPA-266, extensibility for platform specific version column Passed TCK with Derby git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@554803 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/jdbc/sql/DBDictionary.java | 10 ++++++++++ .../java/org/apache/openjpa/jdbc/sql/RowImpl.java | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index e894987d3..620c02bd8 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -3839,4 +3839,14 @@ public class DBDictionary this.bytes = bytes; } } + + /** + * Return version column name + * @param column + * @param tableAlias : this is needed for platform specific version column + * @return + */ + public String getVersionColumn(Column column, String tableAlias) { + return column.toString(); + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java index 38b27c7ca..a4f4a5f2a 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java @@ -20,6 +20,7 @@ package org.apache.openjpa.jdbc.sql; import java.io.InputStream; import java.io.Reader; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Array; @@ -756,7 +757,7 @@ public class RowImpl hasVal = true; } - appendWhere(buf); + appendWhere(buf, dict); return buf.toString(); } @@ -797,14 +798,14 @@ public class RowImpl StringBuffer buf = new StringBuffer(); buf.append("DELETE FROM "). append(dict.getFullName(getTable(), false)); - appendWhere(buf); + appendWhere(buf, dict); return buf.toString(); } /** * Appends the where clause onto the given sql buffer. */ - private void appendWhere(StringBuffer buf) { + private void appendWhere(StringBuffer buf, DBDictionary dict) { boolean hasWhere = false; for (int i = 0; i < _cols.length; i++) { if (_vals[getWhereIndex(_cols[i])] == null) @@ -815,9 +816,13 @@ public class RowImpl else buf.append(" AND "); + // Get platform specific version column name + if (_cols[i].getVersionStrategy() != null) + buf.append(dict.getVersionColumn(_cols[i], _cols[i] + .getTableName())).append(" = ?"); // sqlserver seems to have problems using null parameters in the // where clause - if (_vals[getWhereIndex(_cols[i])] == NULL) + else if (_vals[getWhereIndex(_cols[i])] == NULL) buf.append(_cols[i]).append(" IS NULL"); else if (_types[i] == RAW) buf.append(_cols[i]).append(" = ").append(_vals[i]);