OPENJPA-908 - Commit contribution by Tim McConnell.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@777615 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Albert Lee 2009-05-22 16:45:46 +00:00
parent 056d211658
commit 6d91126dd6
1 changed files with 56 additions and 8 deletions

View File

@ -21,6 +21,8 @@ package org.apache.openjpa.jdbc.sql;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -32,6 +34,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Map;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.kernel.JDBCStore;
@ -550,15 +553,58 @@ public class PostgresDictionary
super.setClobString(stmnt, idx, val, col); 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. * Append XML comparison.
* *
* @param buf the SQL buffer to write the comparison * @param buf
* @param op the comparison operation to perform * the SQL buffer to write the comparison
* @param lhs the left hand side of the comparison * @param op
* @param rhs the right hand side of the comparison * the comparison operation to perform
* @param lhsxml indicates whether the left operand maps to XML * @param lhs
* @param rhsxml indicates whether the right operand maps to XML * 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, public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs,
FilterValue rhs, boolean lhsxml, boolean rhsxml) { FilterValue rhs, boolean lhsxml, boolean rhsxml) {
@ -577,8 +623,10 @@ public class PostgresDictionary
/** /**
* Append XML column value so that it can be used in comparisons. * Append XML column value so that it can be used in comparisons.
* *
* @param buf the SQL buffer to write the value * @param buf
* @param val the value to be written * the SQL buffer to write the value
* @param val
* the value to be written
*/ */
private void appendXmlValue(SQLBuffer buf, FilterValue val) { private void appendXmlValue(SQLBuffer buf, FilterValue val) {
Class rc = Filters.wrap(val.getType()); Class rc = Filters.wrap(val.getType());