Author: allee8285
Date: Fri May 22 16:45:46 2009
New Revision: 777615
URL: http://svn.apache.org/viewvc?rev=777615&view=rev
Log:
OPENJPA-908 - Commit contribution by Tim McConnell.
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=777615&r1=777614&r2=777615&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Fri May 22 16:45:46 2009
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@@ -32,6 +34,7 @@
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+import java.util.Map;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore;
@@ -549,16 +552,59 @@
else
super.setClobString(stmnt, idx, val, col);
}
+
+ /**
+ * Override the getOjbect() method to handle the case where the latest
+ * Postgres JDBC driver returns a org.postgresql.util.PGobject instead of a
+ * java.sql.Timestamp
+ *
+ * @param rs
+ * @param column
+ * @param map
+ *
+ * @return
+ * @exception SQLException
+ */
+ public Object getObject(ResultSet rs, int column, Map map)
+ throws SQLException {
+ Object obj = super.getObject(rs, column, map);
+
+ if (obj == null) {
+ return null;
+ }
+ if (obj.getClass().getName().equals("org.postgresql.util.PGobject")) {
+ try {
+ Method m = obj.getClass().getMethod("getType", (Class[]) null);
+ Object type = m.invoke(obj, (Object[]) null);
+ if (((String) type).equalsIgnoreCase(timestampTypeName)) {
+ return rs.getTimestamp(column);
+ }
+ } catch (Throwable t) {
+ if (t instanceof InvocationTargetException)
+ t = ((InvocationTargetException) t).getTargetException();
+ if (t instanceof SQLException)
+ throw (SQLException) t;
+ throw new SQLException(t.getMessage());
+ }
+ }
+ return obj;
+ }
/**
* 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
- * @param rhs the right hand side of the comparison
- * @param lhsxml indicates whether the left operand maps to XML
- * @param rhsxml indicates whether the right operand maps to XML
+ * @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
+ * @param rhs
+ * the right hand side of the comparison
+ * @param lhsxml
+ * indicates whether the left operand maps to XML
+ * @param rhsxml
+ * indicates whether the right operand maps to XML
*/
public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs,
FilterValue rhs, boolean lhsxml, boolean rhsxml) {
@@ -577,8 +623,10 @@
/**
* 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
+ * @param buf
+ * the SQL buffer to write the value
+ * @param val
+ * the value to be written
*/
private void appendXmlValue(SQLBuffer buf, FilterValue val) {
Class rc = Filters.wrap(val.getType());