You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2009/05/26 16:18:48 UTC

svn commit: r778710 - /openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java

Author: dwoods
Date: Tue May 26 14:18:47 2009
New Revision: 778710

URL: http://svn.apache.org/viewvc?rev=778710&view=rev
Log:
OPENJPA-908 The latest PostgreSQL JDBC driver returns a returns a org.postgresql.util.PGobject object instead of a java.sql.Timestamp.  Contributed by Tim McConnell.

Modified:
    openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java

Modified: openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=778710&r1=778709&r2=778710&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java (original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java Tue May 26 14:18:47 2009
@@ -21,17 +21,21 @@
 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;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Timestamp;
 import java.sql.Types;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.Map;
 
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
@@ -646,4 +650,44 @@
             }
         }
     }
+
+    /**
+     * 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;
+    }   
+
 }