Many thanks for your response. I apologize for my impatience. I just
didn't quite understand what was going on.
If I understand that little snippet of code correctly, does that mean
that when using an updatable result which involves a serialized java
object, like in my test case, you will take the performance hit of
serialization/deserialization on the object, even if you are not
updating the object itself?
In general, i would be curious as to you thoughts on using
UpdatableResultSet. Does it provide any real performance benefit - or
is a straightfoward implementation which is mostly there in the
interest of conforming to JDBC spec.
Thanks
--joel
On Sep 5, 9:40 pm, "Thomas Mueller" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> This is a bug. Thanks a lot for reporting it, and for the great test
> case! The problem is that ValueJavaObject does not override the method
> set(PreparedStatement prep, int parameterIndex). If you add the
> following code to ValueJavaObject, your test case works:
>
> public void set(PreparedStatement prep, int parameterIndex) throws
> SQLException {
> Object obj = ObjectUtils.deserialize(getBytesNoCopy());
> prep.setObject(parameterIndex, obj, Types.JAVA_OBJECT);
> }
>
> I do some more testing, and this will be fixed in the next release.
>
> Regards,
> Thomas
>
> On Thu, Sep 4, 2008 at 11:43 AM, Joel Carranza <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I'm looking at using the H2 engine for a persistant java object store
> > and I ran across a strange problem. I can store and retrieve java
> > objects no problem in the normal case. However, when I update a row
> > using an updatable result set, the object in that row is no longer
> > returned as an object, but rather as an array of bytes.
>
> > I'm including below a simple code example which demonstrates the
> > problem. I store a String as an object in a row, fetch it out again
> > correctly, then update the row, and fetch again.
>
> > The second fetch results in a byte array instead of the correct
> > object. This happens regardless of the object type.
>
> > import java.io.*;
> > import java.sql.*;
>
> > public class UpdateRow {
>
> > static int execute(Connection conn, String sql) throws SQLException {
> > Statement stmt = conn.createStatement();
> > int rv = stmt.executeUpdate(sql);
> > stmt.close();
> > return rv;
> > }
>
> > public static void main(String[] args) throws SQLException,
> > ClassNotFoundException, IOException {
> > Class.forName("org.h2.Driver");
> > File file = File.createTempFile("test", "db");
> > Connection conn =
> > DriverManager.getConnection("jdbc:h2:"+file.getAbsolutePath());
> > execute(conn,"CREATE TABLE object_index (id integer primary
> > key,
> > object other, number integer)");
>
> > PreparedStatement stmt = conn.prepareStatement("INSERT INTO
> > object_index (id,object) VALUES (1,?)");
> > stmt.setObject(1,"hello", Types.JAVA_OBJECT);
> > stmt.execute();
>
> > // select object (as string) from row
> > Statement s = conn.createStatement();
> > ResultSet rs = s.executeQuery("SELECT object,id,number FROM
> > object_index WHERE id =1");
> > if(rs.next()) {
> > // prints out "hello"
> > System.out.println(rs.getObject(1));
> > }
> > rs.close();
> > s.close();
>
> > // update row
> > s =
> > conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE
> > );
> > rs = s.executeQuery("SELECT object,id,number FROM
> > object_index WHERE
> > id =1");
> > if(rs.next()) {
> > // prints out "hello"
> > System.out.println(rs.getObject(1));
> > rs.updateInt(2, 1);
> > rs.updateRow(); // succeeds
> > }
> > rs.close();
> > s.close();
>
> > // select again
> > s = conn.createStatement();
> > rs = s.executeQuery("SELECT object,id,number FROM
> > object_index WHERE
> > id =1");
> > if(rs.next()) {
> > // XXX: is no longer a string - is a byte array[] !
> > System.out.println(rs.getObject(1));
> > }
> > rs.close();
> > s.close();
>
> > conn.close();
> > }
> > }
>
> > -- Joel Carranza
> > [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---