Author: jflesch
Date: 2008-02-16 04:51:48 +0000 (Sat, 16 Feb 2008)
New Revision: 17976
Modified:
trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java
trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java
trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java
trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java
trunk/apps/Thaw/src/thaw/plugins/index/BlackList.java
trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
trunk/apps/Thaw/src/thaw/plugins/index/File.java
trunk/apps/Thaw/src/thaw/plugins/index/Index.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexRoot.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
trunk/apps/Thaw/src/thaw/plugins/index/Link.java
trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
trunk/apps/Thaw/src/thaw/plugins/transferLogs/Transfer.java
trunk/apps/Thaw/src/thaw/plugins/transferLogs/TransferTable.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListDownloader.java
trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
Log:
Close all the sql statement cleanly
Modified: trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -2,7 +2,6 @@
import java.sql.Connection;
import java.sql.DriverManager;
-import java.sql.ResultSet;
import java.sql.Statement;
import thaw.core.Core;
import thaw.core.I18n;
@@ -102,14 +101,12 @@
}
- public ResultSet executeQuery(final String query) throws
java.sql.SQLException {
- ResultSet results;
-
+ public void executeQuery(final String query) throws
java.sql.SQLException {
final Statement stmt = connection.createStatement();
- results = stmt.executeQuery(query);
-
- return results;
+ stmt.execute(query);
+
+ stmt.close();
}
public javax.swing.ImageIcon getIcon() {
Modified: trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -54,7 +54,8 @@
st.execute();
}
-
+
+ st.close();
}
@@ -86,6 +87,7 @@
rebuild(newParentsVector, set.getInt("id"));
}
+ st.close();
/* rebuild all the indexes in this folder */
@@ -100,6 +102,7 @@
rebuildIndex(newParentsVector,
set.getInt("id"));
}
+ st.close();
/* rebuild this folder */
@@ -124,6 +127,7 @@
st.execute();
}
+ st.close();
}
/**
@@ -138,6 +142,8 @@
st = db.getConnection().prepareStatement("DELETE FROM
folderParents");
st.execute();
+
+ st.close();
rebuild(new Vector(), -1);
Modified: trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/SqlConsole.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -246,22 +246,26 @@
result = st.getResultSet();
else {
addToConsole("Ok\n");
+ st.close();
return;
}
} else {
thaw.plugins.index.DatabaseManager.dropTables(hsqldb);
thaw.plugins.TransferLogs.dropTables(hsqldb);
addToConsole("Ok\n");
+ st.close();
return;
}
if(result == null) {
addToConsole("(null)\n");
+ st.close();
return;
}
if(result.getFetchSize() == 0) {
addToConsole("(done)\n");
+ st.close();
return;
}
@@ -317,6 +321,8 @@
}
addToConsole("\n");
}
+
+ st.close();
}
} catch(final java.sql.SQLException e) {
Modified: trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/TransferLogs.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -185,8 +185,12 @@
"WHERE
LOWER(key) LIKE ? AND isSuccess = TRUE");
st.setString(1,
FreenetURIHelper.getComparablePart(key)+"%");
ResultSet set = st.executeQuery();
- return set.next();
+
+ boolean b = set.next();
+
+ st.close();
+ return b;
}
} catch(SQLException e) {
Logger.error(new TransferLogs(), "Unable to know if a
key is dup in the event because : "+e.toString());
@@ -301,10 +305,10 @@
try {
st =
db.getConnection().prepareStatement("INSERT INTO transferLogs "+
-
"(dateStart, dateEnd, transferType,"+
-
" key, filename, size, isDup, isSuccess) "+
-
" VALUES "+
-
"(?, ?, 0, ?, ?, NULL, ?, TRUE)");
+ "(dateStart, dateEnd,
transferType,"+
+ " key, filename, size,
isDup, isSuccess) "+
+ " VALUES "+
+ "(?, ?, 0, ?, ?, NULL, ?, TRUE)");
} catch(SQLException e) {
Logger.error(this, "Error while
preparing to import keys : "+e.toString());
}
@@ -332,8 +336,14 @@
}
}
- in.close();
+ try {
+ st.close();
+ } catch(SQLException e) {
+ /* \_o< */
+ }
+ in.close();
+
} catch(java.io.FileNotFoundException e) {
Logger.error(this, "(1) Unable to import keys
because: "+e.toString());
} catch(java.io.IOException e) {
@@ -372,6 +382,8 @@
while(set.next()) {
out.write((set.getString("key")+"\n").getBytes("UTF-8"));
}
+
+ st.close();
}
out.close();
Modified: trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -228,6 +228,8 @@
up.setNull(3, Types.TIMESTAMP);
up.setInt(4, id);
up.execute();
+
+ up.close();
}
else
{
@@ -236,7 +238,11 @@
in.setTimestamp(2, new
java.sql.Timestamp(dateOfTheKey.getTime()));
in.setInt(3, identity.getId());
in.execute();
+
+ in.close();
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while adding a key to the
list of trust list");
Modified: trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/AutoRefresh.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -104,8 +104,10 @@
results = st.executeQuery();
- if (results == null || !results.next())
+ if (results == null || !results.next()) {
+ st.close();
return -1;
+ }
ret = results.getInt("id");
@@ -131,6 +133,8 @@
browserPanel.getIndexTree().redraw();
}
+
+ st.close();
return ret;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/BlackList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/BlackList.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/BlackList.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -148,6 +148,8 @@
res.getString("name"),
res.getString("publicKey")));
}
+
+ st.close();
}
} catch(SQLException e) {
@@ -242,10 +244,16 @@
ResultSet res = st.executeQuery();
- if (!res.next())
+ if (!res.next()) {
+ st.close();
return -1;
+ }
- return res.getInt("id");
+ int i = res.getInt("id");
+
+ st.close();
+
+ return i;
}
} catch(SQLException e) {
Logger.error(new BlackList(), "Error while checking if
a given key is blacklisted : "+ e.toString());
@@ -286,6 +294,7 @@
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(new BlackList(), "Error while adding an
entry to the blacklist : "+e.toString());
@@ -326,6 +335,8 @@
st =
db.getConnection().prepareStatement("DELETE FROM indexBlackList WHERE id = ?");
st.setInt(1, id);
st.execute();
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(new BlackList(), "Error while removing an
entry from the blacklist : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Comment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Comment.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -241,6 +241,7 @@
st.setInt(1, rev);
st.setInt(2, index.getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to un-blacklist comment
because: "+e.toString());
@@ -255,6 +256,7 @@
st.setInt(1, rev);
st.setInt(2, index.getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to blacklist comment
because: "+e.toString());
@@ -277,7 +279,9 @@
ResultSet set = st.executeQuery();
- return set.next();
+ boolean b= set.next();
+ st.close();
+ return b;
}
} catch(SQLException e) {
Logger.error(db, "thaw.plugins.index.Comment : Error
while checking if the message is in the blacklist :"+e.toString());
@@ -709,6 +713,8 @@
st.execute();
+ st.close();
+
return true;
}
} catch(SQLException e) {
@@ -755,7 +761,9 @@
ResultSet set = st.executeQuery();
- return (set.next());
+ boolean b = (set.next());
+ st.close();
+ return b;
} catch(SQLException e) {
Logger.error(this, "Unable to check if the comment is
already in the bdd, because: "+e.toString());
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -216,6 +216,11 @@
}
}
}
+
+ st.close();
+ countSt.close();
+ countBisSt.close();
+ deleteSt.close();
}
} catch(SQLException e) {
Logger.error(new DatabaseManager(), "Can't cleanup the
unused categories because: "+e.toString());
@@ -256,6 +261,10 @@
}
}
}
+
+ selectLinks.close();
+ selectIndex.close();
+ updateLink.close();
}
} catch(SQLException e) {
Logger.error(new DatabaseManager(), "Can't cleanup the
unused categories because: "+e.toString());
@@ -457,18 +466,24 @@
*/
public static int getNextId(Hsqldb db, String table) {
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st =
db.getConnection().prepareStatement("select id+1 from "+
- table +
- "
order by id desc limit 1");
- ResultSet res = st.executeQuery();
+ st =
db.getConnection().prepareStatement("select id+1 from "+
+ table +
+ " order by id desc limit 1");
+ ResultSet res = st.executeQuery();
+ int r;
- if (res.next())
- return res.getInt(1);
- else
- return 1;
+ if (res.next()) {
+ r = res.getInt(1);
+ } else
+ r = 1;
+ st.close();
+
+ return r;
+ }
} catch(SQLException e) {
Logger.error(new DatabaseManager(), "Unable to
get next id because: "+e.toString());
}
@@ -481,18 +496,22 @@
int nmb;
try {
- final Connection c = db.getConnection();
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ final Connection c = db.getConnection();
+ PreparedStatement st;
- st = c.prepareStatement("SELECT count(id) FROM
indexes");
- st.execute();
+ st = c.prepareStatement("SELECT count(id) FROM
indexes");
+ st.execute();
- try {
- final ResultSet answer = st.getResultSet();
- answer.next();
- nmb = answer.getInt(1);
- } catch(final SQLException e) {
- nmb = 0;
+ try {
+ final ResultSet answer =
st.getResultSet();
+ answer.next();
+ nmb = answer.getInt(1);
+ } catch(final SQLException e) {
+ nmb = 0;
+ }
+
+ st.close();
}
} catch(final SQLException e) {
@@ -836,12 +855,12 @@
/**
* used by convertDatabase_1_to_2()
*/
- public static boolean insertChildIn(Hsqldb db, int folderId) throws
SQLException {
+ private static boolean insertChildIn(Hsqldb db, int folderId) throws
SQLException {
java.util.Vector results;
int i = 0, j;
Logger.notice(new DatabaseManager(), "Expanding folder
"+Integer.toString(folderId));
-
+
PreparedStatement st;
st = db.getConnection().prepareStatement("SELECT id FROM
indexFolders WHERE "+
@@ -856,6 +875,8 @@
while(set.next()) {
results.add(new Integer(set.getInt("id")));
}
+
+ st.close();
for (java.util.Iterator it = results.iterator();
it.hasNext();) {
@@ -881,13 +902,17 @@
j++;
childFolders.add(new
Integer(rs.getInt("folderId")));
}
+
+ st.close();
+
+ st = db.getConnection().prepareStatement("INSERT INTO
folderParents (folderId, parentId) "+
+ "VALUES (?, ?)");
for (Iterator ite = childFolders.iterator();
ite.hasNext();) {
Integer a = (Integer)ite.next();
- st =
db.getConnection().prepareStatement("INSERT INTO folderParents (folderId,
parentId) "+
-
"VALUES (?, ?)");
+
st.setInt(1, a.intValue());
if (folderId < 0)
st.setNull(2, Types.INTEGER);
@@ -896,9 +921,10 @@
st.execute();
}
+
+ st.close();
-
st = db.getConnection().prepareStatement("SELECT
indexId FROM indexParents WHERE folderId = ?");
st.setInt(1, nextId);
@@ -910,17 +936,20 @@
j++;
childIndexes.add(new
Integer(rs.getInt("indexId")));
}
+
+ st.close();
if (j == 0) {
Logger.warning(new DatabaseManager(), "empty
folder (id = "+Integer.toString(nextId)+") ?");
}
+
+ st = db.getConnection().prepareStatement("INSERT INTO
indexParents (indexId, folderId) "+
+
"VALUES (?, ?)");
for (Iterator ite = childIndexes.iterator();
ite.hasNext();) {
Integer a = (Integer)ite.next();
- st =
db.getConnection().prepareStatement("INSERT INTO indexParents (indexId,
folderId) "+
-
"VALUES (?, ?)");
st.setInt(1, a.intValue());
if (folderId < 0)
st.setNull(2, Types.INTEGER);
@@ -929,6 +958,8 @@
st.execute();
}
+
+ st.close();
}
@@ -1045,6 +1076,9 @@
subSt.execute();
}
}
+
+ st.close();
+ subSt.close();
} catch(SQLException e) {
Logger.error(new DatabaseManager(), "Error while
converting SSK into USK : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -109,27 +109,31 @@
this.id = id;
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("SELECT
filename, publicKey, localPath, mime, size, indexParent "+
- " FROM files
WHERE id = ? LIMIT 1");
+ st =
db.getConnection().prepareStatement("SELECT filename, publicKey, localPath,
mime, size, indexParent "+
+ " FROM files WHERE id = ? LIMIT 1");
- st.setInt(1, id);
+ st.setInt(1, id);
- ResultSet rs = st.executeQuery();
+ ResultSet rs = st.executeQuery();
- if (rs.next()) {
- String lp;
+ if (rs.next()) {
+ String lp;
- filename = rs.getString("filename");
- publicKey = rs.getString("publicKey");
- lp = rs.getString("localPath");
- localPath = (lp == null ? null : new
java.io.File(lp));
- mime = rs.getString("mime");
- size = rs.getLong("size");
- parentId = rs.getInt("indexParent");
- } else {
- Logger.error(this, "File
'"+Integer.toString(id)+"' not found");
+ filename = rs.getString("filename");
+ publicKey = rs.getString("publicKey");
+ lp = rs.getString("localPath");
+ localPath = (lp == null ? null : new
java.io.File(lp));
+ mime = rs.getString("mime");
+ size = rs.getLong("size");
+ parentId = rs.getInt("indexParent");
+ } else {
+ Logger.error(this, "File
'"+Integer.toString(id)+"' not found");
+ }
+
+ st.close();
}
} catch(SQLException e) {
@@ -143,13 +147,17 @@
public void setParent(int parent_id) {
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("UPDATE files
SET indexParent = ? "+
- "WHERE id =
?");
- st.setInt(1, parent_id);
- st.setInt(2, id);
- st.execute();
+ st =
db.getConnection().prepareStatement("UPDATE files SET indexParent = ? "+
+ "WHERE id = ?");
+ st.setInt(1, parent_id);
+ st.setInt(2, id);
+ st.execute();
+
+ st.close();
+ }
} catch(SQLException e) {
Logger.error(this, "Unable to set parent:
"+e.toString());
}
@@ -213,14 +221,18 @@
this.publicKey = FreenetURIHelper.cleanURI(publicKey);
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("UPDATE files
SET publicKey = ? "+
- "WHERE id =
?");
+ st =
db.getConnection().prepareStatement("UPDATE files SET publicKey = ? "+
+ "WHERE id = ?");
- st.setString(1, publicKey);
- st.setInt(2, id);
- st.execute();
+ st.setString(1, publicKey);
+ st.setInt(2, id);
+ st.execute();
+
+ st.close();
+ }
} catch(SQLException e) {
Logger.error(this, "Unable to set publicKey:
"+e.toString());
}
@@ -229,14 +241,18 @@
public void setSize(final long size) {
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("UPDATE files
SET size = ? "+
- "WHERE id =
?");
+ st =
db.getConnection().prepareStatement("UPDATE files SET size = ? "+
+ "WHERE id = ?");
- st.setLong(1, size);
- st.setInt(2, id);
- st.execute();
+ st.setLong(1, size);
+ st.setInt(2, id);
+ st.execute();
+
+ st.close();
+ }
} catch(SQLException e) {
Logger.error(this, "Unable to set publicKey:
"+e.toString());
}
@@ -343,20 +359,26 @@
public int getParentId() {
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("SELECT
indexParent FROM files "+
- "WHERE id = ?
LIMIT 1");
- st.setInt(1, id);
+ st =
db.getConnection().prepareStatement("SELECT indexParent FROM files "+
+ "WHERE id = ? LIMIT 1");
+ st.setInt(1, id);
- ResultSet rs = st.executeQuery();
+ ResultSet rs = st.executeQuery();
- if (rs.next()) {
- return rs.getInt("indexParent");
- } else {
- Logger.error(this, "File id not found:
"+Integer.toString(id));
+ if (rs.next()) {
+ int i = rs.getInt("indexParent");
+ st.close();
+ return i;
+ } else {
+ Logger.error(this, "File id not found:
"+Integer.toString(id));
+ }
+
+ st.close();
+
}
-
} catch(SQLException e) {
Logger.error(this, "Unable to get parent id because:
"+e.toString());
}
@@ -373,11 +395,14 @@
public void delete() {
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- st = db.getConnection().prepareStatement("DELETE FROM
files WHERE id = ?");
- st.setInt(1, id);
- st.execute();
+ st =
db.getConnection().prepareStatement("DELETE FROM files WHERE id = ?");
+ st.setInt(1, id);
+ st.execute();
+ st.close();
+ }
} catch(SQLException e) {
Logger.error(this, "Unable to remove file because:
"+e.toString());
}
@@ -402,49 +427,57 @@
* a file in the database
*/
public static boolean resumeTransfers(FCPQueueManager queue, Hsqldb db)
{
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- try {
- st = db.getConnection().prepareStatement("SELECT a.id,
a.filename, a.publicKey, "+
- "a.localPath,
a.mime, a.size, a.indexParent "+
- "FROM files AS
a JOIN indexes AS b ON (a.indexParent = b.id)"+
- "WHERE
b.privateKey IS NOT NULL AND a.filename LIKE ?");
- } catch(SQLException e) {
- Logger.error("thaw.plugin.index.File", "Error while
sending query to the database : "+e.toString());
- return false;
- }
+ try {
+ st =
db.getConnection().prepareStatement("SELECT a.id, a.filename, a.publicKey, "+
+ "a.localPath, a.mime, a.size,
a.indexParent "+
+ "FROM files AS a JOIN indexes
AS b ON (a.indexParent = b.id)"+
+ "WHERE b.privateKey IS NOT NULL AND a.filename
LIKE ?");
+ } catch(SQLException e) {
+ Logger.error("thaw.plugin.index.File", "Error
while sending query to the database : "+e.toString());
+ return false;
+ }
- for (Iterator it = queue.getRunningQueue().iterator();
- it.hasNext();) {
- FCPTransferQuery tq = (FCPTransferQuery)it.next();
+ for (Iterator it = queue.getRunningQueue().iterator();
+ it.hasNext();) {
+ FCPTransferQuery tq =
(FCPTransferQuery)it.next();
- if (tq instanceof FCPClientPut) {
- try {
- st.setString(1, tq.getFilename());
+ if (tq instanceof FCPClientPut) {
+ try {
+ st.setString(1,
tq.getFilename());
- ResultSet rs = st.executeQuery();
+ ResultSet rs =
st.executeQuery();
- while(rs.next()) {
- File file = new File(db,
-
rs.getInt("id"),
-
rs.getString("filename"),
-
rs.getString("publicKey"),
-
rs.getString("localPath") != null ? new java.io.File(rs.getString("localPath"))
: null,
-
rs.getString("mime"),
-
rs.getLong("size"),
-
rs.getInt("indexParent"));
+ while(rs.next()) {
+ File file = new File(db,
+
rs.getInt("id"),
+
rs.getString("filename"),
+
rs.getString("publicKey"),
+
rs.getString("localPath") != null ? new java.io.File(rs.getString("localPath"))
: null,
+
rs.getString("mime"),
+
rs.getLong("size"),
+
rs.getInt("indexParent"));
-
((Observable)tq).addObserver(file);
+
((Observable)tq).addObserver(file);
- if (tq.getFileKey() != null)
-
file.update(((Observable)tq), null);
+ if (tq.getFileKey() !=
null)
+
file.update(((Observable)tq), null);
+ }
+
+ } catch(SQLException e) {
+
Logger.warning("thaw.plugins.index.File", "Error while resuming key
computations : "+e.toString());
+ return false;
}
-
- } catch(SQLException e) {
-
Logger.warning("thaw.plugins.index.File", "Error while resuming key
computations : "+e.toString());
- return false;
}
}
+
+ try {
+ st.close();
+ } catch(SQLException e) {
+ /* \_o< */
+ }
}
return true;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -181,6 +181,8 @@
st.setInt(2, id);
st.execute();
+
+ st.close();
if (parentId >= 0) {
@@ -191,6 +193,7 @@
st.setInt(2, parentId);
st.execute();
+ st.close();
} /* else this parent has no parent ... :) */
st =
db.getConnection().prepareStatement("INSERT INTO indexParents (indexId,
folderId) "+
@@ -203,6 +206,8 @@
st.setNull(2, Types.INTEGER);
st.execute();
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while changing parent
: "+e.toString());
}
@@ -227,6 +232,7 @@
"WHERE
indexId = ?");
st.setInt(1, id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while removing the
index: "+e.toString());
@@ -271,6 +277,8 @@
st.setString(1, name);
st.setInt(2, id);
st.execute();
+
+ st.close();
} catch(final SQLException e) {
Logger.error(this, "Unable to rename the index
in '"+name+"', because: "+e.toString());
@@ -297,6 +305,8 @@
"WHERE
indexId = ?");
st.setInt(1, id);
st.execute();
+
+ st.close();
Logger.notice(this, "DELETING AN INDEX");
@@ -304,6 +314,8 @@
st =
db.getConnection().prepareStatement("DELETE FROM indexes WHERE id = ?");
st.setInt(1, id);
st.execute();
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to delete the index
because : "+e.toString());
}
@@ -333,6 +345,8 @@
st.setInt(1, getId());
st.execute();
+
+ st.close();
} catch(final SQLException e) {
Logger.error(this, "Unable to purge da list !
Exception: "+e.toString());
}
@@ -358,6 +372,8 @@
st = c.prepareStatement("DELETE FROM
files WHERE indexParent = ? AND dontDelete = FALSE");
st.setInt(1, getId());
st.execute();
+
+ st.close();
} catch(final SQLException e) {
Logger.error(this, "Unable to purge da list !
Exception: "+e.toString());
}
@@ -397,9 +413,11 @@
hasChanged = set.getBoolean("newRev");
newComment =
set.getBoolean("newComment");
date = set.getDate("insertionDate");
+ st.close();
return true;
} else {
Logger.error(this, "Unable to find
index "+Integer.toString(id)+" in the database ?!");
+ st.close();
return false;
}
} catch (final SQLException e) {
@@ -475,6 +493,7 @@
st.setBoolean(1, val);
st.setInt(2, id);
st.execute();
+ st.close();
}
publishPrivateKey = val;
@@ -513,6 +532,7 @@
st.setInt(3, id);
st.execute();
+ st.close();
/* we update also all the links in the index
with the private key */
@@ -538,6 +558,9 @@
updateLinkSt.execute();
}
}
+
+ st.close();
+ updateLinkSt.close();
} catch(SQLException e) {
Logger.error(this, "Unable to set public Key
because: "+e.toString());
@@ -568,6 +591,7 @@
st.setInt(2, indexId);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(new Index(), "Unable to set
private Key because: "+e.toString());
}
@@ -591,9 +615,11 @@
if (set.next()) {
realName =
set.getString("originalName");
+ st.close();
return realName;
} else {
Logger.error(this, "Unable to get index
real name: not found");
+ st.close();
return null;
}
} catch(SQLException e) {
@@ -651,6 +677,8 @@
ResultSet set = st.executeQuery();
if (!set.next()) {
+ st.close();
+
/* no link ?! we will warn the
user */
int ret =
@@ -667,7 +695,8 @@
|| ret ==
JOptionPane.NO_OPTION) {
return 0;
}
- }
+ } else
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while
checking the link number before insertion : "+e.toString());
@@ -757,18 +786,23 @@
try {
- PreparedStatement st;
+ synchronized(db.dbLock) {
+ PreparedStatement st;
- String query = "UPDATE # SET dontDelete = FALSE
WHERE indexParent = ?";
+ String query = "UPDATE # SET dontDelete
= FALSE WHERE indexParent = ?";
- st =
db.getConnection().prepareStatement(query.replaceFirst("#", "files"));
- st.setInt(1, id);
- st.execute();
+ st =
db.getConnection().prepareStatement(query.replaceFirst("#", "files"));
+ st.setInt(1, id);
+ st.execute();
+ st.close();
- st =
db.getConnection().prepareStatement(query.replaceFirst("#", "links"));
- st.setInt(1, id);
- st.execute();
+ st =
db.getConnection().prepareStatement(query.replaceFirst("#", "links"));
+ st.setInt(1, id);
+ st.execute();
+ st.close();
+ }
+
} catch(SQLException e) {
Logger.error(this, "Error while reseting
dontDelete flags: "+e.toString());
}
@@ -1008,6 +1042,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while
updating the insertion date : "+e.toString());
@@ -1102,6 +1137,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while updating index
insertion date: "+e.toString());
@@ -1128,6 +1164,8 @@
while (set.next()) {
v.add(new Integer(set.getInt("rev")));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to get comment black list
because: "+e.toString());
@@ -1147,7 +1185,7 @@
st.setInt(2, id);
st.execute();
-
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while adding element to the
blackList: "+e.toString());
@@ -1197,6 +1235,8 @@
localPath, mime, size, id, this);
files.add(file);
}
+
+ st.close();
return (File[])files.toArray(new File[0]);
@@ -1229,6 +1269,7 @@
st.setInt(5, id);
st.execute();
+ st.close();
return true;
}
@@ -1274,6 +1315,8 @@
this);
links.add(l);
}
+
+ st.close();
return (Link[])links.toArray(new Link[0]);
@@ -1329,6 +1372,7 @@
st.setNull(5, Types.INTEGER);
st.execute();
+ st.close();
return true;
}
@@ -1362,9 +1406,12 @@
String key =
FreenetURIHelper.changeUSKRevision(oKey,
set.getInt("revision"),
0);
+ st.close();
return key;
}
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Can't find the latest key
of a link because : "+e.toString());
}
@@ -1415,16 +1462,23 @@
String pubKey =
res.getString("publicKey").replaceAll(".xml", ".frdx");
if
(FreenetURIHelper.compareKeys(pubKey, key)) {
- return res.getInt("id");
+ int r =
res.getInt("id");
+ st.close();
+ return r;
}
}
+ st.close();
return -1;
} else {
- if (!res.next())
+ if (!res.next()) {
+ st.close();
return -1;
-
- return res.getInt("id");
+ }
+
+ int r = res.getInt("id");
+ st.close();
+ return r;
}
} catch(final SQLException e) {
@@ -1487,8 +1541,12 @@
st.setBoolean(1, flag);
st.setInt(2, id);
- if (st.executeUpdate() > 0)
+ if (st.executeUpdate() > 0) {
+ st.close();
return true;
+ }
+
+ st.close();
return false;
} catch(SQLException e) {
Logger.error(this, "Unable to change
'hasChanged' flag because: "+e.toString());
@@ -1514,8 +1572,12 @@
st.setBoolean(1, flag);
st.setInt(2, id);
- if (st.executeUpdate() > 0)
+ if (st.executeUpdate() > 0) {
+ st.close();
return true;
+ }
+
+ st.close();
return false;
} catch(SQLException e) {
Logger.error(this, "Unable to change
'newComment' flag because: "+e.toString());
@@ -1565,10 +1627,16 @@
st.setInt(1, id);
ResultSet set = st.executeQuery();
+
+ String r = null;
- if (set != null && set.next())
- return set.getString("publicKey");
-
+ if (set != null && set.next()) {
+ r = set.getString("publicKey");
+ }
+
+ st.close();
+
+ return r;
}
} catch(SQLException e) {
Logger.error(this, "Unable to get comment public key
because : "+e.toString());
@@ -1590,10 +1658,15 @@
st.setInt(1, id);
ResultSet set = st.executeQuery();
+
+ String r = null;
if (set != null && set.next())
- return set.getString("privateKey");
+ r = set.getString("privateKey");
+
+ st.close();
+ return r;
}
} catch(SQLException e) {
Logger.error(this, "Unable to get comment public key
because : "+e.toString());
@@ -1614,14 +1687,17 @@
st =
db.getConnection().prepareStatement("DELETE FROM indexCommentBlackList WHERE
indexId = ?");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM indexComments WHERE indexId =
?");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM indexCommentKeys WHERE indexId
= ?");
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
@@ -1657,6 +1733,7 @@
st.setInt(3, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to set comment keys, because
: "+e.toString());
@@ -1752,6 +1829,8 @@
set.getInt("rev"),
Identity.getIdentity(db, set.getInt("authorId")),
set.getString("text")));
+
+ st.close();
if (comments.size() == 0)
Logger.notice(this, "No comment for
this index");
@@ -1792,6 +1871,7 @@
if (set.next())
nmb = set.getInt(1);
+ st.close();
return nmb;
}
@@ -1826,6 +1906,7 @@
if (!res.next()) {
Logger.error(this, "Can't find the
index "+Integer.toString(id)+"in the db! The tree is probably broken !");
+ st.close();
return null;
}
@@ -1839,6 +1920,8 @@
i++;
} while(res.next());
+
+ st.close();
int nmb_folders = i+1; /* i + root */
@@ -1922,15 +2005,21 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return -1;
+ }
Object o = set.getObject("categoryId");
-
- if (o == null)
+
+ if (o == null) {
+ st.close();
return -1;
+ }
- return set.getInt("categoryId");
+ int i = set.getInt("categoryId");
+ st.close();
+ return i;
}
} catch(SQLException e) {
Logger.error(this,
@@ -1953,10 +2042,14 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
- return set.getString("name").toLowerCase();
+ String r = set.getString("name").toLowerCase();
+ st.close();
+ return r;
}
} catch(SQLException e) {
Logger.error(this,
@@ -2019,6 +2112,8 @@
set = st.executeQuery();
if (set.next())
catId = set.getInt("id")+1;
+
+ st.close();
/* insertion */
st =
db.getConnection().prepareStatement("INSERT INTO categories "+
@@ -2026,12 +2121,14 @@
st.setInt(1, catId);
st.setString(2, cat);
st.execute();
+ st.close();
return catId;
} else {
-
/* else we return the existing id */
- return set.getInt("id");
+ int i = set.getInt("id");
+ st.close();
+ return i;
}
}
} catch(SQLException e) {
@@ -2067,7 +2164,7 @@
st.setInt(1, catId);
st.setInt(2, id);
st.execute();
-
+ st.close();
}
} catch(SQLException e) {
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -325,6 +325,8 @@
while(set.next()) {
v.add(set.getString("name"));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't get index categories list
because : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexFolder.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -157,6 +157,7 @@
addToVector(v, st.executeQuery(), true);
+ st.close();
if (id >= 0) {
st =
db.getConnection().prepareStatement("SELECT id, positionInTree, "+
@@ -180,6 +181,8 @@
}
addToVector(v, st.executeQuery(), false);
+
+ st.close();
} catch (SQLException e) {
Logger.error(this, "Unable to load child list
because: "+e.toString());
@@ -265,8 +268,13 @@
ResultSet set = st.executeQuery();
- if (set.next())
- return set.getInt("positionInTree");
+ if (set.next()) {
+ int r = set.getInt("positionInTree");
+ st.close();
+ return r;
+ }
+
+ st.close();
return -1;
@@ -327,6 +335,7 @@
st.setInt(1, id);
st.setInt(2, index);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE indexFolders "+
"SET positionInTree = positionInTree + 1 "+
@@ -334,6 +343,7 @@
st.setInt(1, id);
st.setInt(2, index);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE "+
((child instanceof IndexFolder) ? "indexFolders" : "indexes")+
@@ -343,18 +353,21 @@
st.setInt(2, index);
st.setInt(3,
((IndexTreeNode)child).getId());
st.execute();
+ st.close();
} else {
st =
db.getConnection().prepareStatement("UPDATE indexes "+
"SET positionInTree = positionInTree + 1 "+
"WHERE parent IS NULL AND positionInTree >= ?");
st.setInt(1, index);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE indexFolders "+
"SET positionInTree = positionInTree + 1 "+
"WHERE parent IS NULL AND positionInTree >= ?");
st.setInt(1, index);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE "+
((child instanceof IndexFolder) ? "indexFolders" : "indexes")+
@@ -364,7 +377,7 @@
st.setInt(2, index);
st.setInt(3,
((IndexTreeNode)child).getId());
st.execute();
-
+ st.close();
}
@@ -412,6 +425,7 @@
st.setInt(1, id);
st.setInt(2, pos);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE indexFolders "+
"SET positionInTree = positionInTree - 1 "+
@@ -419,6 +433,7 @@
st.setInt(1, id);
st.setInt(2, pos);
st.execute();
+ st.close();
} else {
st =
db.getConnection().prepareStatement("UPDATE indexes "+
@@ -426,12 +441,14 @@
"WHERE parent IS NULL AND positionInTree > ?");
st.setInt(1, pos);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE indexFolders "+
"SET positionInTree = positionInTree - 1 "+
"WHERE parent IS NULL AND positionInTree > ?");
st.setInt(1, pos);
st.execute();
+ st.close();
}
} catch(SQLException e) {
@@ -467,8 +484,11 @@
index = n instanceof Index;
} else {
Logger.error(this, "Node not found !");
+ st.close();
return;
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to remove node
"+Integer.toString(node.getId())+" because: "+
@@ -511,6 +531,7 @@
st.setInt(1, id);
st.setInt(2, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM folderParents "+
"WHERE
( ((folderId IN "+
@@ -525,8 +546,8 @@
st.setInt(1, id);
st.setInt(2, id);
st.setInt(3, id);
-
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while removing from
parent: "+e.toString());
@@ -581,6 +602,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
/* put all its child folders into its new
parents */
@@ -600,6 +622,7 @@
st.setInt(1, id);
st.setInt(2, parentId);
st.execute();
+ st.close();
} /* else no parent of the parent */
@@ -613,6 +636,7 @@
st.setNull(1, Types.INTEGER);
st.setInt(2, id);
st.execute();
+ st.close();
/* we put itself in the parents of its parent */
if (parentId >= 0) {
@@ -622,6 +646,7 @@
st.setInt(1, id);
st.setInt(2, parentId);
st.execute();
+ st.close();
}
/* and then in its parent */
@@ -633,6 +658,7 @@
else
st.setNull(2, Types.INTEGER);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("INSERT INTO indexParents (indexId,
folderId) "+
@@ -642,6 +668,7 @@
"
WHERE folderParents.folderId = ?");
st.setInt(1, id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to change parent
because: "+e.toString());
}
@@ -680,6 +707,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while renaming the
folder: "+e.toString());
}
@@ -703,6 +731,8 @@
while(set.next()) {
children.add(new Integer(set.getInt("id")));
}
+
+ st.close();
st = db.getConnection().prepareStatement("DELETE from
indexfolders where id = ?");
@@ -713,6 +743,8 @@
st.setInt(1, nextId.intValue());
st.execute();
}
+
+ st.close();
}
@@ -745,6 +777,7 @@
"
WHERE indexParents.folderId = ?)");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM indexComments "+
"WHERE
indexComments.indexId IN "+
@@ -753,6 +786,7 @@
"
WHERE indexParents.folderId = ?)");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM indexCommentBlackList "+
"WHERE
indexCommentBlackList.indexId IN "+
@@ -761,6 +795,7 @@
"
WHERE indexParents.folderId = ?)");
st.setInt(1, id);
st.execute();
+ st.close();
/* we remove all the files */
@@ -771,6 +806,7 @@
st.setInt(1, id);
st.execute();
+ st.close();
/* we remove all the links */
@@ -779,17 +815,16 @@
"(SELECT indexParents.indexId FROM indexParents WHERE indexParents.folderId =
?)");
st.setInt(1, id);
-
st.execute();
+ st.close();
/* we remove all the indexes */
st =
db.getConnection().prepareStatement("DELETE FROM indexes WHERE indexes.id IN "+
"(SELECT indexParents.indexId FROM indexParents WHERE indexParents.folderId =
?)");
-
st.setInt(1, id);
-
st.execute();
+ st.close();
/* we remove all the child folders */
@@ -798,10 +833,9 @@
deleteChildFoldersRecursivly(id);
st =
db.getConnection().prepareStatement("DELETE FROM indexFolders WHERE
indexFolders.id = ?");
-
st.setInt(1, id);
-
st.execute();
+ st.close();
/* we clean the joint tables */
@@ -810,21 +844,22 @@
"(SELECT indexParents.indexId FROM indexParents WHERE indexParents.folderId =
?)");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM folderParents "+
"WHERE
(folderId IN "+
"(SELECT folderParents.folderId FROM folderParents WHERE folderParents.parentId
= ?))");
st.setInt(1, id);
-
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM folderParents "+
"WHERE
folderId = ?");
st.setInt(1, id);
-
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while removing the
folder: "+e.toString());
@@ -857,6 +892,8 @@
set.getInt("indexId"))).insertOnFreenet(observer, indexBrowser, queueManager);
i++;
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to start insertions
because: "+e.toString());
@@ -904,6 +941,8 @@
(new Index(db, config,
indexId)).downloadFromFreenet(observer, indexTree, queueManager, rev);
i++;
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to start insertions
because: "+e.toString());
@@ -944,6 +983,8 @@
while(set.next()) {
keys += set.getString("publicKey") +
"\n";
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to get public keys
because: "+e.toString());
@@ -981,6 +1022,8 @@
while(set.next()) {
keys += set.getString("privateKey") +
"\n";
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to get private keys
because: "+e.toString());
@@ -1034,8 +1077,9 @@
position++;
}
+ selectSt.close();
+ updateSt.close();
-
/* next we sort the indexes */
@@ -1066,6 +1110,8 @@
position++;
}
+ selectSt.close();
+ updateSt.close();
} catch(SQLException e) {
Logger.error(this, "Error while reordering:
"+e.toString());
@@ -1098,9 +1144,12 @@
st.setInt(1, id);
ResultSet set = st.executeQuery();
if (set.next()) {
+ st.close();
name = set.getString("name");
return name;
}
+
+ st.close();
Logger.error(this, "toString(): not found in
the db ?!");
return null;
@@ -1169,12 +1218,16 @@
int res;
res = set.getInt(1);
+
+ st.close();
if (res > 0)
return false;
else
return true;
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "unable to know if the
folder contains only modifiable indexes because: "+e.toString());
}
@@ -1202,6 +1255,7 @@
st.setBoolean(1, flag);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while changing
'hasChanged' flag: "+e.toString());
return false;
@@ -1232,6 +1286,7 @@
st.setBoolean(1, flag);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while changing
'newComment' flag: "+e.toString());
return false;
@@ -1331,6 +1386,8 @@
boolean ret;
ret = set.next();
+
+ st.close();
lastHasChangedValue = ret;
hasLastHasChangedValueBeenSet = true;
@@ -1381,6 +1438,8 @@
boolean ret;
ret = set.next();
+
+ st.close();
lastNewCommentValue = ret;
hasLastHasChangedValueBeenSet = true;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -247,6 +247,7 @@
st.setNull(11, Types.INTEGER);
st.execute();
+ st.close();
index = new Index(db,
getIndexBrowserPanel().getConfig(),
id,
(TreeNode)getTarget(),
@@ -469,6 +470,7 @@
st.setNull(10, Types.INTEGER);
st.execute();
+ st.close();
index = new Index(db, indexBrowser.getConfig(),
id, parent,
@@ -555,6 +557,7 @@
st.setNull(5, Types.INTEGER);
st.execute();
+ st.close();
folder = new IndexFolder(indexBrowser.getDb(),
indexBrowser.getConfig(),
nextId, target, name,
false);
@@ -1277,9 +1280,12 @@
" ?,
?, ?, "+
" ?,
?, TRUE)");
nextId = DatabaseManager.getNextId(db, "files");
-
- if (nextId < 0)
+
+ if (nextId < 0) {
+ selectSt.close();
+ st.close();
return;
+ }
} catch(SQLException e) {
Logger.error(new IndexManagementHelper(),
"Exception while trying to add file: "+e.toString());
return;
@@ -1327,6 +1333,13 @@
Logger.error(new
IndexManagementHelper(), "Error while adding file: "+e.toString());
}
}
+
+ try {
+ selectSt.close();
+ st.close();
+ } catch(SQLException e) {
+ /* \_o< */
+ }
}
indexBrowser.getTables().getFileTable().refresh();
@@ -1467,8 +1480,11 @@
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, TRUE)");
nextId = DatabaseManager.getNextId(db, "files");
- if (nextId < 0)
+ if (nextId < 0) {
+ preSt.close();
+ st.close();
return;
+ }
} catch(SQLException e) {
Logger.error(new IndexManagementHelper(),
"Exception while trying to add file: "+e.toString());
return;
@@ -1515,6 +1531,13 @@
Logger.error(new
IndexManagementHelper(), "Error while adding file: "+e.toString());
}
}
+
+ try {
+ preSt.close();
+ st.close();
+ } catch(SQLException e) {
+ /* \_o< */
+ }
}
indexBrowser.getTables().getFileTable().refresh();
@@ -1573,6 +1596,7 @@
st.setNull(7, Types.INTEGER);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(new IndexManagementHelper(),
"Error while adding link: "+e.toString());
}
@@ -1866,16 +1890,19 @@
rs = st.executeQuery();
rs.next();
nmbFilesInt =
rs.getInt(1);
+ st.close();
st =
db.getConnection().prepareStatement("SELECT count(id) from links");
rs = st.executeQuery();
rs.next();
nmbLinksInt =
rs.getInt(1);
+ st.close();
st =
db.getConnection().prepareStatement("SELECT sum(size) from files");
rs = st.executeQuery();
rs.next();
totalSize =
rs.getLong(1);
+ st.close();
} else {
st =
db.getConnection().prepareStatement("SELECT count(id) "+
"FROM files WHERE files.indexParent IN "+
@@ -1887,8 +1914,8 @@
rs = st.executeQuery();
rs.next();
nmbFilesInt =
rs.getInt(1);
+ st.close();
-
st =
db.getConnection().prepareStatement("SELECT count(id) "+
"FROM links WHERE links.indexParent IN "+
"(SELECT indexParents.indexId "+
@@ -1898,8 +1925,8 @@
rs = st.executeQuery();
rs.next();
nmbLinksInt =
rs.getInt(1);
+ st.close();
-
st =
db.getConnection().prepareStatement("SELECT sum(files.size) "+
"FROM files WHERE files.indexParent IN "+
"(SELECT indexParents.indexId "+
@@ -1910,13 +1937,14 @@
rs = st.executeQuery();
rs.next();
totalSize =
rs.getLong(1);
-
+ st.close();
}
insertionDate = null;
} else if (node instanceof Index) {
+ /* mode lazy bastard => on */
thaw.plugins.index.File[] files
= ((Index)node).getFileList(null, true);
nmbFilesInt = files.length;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexRoot.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexRoot.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexRoot.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -59,9 +59,12 @@
ResultSet set = select.executeQuery();
- if (!set.next())
+ if (!set.next()) {
break;
+ }
}
+
+ select.close();
} catch(SQLException e) {
Logger.error(this, "Unable to find a name for
the import folder !");
return null;
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -679,6 +679,8 @@
else
parentFolders[nmbFolders] = -1;
}
+
+ st.close();
if (nmbFolders == 0) {
Logger.error(this, "Unable to select
specified index : Not found.");
@@ -867,11 +869,15 @@
if (st.execute()) {
final ResultSet results = st.getResultSet();
- if (results.next())
+ if (results.next()) {
+ st.close();
return true;
+ }
+ st.close();
}
+ else
+ st.close();
-
} catch(final java.sql.SQLException e) {
Logger.warning(this, "Exception while trying to check
if '"+key+"' is already know: '"+e.toString()+"'");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2008-02-16 03:01:26 UTC
(rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2008-02-16 04:51:48 UTC
(rev 17976)
@@ -81,6 +81,8 @@
} else {
Logger.error(this, "Link
'"+Integer.toString(id)+"' not found.");
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while loading data for link
'"+Integer.toString(id)+"': "+e.toString());
}
@@ -172,6 +174,7 @@
st.setInt(1, index.getId());
st.setInt(2, id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to set parent because:
"+e.toString());
}
@@ -242,6 +245,7 @@
st.setString(1, key);
st.setInt(2, id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while changing publicKey:
"+e.toString());
}
@@ -258,7 +262,7 @@
st.setInt(1, id);
st.execute();
-
+ st.close();
} catch(final SQLException e) {
Logger.error(this, "Unable to remove link because:
"+e.toString());
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -92,6 +92,8 @@
set.getLong("size"),
set.getInt("indexParent")));
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while searching:
"+e.toString());
@@ -129,6 +131,8 @@
set.getInt("indexParent") ));
}
}
+
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Error while searching:
"+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -101,6 +101,8 @@
graphPanel);
nmb++;
}
+
+ st.close();
Logger.info(this, Integer.toString(nmb)+" nodes
loaded");
}
@@ -147,6 +149,8 @@
node.setLinkTo(target);
}
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't load the links because :
"+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoard.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -234,6 +234,8 @@
encryptedFor,
daBoard));
}
+
+ st.close();
}
} catch(SQLException e) {
@@ -305,7 +307,7 @@
int sigId = set.getInt("sigId");
- return new KSKMessage(set.getInt("id"),
+ KSKMessage m = new
KSKMessage(set.getInt("id"),
set.getString("msgId"),
set.getString("inReplyToId"),
set.getString("subject"),
@@ -324,7 +326,11 @@
false, false,
encryptedFor,
this);
+ st.close();
+ return m;
}
+
+ st.close();
}
} catch(SQLException e) {
@@ -444,6 +450,8 @@
lastRev = newRev;
}
+
+ st.close();
/* no hole found */
return lastRev+1;
@@ -489,9 +497,16 @@
st.setInt(2, id);
ResultSet set = st.executeQuery();
+
+ int r = 0;
- if (set.next())
- return set.getInt("rev");
+ if (set.next()) {
+ r = set.getInt("rev");
+ }
+
+ st.close();
+
+ return r;
}
} catch(SQLException e) {
Logger.error(this, "Can't get the next non-downloaded
rev in the board because : "+e.toString());
@@ -568,6 +583,7 @@
st.setDate(1, new java.sql.Date(new
java.util.Date().getTime()));
st.setInt(2, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to update the
lastUpdate date :"+e.toString());
@@ -810,8 +826,8 @@
}
- protected static int countNewMessages(Hsqldb db, int boardId, String
boardName,
- boolean unsigned, boolean
archived, int minTrustLevel) {
+ protected static int countNewMessages(Hsqldb db, int boardId, String
boardName,
+ boolean unsigned, boolean archived, int minTrustLevel) {
int count = -1;
String archivedStr = "";
@@ -825,25 +841,28 @@
unsignedStr = " AND frostKSKMessages.sigId IS NOT NULL
AND signatures.trustLevel >= ?";
String query = "SELECT count(frostKSKMessages.id) "+
- "FROM frostKSKMessages LEFT JOIN signatures "+
- " ON frostKSKMessages.sigId = signatures.id "+
- "WHERE frostKSKMessages.boardId = ? "+
- "AND frostKSKMessages.read = FALSE"+
- archivedStr+
- unsignedStr;
+ "FROM frostKSKMessages LEFT
JOIN signatures "+
+ " ON frostKSKMessages.sigId =
signatures.id "+
+ "WHERE frostKSKMessages.boardId
= ? "+
+ "AND frostKSKMessages.read =
FALSE"+
+ archivedStr+
+ unsignedStr;
try {
- PreparedStatement subSt;
+ synchronized(db.dbLock) {
+ PreparedStatement subSt;
- subSt = db.getConnection().prepareStatement(query);
- subSt.setInt(1, boardId);
- subSt.setInt(2, minTrustLevel);
+ subSt =
db.getConnection().prepareStatement(query);
+ subSt.setInt(1, boardId);
+ subSt.setInt(2, minTrustLevel);
- ResultSet subRes = subSt.executeQuery();
+ ResultSet subRes = subSt.executeQuery();
- if (subRes.next())
- count = subRes.getInt(1);
-
+ if (subRes.next())
+ count = subRes.getInt(1);
+
+ subSt.close();
+ }
} catch(SQLException e) {
Logger.error(db, "Can't count the number of new message
on the board "+
"'"+boardName+"'because : "+e.toString());
@@ -892,11 +911,13 @@
st =
db.getConnection().prepareStatement("DELETE FROM frostKSKInvalidSlots WHERE
boardId = ?");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM frostKSKBoards "+
- "WHERE
id = ?");
+
"WHERE id = ?");
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't destroy the board because :
"+e.toString());
@@ -971,6 +992,7 @@
if (!set.next()) {
/* no existing interval near our rev */
/* => we create one */
+ st.close();
st =
db.getConnection().prepareStatement("INSERT INTO frostKSKInvalidSlots (boardId,
date, minRev, maxRev) "+
"VALUES (?, ?, ?, ?)");
@@ -979,27 +1001,30 @@
st.setInt(3, rev);
st.setInt(4, rev);
st.execute();
-
+ st.close();
} else {
/* an interval near this one already
exist */
/* => we adjust */
-
int intervalId = set.getInt("id");
int intervalMinRev =
set.getInt("minRev");
int intervalMaxRev =
set.getInt("maxRev");
+ st.close();
+
if (intervalMaxRev == (rev-1)) {
st =
db.getConnection().prepareStatement("UPDATE frostKSKInvalidSlots SET maxRev = ?
"+
"WHERE id = ?");
st.setInt(1, rev);
st.setInt(2, intervalId);
st.execute();
+ st.close();
} else if (intervalMinRev == (rev+1)) {
st =
db.getConnection().prepareStatement("UPDATE frostKSKInvalidSlots SET minRev = ?
"+
"WHERE id = ?");
st.setInt(1, rev);
st.setInt(2, intervalId);
st.execute();
+ st.close();
} else {
Logger.error(this, "Unmanaged
case !");
}
@@ -1035,6 +1060,7 @@
ResultSet set = st.executeQuery();
if (!set.next()) {
+ st.close();
return rev;
}
rev = set.getInt("maxRev")+1;
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardAttachment.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -237,6 +237,7 @@
st.setInt(5, messageId);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't insert the file attachment
because : "+e.toString());
@@ -269,6 +270,8 @@
msg,
boardFactory));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(e, "Can't select file attachments because:
"+e.toString());
@@ -306,6 +309,7 @@
"WHERE
messageId = ?");
st.setInt(1, msg.getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the message
attachments of the board because : "+e.toString());
@@ -334,6 +338,8 @@
st.setInt(1, id);
st.execute();
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the board attachments
of the board because : "+e.toString());
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -142,9 +142,12 @@
msg.destroy(db);
}
+ st.close();
+
st =
db.getConnection().prepareStatement("DELETE FROM frostKSKInvalidSlots WHERE
date < ?");
st.setTimestamp(1, timestamp);
st.execute();
+ st.close();
timestamp = new java.sql.Timestamp(new
Date().getTime()
@@ -155,6 +158,7 @@
st =
db.getConnection().prepareStatement("UPDATE frostKSKMessages SET archived =
TRUE WHERE date < ?");
st.setTimestamp(1, timestamp);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't cleanup the db because :
"+e.toString());
@@ -254,6 +258,8 @@
st.setInt(2, id);
st.execute();
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while converting the board
database from version 2 to 3: "+e.toString());
@@ -370,6 +376,8 @@
boardsHashMap.put(name, board);
}
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't get the board list because :
"+e.toString());
@@ -458,6 +466,8 @@
}
}
+
+ st.close();
}
} catch(SQLException e) {
@@ -515,13 +525,17 @@
if (set.next()) {
if (warningIfExisting)
Logger.warning(this, "Board
already added");
+ st.close();
return;
}
+
+ st.close();
st =
db.getConnection().prepareStatement("INSERT INTO frostKSKBoards (name) "+
"VALUES (?)");
st.setString(1, name.toLowerCase());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't add board because:
"+e.toString());
@@ -567,8 +581,11 @@
if (set.next()) {
if (warningIfExisting)
Logger.warning(this, "Board
already added");
+ st.close();
return;
}
+
+ st.close();
/* we must get the id first, else we will mix
up things */
@@ -581,6 +598,7 @@
if (set.next())
id = set.getInt("id") + 1;
+ st.close();
name = name.toLowerCase();
@@ -591,8 +609,8 @@
st.setString(2, name);
st.execute();
+ st.close();
-
st =
db.getConnection().prepareStatement("INSERT INTO frostSSKBoards "+
"(publicKey, privateKey, kskBoardId) "+
"VALUES (?, ?, ?)");
@@ -604,7 +622,7 @@
st.setInt(3, id);
st.execute();
-
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't add the board because :
"+e.toString());
@@ -629,6 +647,8 @@
set.getString("privateKey"),
null));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't get the list of know boards
because: "+e.toString());
@@ -703,7 +723,11 @@
/* if no => we continue our progression */
pos++;
}
- }
+ }
+
+ select.close();
+ update.close();
+ delete.close();
}
@@ -720,6 +744,8 @@
dates.push(set.getDate("date"));
}
+ st.close();
+
while(!dates.empty()) {
recompactInvalidSlots(db, boardId,
(java.sql.Date)dates.pop());
}
@@ -741,6 +767,8 @@
boardNames.push(set.getString("name"));
}
+ st.close();
+
while(!boardIds.empty() && !boardNames.empty())
{
String name = (String)boardNames.pop();
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKFileAttachment.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -295,6 +295,7 @@
st.setInt(4, messageId);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't insert the file attachment
because : "+e.toString());
@@ -324,6 +325,8 @@
msg,
boardFactory.getCore().getQueueManager()));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(e, "Can't select file attachments because:
"+e.toString());
@@ -351,6 +354,7 @@
"WHERE
messageId = ?");
st.setInt(1, msg.getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the file attachments
of the message because : "+e.toString());
@@ -379,6 +383,8 @@
st.setInt(1, id);
st.execute();
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the file attachments
of the board because : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessage.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -309,6 +309,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't update read status because :
"+e.toString());
@@ -334,6 +335,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't update archived status
because : "+e.toString());
@@ -411,10 +413,14 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
- return set.getString("content");
+ String s = set.getString("content");
+ st.close();
+ return s;
}
} catch(SQLException e) {
Logger.error(this, "Error while getting the messages :
"+e.toString());
@@ -473,10 +479,14 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
content = set.getString("content");
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while getting the messages :
"+e.toString());
@@ -547,11 +557,13 @@
st =
db.getConnection().prepareStatement("UPDATE frostKSKMessages SET "+
"inReplyTo = NULL");
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM frostKSKMessages "+
"WHERE
boardId = ?");
st.setInt(1, board.getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the board messages
because : "+e.toString());
@@ -577,11 +589,13 @@
"inReplyTo = NULL WHERE inReplyTo = ?");
st.setInt(1, id);
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("DELETE FROM frostKSKMessages "+
"WHERE
id = ?");
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(null, "Can't destroy the message
"+Integer.toString(id)+" because : "+e.toString());
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKMessageParser.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -168,7 +168,9 @@
ResultSet res = st.executeQuery();
- return (res.next());
+ boolean b = (res.next());
+ st.close();
+ return b;
}
} catch(SQLException e) {
Logger.error(this,
@@ -279,6 +281,7 @@
if (res.next())
replyToId = res.getInt("id");
+ st.close();
}
/* we insert the message */
@@ -327,6 +330,7 @@
st.setInt(14, boardId);
st.execute();
+ st.close();
String boardName = (board != null) ? board :
"(null)";
@@ -339,7 +343,7 @@
/* we need the id of the message */
st =
db.getConnection().prepareStatement("SELECT id FROM frostKSKmessages "+
- "WHERE
msgId = ? LIMIT 1");
+
"WHERE msgId = ? LIMIT 1");
st.setString(1, messageId);
ResultSet set = st.executeQuery();
@@ -347,6 +351,8 @@
set.next();
int id = set.getInt("id");
+
+ st.close();
/* we insert the attachments */
@@ -749,41 +755,48 @@
String lastId = inReplyTo;
PreparedStatement st;
-
- try {
- st = db.getConnection().prepareStatement("SELECT
inReplyToId FROM frostKSKMessages "+
-
"WHERE msgId = ? LIMIT 1");
- } catch(SQLException e) {
- Logger.error(this, "Can't get full inReplyTo String
because: "+e.toString());
- return inReplyTo;
- }
-
- while(lastId != null) {
- /* I don't remember if inReplyTo is correctly set, so
we will
- * use inReplyToId to be safer
- */
-
+
+ synchronized(db.dbLock) {
+
try {
- synchronized(db.dbLock) {
-
+ st =
db.getConnection().prepareStatement("SELECT inReplyToId FROM frostKSKMessages "+
+ "WHERE msgId = ? LIMIT 1");
+ } catch(SQLException e) {
+ Logger.error(this, "Can't get full inReplyTo
String because: "+e.toString());
+ return inReplyTo;
+ }
+
+ while(lastId != null) {
+ /* I don't remember if inReplyTo is correctly
set, so we will
+ * use inReplyToId to be safer
+ */
+
+ try {
+
+
st.setString(1, lastId);
-
+
ResultSet set = st.executeQuery();
-
+
if (set.next()) {
lastId =
set.getString("inReplyToId");
-
+
if (lastId != null)
inReplyTo = lastId +
","+inReplyTo;
} else
lastId = null;
- }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't find message
parent because : "+e.toString());
+ lastId = null;
+ }
+ }
+
+ try {
+ st.close();
} catch(SQLException e) {
- Logger.error(this, "Can't find message parent
because : "+e.toString());
- lastId = null;
+ /* \_o< */
}
}
-
return inReplyTo;
}
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoard.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -88,6 +88,7 @@
"WHERE
kskBoardId = ?");
st.setInt(1, getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't destroy the board because :
"+e.toString());
@@ -117,6 +118,7 @@
st.setInt(3, getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Oops ! Unable to delete the
board, and I think that I've broken something :(");
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/SSKBoardFactory.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -105,6 +105,8 @@
boards.put(name+publicKey,
board);
}
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't get the board list because :
"+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/Identity.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -246,6 +246,7 @@
st.setInt(2, id);
st.execute();
+ st.close();
}
trustLevel = i;
@@ -273,12 +274,14 @@
st.setString(1, nick.toLowerCase());
st.execute();
+ st.close();
st =
db.getConnection().prepareStatement("UPDATE signatures SET isDup = FALSE "
+
"WHERE id = ?");
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this,
@@ -332,8 +335,11 @@
set.getString("publicKey"), set.getString("privateKey"),
set.getBoolean("isDup"), set.getInt("trustLevel"));
Logger.debug(i, "Identity found");
+ st.close();
return i;
}
+
+ st.close();
if (!create)
return null;
@@ -347,6 +353,8 @@
set = st.executeQuery();
boolean isDup = set.next();
+
+ st.close();
/* and we add */
@@ -360,8 +368,8 @@
st.setBoolean(4, isDup);
st.execute();
+ st.close();
-
/* and next we find back the id */
st =
db.getConnection().prepareStatement("SELECT id "+
@@ -374,6 +382,8 @@
set.next();
int id = set.getInt("id");
+
+ st.close();
Identity i = new Identity(db, id, nick,
publicKey, null, isDup, 0);
Logger.info(i, "New identity found");
@@ -411,12 +421,15 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
i = new Identity(db, id,
set.getString("nickName"),
set.getString("publicKey"),
set.getString("privateKey"),
set.getBoolean("isDup"),
set.getInt("trustLevel"));
+ st.close();
}
} catch(SQLException e) {
Logger.error(new Identity(), "Error while getting
identity (1) : "+e.toString());
@@ -464,6 +477,7 @@
"WHERE
publicKey = ? LIMIT 1");
st.setString(1, publicKey);
st.execute();
+ st.close();
ResultSet set = st.executeQuery();
@@ -478,6 +492,7 @@
st.setInt(3, id);
st.execute();
+ st.close();
Signatures.notifyIdentityUpdated(this);
} else {
@@ -493,6 +508,7 @@
st.setInt(5, trustLevel);
st.execute();
+ st.close();
if (privateKey == null)
Signatures.notifyPublicIdentityAdded(this);
@@ -516,7 +532,11 @@
ResultSet set = st.executeQuery();
- return set.next();
+ boolean b= set.next();
+
+ st.close();
+
+ return b;
}
} catch(SQLException e) {
Logger.error(new Identity(), "Exception while accessing
the signature table : "+e.toString());
@@ -537,6 +557,7 @@
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.warning(this, "Exception while deleting the
identity from the bdd: "+e.toString());
@@ -621,6 +642,8 @@
set.getBoolean("isDup"),
set.getInt("trustLevel")));
}
+
+ st.close();
return v;
}
Modified: trunk/apps/Thaw/src/thaw/plugins/transferLogs/Transfer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/transferLogs/Transfer.java 2008-02-16
03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/transferLogs/Transfer.java 2008-02-16
04:51:48 UTC (rev 17976)
@@ -101,6 +101,8 @@
this.isDup =
set.getBoolean("isDup");
this.isSuccess =
set.getBoolean("isSuccess");
}
+
+ st.close();
}
@@ -132,6 +134,8 @@
this.isDup =
set.getBoolean("isDup");
this.isSuccess =
set.getBoolean("isSuccess");
}
+
+ st.close();
}
@@ -224,6 +228,7 @@
st.setBoolean(7, TransferLogs.isDup(db,
query.getFileKey()));
st.setBoolean(8, query.isFinished() &&
query.isSuccessful());
st.execute();
+ st.close();
}
@@ -251,6 +256,7 @@
st.setString(1, qKey);
st.setInt(2, this.id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to update key in transfer
logs because : "+e.toString());
}
@@ -265,6 +271,7 @@
st.setLong(1, size);
st.setInt(2, this.id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to update size in transfer
logs because : "+e.toString());
}
@@ -283,6 +290,7 @@
st.setBoolean(2, successful);
st.setInt(3, this.id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to update dateEnd in
transfer logs because : "+e.toString());
}
@@ -299,6 +307,7 @@
st.setTimestamp(1, dateStart);
st.setInt(2, this.id);
st.execute();
+ st.close();
} catch(SQLException e) {
Logger.error(this, "Unable to update dateEnd in
transfer logs because : "+e.toString());
}
@@ -394,6 +403,7 @@
st =
db.getConnection().prepareStatement("DELETE FROM transferLogs WHERE id = ?");
st.setInt(1, id);
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Can't delete transfer because:
"+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/transferLogs/TransferTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/transferLogs/TransferTable.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/transferLogs/TransferTable.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -368,6 +368,8 @@
res.getBoolean("isDup"),
res.getBoolean("isSuccess")));
}
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while reading
transfer logs: "+e.toString());
@@ -435,6 +437,8 @@
res.next();
nmb_elements = res.getInt(1);
+
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Unable to compute the
number of pages in the logs because : "+e.toString());
Modified: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListDownloader.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListDownloader.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/TrustListDownloader.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -26,7 +26,7 @@
*/
public class TrustListDownloader implements Observer,
Signatures.SignaturesObserver {
public final static long KEY_OBSOLETE_AFTER = 2 /* week */ *7 /* days
*/ * 24 /* hour */ * 60 /*min */ * 60 /* sec */ * 1000 /* ms */;
- public final static int CLIENTGET_PRIORITY = 2;
+ public final static int CLIENTGET_PRIORITY = 3;
public final static int MAX_SIZE = 102400; /* 100 KB */
public final static int MIN_TRUSTLEVEL = 0;
@@ -117,6 +117,8 @@
startULPR(key, id);
}
+ st.close();
+
} catch(SQLException e) {
Logger.error(this, "Error while starting ULPRs
: "+e.toString());
e.printStackTrace();
Modified: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
2008-02-16 03:01:26 UTC (rev 17975)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WotIdentity.java
2008-02-16 04:51:48 UTC (rev 17976)
@@ -47,8 +47,15 @@
ResultSet set = st.executeQuery();
- if (set.next())
- return
(set.getTimestamp("lastDownload") != null);
+ boolean b = false;
+
+ if (set.next()) {
+ b = (set.getTimestamp("lastDownload")
!= null);
+ }
+
+ st.close();
+
+ return b;
}
} catch(SQLException e) {
Logger.error(this, "Error while checking if we already
have the trust list of the identity '"+toString()+"'");
@@ -71,10 +78,14 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
- return new WotIdentity(Identity.getIdentity(db,
set.getInt("sigId")));
+ WotIdentity wi = new
WotIdentity(Identity.getIdentity(db, set.getInt("sigId")));
+ st.close();
+ return wi;
}
} catch(SQLException e) {
Logger.error(new WotIdentity(), "Error while getting
the identity corresponding to a wot public key: "+e.toString());
@@ -186,8 +197,19 @@
}
return true;
}
+
+
+ private PreparedStatement insertTrustLinkSt = null;
+
public void start() {
+ try {
+ insertTrustLinkSt =
getDb().getConnection().prepareStatement("INSERT INTO wotTrustLists (source,
destination, trustLevel) VALUES (?, ?, ?)");
+ } catch(SQLException e) {
+ Logger.error(this, "Error while updating a trust list
in the db (3) : "+e.toString());
+ return;
+ }
+
purgeTrustList();
}
@@ -199,6 +221,7 @@
st =
getDb().getConnection().prepareStatement("DELETE FROM wotTrustLists WHERE
source = ?");
st.setInt(1, getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while updating a trust list
in the db (1) : "+e.toString());
@@ -207,20 +230,16 @@
}
public void end() {
- /* \_o< */
+ try {
+ insertTrustLinkSt.close();
+ insertTrustLinkSt = null;
+ } catch(SQLException e) {
+
+ }
}
-
- private PreparedStatement insertTrustLinkSt = null;
public void updateIdentity(Identity i) {
- try {
- if (insertTrustLinkSt == null)
- insertTrustLinkSt =
getDb().getConnection().prepareStatement("INSERT INTO wotTrustLists (source,
destination, trustLevel) VALUES (?, ?, ?)");
- } catch(SQLException e) {
- Logger.error(this, "Error while updating a trust list
in the db (3) : "+e.toString());
- return;
- }
-
+
if (i.getTrustLevel() == 0
|| i.getTrustLevel() <
Identity.trustLevelInt[Identity.trustLevelInt.length-1]
|| i.getTrustLevel() > Identity.trustLevelInt[1]) {
@@ -262,6 +281,7 @@
st.setInt(4, getId());
st.execute();
+ st.close();
}
} catch(SQLException e) {
Logger.error(this, "Error while updating infos in the
wotKeys table : "+e.toString());
@@ -280,10 +300,14 @@
ResultSet set = st.executeQuery();
- if (!set.next())
+ if (!set.next()) {
+ st.close();
return null;
+ }
- return set.getString("publicKey");
+ String r = set.getString("publicKey");
+ st.close();
+ return r;
}
} catch(SQLException e) {
Logger.error(this, "Unable to check if an identity is
in the WoT because : "+e.toString());