Great stuff, Thomas! This takes us one step closer to completing the =
scope of the jdbc.object package.
=20
Now we just need to move the BatchSqlUpdate class over to the main =
source tree, and add support for special parameter types (like Oracle =
arrays) to SqlOperation - then it will be quite hard to find a further =
gap :-)
=20
Do you see a chance to address the special parameter types issue within =
the 1.0.3 timeframe?
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von Thomas Risberg
Gesendet: Fr 04.06.2004 19:57
An: spr...@li...
Betreff: [Springframework-developer] Added BLOB/CLOB support to =
SqlUpdate and StoredProcedure
OK, I'm done adding support for BLOB/CLOB to SqlUpdate and
StoredProcedure. I have commited these changes and you are welcome to
take them for a spin. If you notice any problems let me know. I'll
add some mocked unit tests to our testsuite the next couple of days.=20
All tests I have now are live connection ones.
Here is a short example of usage.
I'm reusing the LobHandler that Juergen added recently. It works very
well and it supports the following input types for LOBs:
BLOB - byte array or java.io.InputStream
CLOB - String, java.io.InputStream or java.io.Reader
If you are running in an appserver with a connection pool that wraps
your connection, depending on which LobHandler you use, you might have
to set a NativeJdbcExtractor. For Oracle 9i and Weblogic 8.1 I used the
following setup:
LobHandler lobHandler =3D new OracleLobHandler();
NativeJdbcExtractor jdbcExtractor =3D new =
WebLogicNativeJdbcExtractor();
lobHandler.setNativeJdbcExtractor(jdbcExtractor);
This should of course be set via IoC for a real app.
Now you need to create your SqlUpdate and declare you parameters:
String sql =3D "insert into docs (doc_id, content) values(?, ?)";
SqlUpdate su =3D new SqlUpdate(ds, sql);
su.declareParameter(new SqlParameter("id", Types.INTEGER));
su.declareParameter(new SqlParameter("lob", Types.BLOB,
lobHandler));
su.compile();
The LOB parameter is declared with a new constructor that takes the
LobHandler as the third argument. If you don't specify a LobHandler we
will automatically generate a DefaultLobHandler.
Next we need to create an array with all parameters and call the
update() method to insert each row. The LOB value must be passed in as
an SqlLobValue object together with the length (unless you use a byte
array or String in which case we can easily figure out the length).=20
SqlLobValue is a new class that holds the actual LOB value plus the
LobCreator that the framework internally populates during the update.
Object[] inval =3D new Object[2];
inval[0] =3D new Integer(newId);
File in =3D new File("some.doc");
InputStream is =3D new FileInputStream(in);
inval[1] =3D new SqlLobValue(is, (int) in.length());
int count =3D su.update(inval);
is.close();
That is it. It works the same way for CLOBs and it also works for
parameters passed in to a StoredProcedure.
While making this change I combined the setXxxxx logic for
PreparedStatement and CallableStatement to one static method that I
added to JdbcUtils. If you notice anything odd due to this refactoring,
please let me know.
Thomas
-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|