Get rid of JdbcSQLException while numbers are read from cache

Exception org.h2.jdbc.JdbcSQLException: Hexadecimal string with odd
number of characters: "0" is thrown when number with value 0 or string
with value "0" is stored in H2Cache and read is performed.
The fix modifies implementation so that Java de-serialization is
performed even for built-in (e.g. Integer) types.

Change-Id: I953487cb75b3712e8825a74613977425873507a1
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
This commit is contained in:
Jacek Centkowski
2013-10-24 07:24:52 -07:00
parent dd1ef1d114
commit b294b033bb

View File

@@ -27,6 +27,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
@@ -267,7 +268,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
}
void set(PreparedStatement ps, int col, K value) throws SQLException {
ps.setObject(col, value);
ps.setObject(col, value, Types.JAVA_OBJECT);
}
Funnel<K> funnel() {
@@ -488,7 +489,7 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
}
try {
keyType.set(c.put, 1, key);
c.put.setObject(2, holder.value);
c.put.setObject(2, holder.value, Types.JAVA_OBJECT);
c.put.setTimestamp(3, new Timestamp(holder.created));
c.put.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
c.put.executeUpdate();