OPENJPA-1122: Remove JDBC 3 related reflection from DBDictionary

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@782338 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Milosz Tylenda 2009-06-07 08:13:41 +00:00
parent ff52a40fb4
commit a2c286bf3b
6 changed files with 18 additions and 67 deletions

View File

@ -18,6 +18,7 @@
*/ */
package org.apache.openjpa.jdbc.meta.strats; package org.apache.openjpa.jdbc.meta.strats;
import java.sql.Blob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -89,7 +90,7 @@ public class MaxEmbeddedBlobFieldStrategy
DBDictionary dict) DBDictionary dict)
throws SQLException { throws SQLException {
byte[] b = (byte[]) sm.setImplData(field.getIndex(), null); byte[] b = (byte[]) sm.setImplData(field.getIndex(), null);
Object blob = rs.getBlob(1); Blob blob = rs.getBlob(1);
dict.putBytes(blob, b); dict.putBytes(blob, b);
} }

View File

@ -19,6 +19,7 @@
package org.apache.openjpa.jdbc.meta.strats; package org.apache.openjpa.jdbc.meta.strats;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.sql.Blob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -72,7 +73,7 @@ public class MaxEmbeddedByteArrayFieldStrategy
protected void putData(OpenJPAStateManager sm, ResultSet rs, protected void putData(OpenJPAStateManager sm, ResultSet rs,
DBDictionary dict) DBDictionary dict)
throws SQLException { throws SQLException {
Object blob = rs.getBlob(1); Blob blob = rs.getBlob(1);
dict.putBytes(blob, PrimitiveWrapperArrays.toByteArray(sm.fetchObject dict.putBytes(blob, PrimitiveWrapperArrays.toByteArray(sm.fetchObject
(field.getIndex()))); (field.getIndex())));
} }
@ -80,7 +81,7 @@ public class MaxEmbeddedByteArrayFieldStrategy
protected Object load(Column col, Result res, Joins joins) protected Object load(Column col, Result res, Joins joins)
throws SQLException { throws SQLException {
return PrimitiveWrapperArrays.toObjectValue(field, return PrimitiveWrapperArrays.toObjectValue(field,
(byte[]) res.getBytes(col, joins)); res.getBytes(col, joins));
} }
public void map(boolean adapt) { public void map(boolean adapt) {

View File

@ -23,6 +23,7 @@ import java.io.CharArrayWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.sql.Clob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -77,7 +78,7 @@ public class MaxEmbeddedCharArrayFieldStrategy
protected void putData(OpenJPAStateManager sm, ResultSet rs, protected void putData(OpenJPAStateManager sm, ResultSet rs,
DBDictionary dict) DBDictionary dict)
throws SQLException { throws SQLException {
Object clob = rs.getClob(1); Clob clob = rs.getClob(1);
dict.putChars(clob, PrimitiveWrapperArrays. dict.putChars(clob, PrimitiveWrapperArrays.
toCharArray(sm.fetchObject(field.getIndex()))); toCharArray(sm.fetchObject(field.getIndex())));
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.apache.openjpa.jdbc.meta.strats; package org.apache.openjpa.jdbc.meta.strats;
import java.sql.Clob;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -66,7 +67,7 @@ public class MaxEmbeddedClobFieldStrategy
protected void putData(OpenJPAStateManager sm, ResultSet rs, protected void putData(OpenJPAStateManager sm, ResultSet rs,
DBDictionary dict) DBDictionary dict)
throws SQLException { throws SQLException {
Object clob = rs.getClob(1); Clob clob = rs.getClob(1);
dict.putString(clob, sm.fetchString(field.getIndex())); dict.putString(clob, sm.fetchString(field.getIndex()));
} }

View File

@ -28,8 +28,6 @@ import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.io.Writer; import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.Array; import java.sql.Array;
@ -394,11 +392,6 @@ public class DBDictionary
// first time it happens we can warn the user // first time it happens we can warn the user
private Set _precisionWarnedTypes = null; private Set _precisionWarnedTypes = null;
// cache lob methods
private Method _setBytes = null;
private Method _setString = null;
private Method _setCharStream = null;
// batchLimit value: // batchLimit value:
// -1 = unlimited // -1 = unlimited
// 0 = no batch // 0 = no batch
@ -1421,55 +1414,27 @@ public class DBDictionary
/** /**
* Invoke the JDK 1.4 <code>setBytes</code> method on the given BLOB object. * Invoke the JDK 1.4 <code>setBytes</code> method on the given BLOB object.
*/ */
public void putBytes(Object blob, byte[] data) public void putBytes(Blob blob, byte[] data)
throws SQLException { throws SQLException {
if (_setBytes == null) { blob.setBytes(1L, data);
try {
_setBytes = blob.getClass().getMethod("setBytes",
new Class[]{ long.class, byte[].class });
} catch (Exception e) {
throw new StoreException(e);
}
}
invokePutLobMethod(_setBytes, blob,
new Object[]{ Numbers.valueOf(1L), data });
} }
/** /**
* Invoke the JDK 1.4 <code>setString</code> method on the given CLOB * Invoke the JDK 1.4 <code>setString</code> method on the given CLOB
* object. * object.
*/ */
public void putString(Object clob, String data) public void putString(Clob clob, String data)
throws SQLException { throws SQLException {
if (_setString == null) { clob.setString(1L, data);
try {
_setString = clob.getClass().getMethod("setString",
new Class[]{ long.class, String.class });
} catch (Exception e) {
throw new StoreException(e);
}
}
invokePutLobMethod(_setString, clob,
new Object[]{ Numbers.valueOf(1L), data });
} }
/** /**
* Invoke the JDK 1.4 <code>setCharacterStream</code> method on the given * Invoke the JDK 1.4 <code>setCharacterStream</code> method on the given
* CLOB object. * CLOB object.
*/ */
public void putChars(Object clob, char[] data) public void putChars(Clob clob, char[] data)
throws SQLException { throws SQLException {
if (_setCharStream == null) { Writer writer = clob.setCharacterStream(1L);
try {
_setCharStream = clob.getClass().getMethod
("setCharacterStream", new Class[]{ long.class });
} catch (Exception e) {
throw new StoreException(e);
}
}
Writer writer = (Writer) invokePutLobMethod(_setCharStream, clob,
new Object[]{ Numbers.valueOf(1L) });
try { try {
writer.write(data); writer.write(data);
writer.flush(); writer.flush();
@ -1478,24 +1443,6 @@ public class DBDictionary
} }
} }
/**
* Invoke the given LOB method on the given target with the given data.
*/
private static Object invokePutLobMethod(Method method, Object target,
Object[] args)
throws SQLException {
try {
return method.invoke(target, args);
} catch (InvocationTargetException ite) {
Throwable t = ite.getTargetException();
if (t instanceof SQLException)
throw(SQLException) t;
throw new StoreException(t);
} catch (Exception e) {
throw new StoreException(e);
}
}
/** /**
* Warn that a particular value could not be stored precisely. * Warn that a particular value could not be stored precisely.
* After the first warning for a particular type, messages * After the first warning for a particular type, messages

View File

@ -949,7 +949,7 @@ public class OracleDictionary
* vendor-specific class; for example Weblogic wraps oracle thin driver * vendor-specific class; for example Weblogic wraps oracle thin driver
* lobs in its own interfaces with the same methods. * lobs in its own interfaces with the same methods.
*/ */
public void putBytes(Object blob, byte[] data) public void putBytes(Blob blob, byte[] data)
throws SQLException { throws SQLException {
if (blob == null) if (blob == null)
return; return;
@ -970,7 +970,7 @@ public class OracleDictionary
* vendor-specific class; for example Weblogic wraps oracle thin driver * vendor-specific class; for example Weblogic wraps oracle thin driver
* lobs in its own interfaces with the same methods. * lobs in its own interfaces with the same methods.
*/ */
public void putString(Object clob, String data) public void putString(Clob clob, String data)
throws SQLException { throws SQLException {
if (_putString == null) { if (_putString == null) {
try { try {
@ -989,7 +989,7 @@ public class OracleDictionary
* vendor-specific class; for example Weblogic wraps oracle thin driver * vendor-specific class; for example Weblogic wraps oracle thin driver
* lobs in its own interfaces with the same methods. * lobs in its own interfaces with the same methods.
*/ */
public void putChars(Object clob, char[] data) public void putChars(Clob clob, char[] data)
throws SQLException { throws SQLException {
if (_putChars == null) { if (_putChars == null) {
try { try {