|
From: Colin S. <col...@ex...> - 2004-02-09 17:48:34
|
No, there's no temporary LOBs, you essentially create it empty, then get=20
it back for update, and write to it. For example, here's some code for=20
writing LOBs (mixes in the selection code too, have to think how this=20
would translate to Spring's LobHandler):
/**
*
* Writes a lob object into the database
*
* @param tableName - the name of the table
* @param lobColumn - the name of the lob column
* @param idColumns - String array of reference column names
* @param ids - String array of reference column values
* @param in - InputStream which holds the data
* @param lobType - the type of the lob data: BLOB|CLOB
* @throws DataAccessException if there is a database or IO exception
*/
public void writeLob(String tableName, final String lobColumn,=20
String[] idColumns,
String[] ids, final InputStream in, String lobType) throws=20
DataAccessException {
Statement stmt =3D null;
ResultSet rset =3D null;
final boolean blob =3D checkLobType(lobType);
StringBuffer upd =3D new StringBuffer("update " + tableName + " set "=
=20
+ lobColumn
+ " =3D empty_" + lobType + "() where ");
StringBuffer cmds =3D new StringBuffer("select * from " + tableName +=
=20
" where ");
for (int i =3D 0; i < idColumns.length; i++) {
cmds.append(idColumns[i] + " =3D '" + ids[i] + "'");
upd.append(idColumns[i] + " =3D '" + ids[i] + "'");
if (i !=3D idColumns.length - 1) {
cmds.append(" and ");
upd.append(" and ");
}
}
cmds.append(" for update");
//logger.debug(cmds.toString());
//logger.debug(upd.toString());
_jdbcTemplate.update(upd.toString());
final boolean[] processedRow =3D {false};
_jdbcTemplate.query(cmds.toString(), new RowCallbackHandler() {
/* (non-Javadoc)
* @see=20
org.springframework.jdbc.core.RowCallbackHandler#processRow(java.sql.Resu=
ltSet)
*/
public void processRow(ResultSet rs) throws SQLException {
=20
processedRow[0] =3D true;
_log.debug("Inserting " + lobColumn);
BLOB blob_loc =3D null;
CLOB clob_loc =3D null;
if (blob)
blob_loc =3D ((OracleResultSet) rs).getBLOB(lobColumn);
else
clob_loc =3D ((OracleResultSet) rs).getCLOB(lobColumn);
if ((blob && blob_loc !=3D null) || (!blob && clob_loc !=3D null)=
) {
//logger.debug("Lob not null");
int size =3D 0;
OutputStream os =3D null;
if (blob) {
os =3D blob_loc.getBinaryOutputStream();
size =3D blob_loc.getBufferSize();
}
else {
os =3D clob_loc.getAsciiOutputStream();
size =3D clob_loc.getBufferSize();
}
byte[] buffer =3D new byte[size];
int length =3D -1;
try {
while ((length =3D in.read(buffer)) !=3D -1) {
os.write(buffer, 0, length);
//logger.debug("Writing " + length);
}
os.close();
}
catch (IOException e) {
throw new DataAccessResourceFailureException(
"Stream IO Error during LOB access", e);
}
}
else {
_log.debug("Lob is null");
}
}
});
if (!processedRow[0])
_log.warn("select returns no records");
try {
in.close();
}
catch (IOException e) {
// I think if everything worked this far, we don't care about a=20
failure to close the stream
}
}
j=FCrgen h=F6ller [werk3AT] wrote:
>I take your word for it - as I said in another mail, I haven't seen the =
9i driver work on an 8i database myself, and frankly, I have no trust in =
the general viability of such a combo. So it'd be great if you can come u=
p with an 8i-capable OracleLobHandler! (possibly in the Spring 1.1 timefr=
ame)
>
>Maybe we can simply auto-detect the Oracle driver version through intros=
pection in a single unified OracleLobHandler implementation. AFAIK, the d=
ifference is that the 8i driver didn't have the notion of temporary LOBs;=
the Oracle BLOB and CLOB implementation classes themselves should be com=
patible. So there's a chance for some code reuse.
>
>Juergen
>
>
>-----Original Message-----
>From: spr...@li...
>[mailto:spr...@li...]On Behalf
>Of Colin Sampaleanu
>Sent: Monday, February 09, 2004 5:53 PM
>To: spr...@li...
>Subject: Re: [Springframework-developer] Ready for 1.0 RC1
>
>
>No, I have personal experience that using the 9i classes12 against an 8i=
=20
>database has weird (bad) results.
>
>As I mentioned in a subsequent message, I do have working code for the=20
>8i driver (figured out at great pain :-) ), and can produce a lobhandler=
=20
>for that. Given the fact that database migration is such a pain, a lot=20
>of people are still using 8i, so it's probably worth it for me to do it.
>
>Colin
>
>
>j=FCrgen h=F6ller [werk3AT] wrote:
>
> =20
>
>>Colin,
>>
>>The answer is in OracleLobHandler's javadoc, end of first paragraph: "D=
eveloped and tested on Oracle 9i." ;-)=20
>>
>>The Oracle 8i drivers did not have the current proprietary BLOB/CLOB AP=
I. Nevertheless, I've heard that someone has used the Oracle 9i drivers a=
gainst an 8i database with OracleLobHandler, and it did work. In any case=
, I don't see a chance to explicitly support Oracle 8i here, as we need t=
he LOB API.
>>
>>Juergen
>>
>>
>>-----Original Message-----
>>From: spr...@li...
>>[mailto:spr...@li...]On Behalf
>>Of Colin Sampaleanu
>>Sent: Monday, February 09, 2004 5:07 PM
>>To: spr...@li...
>>Subject: Re: [Springframework-developer] Ready for 1.0 RC1
>>
>>
>>Juergen,
>>
>>What Oracle JDBC driver version did you develop Oracle LobHandler with?
>>
>>I am using it with the last version of the JDK 1.2/1.3 'classes12'=20
>>zip/jar from Oracle, which works with Oracle 8. With that version, I ge=
t=20
>>the following exception:
>>
>>2004-02-09 10:56:09,655 ERROR [org.jboss.web.localhost.Engine] -----=20
>>Root Cause -----
>>java.lang.NoSuchFieldException: DURATION_SESSION
>> at java.lang.Class.getField(Class.java:911)
>> at=20
>>org.springframework.jdbc.support.lob.OracleLobHandler.<init>(OracleLobH=
andler.java:101)
>> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Met=
hod)
>> at=20
>>sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructor=
AccessorImpl.java:39)
>> at=20
>>sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCon=
structorAccessorImpl.java:27)
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
>> at java.lang.Class.newInstance0(Class.java:308)
>> at java.lang.Class.newInstance(Class.java:261)
>> at=20
>>org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:31)
>> at=20
>>org.springframework.beans.BeanWrapperImpl.<init>(BeanWrapperImpl.java:1=
50)
>> at=20
>>org.springframework.beans.factory.support.AbstractBeanFactory.createBea=
n(AbstractBeanFactory.java:570)
>> at=20
>>org.springframework.beans.factory.support.AbstractBeanFactory.getBean(A=
bstractBeanFactory.java:184)
>>
>>Note that there is a later 'classes12' zip/jar targetted at Oracle 9,=20
>>which will not work with Oracle 8.
>>
>>There is also a JDK 1.4 'ojdbc14.jar' which is good with Oracle 9 only.
>>
>>Regards,
>>Colin
>>
>>
>>
>>j=FCrgen h=F6ller [werk3AT] wrote:
>>
>>=20
>>
>> =20
>>
>>>I'm gonna commit some minor code polishing within the next couple of h=
ours; I'm gonna re-test everything I have this afternoon. I'll also updat=
e our CVS libs to Hibernate 2.1.2 and iBATIS Database Layer 1.3.1 (unfort=
unately, CGLIB 2.0 is still at RC2).
>>>
>>>Colin, Darren, It would be great if you could give the most current CV=
S head another go then. I'm gonna do the release tomorrow morning (my tim=
e, that is in less than 24 hours). Please report any urgent issues prompt=
ly. I'd also be happy if you give some of the sample apps a try (particul=
arly the new "imagedb").
>>>
>>>I'm inclined to include neither a PlatformTransactionManagerUtils nor =
a CurrentTransactionStatus class in this release, if we haven't settled o=
n how we want to proceed there. For the time being, the 4-line code snipp=
et I posted for a setCurrentTransactionRollbackOnly method works nicely w=
hen coded by hand.
>>>
>>>BTW, could someone please generate a current reference doc PDF into th=
e docs directory in CVS? The current version there is from November, and =
I still haven't set up the required libraries on my machine here...
>>>
>>>Juergen
>>>
>>>
>>>________________________________
>>>
>>>Von: spr...@li... im Auftrag =
von Colin Sampaleanu
>>>Gesendet: Mo 09.02.2004 01:15
>>>An: spr...@li...
>>>Betreff: Re: [Springframework-developer] Ready for 1.0 RC1
>>>
>>>
>>>
>>>I've been in a big crunch mode here, including working most of the
>>>weekend, so have not tested Spring functionality not related to my mai=
n
>>>app. However, for my main app, the new code from Wed/Thurs has been
>>>running with no problems (this includes multi-context use, AOP for
>>>transaction and Hibernate session wrapping, Hibernate OR support code,
>>>and small amounts of JDBC code, against Oracle).
>>>
>>>Some time later tonight I'll pull down any changes, and give that ago,
>>>also adding in the new Hibernate 2.12...
>>>
>>>
>>>Darren Davison wrote:
>>>
>>>
>>>
>>> =20
>>>
>>> =20
>>>
>>>>-----BEGIN PGP SIGNED MESSAGE-----
>>>>Hash: SHA1
>>>>
>>>>On Wednesday 04 February 2004 19:11, j=FCrgen h=F6ller [werk3AT] wrot=
e:
>>>>
>>>>
>>>>
>>>> =20
>>>>
>>>> =20
>>>>
>>>> =20
>>>>
>>>>>I'd like to encourage everybody to test the current CVS head thoroug=
hly.
>>>>>I will test our sample apps myself too, against HSQLDB and MySQL, bu=
t I'm
>>>>>primarily talking of custom applications here. Please report any
>>>>>remaining issues promptly; I intend to release RC1 this weekend.
>>>>>
>>>>>
>>>>> =20
>>>>>
>>>>> =20
>>>>>
>>>>> =20
>>>>>
>>>>I've run a couple of apps this weekend without any issues on tomcat5 =
-
>>>>they're lightweight web apps, one with JDBC access to MySQL and one w=
ith
>>>>hibernate. Both seem fine through normal usage.
>>>>
>>>>Using the autobuilds' modified jpetstore app, I tested on resin2, res=
in3,
>>>>tomcat4, tomcat5, jboss3/tomcat (all using hsqldb) with no problems. =
Jetty
>>>>4.2.17 standalone failed as usual due to not reading the tld's in the=
jar
>>>>files.
>>>>
>>>>Just for the hell of it, I ran all of the above tests on Sun JDK 1.4.=
1,
>>>>Blackdown JDK 1.3.1 and Blackdown JDK 1.4.1.
>>>>
>>>>Fairly meaningless, but interesting nonetheless, the average time tak=
en by
>>>>each app server for the 'testPurchase' test case over 5 runs each on =
my
>>>>machine (with the Sun JDK) is below.
>>>>
>>>>resin2: 10s
>>>>resin3: 30s
>>>>tomcat4: 25s
>>>>tomcat5: 12s
>>>>jboss3/tomcat: 36s (gotta love those JBoss guys)
>>>>
>>>>(testPurchase involves browsing the items, adding to cart, changing t=
he
>>>>order, logging in incorrectly, logging in correctly, changing user
>>>>registration details, completing the purchase and checking the databa=
se
>>>>tables for sane numbers)
>>>> =20
>>>> =20
>>>>
|