|
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
|