mirror of https://github.com/apache/openjpa.git
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:
parent
ff52a40fb4
commit
a2c286bf3b
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.openjpa.jdbc.meta.strats;
|
||||
|
||||
import java.sql.Blob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@ -89,7 +90,7 @@ public class MaxEmbeddedBlobFieldStrategy
|
|||
DBDictionary dict)
|
||||
throws SQLException {
|
||||
byte[] b = (byte[]) sm.setImplData(field.getIndex(), null);
|
||||
Object blob = rs.getBlob(1);
|
||||
Blob blob = rs.getBlob(1);
|
||||
dict.putBytes(blob, b);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.openjpa.jdbc.meta.strats;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.sql.Blob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class MaxEmbeddedByteArrayFieldStrategy
|
|||
protected void putData(OpenJPAStateManager sm, ResultSet rs,
|
||||
DBDictionary dict)
|
||||
throws SQLException {
|
||||
Object blob = rs.getBlob(1);
|
||||
Blob blob = rs.getBlob(1);
|
||||
dict.putBytes(blob, PrimitiveWrapperArrays.toByteArray(sm.fetchObject
|
||||
(field.getIndex())));
|
||||
}
|
||||
|
@ -80,7 +81,7 @@ public class MaxEmbeddedByteArrayFieldStrategy
|
|||
protected Object load(Column col, Result res, Joins joins)
|
||||
throws SQLException {
|
||||
return PrimitiveWrapperArrays.toObjectValue(field,
|
||||
(byte[]) res.getBytes(col, joins));
|
||||
res.getBytes(col, joins));
|
||||
}
|
||||
|
||||
public void map(boolean adapt) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.io.CharArrayWriter;
|
|||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.sql.Clob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class MaxEmbeddedCharArrayFieldStrategy
|
|||
protected void putData(OpenJPAStateManager sm, ResultSet rs,
|
||||
DBDictionary dict)
|
||||
throws SQLException {
|
||||
Object clob = rs.getClob(1);
|
||||
Clob clob = rs.getClob(1);
|
||||
dict.putChars(clob, PrimitiveWrapperArrays.
|
||||
toCharArray(sm.fetchObject(field.getIndex())));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.openjpa.jdbc.meta.strats;
|
||||
|
||||
import java.sql.Clob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class MaxEmbeddedClobFieldStrategy
|
|||
protected void putData(OpenJPAStateManager sm, ResultSet rs,
|
||||
DBDictionary dict)
|
||||
throws SQLException {
|
||||
Object clob = rs.getClob(1);
|
||||
Clob clob = rs.getClob(1);
|
||||
dict.putString(clob, sm.fetchString(field.getIndex()));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ import java.io.OutputStream;
|
|||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Array;
|
||||
|
@ -394,11 +392,6 @@ public class DBDictionary
|
|||
// first time it happens we can warn the user
|
||||
private Set _precisionWarnedTypes = null;
|
||||
|
||||
// cache lob methods
|
||||
private Method _setBytes = null;
|
||||
private Method _setString = null;
|
||||
private Method _setCharStream = null;
|
||||
|
||||
// batchLimit value:
|
||||
// -1 = unlimited
|
||||
// 0 = no batch
|
||||
|
@ -1421,55 +1414,27 @@ public class DBDictionary
|
|||
/**
|
||||
* 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 {
|
||||
if (_setBytes == null) {
|
||||
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 });
|
||||
blob.setBytes(1L, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the JDK 1.4 <code>setString</code> method on the given CLOB
|
||||
* object.
|
||||
*/
|
||||
public void putString(Object clob, String data)
|
||||
public void putString(Clob clob, String data)
|
||||
throws SQLException {
|
||||
if (_setString == null) {
|
||||
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 });
|
||||
clob.setString(1L, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the JDK 1.4 <code>setCharacterStream</code> method on the given
|
||||
* CLOB object.
|
||||
*/
|
||||
public void putChars(Object clob, char[] data)
|
||||
public void putChars(Clob clob, char[] data)
|
||||
throws SQLException {
|
||||
if (_setCharStream == null) {
|
||||
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) });
|
||||
Writer writer = clob.setCharacterStream(1L);
|
||||
try {
|
||||
writer.write(data);
|
||||
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.
|
||||
* After the first warning for a particular type, messages
|
||||
|
|
|
@ -949,7 +949,7 @@ public class OracleDictionary
|
|||
* vendor-specific class; for example Weblogic wraps oracle thin driver
|
||||
* 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 {
|
||||
if (blob == null)
|
||||
return;
|
||||
|
@ -970,7 +970,7 @@ public class OracleDictionary
|
|||
* vendor-specific class; for example Weblogic wraps oracle thin driver
|
||||
* 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 {
|
||||
if (_putString == null) {
|
||||
try {
|
||||
|
@ -989,7 +989,7 @@ public class OracleDictionary
|
|||
* vendor-specific class; for example Weblogic wraps oracle thin driver
|
||||
* 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 {
|
||||
if (_putChars == null) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue