|
From: <Jon...@o2...> - 2004-07-08 13:25:35
|
Dear spring developers,
as my question was unanswered at the forum, I'm re-posting it here. Still
at the beginning of spring usage, thus very excited about its capabilities
and the code quality I saw so far :-)
How to flush rowsets to the database without manually doing the connection
closing, transaction stuff etc., but using these nice callbacks instead?
neither getJdbcTemplate().execute(..) nor getJdbcTemplate().update(..)
will work, as they assume me to create a java.sql.Statement resp. write
handcoded SQL update string...?
The same applies to pure metdata handling, when I just want to read infos
from Connection without having statements and the like.
To make it clear, this is how my code looks like, which I want to re-write
using callbacks:
<code>
public final class RowsetDAO
extends JdbcDaoSupport
{
...
/**
* Saves the given disconnected rowset to the database.
*
* @param rowSet rowset to save
* @throws DataAccessException runtime exception on database error
* @throws NullPointerException if given rowset is null
*/
public synchronized void saveMutableRowSet(CachedRowSet rowSet)
throws
NullPointerException,
DataAccessException
{
Connection conn;
if (rowSet==null)
{
throw new NullPointerException("Given mutable rowset to save must not
be null!");
}
conn = getConnection();
try
{
LOG.debug("Saving rowset into table : " + rowSet.getTableName() );
long startTime = System.currentTimeMillis();
rowSet.setUrl( conn.getMetaData().getURL() );
rowSet.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
rowSet.acceptChanges(conn);
conn.commit();
long endTime = System.currentTimeMillis();
LOG.debug("Executed SQL in : " + (endTime - startTime) + " ms");
}
catch (SQLException e)
{
LOG.error(e);
try
{
conn.rollback();
}
catch (SQLException e1)
{
LOG.error("Could not rollback changes", e1);
}
throw getJdbcTemplate().getExceptionTranslator().translate(
e.toString(),
"saving mutable rowset",
e
);
}
finally
{
try
{
conn.close();
}
catch (SQLException e1)
{
LOG.error("Could not close connection", e1);
}
}
}
...
</code>
Jonas
|
|
From: Thomas R. <tho...@tr...> - 2004-07-08 15:37:18
|
Jonas,
There is currently no support for RowSets. We have some code in the
sandbox that allows you to retrieve a cached rowset, but nothing for
updating. We might add this at some point since it would be fairly
simple to add - probably a new method update(RowSet rset) on
JdbcTemplate. This might go in the 1.2 release since 1.1 is pretty much
set with the 1.1 RC1 due out this weekend. What is the demand for this
support?
Thomas
Jon...@o2... wrote:
>Dear spring developers,
>
>as my question was unanswered at the forum, I'm re-posting it here. Still
>at the beginning of spring usage, thus very excited about its capabilities
>and the code quality I saw so far :-)
>
>How to flush rowsets to the database without manually doing the connection
>closing, transaction stuff etc., but using these nice callbacks instead?
>
>neither getJdbcTemplate().execute(..) nor getJdbcTemplate().update(..)
>will work, as they assume me to create a java.sql.Statement resp. write
>handcoded SQL update string...?
>
>The same applies to pure metdata handling, when I just want to read infos
>from Connection without having statements and the like.
>
>To make it clear, this is how my code looks like, which I want to re-write
>using callbacks:
>
><code>
>
>public final class RowsetDAO
> extends JdbcDaoSupport
>{
>
>...
>
>/**
> * Saves the given disconnected rowset to the database.
> *
> * @param rowSet rowset to save
> * @throws DataAccessException runtime exception on database error
> * @throws NullPointerException if given rowset is null
> */
>public synchronized void saveMutableRowSet(CachedRowSet rowSet)
> throws
> NullPointerException,
> DataAccessException
>{
> Connection conn;
>
> if (rowSet==null)
> {
> throw new NullPointerException("Given mutable rowset to save must not
>be null!");
> }
>
> conn = getConnection();
>
> try
> {
> LOG.debug("Saving rowset into table : " + rowSet.getTableName() );
> long startTime = System.currentTimeMillis();
>
> rowSet.setUrl( conn.getMetaData().getURL() );
> rowSet.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
> rowSet.acceptChanges(conn);
> conn.commit();
>
> long endTime = System.currentTimeMillis();
> LOG.debug("Executed SQL in : " + (endTime - startTime) + " ms");
> }
> catch (SQLException e)
> {
> LOG.error(e);
> try
> {
> conn.rollback();
> }
> catch (SQLException e1)
> {
> LOG.error("Could not rollback changes", e1);
> }
> throw getJdbcTemplate().getExceptionTranslator().translate(
> e.toString(),
> "saving mutable rowset",
> e
> );
> }
> finally
> {
> try
> {
> conn.close();
> }
> catch (SQLException e1)
> {
> LOG.error("Could not close connection", e1);
> }
> }
>}
>
>...
></code>
>
>Jonas
>
>
>
>-------------------------------------------------------
>This SF.Net email sponsored by Black Hat Briefings & Training.
>Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
>digital self defense, top technical experts, no vendor pitches,
>unmatched networking opportunities. Visit www.blackhat.com
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
>
|
|
From: Danilo L. R. <da...@fl...> - 2004-07-30 00:40:28
|
Thomas Risberg wrote: > We have some code in the sandbox that allows you to retrieve a cached > rowset ... Will the queryForRowSet included on Spring 1.1 ? I think this is usefull and easy to implement. Are there any reason to not include it ? Danilo. |
|
From: Thomas R. <tho...@tr...> - 2004-08-06 13:21:55
|
Danilo, I have the basic functionality done and it's just a matter of fixing up the JavaDoc and documentation. This can hopefully be done before 1.1 final. If not it will be part of 1.2. I will probably add support for an updatable RowSet in 1.2. Thomas Danilo Luiz Rheinheimer wrote: > Thomas Risberg wrote: > >> We have some code in the sandbox that allows you to retrieve a cached >> rowset ... > > > Will the queryForRowSet included on Spring 1.1 ? > I think this is usefull and easy to implement. > Are there any reason to not include it ? > > Danilo. > > > > ------------------------------------------------------- > This SF.Net email is sponsored by OSTG. Have you noticed the changes on > Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, > one more big change to announce. We are now OSTG- Open Source Technology > Group. Come see the changes on the new OSTG site. www.ostg.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > > |