diff --git a/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java b/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java index 121e6eb..6dc55c5 100644 --- a/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ diff --git a/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java b/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java index 1d5daa0..d46d53f 100644 --- a/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -76,22 +76,33 @@ class AdminUserContextImpl implements AdminUserContext this.my_locale = International.get().createLocale(rs.getString("localeid")); this.my_tz = TimeZone.getTimeZone(rs.getString("tzid")); - Statement stmt = conn.createStatement(); - ResultSet rs2 = stmt.executeQuery("SELECT ndx, data FROM propuser WHERE uid = " + this.uid + ";"); - while (rs2.next()) - { // load the properties... - switch (rs2.getInt(1)) - { // based on the property, do what is needed - case UserContextImpl.PROP_FLAGS: - flags = new OptionSet(rs2.getString(2)); - break; + Statement stmt = null; - default: - break; + try + { // get user properties + stmt = conn.createStatement(); + ResultSet rs2 = stmt.executeQuery("SELECT ndx, data FROM propuser WHERE uid = " + this.uid + ";"); + while (rs2.next()) + { // load the properties... + switch (rs2.getInt(1)) + { // based on the property, do what is needed + case UserContextImpl.PROP_FLAGS: + flags = new OptionSet(rs2.getString(2)); + break; - } // end switch + default: + break; - } // end while + } // end switch + + } // end while + + } // end try + finally + { // close statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end constructor @@ -103,10 +114,11 @@ class AdminUserContextImpl implements AdminUserContext private final void updateProperties(BitSet delta) throws DataException { Connection conn = null; + Statement stmt = null; try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (delta.get(UserContextImpl.PROP_FLAGS)) @@ -127,6 +139,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -196,6 +209,7 @@ class AdminUserContextImpl implements AdminUserContext public void setDescription(String new_descr) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; if (new_descr.equals(description)) @@ -204,7 +218,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -221,6 +235,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -237,6 +252,7 @@ class AdminUserContextImpl implements AdminUserContext public void setBaseLevel(int new_level) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; if (level==new_level) @@ -245,7 +261,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET base_lvl = "); sql.append(new_level).append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -262,6 +278,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -290,6 +307,7 @@ class AdminUserContextImpl implements AdminUserContext public void setEmailVerified(boolean flag) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; if (flag==email_verified) @@ -298,7 +316,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = "); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -315,6 +333,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -331,6 +350,7 @@ class AdminUserContextImpl implements AdminUserContext public void setLockedOut(boolean flag) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; if (flag==lockout) @@ -339,7 +359,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET lockout = "); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -356,6 +376,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -436,12 +457,13 @@ class AdminUserContextImpl implements AdminUserContext public void setPassword(String password, String reminder) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); PasswordHash phash = new PasswordHash(password); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder)); @@ -460,6 +482,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -476,12 +499,13 @@ class AdminUserContextImpl implements AdminUserContext public void setLocale(Locale locale) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the update statement StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '"); @@ -503,6 +527,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -519,12 +544,13 @@ class AdminUserContextImpl implements AdminUserContext public void setTimeZone(TimeZone timezone) throws DataException { Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the update statement StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '"); @@ -546,6 +572,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -602,11 +629,12 @@ class AdminUserContextImpl implements AdminUserContext static AdminUserContext getAdminUserContext(EnvUser env, int uid) throws DataException { Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " + "ON users.uid = userprefs.uid WHERE users.uid = " + uid + ";"); if (!(rs.next())) @@ -625,6 +653,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // release the connection where necessary + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -634,11 +663,12 @@ class AdminUserContextImpl implements AdminUserContext static AdminUserContext getAdminUserContext(EnvUser env, String username) throws DataException { Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " + "ON users.uid = userprefs.uid WHERE users.username = '" + SQLUtil.encodeString(username) + "';"); @@ -658,6 +688,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // release the connection where necessary + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java b/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java index b7fb5e9..d26c043 100644 --- a/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -68,17 +68,18 @@ class AdvertisementImpl implements Advertisement *-------------------------------------------------------------------------------- */ - private static Advertisement getTheAd(EnvEngine env, Statement stmt, int ad_id) throws SQLException + private static final Advertisement getTheAd(EnvEngine env, Statement stmt, int ad_id) throws SQLException { Integer my_ad_id = new Integer(ad_id); Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id)); if (rc!=null) return rc; - ResultSet rs = stmt.executeQuery("SELECT * From adverts WHERE adid = " + ad_id + ";"); + ResultSet rs = stmt.executeQuery("SELECT * FROM adverts WHERE adid = " + ad_id + ";"); if (!(rs.next())) return null; rc = new AdvertisementImpl(env,rs); + SQLUtil.shutdown(rs); ad_cache.put(my_ad_id,rc); return rc; @@ -131,11 +132,12 @@ class AdvertisementImpl implements Advertisement static Advertisement getAdByID(EnvEngine env, int id) { Connection conn = null; + Statement stmt = null; try { // get a database connection and call the internal function conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); return getTheAd(env,stmt,id); } // end try @@ -146,6 +148,7 @@ class AdvertisementImpl implements Advertisement } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -155,11 +158,12 @@ class AdvertisementImpl implements Advertisement static Advertisement getRandomAd(EnvEngine env) { Connection conn = null; + Statement stmt = null; try { // get a database connection and call the internal function conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;"); if (!(rs.next())) throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!"); @@ -184,6 +188,7 @@ class AdvertisementImpl implements Advertisement } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java index 134f109..e99a1f8 100644 --- a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java +++ b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -73,12 +73,13 @@ class BackgroundCommunityPurge implements Runnable logger.debug("BackgroundCommunityPurge running on community #" + cid); Connection conn = null; // pooled database connection + Statement stmt = null; ParallelRunQueue rq = new ParallelRunQueue(2); try { // get a database connection from the pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // run some "lower priority" deletes stmt.executeUpdate("DELETE FROM contacts WHERE owner_sigid = " + cid + ";"); @@ -94,6 +95,7 @@ class BackgroundCommunityPurge implements Runnable int conferences = 0; while (rs.next()) conf_ids[conferences++] = rs.getInt(1); + SQLUtil.shutdown(rs); for (int i=0; i, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -39,9 +39,9 @@ class BackgroundConferencePurge implements Runnable */ private EnvEngine env; // the environment - private int confid; - private int num_topics; - private int max_topicid; + private int confid; // the conference ID + private int num_topics; // the number of topics + private int max_topicid; // the maximum topic ID /*-------------------------------------------------------------------------------- * Constructor @@ -68,12 +68,13 @@ class BackgroundConferencePurge implements Runnable logger.debug("BackgroundConferencePurge running on conference #" + confid); Connection conn = null; // pooled database connection + Statement stmt = null; ParallelRunQueue rq = new ParallelRunQueue(2); try { // get a database connection from the pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // purge out some auxiliary tables first stmt.executeUpdate("DELETE FROM confmember WHERE confid = " + confid + ";"); @@ -90,6 +91,7 @@ class BackgroundConferencePurge implements Runnable int topics = 0; while (rs.next()) topicids[topics++] = rs.getInt(1); + SQLUtil.shutdown(rs); for (int i=0; i, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -37,9 +37,9 @@ class BackgroundTopicPurge implements Runnable */ private EnvEngine env; // the environment block - private int topicid; - private int num_posts; - private long max_postid; + private int topicid; // the topic ID + private int num_posts; // the number of posts in this topic + private long max_postid; // the maximum post ID /*-------------------------------------------------------------------------------- * Constructor @@ -67,11 +67,12 @@ class BackgroundTopicPurge implements Runnable long[] postids = new long[num_posts]; // stores the post IDs Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection from the pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // look up all the post IDs that are present for this topic StringBuffer sql = new StringBuffer("SELECT postid FROM posts WHERE topicid = "); @@ -80,6 +81,7 @@ class BackgroundTopicPurge implements Runnable int posts = 0; while (rs.next()) postids[posts++] = rs.getLong(1); + SQLUtil.shutdown(rs); for (int i=0; i, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -34,8 +34,8 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable static class CatSegment { - private int id; - private String name; + private int id; // ID of this category + private String name; // name of this segment CatSegment(int id, String name) { @@ -44,13 +44,13 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end constructor - public int getID() + public final int getID() { return id; } // end getID - public String getName() + public final String getName() { return name; @@ -154,13 +154,11 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int id, int symlink, String name) { this.env = other.env; - this.cats = new LinkedList(); + this.cats = (LinkedList)(other.cats.clone()); this.symlink = symlink; this.do_hide = other.do_hide; - // copy the references to the objects directly - for (int i=0; i0) - throw new InternalStateError("invalid symlink in category table (" + String.valueOf(curr_catid) - + " => " + String.valueOf(symlink_field) + ")"); - symlink = symlink_field; + // Save off the symbolic link value, if this category is a symlink. + int symlink_field = rs.getInt("symlink"); + if (symlink_field!=-1) + { // handle saving our symlink value - can only occur at END of path + if (cats.size()>0) + throw new InternalStateError("invalid symlink in category table (" + String.valueOf(curr_catid) + + " => " + String.valueOf(symlink_field) + ")"); + symlink = symlink_field; - } // end if + } // end if - cats.addFirst(new CatSegment(curr_catid,rs.getString("name"))); - curr_catid = rs.getInt("parent"); + cats.addFirst(new CatSegment(curr_catid,rs.getString("name"))); + curr_catid = rs.getInt("parent"); + SQLUtil.shutdown(rs); - } // end while + } // end while + + } // end try + finally + { // close down the statement when we're done + SQLUtil.shutdown(stmt); + + } // end finally } // end doFillFromTop @@ -243,11 +253,12 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end if Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = "); sql.append(getCategoryID()); if (do_hide) @@ -272,6 +283,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end catch finally { // make sure and release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -371,14 +383,16 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable *-------------------------------------------------------------------------------- */ - static List getTopLevelCategoryList(EnvEngine env, boolean show_all) throws DataException + static final List getTopLevelCategoryList(EnvEngine env, boolean show_all) throws DataException { Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); + try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = -1"); if (!show_all) sql.append(" AND hide_dir = 0"); @@ -402,6 +416,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end catch finally { // make sure and release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -410,8 +425,8 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end getTopLevelCategoryList - static List searchForCategories(EnvEngine env, boolean show_all, boolean search_all, int mode, - String term, int offset, int count) throws DataException + static final List searchForCategories(EnvEngine env, boolean show_all, boolean search_all, int mode, + String term, int offset, int count) throws DataException { if (logger.isDebugEnabled()) logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "', offset = " @@ -419,11 +434,12 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable ArrayList rc = new ArrayList(); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE name "); switch (mode) @@ -462,6 +478,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable while (rs.next()) // just read off the matching CATIDs for now rc_raw[n++] = rs.getInt("catid"); + SQLUtil.shutdown(rs); for (int i=0; i, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -120,13 +120,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend this.cid = cid; Connection conn = null; + Statement stmt = null; try { // get a database connection from this object conn = env.getConnection(); // get the community basic data from the database - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT * FROM sigs WHERE sigid = "); sql.append(cid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -134,6 +135,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("community #" + cid + " does not exist in the database."); loadData(rs); // load the community data + SQLUtil.shutdown(rs); sql.setLength(0); sql.append("SELECT ndx, data FROM propcomm WHERE cid = ").append(cid).append(';'); @@ -153,6 +155,8 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end while + SQLUtil.shutdown(rs); + // get the set of community services services = new HashSet(); sql.setLength(0); @@ -175,6 +179,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -225,7 +230,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend *-------------------------------------------------------------------------------- */ - private synchronized void loadData(ResultSet rs) throws SQLException + private final synchronized void loadData(ResultSet rs) throws SQLException { // "cid" field is skipped created = SQLUtil.getFullDateTime(rs,"createdate"); @@ -264,40 +269,63 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end loadData - private synchronized void touchUpdate(Connection conn) throws SQLException + private final synchronized void touchUpdate(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("UPDATE sigs SET lastupdate = '"); - java.util.Date now = new java.util.Date(); - sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); - stmt.executeUpdate(sql.toString()); - last_update = now; + Statement stmt = null; + + try + { // create and execute the Update statement + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("UPDATE sigs SET lastupdate = '"); + java.util.Date now = new java.util.Date(); + sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); + stmt.executeUpdate(sql.toString()); + last_update = now; + + } // end try + finally + { // shutdown statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end touchUpdate - private void newProperties(Connection conn) throws SQLException + private final void newProperties(Connection conn) throws SQLException { - // generate start of SQL statement - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("INSERT INTO propcomm (cid, ndx, data) VALUES "); + Statement stmt = null; - // append Property 0: flags - sql.append('(').append(cid).append(", ").append(PROP_FLAGS).append(", '"); - sql.append(flags.asString()).append("')"); + try + { // generate start of SQL statement + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("INSERT INTO propcomm (cid, ndx, data) VALUES "); - // finish up - sql.append(';'); - stmt.executeUpdate(sql.toString()); + // append Property 0: flags + sql.append('(').append(cid).append(", ").append(PROP_FLAGS).append(", '"); + sql.append(flags.asString()).append("')"); + + // finish up + sql.append(';'); + stmt.executeUpdate(sql.toString()); + + } // end try + finally + { // shutdown the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end newProperties - private synchronized void updateProperties(BitSet delta) throws DataException + private final synchronized void updateProperties(BitSet delta) throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (delta.get(PROP_FLAGS)) @@ -318,13 +346,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end updateProperties - private synchronized void updateProperties() throws DataException + private final synchronized void updateProperties() throws DataException { updateProperties(ALL_PROPS); @@ -495,11 +524,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend return false; // rejected on a level basis Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // check to see if the UID is listed in "sigban" table... StringBuffer sql = new StringBuffer("SELECT by_uid FROM sigban WHERE sigid = "); @@ -516,6 +546,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -621,12 +652,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend return; Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES sigftrs WRITE;"); try @@ -654,8 +686,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end try finally { // make sure we unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -671,6 +702,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -684,12 +716,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET signame = '"); sql.append(SQLUtil.encodeString(name)).append("', lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -708,6 +741,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -721,12 +755,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET alias = '"); sql.append(alias).append("', lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -745,6 +780,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -758,12 +794,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET catid = "); sql.append(catid).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -782,6 +819,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -795,11 +833,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET synopsis = "); sql.append(SQLUtil.encodeStringArg(synopsis)).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -817,6 +856,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -829,11 +869,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET language = '"); sql.append(SQLUtil.encodeString(language)).append("', lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -851,6 +892,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -863,11 +905,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET rules = "); sql.append(SQLUtil.encodeStringArg(rules)).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -885,6 +928,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -897,11 +941,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend return; // no need to touch anything Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET lastaccess = '"); java.util.Date now = new java.util.Date(); sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); @@ -917,6 +962,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -942,12 +988,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET hide_dir = "); sql.append(directory ? '1' : '0').append(", hide_search = ").append(search ? '1' : '0'); sql.append(", lastupdate = '"); @@ -968,6 +1015,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -987,12 +1035,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET membersonly = "); sql.append(flag ? '1' : '0').append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -1011,6 +1060,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1030,11 +1080,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = "); sql.append(token.getIndex()).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -1052,6 +1103,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1064,11 +1116,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT joinkey FROM sigs WHERE sigid = "); sql.append(cid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -1090,6 +1143,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1102,12 +1156,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET joinkey = "); sql.append(SQLUtil.encodeStringArg(key)).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -1126,6 +1181,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1170,6 +1226,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -1177,7 +1234,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET read_lvl = "); sql.append(read).append(", write_lvl = ").append(write).append(", create_lvl = ").append(create); sql.append(", delete_lvl = ").append(delete).append(", join_lvl = ").append(join); @@ -1208,6 +1265,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1228,14 +1286,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // successful audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); - boolean did_it = false; + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES sigmember WRITE;"); + boolean did_it = false; try { // perform the actual manipulation of the SIGMEMBER table... @@ -1262,6 +1321,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end else + SQLUtil.shutdown(rs); stmt.executeUpdate(sql.toString()); // update me! did_it = true; @@ -1277,8 +1337,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end try finally { // make sure the tables are unlocked before we go - Statement ulk_stmt = conn.createStatement(); - stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1298,6 +1357,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1311,11 +1371,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection and create the appropriate SELECT statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigmember WHERE sigid = "); sql.append(cid); if (!include_hidden) @@ -1338,6 +1399,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1424,11 +1486,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create a new SQL statement StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " @@ -1508,6 +1571,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1527,11 +1591,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend + term + "'"); Connection conn = null; // pooled database connection - + Statement stmt = null; + try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c, sigmember m WHERE " + "u.contactid = c.contactid AND u.uid = m.uid AND m.sigid = "); sql.append(cid).append(" AND "); @@ -1602,6 +1667,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1618,11 +1684,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create a new SQL statement StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " @@ -1659,6 +1726,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1676,11 +1744,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend logger.debug("Member level: community = " + cid + ", user = " + uid); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // a relatively simple search StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM sigmember WHERE sigid = "); @@ -1702,6 +1771,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1717,13 +1787,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend logger.debug("Delete community: community = " + cid); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record int conf_count, conf_max; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we need to reference immediately stmt.executeUpdate("LOCK TABLES sigs WRITE, sigmember WRITE, confhotlist WRITE, sigtoconf READ;"); @@ -1745,6 +1816,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new InternalStateError("CommunityCoreData.delete screwup on conference SELECT"); conf_count = rs.getInt(1); conf_max = rs.getInt(2); + SQLUtil.shutdown(rs); // record that we're now deleted created = null; @@ -1761,8 +1833,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end try finally { // make sure to unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1778,6 +1849,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1829,12 +1901,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend throw new DataException("This community has been deleted."); Connection conn = null; // database connection + Statement stmt = null; ArrayList rc = new ArrayList(); // return from this function try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1860,6 +1933,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1895,6 +1969,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend boolean hide_search) throws DataException, AccessError { Connection conn = null; // database connection + Statement stmt = null; int new_cid; // ID of the new community java.util.Date creation; // creation date! AuditRecord ar = null; // the audit record @@ -1903,7 +1978,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend try { // get a database connection and create the appropriate SELECT statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES sigs WRITE, sigftrs WRITE, propcomm WRITE, sigmember WRITE;"); try @@ -1913,6 +1988,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) // we should get 0 rows back on this one throw new AccessError("A community with that alias already exists."); + SQLUtil.shutdown(rs); // Now, here comes the BIG INSERT to create the community! sql.setLength(0); @@ -1952,6 +2028,8 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end else + SQLUtil.shutdown(rs); + // Assign the new community the default services for new communities. Set default_service = env.getSCM().getDefaultServices(ServiceControl.SVCGRP_COMMUNITY); if (default_service.size()>0) @@ -1997,8 +2075,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end try finally { // unlock the tables before we bail out - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -2017,6 +2094,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); diff --git a/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java b/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java index 972e01d..8f75149 100644 --- a/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/CommunityUserContextImpl.java @@ -48,13 +48,13 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end constructor - public String getName() + public final String getName() { return name; } // end getName - public String getAlias() + public final String getAlias() { return alias; @@ -137,7 +137,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend *-------------------------------------------------------------------------------- */ - private void setMemberValues(int granted_level, boolean member, boolean locked) + private final void setMemberValues(int granted_level, boolean member, boolean locked) { if (logger.isDebugEnabled()) logger.debug("setMemberValues(" + String.valueOf(granted_level) + ", " + String.valueOf(member) @@ -150,7 +150,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end setMemberValues - private CommunityData getData() throws DataException + private final CommunityData getData() throws DataException { if (data==null) { // attempt to load the CommunityData object @@ -169,7 +169,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getData - private CommunityData getDataNE() + private final CommunityData getDataNE() { if (data==null) { // we need to load the CommunityData... @@ -198,7 +198,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getDataNE - private void testConferenceAccess() throws DataException, AccessError + private final void testConferenceAccess() throws DataException, AccessError { if (deleted) throw new DataException("This community has been deleted."); @@ -234,12 +234,14 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end testConferenceAccess - private static CommunityUserContextImpl getCommunityPrivate(EnvUser env, Connection conn, int cid) + private static final CommunityUserContextImpl getCommunityPrivate(EnvUser env, Connection conn, int cid) throws DataException { + Statement stmt = null; + try { // create the query to find the community in the table - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT signame, alias FROM sigs WHERE sigid = "); sql.append(cid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -252,6 +254,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // initialize the object and check membership info CommunityUserContextImpl sc = new CommunityUserContextImpl(env,cid,rs.getString(1),rs.getString(2)); + SQLUtil.shutdown(rs); sc.checkMembership(conn); return sc; @@ -262,6 +265,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend throw new DataException("unable to retrieve community information: " + e.getMessage(),e); } // end catch + finally + { // shut down statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end getCommunityPrivate @@ -1290,8 +1298,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - env.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1327,8 +1334,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - env.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1419,13 +1425,14 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend testConferenceAccess(); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // get a database connection conn = env.getConnection(); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1458,6 +1465,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1478,11 +1486,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend testConferenceAccess(); Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1512,6 +1521,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1627,17 +1637,18 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend *-------------------------------------------------------------------------------- */ - static List getMemberCommunityEntries(EnvUser env) throws DataException + static final List getMemberCommunityEntries(EnvUser env) throws DataException { if (logger.isDebugEnabled()) logger.debug("getMemberCommunityEntries for user #" + String.valueOf(env.getUserID())); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sm.sigid, sm.granted_lvl, sm.locked, s.signame, s.alias " + "FROM sigmember sm, sigs s WHERE sm.sigid = s.sigid " + "AND sm.uid = "); @@ -1663,6 +1674,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1671,7 +1683,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getMemberCommunityEntries - static CommunityContext getCommunityContext(EnvUser env, int cid) throws DataException + static final CommunityContext getCommunityContext(EnvUser env, int cid) throws DataException { Connection conn = null; // pooled database connection @@ -1697,16 +1709,17 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getCommunityContext - static CommunityContext getCommunityContext(EnvUser env, String alias) throws DataException + static final CommunityContext getCommunityContext(EnvUser env, String alias) throws DataException { Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); // create the query to find the community in the table - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid, signame FROM sigs WHERE alias = '"); sql.append(SQLUtil.encodeString(alias)).append("';"); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -1719,6 +1732,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // initialize the object and check membership info CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2),alias); + SQLUtil.shutdown(rs); c.checkMembership(conn); return c; @@ -1731,19 +1745,20 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end getCommunityContext - static CommunityBackend getCommunityBackend(EnvUser env, Connection conn, int cid) throws DataException + static final CommunityBackend getCommunityBackend(EnvUser env, Connection conn, int cid) throws DataException { return getCommunityPrivate(env,conn,cid); } // end getCommunityBackend - static List searchForCommunities(EnvUser env, int field, int mode, String term, int offset, int count) + static final List searchForCommunities(EnvUser env, int field, int mode, String term, int offset, int count) throws DataException { if (logger.isDebugEnabled()) @@ -1752,11 +1767,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE "); switch (field) @@ -1822,6 +1838,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1830,18 +1847,19 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end searchForCommunities - static int getSearchCommunityCount(EnvUser env, int field, int mode, String term) + static final int getSearchCommunityCount(EnvUser env, int field, int mode, String term) throws DataException { if (logger.isDebugEnabled()) logger.debug("Community search: field = " + field + ", mode = " + mode + ", term '" + term + "'"); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE "); switch (field) @@ -1902,24 +1920,27 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end getSearchCommunityCount - static List getCommunitiesInCategory(EnvUser env, int catid, int offset, int count) throws DataException + static final List getCommunitiesInCategory(EnvUser env, int catid, int offset, int count) + throws DataException { if (logger.isDebugEnabled()) logger.debug("reading communities in category " + catid + ", offset = " + offset + ", count = " + count); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE catid = "); sql.append(catid); if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES))) @@ -1951,6 +1972,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1959,17 +1981,18 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getCommunitiesInCategory - static int getNumCommunitiesInCategory(EnvUser env, int catid) throws DataException + static final int getNumCommunitiesInCategory(EnvUser env, int catid) throws DataException { if (logger.isDebugEnabled()) logger.debug("reading communities in category " + catid); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE catid = "); sql.append(catid); if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES))) @@ -1996,6 +2019,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -2009,24 +2033,35 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend protected void checkMembership(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT granted_lvl, locked FROM sigmember WHERE sigid = "); - sql.append(cid).append(" AND uid = ").append(env.getUserID()).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (rs.next()) - { // we are a member... - if (logger.isDebugEnabled()) - logger.debug("we are a member of this community"); - setMemberValues(rs.getInt(1),true,rs.getBoolean(2)); + Statement stmt = null; - } // end if - else - { // we're NOT a member... - if (logger.isDebugEnabled()) - logger.debug("we are NOT a member of this community"); - setMemberValues(0,false,false); + try + { // look up the membership data + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT granted_lvl, locked FROM sigmember WHERE sigid = "); + sql.append(cid).append(" AND uid = ").append(env.getUserID()).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (rs.next()) + { // we are a member... + if (logger.isDebugEnabled()) + logger.debug("we are a member of this community"); + setMemberValues(rs.getInt(1),true,rs.getBoolean(2)); - } // end else + } // end if + else + { // we're NOT a member... + if (logger.isDebugEnabled()) + logger.debug("we are NOT a member of this community"); + setMemberValues(0,false,false); + + } // end else + + } // end try + finally + { // shutdown the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end checkMembership diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java index 0c63c0f..d4fd705 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -104,11 +104,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext this.confid = confid; Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build a monster query! This is like the query for retrieving the ConferenceUserContextImpl // data, except without the left outer join to the user conference membership table. @@ -140,6 +141,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -167,7 +169,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext *-------------------------------------------------------------------------------- */ - private synchronized ConferenceData getConferenceData() throws DataException + private final synchronized ConferenceData getConferenceData() throws DataException { if (confdata==null) { // attempt to load the ConferenceCommunityContext @@ -184,7 +186,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end getConferenceData - private synchronized ConferenceData getConferenceDataNE() + private final synchronized ConferenceData getConferenceDataNE() { if (confdata==null) { // we need to load the ConferenceCommunityContext... @@ -420,6 +422,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -427,7 +430,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET granted_lvl = "); sql.append(new_level).append(" WHERE sigid = ").append(this.env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); @@ -450,6 +453,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -469,13 +473,14 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET sequence = "); sql.append(seq).append(" WHERE sigid = ").append(env.getCommunityID()).append(" AND confid = "); sql.append(confid).append(';'); @@ -495,6 +500,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -527,6 +533,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end if Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -534,7 +541,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET hide_list = "); sql.append(flag ? '1' : '0').append(" WHERE sigid = ").append(env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); @@ -559,6 +566,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -698,12 +706,13 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext { ConferenceData c = getConferenceData(); Connection conn = null; + Statement stmt = null; boolean delete_core = true; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // see if we have to delete the core object as well StringBuffer sql = new StringBuffer("SELECT sigid FROM sigtoconf WHERE confid = "); @@ -711,6 +720,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) delete_core = false; // we don't delete the core yet + SQLUtil.shutdown(rs); // remove the row that links this conference to this community sql.setLength(0); @@ -734,6 +744,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java b/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java index f33a538..6e77c9e 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -85,13 +85,14 @@ class ConferenceCoreData implements ConferenceData this.confid = confid; Connection conn = null; + Statement stmt = null; try { // get a database connection from this object conn = env.getConnection(); // get the conference basic data from the database - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT * FROM confs WHERE confid = "); sql.append(confid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -99,6 +100,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("Conference #" + confid + " does not exist in the database."); loadData(rs); // load the conference data + SQLUtil.shutdown(rs); flags = new OptionSet(); loadProperties(conn); loadCustom(conn); @@ -112,6 +114,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -148,7 +151,7 @@ class ConferenceCoreData implements ConferenceData *-------------------------------------------------------------------------------- */ - private synchronized void loadData(ResultSet rs) throws SQLException + private synchronized final void loadData(ResultSet rs) throws SQLException { // "confid" field is skipped create_date = SQLUtil.getFullDateTime(rs,"createdate"); @@ -167,92 +170,138 @@ class ConferenceCoreData implements ConferenceData } // end loadData - private synchronized void loadProperties(Connection conn) throws SQLException + private synchronized final void loadProperties(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT ndx, data FROM propconf WHERE confid = "); - sql.append(confid).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - while (rs.next()) - { // load the property records one at a time - switch (rs.getInt(1)) - { // figure out which properties to load - case PROP_FLAGS: - flags.assign(rs.getString(2)); - break; + Statement stmt = null; - default: - break; + try + { // load the properties + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT ndx, data FROM propconf WHERE confid = "); + sql.append(confid).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + while (rs.next()) + { // load the property records one at a time + switch (rs.getInt(1)) + { // figure out which properties to load + case PROP_FLAGS: + flags.assign(rs.getString(2)); + break; - } // end switch + default: + break; - } // end while + } // end switch + + } // end while + + } // end try + finally + { // shutdown the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end loadProperties - private synchronized void loadCustom(Connection conn) throws SQLException + private synchronized final void loadCustom(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT htmltop, htmlbottom FROM confcustom WHERE confid = "); - sql.append(confid).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (rs.next()) - { // load the custom data and save it as SoftReferences (so it can be erased - has_custom = true; - String s; - if ((cust_top==null) || (cust_top.get()==null)) - { // retrieve the top custom block - s = rs.getString(1); - if (s!=null) - cust_top = new SoftReference(s); + Statement stmt = null; + + try + { // retrieve the custom HTML blocks + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT htmltop, htmlbottom FROM confcustom WHERE confid = "); + sql.append(confid).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (rs.next()) + { // load the custom data and save it as SoftReferences (so it can be erased + has_custom = true; + String s; + if ((cust_top==null) || (cust_top.get()==null)) + { // retrieve the top custom block + s = rs.getString(1); + if (s!=null) + cust_top = new SoftReference(s); + + } // end if + + if ((cust_bottom==null) || (cust_bottom.get()==null)) + { // retrieve the bottom custom block + s = rs.getString(2); + if (s!=null) + cust_bottom = new SoftReference(s); + + } // end if } // end if - if ((cust_bottom==null) || (cust_bottom.get()==null)) - { // retrieve the bottom custom block - s = rs.getString(2); - if (s!=null) - cust_bottom = new SoftReference(s); + } // end try + finally + { // shutdown the statement to conserve resources + SQLUtil.shutdown(stmt); - } // end if - - } // end if + } // end finally } // end loadCustom - private synchronized void touchUpdate(Connection conn) throws SQLException + private synchronized final void touchUpdate(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '"); - java.util.Date now = new java.util.Date(); - sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';'); - stmt.executeUpdate(sql.toString()); - last_update = now; + Statement stmt = null; + + try + { // set the last update field + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '"); + java.util.Date now = new java.util.Date(); + sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';'); + stmt.executeUpdate(sql.toString()); + last_update = now; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end touchUpdate - private void newProperties(Connection conn) throws SQLException + private final void newProperties(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("INSERT INTO propconf (confid, ndx, data) VALUES "); + Statement stmt = null; - // Append Property 0 - the "flags" property. - sql.append('(').append(confid).append(", ").append(PROP_FLAGS).append(", '"); - sql.append(flags.asString()).append("')"); + try + { // store off the properties + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("INSERT INTO propconf (confid, ndx, data) VALUES "); - // Finish up. - sql.append(';'); - stmt.executeUpdate(sql.toString()); + // Append Property 0 - the "flags" property. + sql.append('(').append(confid).append(", ").append(PROP_FLAGS).append(", '"); + sql.append(flags.asString()).append("')"); + + // Finish up. + sql.append(';'); + stmt.executeUpdate(sql.toString()); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end newProperties - private synchronized void updateProperties(BitSet delta) throws DataException + private synchronized final void updateProperties(BitSet delta) throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (delta.get(PROP_FLAGS)) @@ -273,13 +322,14 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end updateProperties - private synchronized void updateProperties() throws DataException + private synchronized final void updateProperties() throws DataException { updateProperties(ALL_PROPS); @@ -345,6 +395,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try @@ -352,7 +403,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); // get a list of all aliases - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = "); sql.append(confid).append(" ORDER BY alias;"); @@ -370,6 +421,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -384,6 +436,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try @@ -391,7 +444,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); // get a list of all hosts (with user info) - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, c.family_name, " + "c.locality, c.region, c.country FROM users u, contacts c, confmember m " @@ -418,6 +471,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -507,6 +561,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -514,7 +569,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE confs SET read_lvl = "); sql.append(read).append(", post_lvl = ").append(post).append(", create_lvl = ").append(create); sql.append(", hide_lvl = ").append(hide).append(", nuke_lvl = ").append(nuke).append(", change_lvl = "); @@ -547,6 +602,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -560,6 +616,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -567,7 +624,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE confs SET name = '"); sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -592,6 +649,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -605,13 +663,14 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); // create the SQL statement - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE confs SET descr = '"); sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '"); java.util.Date now = new java.util.Date(); @@ -632,6 +691,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -644,13 +704,14 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confalias WRITE;"); try { // first check to see if the alias already exists @@ -666,6 +727,8 @@ class ConferenceCoreData implements ConferenceData } // end if + SQLUtil.shutdown(rs); + // now add it! sql.setLength(0); sql.append("INSERT INTO confalias (confid, alias) VALUES (").append(confid).append(", '"); @@ -675,8 +738,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // make sure we unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -693,6 +755,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -706,6 +769,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -713,7 +777,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); boolean did_it = false; - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confalias WRITE;"); try { // first check to see how many aliases there are @@ -738,6 +802,8 @@ class ConferenceCoreData implements ConferenceData } // end if + SQLUtil.shutdown(rs); + // OK, go delete the row (or not, if this alias is not in the table) sql.setLength(0); sql.append("DELETE FROM confalias WHERE confid = ").append(confid).append(" AND alias = '"); @@ -747,8 +813,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // make sure we unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -770,6 +835,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -783,6 +849,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record try @@ -790,7 +857,7 @@ class ConferenceCoreData implements ConferenceData conn = env.getConnection(); boolean did_it = false; - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confmember WRITE;"); try { // how we go about this depends on whether we're adding or removing @@ -815,6 +882,7 @@ class ConferenceCoreData implements ConferenceData } // end else + SQLUtil.shutdown(rs); stmt.executeUpdate(sql.toString()); did_it = true; @@ -830,8 +898,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // make sure we unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -851,6 +918,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -875,11 +943,12 @@ class ConferenceCoreData implements ConferenceData return cached_alias; Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement and execute it StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = "); @@ -899,6 +968,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -912,6 +982,7 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record short new_topic_num; // sequential number of the new topic int new_topic_id; // ID of the new topic @@ -920,7 +991,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we need to use so we can update them stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, postdata WRITE;"); @@ -946,6 +1017,7 @@ class ConferenceCoreData implements ConferenceData if (!(rs.next())) throw new InternalStateError("createNewTopic() could not get back inserted Topic ID"); new_topic_id = rs.getInt(1); + SQLUtil.shutdown(rs); // insert the "header" for the "zero post" in the topic sql.setLength(0); @@ -961,6 +1033,7 @@ class ConferenceCoreData implements ConferenceData if (!(rs.next())) throw new InternalStateError("createNewTopic() could not get back inserted zero post ID"); long zero_post_id = rs.getLong(1); + SQLUtil.shutdown(rs); // insert the post data sql.setLength(0); @@ -987,8 +1060,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // we need to unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1001,6 +1073,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1032,9 +1105,11 @@ class ConferenceCoreData implements ConferenceData if (deleted) throw new DataException("This conference has been deleted."); + Statement stmt = null; + try { // update the last update date - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '"); sql.append(SQLUtil.encodeDate(date)).append("' WHERE confid = ").append(confid).append(';'); stmt.executeUpdate(sql.toString()); @@ -1046,6 +1121,11 @@ class ConferenceCoreData implements ConferenceData throw new DataException("Database error updating conference: " + e.getMessage(),e); } // end catch + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end touchUpdate @@ -1093,11 +1173,12 @@ class ConferenceCoreData implements ConferenceData ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create a new SQL statement StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " @@ -1131,6 +1212,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1145,11 +1227,12 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the statement StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM confmember WHERE confid = "); @@ -1169,6 +1252,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1197,13 +1281,14 @@ class ConferenceCoreData implements ConferenceData throw new DataException("This conference has been deleted."); Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record int topic_count, topic_max; // count and maximum topic try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock tables on the critical stuff that MUST be deleted now stmt.executeUpdate("LOCK TABLES confs WRITE, confalias WRITE, topics READ;"); @@ -1226,6 +1311,7 @@ class ConferenceCoreData implements ConferenceData throw new InternalStateError("ConferenceCoreData.delete screwup on topic SELECT"); topic_count = rs.getInt(1); topic_max = rs.getInt(2); + SQLUtil.shutdown(rs); // record that we're now deleted create_date = null; @@ -1239,8 +1325,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1256,6 +1341,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1366,10 +1452,12 @@ class ConferenceCoreData implements ConferenceData throw new IndexOutOfBoundsException("invalid custom block selector"); Connection conn = null; + Statement stmt = null; + try { // get a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // build the right SQL command StringBuffer sql = null; @@ -1418,6 +1506,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1427,10 +1516,12 @@ class ConferenceCoreData implements ConferenceData public synchronized void removeCustomBlocks() throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // execute the delete statement stmt.executeUpdate("DELETE FROM confcustom WHERE confid = " + confid + ";"); @@ -1452,6 +1543,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1468,6 +1560,7 @@ class ConferenceCoreData implements ConferenceData throws DataException { Connection conn = null; // database connection + Statement stmt = null; AuditRecord ar = null; // audit record int new_confid; // new conference ID short new_sequence; // new sequence number @@ -1480,7 +1573,7 @@ class ConferenceCoreData implements ConferenceData try { // start by locking all the tables we need conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confs WRITE, sigtoconf WRITE, confalias WRITE, confmember WRITE, " + "propconf WRITE;"); @@ -1505,6 +1598,7 @@ class ConferenceCoreData implements ConferenceData if (!(rs.next())) throw new InternalStateError("bogus query in createConference - must return at least 1 row!"); new_sequence = (short)(rs.getShort(1) + 10); + SQLUtil.shutdown(rs); // insert the record into the conferences table! sql.setLength(0); @@ -1546,6 +1640,7 @@ class ConferenceCoreData implements ConferenceData if (!(rs.next())) throw new InternalStateError("bogus query in createConference - must get new confid!"); new_confid = rs.getInt(1); + SQLUtil.shutdown(rs); // Make the insert into the confalias table to give the conference an alias. sql.setLength(0); @@ -1581,8 +1676,7 @@ class ConferenceCoreData implements ConferenceData } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1600,6 +1694,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); diff --git a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java index 01918c9..d8280ff 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -51,25 +51,25 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end constructor - public String getName() + public final String getName() { return name; } // end getName - public String getDescription() + public final String getDescription() { return description; } // end getDescription - public java.util.Date getCreated() + public final java.util.Date getCreated() { return created; } // end getCreated - public int getGrantsLevel() + public final int getGrantsLevel() { return grants_level; @@ -211,7 +211,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend *-------------------------------------------------------------------------------- */ - private ConferenceCommunityContext getConferenceData() throws DataException + private final ConferenceCommunityContext getConferenceData() throws DataException { if (confdata==null) { // attempt to load the ConferenceCommunityContext @@ -230,7 +230,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end getConferenceData - private ConferenceCommunityContext getConferenceDataNE() + private final ConferenceCommunityContext getConferenceDataNE() { if (confdata==null) { // we need to load the ConferenceCommunityContext... @@ -260,7 +260,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end getConferenceDataNE - private void recalcLevel(int new_level) + private final void recalcLevel(int new_level) { level = env.getCommunity().realCommunityLevel(); @@ -282,14 +282,16 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end recalcLevel - private void tryLoadSettings(Connection conn) throws DataException + private final void tryLoadSettings(Connection conn) throws DataException { if (deleted) return; // this is a no-op + Statement stmt = null; + try { // look up the conference settings for this user - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT * FROM confsettings WHERE confid = "); sql.append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -318,6 +320,11 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend throw new DataException("Unable to load conference settings: " + e.getMessage(),e); } // end catch + finally + { // shutdown the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end tryLoadSettings @@ -769,11 +776,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend throw new DataException("This conference has been deleted."); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (settings_loaded) @@ -806,6 +814,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -817,6 +826,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (deleted || env.getUser().userIsAnonymous()) return false; Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection @@ -828,7 +838,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend // JOIN to topicsettings, which in turn necessitates the IFNULL guards on references to topicsettings // columns in the WHERE clause (as there's only a topicsettings row if the user has read anything // in this topic or otherwise set it). - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT t.topicid FROM topics t LEFT JOIN topicsettings s " + "ON t.topicid = s.topicid AND s.uid = "); sql.append(env.getUserID()).append(" WHERE t.confid = ").append(confid); @@ -849,6 +859,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -934,12 +945,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend // now we need to reset our last post date Connection conn = null; + Statement stmt = null; + try { // get a connection conn = env.getConnection(); // create a new record in topicsettings (we WERE the first to post in the topic after all!) - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("INSERT INTO topicsettings (topicid, uid, last_post) VALUES ("); sql.append(new_topic_inf.getTopicID()).append(", ").append(env.getUserID()).append(", '"); sql.append(SQLUtil.encodeDate(new_topic_inf.getCreateDate())).append("');"); @@ -959,6 +972,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1009,11 +1023,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend return; // anonymous user can't fixseen Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables that we need stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;"); @@ -1031,6 +1046,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ArrayList tmp = new ArrayList(); while (rs.next()) tmp.add(new FixSeenHelper(rs.getInt(1),rs.getInt(2),rs.getBoolean(3))); + SQLUtil.shutdown(rs); // now iterate over the list and call doFix on each one Iterator it = tmp.iterator(); @@ -1048,8 +1064,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end try finally { // make sure we unlock everything before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1062,6 +1077,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1078,12 +1094,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to retrieve all posters StringBuffer sql = @@ -1114,6 +1131,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1144,12 +1162,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to retrieve all readers StringBuffer sql = @@ -1180,6 +1199,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1271,11 +1291,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public boolean isInHotlist() { Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // do a quickie query StringBuffer sql = new StringBuffer("SELECT sequence FROM confhotlist WHERE uid = "); @@ -1293,6 +1314,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1302,11 +1324,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void addToHotlist() throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confhotlist WRITE;"); try @@ -1325,6 +1348,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (!(rs.next())) throw new InternalStateError("bogus query result on addToHotlist"); int new_sequence = rs.getInt(1) + 100; + SQLUtil.shutdown(rs); // add the new record sql.setLength(0); @@ -1336,8 +1360,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end try finally { // make sure the table is unlocked before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1350,6 +1373,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1373,11 +1397,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void removeFromHotlist() throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the DELETE statement and just execute it blind (if this conference is not in the hotlist, // the DELETE is a no-op). @@ -1395,6 +1420,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1404,11 +1430,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void setHotlistSequence(int seq) throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the UPDATE statement and just execute it blind (if this conference is not in the hotlist, // the UPDATE is a no-op). @@ -1426,6 +1453,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1521,12 +1549,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build the SQL statement. StringBuffer sql = new StringBuffer("SELECT c.email, "); @@ -1574,6 +1603,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1645,13 +1675,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend throw new AccessError("You are not permitted to search for posts within this conference."); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // get a database connection conn = env.getConnection(); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1679,6 +1710,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1701,11 +1733,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend throw new AccessError("You are not permitted to search for posts within this conference."); Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1730,6 +1763,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1777,30 +1811,42 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (deleted || env.getUser().userIsAnonymous()) return; // anonymous user can't update squat - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer(); + Statement stmt = null; - java.util.Date now = new java.util.Date(); - if (settings_loaded) - { // generate an update statement - sql.append("UPDATE confsettings SET last_read = '").append(SQLUtil.encodeDate(now)); - sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); + try + { // create the SQL statement + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer(); - } // end if - else - { // need to insert a confsettings row - sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); - sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); - sql.append("', '").append(SQLUtil.encodeDate(now)).append("');"); + java.util.Date now = new java.util.Date(); + if (settings_loaded) + { // generate an update statement + sql.append("UPDATE confsettings SET last_read = '").append(SQLUtil.encodeDate(now)); + sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()); + sql.append(';'); - } // end else + } // end if + else + { // need to insert a confsettings row + sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); + sql.append("', '").append(SQLUtil.encodeDate(now)).append("');"); - // execute the statement - stmt.executeUpdate(sql.toString()); + } // end else - // save off the values to our local fields - last_read = now; - settings_loaded = true; + // execute the statement + stmt.executeUpdate(sql.toString()); + + // save off the values to our local fields + last_read = now; + settings_loaded = true; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end touchRead @@ -1809,29 +1855,41 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (deleted || env.getUser().userIsAnonymous()) return; // anonymous user can't update squat - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer(); + Statement stmt = null; - if (settings_loaded) - { // generate an update statement - sql.append("UPDATE confsettings SET last_post = '").append(SQLUtil.encodeDate(post_date)); - sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); + try + { // create the statement + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer(); - } // end if - else - { // need to insert a confsettings row - sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); - sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); - sql.append("', '").append(SQLUtil.encodeDate(post_date)).append("');"); + if (settings_loaded) + { // generate an update statement + sql.append("UPDATE confsettings SET last_post = '").append(SQLUtil.encodeDate(post_date)); + sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()); + sql.append(';'); - } // end else + } // end if + else + { // need to insert a confsettings row + sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); + sql.append("', '").append(SQLUtil.encodeDate(post_date)).append("');"); - // execute the statement - stmt.executeUpdate(sql.toString()); + } // end else - // save off the values to our local fields - last_post = post_date; - settings_loaded = true; + // execute the statement + stmt.executeUpdate(sql.toString()); + + // save off the values to our local fields + last_post = post_date; + settings_loaded = true; + + } // end try + finally + { // shut down statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end touchRead @@ -1913,18 +1971,19 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend *-------------------------------------------------------------------------------- */ - static List getCommunityConferences(EnvCommunity env) throws DataException + static final List getCommunityConferences(EnvCommunity env) throws DataException { if (logger.isDebugEnabled()) logger.debug("getCommunityConferences for community # " + env.getCommunityID() + ", user #" + env.getUserID()); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build a monster query! The idea is that we get the basic info of all conferences linked to the // community, as well as the user level (within the conference) that gets granted to all members of the @@ -1965,6 +2024,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1973,18 +2033,19 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end getCommunityConferences - static ConferenceContext getConference(EnvCommunity env, int confid) throws DataException + static final ConferenceContext getConference(EnvCommunity env, int confid) throws DataException { if (logger.isDebugEnabled()) logger.debug("getConference(#" + confid + ") for community # " + env.getCommunityID() + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build a monster query! This is like the query in getCommunityConferences, except that we add the // conference ID as a search term (thus we can return at most one row). @@ -2016,24 +2077,26 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end getConference - static ConferenceContext getConference(EnvCommunity env, String alias) throws DataException + static final ConferenceContext getConference(EnvCommunity env, String alias) throws DataException { if (logger.isDebugEnabled()) logger.debug("getConference(\"" + alias + "\") for community # " + env.getCommunityID() + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build a monster query! This is similar to the other getConference query, except that now we // have an extra table in the query (confalias) and we match on that. Notice that pretty much @@ -2067,24 +2130,26 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end getConference - static List getUserHotlist(EnvUser env) throws DataException + static final List getUserHotlist(EnvUser env) throws DataException { if (logger.isDebugEnabled()) logger.debug("getUserHotlist for user #" + env.getUserID()); Connection conn = null; // pooled database connection + Statement stmt = null; ArrayList rc = new ArrayList(); // return from this function try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build a monster query! We pull the CommunityID and ConfID entries from the confhotlist table, // but we need to pull in "confs" and "confmember" (left joined) to get enough data to create @@ -2138,6 +2203,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java b/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java index 075b011..e95e3a4 100644 --- a/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java +++ b/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -213,7 +213,7 @@ class ContactInfoImpl implements ContactInfo, Stashable *-------------------------------------------------------------------------------- */ - private void makeEmpty(int owner_uid, int owner_cid) + private final void makeEmpty(int owner_uid, int owner_cid) { this.contactid = -1; this.given_name = null; @@ -244,11 +244,13 @@ class ContactInfoImpl implements ContactInfo, Stashable } // end makeEmpty - private void loadData(Connection conn, int contactid) throws DataException + private final void loadData(Connection conn, int contactid) throws DataException { + Statement stmt = null; + try { // do a simple SELECT in contacts to look this up - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = "); sql.append(contactid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -300,6 +302,11 @@ class ContactInfoImpl implements ContactInfo, Stashable throw new DataException("Unable to look up contact info: " + e.getMessage(),e); } // end catch + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end loadData @@ -938,141 +945,151 @@ class ContactInfoImpl implements ContactInfo, Stashable if (logger.isDebugEnabled()) logger.debug("stashing contact ID " + contactid); java.util.Date update = null; - Statement stmt = conn.createStatement(); - StringBuffer buf; + Statement stmt = null; - if (image_hook!=null) - { // call the image hook to store an image and get a new photo URL (where applicable) - String new_photo_url = image_hook.doImage(conn); - if (new_photo_url!=null) - photo_url = new_photo_url; - image_hook = null; + try + { // start updating the contact in the database + stmt = conn.createStatement(); + StringBuffer buf; - } // end if + if (image_hook!=null) + { // call the image hook to store an image and get a new photo URL (where applicable) + String new_photo_url = image_hook.doImage(conn); + if (new_photo_url!=null) + photo_url = new_photo_url; + image_hook = null; - if (contactid>=0) - { // this involves updating an existing record - buf = new StringBuffer("UPDATE contacts SET given_name = "); - buf.append(SQLUtil.encodeStringArg(given_name)).append(", family_name = "); - buf.append(SQLUtil.encodeStringArg(family_name)).append(", middle_init = "); - if (middle_initial==' ') - buf.append("NULL"); - else - buf.append('\'').append(middle_initial).append('\''); - buf.append(", prefix = ").append(SQLUtil.encodeStringArg(prefix)); - buf.append(", suffix = ").append(SQLUtil.encodeStringArg(suffix)); - buf.append(", company = ").append(SQLUtil.encodeStringArg(company)); - buf.append(", addr1 = ").append(SQLUtil.encodeStringArg(addr1)); - buf.append(", addr2 = ").append(SQLUtil.encodeStringArg(addr2)); - buf.append(", locality = ").append(SQLUtil.encodeStringArg(locality)); - buf.append(", region = ").append(SQLUtil.encodeStringArg(region)); - buf.append(", pcode = ").append(SQLUtil.encodeStringArg(postal_code)); - buf.append(", country = ").append(SQLUtil.encodeStringArg(country)); - buf.append(", phone = ").append(SQLUtil.encodeStringArg(phone)); - buf.append(", fax = ").append(SQLUtil.encodeStringArg(fax)); - buf.append(", mobile = ").append(SQLUtil.encodeStringArg(mobile)); - buf.append(", email = ").append(SQLUtil.encodeStringArg(email)); - buf.append(", pvt_addr = ").append(private_addr ? '1' : '0'); - buf.append(", pvt_phone = ").append(private_phone ? '1' : '0'); - buf.append(", pvt_fax = ").append(private_fax ? '1' : '0'); - buf.append(", pvt_email = ").append(private_email ? '1' : '0'); - buf.append(", photo_url = ").append(SQLUtil.encodeStringArg(photo_url)); - buf.append(", url = ").append(SQLUtil.encodeStringArg(url)).append(", lastupdate = '"); - update = new java.util.Date(); - buf.append(SQLUtil.encodeDate(update)).append("' WHERE contactid = ").append(contactid).append(';'); - - stmt.executeUpdate(buf.toString()); + } // end if - } // end if - else - { // this involves creating a new record - if (owner_cid>=0) - stmt.executeUpdate("LOCK TABLES contacts WRITE, sigs WRITE;"); - else - stmt.executeUpdate("LOCK TABLES contacts WRITE, users WRITE;"); - - try - { // insert contact record data - buf = new StringBuffer("INSERT INTO contacts (given_name, family_name, middle_init, prefix, " - + "suffix, company, addr1, addr2, locality, region, pcode, country, " - + "phone, fax, mobile, email, pvt_addr, pvt_phone, pvt_fax, pvt_email, " - + "owner_uid, owner_sigid, photo_url, url, lastupdate) VALUES ("); - buf.append(SQLUtil.encodeStringArg(given_name)).append(", "); - buf.append(SQLUtil.encodeStringArg(family_name)).append(", "); + if (contactid>=0) + { // this involves updating an existing record + buf = new StringBuffer("UPDATE contacts SET given_name = "); + buf.append(SQLUtil.encodeStringArg(given_name)).append(", family_name = "); + buf.append(SQLUtil.encodeStringArg(family_name)).append(", middle_init = "); if (middle_initial==' ') - buf.append("NULL, "); + buf.append("NULL"); else - buf.append('\'').append(middle_initial).append("', "); - buf.append(SQLUtil.encodeStringArg(prefix)).append(", "); - buf.append(SQLUtil.encodeStringArg(suffix)).append(", "); - buf.append(SQLUtil.encodeStringArg(company)).append(", "); - buf.append(SQLUtil.encodeStringArg(addr1)).append(", "); - buf.append(SQLUtil.encodeStringArg(addr2)).append(", "); - buf.append(SQLUtil.encodeStringArg(locality)).append(", "); - buf.append(SQLUtil.encodeStringArg(region)).append(", "); - buf.append(SQLUtil.encodeStringArg(postal_code)).append(", "); - buf.append(SQLUtil.encodeStringArg(country)).append(", "); - buf.append(SQLUtil.encodeStringArg(phone)).append(", "); - buf.append(SQLUtil.encodeStringArg(fax)).append(", "); - buf.append(SQLUtil.encodeStringArg(mobile)).append(", "); - buf.append(SQLUtil.encodeStringArg(email)).append(", "); - buf.append(private_addr ? '1' : '0').append(", "); - buf.append(private_phone ? '1' : '0').append(", "); - buf.append(private_fax ? '1' : '0').append(", "); - buf.append(private_email ? '1' : '0').append(", "); - buf.append(owner_uid).append(", ").append(owner_cid).append(", "); - buf.append(SQLUtil.encodeStringArg(photo_url)).append(", "); - buf.append(SQLUtil.encodeStringArg(url)).append(", '"); + buf.append('\'').append(middle_initial).append('\''); + buf.append(", prefix = ").append(SQLUtil.encodeStringArg(prefix)); + buf.append(", suffix = ").append(SQLUtil.encodeStringArg(suffix)); + buf.append(", company = ").append(SQLUtil.encodeStringArg(company)); + buf.append(", addr1 = ").append(SQLUtil.encodeStringArg(addr1)); + buf.append(", addr2 = ").append(SQLUtil.encodeStringArg(addr2)); + buf.append(", locality = ").append(SQLUtil.encodeStringArg(locality)); + buf.append(", region = ").append(SQLUtil.encodeStringArg(region)); + buf.append(", pcode = ").append(SQLUtil.encodeStringArg(postal_code)); + buf.append(", country = ").append(SQLUtil.encodeStringArg(country)); + buf.append(", phone = ").append(SQLUtil.encodeStringArg(phone)); + buf.append(", fax = ").append(SQLUtil.encodeStringArg(fax)); + buf.append(", mobile = ").append(SQLUtil.encodeStringArg(mobile)); + buf.append(", email = ").append(SQLUtil.encodeStringArg(email)); + buf.append(", pvt_addr = ").append(private_addr ? '1' : '0'); + buf.append(", pvt_phone = ").append(private_phone ? '1' : '0'); + buf.append(", pvt_fax = ").append(private_fax ? '1' : '0'); + buf.append(", pvt_email = ").append(private_email ? '1' : '0'); + buf.append(", photo_url = ").append(SQLUtil.encodeStringArg(photo_url)); + buf.append(", url = ").append(SQLUtil.encodeStringArg(url)).append(", lastupdate = '"); update = new java.util.Date(); - buf.append(SQLUtil.encodeDate(update)).append("');"); - - stmt.executeUpdate(buf.toString()); - - // now read back the contact ID we just added - int new_contactid; - ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();"); - if (rs.next()) - { // found the contact ID... - new_contactid = rs.getInt(1); - if (logger.isDebugEnabled()) - logger.debug("created new contact ID " + new_contactid); - - } // end if - else - { // error reading back the contact ID - logger.error("unable to read back contact ID"); - throw new DataException("unable to read back new contact ID"); - - } // end else - - // and patch the database table so we know what our contact ID is - buf.setLength(0); - if (owner_cid>=0) - { // update the SIGS table - buf.append("UPDATE sigs SET contactid = ").append(new_contactid).append(" WHERE sigid = "); - buf.append(owner_cid).append(';'); - - } // end if - else - { // update the USERS table - buf.append("UPDATE users SET contactid = ").append(new_contactid).append(" WHERE uid = "); - buf.append(owner_uid).append(';'); - - } // end else - - stmt.executeUpdate(buf.toString()); - - contactid = new_contactid; // save link - - } // end try - finally - { // make sure the tables get unlocked - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); - - } // end finally + buf.append(SQLUtil.encodeDate(update)).append("' WHERE contactid = ").append(contactid).append(';'); - } // end else + stmt.executeUpdate(buf.toString()); + + } // end if + else + { // this involves creating a new record + if (owner_cid>=0) + stmt.executeUpdate("LOCK TABLES contacts WRITE, sigs WRITE;"); + else + stmt.executeUpdate("LOCK TABLES contacts WRITE, users WRITE;"); + + try + { // insert contact record data + buf = new StringBuffer("INSERT INTO contacts (given_name, family_name, middle_init, prefix, " + + "suffix, company, addr1, addr2, locality, region, pcode, country, " + + "phone, fax, mobile, email, pvt_addr, pvt_phone, pvt_fax, pvt_email, " + + "owner_uid, owner_sigid, photo_url, url, lastupdate) VALUES ("); + buf.append(SQLUtil.encodeStringArg(given_name)).append(", "); + buf.append(SQLUtil.encodeStringArg(family_name)).append(", "); + if (middle_initial==' ') + buf.append("NULL, "); + else + buf.append('\'').append(middle_initial).append("', "); + buf.append(SQLUtil.encodeStringArg(prefix)).append(", "); + buf.append(SQLUtil.encodeStringArg(suffix)).append(", "); + buf.append(SQLUtil.encodeStringArg(company)).append(", "); + buf.append(SQLUtil.encodeStringArg(addr1)).append(", "); + buf.append(SQLUtil.encodeStringArg(addr2)).append(", "); + buf.append(SQLUtil.encodeStringArg(locality)).append(", "); + buf.append(SQLUtil.encodeStringArg(region)).append(", "); + buf.append(SQLUtil.encodeStringArg(postal_code)).append(", "); + buf.append(SQLUtil.encodeStringArg(country)).append(", "); + buf.append(SQLUtil.encodeStringArg(phone)).append(", "); + buf.append(SQLUtil.encodeStringArg(fax)).append(", "); + buf.append(SQLUtil.encodeStringArg(mobile)).append(", "); + buf.append(SQLUtil.encodeStringArg(email)).append(", "); + buf.append(private_addr ? '1' : '0').append(", "); + buf.append(private_phone ? '1' : '0').append(", "); + buf.append(private_fax ? '1' : '0').append(", "); + buf.append(private_email ? '1' : '0').append(", "); + buf.append(owner_uid).append(", ").append(owner_cid).append(", "); + buf.append(SQLUtil.encodeStringArg(photo_url)).append(", "); + buf.append(SQLUtil.encodeStringArg(url)).append(", '"); + update = new java.util.Date(); + buf.append(SQLUtil.encodeDate(update)).append("');"); + + stmt.executeUpdate(buf.toString()); + + // now read back the contact ID we just added + int new_contactid; + ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();"); + if (rs.next()) + { // found the contact ID... + new_contactid = rs.getInt(1); + if (logger.isDebugEnabled()) + logger.debug("created new contact ID " + new_contactid); + + } // end if + else + { // error reading back the contact ID + logger.error("unable to read back contact ID"); + throw new DataException("unable to read back new contact ID"); + + } // end else + + // and patch the database table so we know what our contact ID is + buf.setLength(0); + if (owner_cid>=0) + { // update the SIGS table + buf.append("UPDATE sigs SET contactid = ").append(new_contactid).append(" WHERE sigid = "); + buf.append(owner_cid).append(';'); + + } // end if + else + { // update the USERS table + buf.append("UPDATE users SET contactid = ").append(new_contactid).append(" WHERE uid = "); + buf.append(owner_uid).append(';'); + + } // end else + + stmt.executeUpdate(buf.toString()); + + contactid = new_contactid; // save link + + } // end try + finally + { // make sure the tables get unlocked + SQLUtil.unlockTables(conn); + + } // end finally + + } // end else + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally last_update = update; // save last update date is_modified = false; diff --git a/src/com/silverwrist/venice/core/impl/ImageStore.java b/src/com/silverwrist/venice/core/impl/ImageStore.java index e1a6119..0917347 100644 --- a/src/com/silverwrist/venice/core/impl/ImageStore.java +++ b/src/com/silverwrist/venice/core/impl/ImageStore.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -89,12 +89,13 @@ class ImageStore implements BinaryData public InputStream getData() throws DataException { Connection conn = null; + Statement stmt = null; InputStream rc = null; try { // open up a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Create the SQL we need to retrieve the image. StringBuffer sql = new StringBuffer("SELECT data FROM imagestore WHERE imgid = "); @@ -128,6 +129,7 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -141,17 +143,18 @@ class ImageStore implements BinaryData *-------------------------------------------------------------------------------- */ - static ImageStore loadImageByID(EnvEngine env, int id) throws DataException + static final ImageStore loadImageByID(EnvEngine env, int id) throws DataException { if (logger.isDebugEnabled()) logger.debug("loadImageByID # " + id); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT mimetype, length FROM imagestore WHERE imgid = "); sql.append(id).append(';'); @@ -173,14 +176,15 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end loadImageByID - static int storeNewImage(Connection conn, short type, int owner, String mime, int length, InputStream data) - throws SQLException + static final int storeNewImage(Connection conn, short type, int owner, String mime, int length, + InputStream data) throws SQLException { // Create the SQL statement that inserts the image into the store. StringBuffer sql = @@ -190,22 +194,34 @@ class ImageStore implements BinaryData if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); - // Prepare the statement, set the BLOB parameter, and execute it. - PreparedStatement stmt = conn.prepareStatement(sql.toString()); - stmt.setBinaryStream(1,data,length); - stmt.executeUpdate(); + PreparedStatement stmt = null; + Statement stmt2 = null; - // Get the ID of the new image and return it. - Statement stmt2 = conn.createStatement(); - ResultSet rs = stmt2.executeQuery("SELECT LAST_INSERT_ID();"); - if (!(rs.next())) - throw new InternalStateError("storeNewImage(): Unable to get new image ID!"); - return rs.getInt(1); + try + { // Prepare the statement, set the BLOB parameter, and execute it. + stmt = conn.prepareStatement(sql.toString()); + stmt.setBinaryStream(1,data,length); + stmt.executeUpdate(); + + // Get the ID of the new image and return it. + stmt2 = conn.createStatement(); + ResultSet rs = stmt2.executeQuery("SELECT LAST_INSERT_ID();"); + if (!(rs.next())) + throw new InternalStateError("storeNewImage(): Unable to get new image ID!"); + return rs.getInt(1); + + } // end try + finally + { // shut down the statements to conserve resources + SQLUtil.shutdown(stmt); + SQLUtil.shutdown(stmt2); + + } // end finally } // end storeNewImage - static int storeNewImage(EnvEngine env, short type, int owner, String mime, int length, InputStream data) - throws DataException + static final int storeNewImage(EnvEngine env, short type, int owner, String mime, int length, + InputStream data) throws DataException { if (logger.isDebugEnabled()) logger.debug("storeNewImage: type " + type + ", owner " + owner + ", mime " + mime + ", len " + length); @@ -232,7 +248,7 @@ class ImageStore implements BinaryData } // end storeNewImage - static void replaceImage(Connection conn, int imgid, String mime, int length, InputStream data) + static final void replaceImage(Connection conn, int imgid, String mime, int length, InputStream data) throws SQLException { // Create the SQL statement that inserts the image into the store. @@ -242,14 +258,24 @@ class ImageStore implements BinaryData if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); - // Prepare the statement, set the BLOB parameter, and execute it. - PreparedStatement stmt = conn.prepareStatement(sql.toString()); - stmt.setBinaryStream(1,data,length); - stmt.executeUpdate(); + PreparedStatement stmt = null; + + try + { // Prepare the statement, set the BLOB parameter, and execute it. + stmt = conn.prepareStatement(sql.toString()); + stmt.setBinaryStream(1,data,length); + stmt.executeUpdate(); + + } // end try + finally + { // shut down the sattement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end replaceImage - static void replaceImage(EnvEngine env, int imgid, String mime, int length, InputStream data) + static final void replaceImage(EnvEngine env, int imgid, String mime, int length, InputStream data) throws DataException { if (logger.isDebugEnabled()) diff --git a/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java b/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java index c950ddf..4c6529e 100644 --- a/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java +++ b/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -100,14 +100,25 @@ class PublishedMessageImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - private static String quickGetUserName(Connection conn, int uid) throws SQLException + private static final String quickGetUserName(Connection conn, int uid) throws SQLException { - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + String.valueOf(uid) + ";"); - if (rs.next()) - return rs.getString(1); - else - return "(unknown)"; + Statement stmt = null; + + try + { // run the quick select + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + String.valueOf(uid) + ";"); + if (rs.next()) + return rs.getString(1); + else + return "(unknown)"; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end quickGetUserName @@ -217,12 +228,12 @@ class PublishedMessageImpl implements TopicMessageContext if (text_cache==null) { // we don't have the body text yet, go get it Connection conn = null; + Statement stmt = null; try { // use a database connection to get the body text conn = env.getConnection(); - - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " + String.valueOf(postid) + ";"); if (rs.next()) @@ -239,6 +250,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -323,6 +335,12 @@ class PublishedMessageImpl implements TopicMessageContext } // end attachData + public void attachData(String m_type, String file, byte[] data) throws AccessError, DataException + { + throw new AccessError("You are not permitted to add an attachment to this message."); + + } // end attachData + public boolean canPublish() { return false; @@ -349,19 +367,32 @@ class PublishedMessageImpl implements TopicMessageContext } // end getPostLink + public void moveToTopic(int newtopicid) throws DataException + { + throw new DataException("Cannot move a message that has already been published."); + + } // end moveToTopic + + public boolean canMove() + { + return false; + + } // end canMove + /*-------------------------------------------------------------------------------- * Static operations usable only within package *-------------------------------------------------------------------------------- */ - static void backfillCache(List cache_list, int desired_size, EnvEngine env) throws DataException + static final void backfillCache(List cache_list, int desired_size, EnvEngine env) throws DataException { Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the statement to retrieve the post information StringBuffer sql = @@ -390,6 +421,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -399,11 +431,12 @@ class PublishedMessageImpl implements TopicMessageContext static void backfillReturn(List return_list, EnvEngine env) throws DataException { Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // How many posts have been published anyway? ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM postpublish;"); @@ -443,6 +476,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/PublishedMessageTopicImpl.java b/src/com/silverwrist/venice/core/impl/PublishedMessageTopicImpl.java index d3e7d22..c8600a2 100644 --- a/src/com/silverwrist/venice/core/impl/PublishedMessageTopicImpl.java +++ b/src/com/silverwrist/venice/core/impl/PublishedMessageTopicImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -61,10 +61,12 @@ class PublishedMessageTopicImpl implements TopicContext PublishedMessageTopicImpl(EnvEngine env, int cid, int topicid) throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // query the topics table for information StringBuffer sql = @@ -110,6 +112,7 @@ class PublishedMessageTopicImpl implements TopicContext } // end catch finally { // release the connection + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java b/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java index b4bf747..9a2b6a6 100644 --- a/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java +++ b/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -98,11 +98,12 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor public void setSequence(int seq) throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the UPDATE statement and just execute it blind (if this sidebox is not in the list, // the UPDATE is a no-op). @@ -121,6 +122,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -130,11 +132,12 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor public void remove() throws DataException { Connection conn = null; - + Statement stmt = null; + try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the DELETE statement and just execute it blind (if this conference is not in the hotlist, // the DELETE is a no-op). @@ -151,6 +154,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/TopicMessageFoundHelper.java b/src/com/silverwrist/venice/core/impl/TopicMessageFoundHelper.java index 99f5a01..f266e0f 100644 --- a/src/com/silverwrist/venice/core/impl/TopicMessageFoundHelper.java +++ b/src/com/silverwrist/venice/core/impl/TopicMessageFoundHelper.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -19,6 +19,7 @@ package com.silverwrist.venice.core.impl; import java.sql.*; import java.util.*; +import com.silverwrist.venice.db.SQLUtil; class TopicMessageFoundHelper { @@ -54,12 +55,23 @@ class TopicMessageFoundHelper String rc = (String)(comm_aliases.get(key)); if (rc==null) { // create an SQL statement to find the alias - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT alias FROM sigs WHERE sigid = " + cid + ";"); - if (rs.next()) - rc = rs.getString(1); - else - rc = "(unknown)"; + Statement stmt = null; + + try + { // use the statement + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT alias FROM sigs WHERE sigid = " + cid + ";"); + if (rs.next()) + rc = rs.getString(1); + else + rc = "(unknown)"; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally comm_aliases.put(key,rc); @@ -75,12 +87,23 @@ class TopicMessageFoundHelper String rc = (String)(conf_aliases.get(key)); if (rc==null) { // create an SQL statement to find the alias - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT alias FROM confalias WHERE confid = " + confid + " LIMIT 1;"); - if (rs.next()) - rc = rs.getString(1); - else - rc = "(unknown)"; + Statement stmt = null; + + try + { // use the SQL statement + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT alias FROM confalias WHERE confid = " + confid + " LIMIT 1;"); + if (rs.next()) + rc = rs.getString(1); + else + rc = "(unknown)"; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally conf_aliases.put(key,rc); @@ -96,12 +119,23 @@ class TopicMessageFoundHelper String rc = (String)(user_names.get(key)); if (rc==null) { // create an SQL statement to find the username - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";"); - if (rs.next()) - rc = rs.getString(1); - else - rc = "(unknown)"; + Statement stmt = null; + + try + { // use the statement + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";"); + if (rs.next()) + rc = rs.getString(1); + else + rc = "(unknown)"; + + } // end try + finally + { // shut down the statement to save resources + SQLUtil.shutdown(stmt); + + } // end finally user_names.put(key,rc); @@ -112,4 +146,3 @@ class TopicMessageFoundHelper } // end getUserName } // end TopicMessageFoundHelper - diff --git a/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java b/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java index e9802e0..04144b3 100644 --- a/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -122,59 +122,81 @@ class TopicMessageUserContextImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - private static String quickGetUserName(Connection conn, int uid) throws SQLException + private static final String quickGetUserName(Connection conn, int uid) throws SQLException { - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";"); - if (rs.next()) - return rs.getString(1); - else - return "(unknown)"; + Statement stmt = null; + + try + { // do a quick search + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";"); + if (rs.next()) + return rs.getString(1); + else + return "(unknown)"; + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end quickGetUserName - private void refresh(Connection conn) throws SQLException + private final void refresh(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT posts.hidden, posts.scribble_uid, posts.scribble_date, " - + "posts.pseud, postattach.datalen, postattach.filename, " - + "postattach.mimetype, postattach.stgmethod FROM posts " - + "LEFT JOIN postattach ON posts.postid = postattach.postid " - + "WHERE posts.postid = "); - sql.append(postid).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (rs.next()) - { // update a variety of fields - hidden = rs.getBoolean(1); - scribble_uid = rs.getInt(2); - scribble_date = SQLUtil.getFullDateTime(rs,3); - pseud = rs.getString(4); - datalen = rs.getInt(5); - filename = rs.getString(6); - mimetype = rs.getString(7); - stgmethod = rs.getInt(8); - if (rs.wasNull()) + Statement stmt = null; + + try + { // run against the database + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT posts.hidden, posts.scribble_uid, posts.scribble_date, " + + "posts.pseud, postattach.datalen, postattach.filename, " + + "postattach.mimetype, postattach.stgmethod FROM posts " + + "LEFT JOIN postattach ON posts.postid = postattach.postid " + + "WHERE posts.postid = "); + sql.append(postid).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (rs.next()) + { // update a variety of fields + hidden = rs.getBoolean(1); + scribble_uid = rs.getInt(2); + scribble_date = SQLUtil.getFullDateTime(rs,3); + pseud = rs.getString(4); + datalen = rs.getInt(5); + filename = rs.getString(6); + mimetype = rs.getString(7); + stgmethod = rs.getInt(8); + if (rs.wasNull()) + stgmethod = -1; + + } // end if + else + { // the post has been nuked - update accordingly + linecount = 0; + creator_uid = -1; + posted = null; + hidden = false; + scribble_uid = -1; + scribble_date = null; + pseud = null; + datalen = 0; + filename = null; + mimetype = null; stgmethod = -1; + nuked = true; + creator_cache = null; + text_cache = null; - } // end if - else - { // the post has been nuked - update accordingly - linecount = 0; - creator_uid = -1; - posted = null; - hidden = false; - scribble_uid = -1; - scribble_date = null; - pseud = null; - datalen = 0; - filename = null; - mimetype = null; - stgmethod = -1; - nuked = true; - creator_cache = null; - text_cache = null; + } // end else - } // end else + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end refresh @@ -302,12 +324,23 @@ class TopicMessageUserContextImpl implements TopicMessageContext if (scribble_date==null) { // let's go get the body text! - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " + postid + ";"); - if (rs.next()) - text_cache = rs.getString(1); - else - return "Data Missing"; // FUTURE: throw an exception? + Statement stmt = null; + + try + { // retrieve the body text + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " + postid + ";"); + if (rs.next()) + text_cache = rs.getString(1); + else + return "Data Missing"; // FUTURE: throw an exception? + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end if else // for scribbled posts, we return the scribbler's name only @@ -366,6 +399,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if Connection conn = null; + Statement stmt = null; InputStream rc = null; try { // open up a database connection @@ -388,7 +422,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if // This will cause a "hit" on the attachment data. Update that record. - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE postattach SET hits = hits + 1, last_hit = '"); sql.append(SQLUtil.encodeDate(new java.util.Date())).append("' WHERE postid = ").append(postid); sql.append(';'); @@ -445,6 +479,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -488,12 +523,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext return; // changing the status of a nuked or scribbled post is futile Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // open up a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we reference stmt.executeUpdate("LOCK TABLES posts WRITE, postattach READ;"); @@ -515,8 +551,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -533,6 +568,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -555,12 +591,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext return; // scribbling a nuked or scribbled post is futile Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // open up a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we reference stmt.executeUpdate("LOCK TABLES posts WRITE, postdata WRITE, postattach WRITE, postpublish WRITE;"); @@ -606,6 +643,8 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if // else don't try...we're deleting the row anyway + SQLUtil.shutdown(rs); + // Delete the actual post data row. sql.setLength(0); sql.append("DELETE FROM postdata WHERE postid = ").append(postid).append(';'); @@ -634,8 +673,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -651,6 +689,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -671,12 +710,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext return; // nuking a nuked post is futile Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // open up a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we reference stmt.executeUpdate("LOCK TABLES posts WRITE, postdata WRITE, postattach WRITE, postdogear WRITE, " @@ -694,6 +734,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext throw new InternalStateError("lost the post to be nuked after refresh?"); int x_topic_id = rs.getInt(1); int x_post_num = rs.getInt(2); + SQLUtil.shutdown(rs); // Delete any and all references to this post! stmt.executeUpdate("DELETE FROM posts WHERE postid = " + postid + ";"); @@ -730,8 +771,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -747,6 +787,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -866,6 +907,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext Connection conn = null; AuditRecord ar = null; + PreparedStatement stmt = null; try { // open up a database connection @@ -892,7 +934,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext logger.debug("SQL: " + sql.toString()); // Prepare the statement, set the BLOB parameter, and execute it. - PreparedStatement stmt = conn.prepareStatement(sql.toString()); + stmt = conn.prepareStatement(sql.toString()); stmt.setBinaryStream(1,real_data,real_length); stmt.executeUpdate(); @@ -916,6 +958,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -938,15 +981,17 @@ class TopicMessageUserContextImpl implements TopicMessageContext return false; } // end if + if ((scribble_date!=null) || nuked) return false; // cannot publish a scribbled or nuked message Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // see if the post has already been published ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid @@ -961,6 +1006,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -987,12 +1033,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // see if post has already been published ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid @@ -1038,6 +1085,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1058,11 +1106,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext String prefix = env.getConference().selfConference().getPostLink(); short topicnum = -1; Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT num FROM topics WHERE topicid = " + topicid + ";"); if (!(rs.next())) @@ -1078,6 +1127,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1114,6 +1164,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if Connection conn = null; + Statement stmt = null; AuditRecord ar = null; ArrayList mailto_addrs = null; int new_topic_num = -1; @@ -1124,7 +1175,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock the tables we reference stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, topicsettings READ;"); @@ -1216,8 +1267,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1254,6 +1304,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1280,7 +1331,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - static List loadMessageRange(EnvConference env, int topicid, int post_low, int post_high) + static final List loadMessageRange(EnvConference env, int topicid, int post_low, int post_high) throws DataException { if (logger.isDebugEnabled()) @@ -1289,11 +1340,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext ArrayList rc = new ArrayList(); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // run a query to get all the posts in a particular topic StringBuffer sql = @@ -1327,6 +1379,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1335,18 +1388,20 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end loadMessageRange - static TopicMessageContext loadMessage(EnvConference env, int topicid, int message_num) throws DataException + static final TopicMessageContext loadMessage(EnvConference env, int topicid, int message_num) + throws DataException { if (logger.isDebugEnabled()) logger.debug("loadMessage for conf # " + env.getConfID() + ", topic #" + topicid + ", message " + message_num); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // run a query to get all the posts in a particular topic StringBuffer sql = @@ -1378,23 +1433,25 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end loadMessage - static TopicMessageContext getMessage(EnvConference env, long postid) throws DataException + static final TopicMessageContext getMessage(EnvConference env, long postid) throws DataException { if (logger.isDebugEnabled()) logger.debug("getMessage for conf # " + env.getConfID() + ", post #" + postid); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT p.postid, p.parent, p.topicid, p.num, p.linecount, p.creator_uid, " @@ -1426,6 +1483,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java index f773f41..6e6b661 100644 --- a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -109,7 +109,7 @@ class TopicUserContextImpl implements TopicContext *-------------------------------------------------------------------------------- */ - private static ResultSet queryByTopic(Statement stmt, int topicid, int uid) throws SQLException + private static final ResultSet queryByTopic(Statement stmt, int topicid, int uid) throws SQLException { StringBuffer sql = new StringBuffer("SELECT topics.topicid, topics.num, topics.creator_uid, topics.top_message, " @@ -126,7 +126,7 @@ class TopicUserContextImpl implements TopicContext } // end queryByTopic - private void makeDeleted() + private final void makeDeleted() { top_message = -1; frozen = false; @@ -141,39 +141,61 @@ class TopicUserContextImpl implements TopicContext } // end if - private void refresh(Connection conn) throws SQLException + private final void refresh(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - - // perform a requery of the database - ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); - if (rs.next()) - { // update the fields that are capable of changing - top_message = rs.getInt(4); - frozen = rs.getBoolean(5); - archived = rs.getBoolean(6); - lastupdate = SQLUtil.getFullDateTime(rs,8); - hidden = rs.getBoolean(10); - unread = rs.getInt(11); - if (unread<0) - unread = 0; - subscribed = rs.getBoolean(12); + Statement stmt = null; - } // end if - else // this topic must have been deleted - fsck it - makeDeleted(); + try + { // use database to refresh object + stmt = conn.createStatement(); + + // perform a requery of the database + ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); + if (rs.next()) + { // update the fields that are capable of changing + top_message = rs.getInt(4); + frozen = rs.getBoolean(5); + archived = rs.getBoolean(6); + lastupdate = SQLUtil.getFullDateTime(rs,8); + hidden = rs.getBoolean(10); + unread = rs.getInt(11); + if (unread<0) + unread = 0; + subscribed = rs.getBoolean(12); + + } // end if + else // this topic must have been deleted - fsck it + makeDeleted(); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end refresh - private void loadBozo(Connection conn) throws SQLException + private final void loadBozo(Connection conn) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT bozo_uid FROM topicbozo WHERE topicid = "); - sql.append(topicid).append(" AND uid = ").append(env.getUserID()).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - bozo_uids = new HashSet(); - while (rs.next()) - bozo_uids.add(new Integer(rs.getInt(1))); + Statement stmt = null; + + try + { // load the bozo UIDs list + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT bozo_uid FROM topicbozo WHERE topicid = "); + sql.append(topicid).append(" AND uid = ").append(env.getUserID()).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + bozo_uids = new HashSet(); + while (rs.next()) + bozo_uids.add(new Integer(rs.getInt(1))); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end loadBozo @@ -304,12 +326,13 @@ class TopicUserContextImpl implements TopicContext } // end if Connection conn = null; // pooled database connection + Statement stmt = null; AuditRecord ar = null; // audit record indicating success try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to freeze or unfreeze the topic StringBuffer sql = new StringBuffer("UPDATE topics SET frozen = "); @@ -333,6 +356,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -352,12 +376,13 @@ class TopicUserContextImpl implements TopicContext } // end if Connection conn = null; // pooled database connection + Statement stmt = null; AuditRecord ar = null; // audit record indicating success try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to freeze or unfreeze the topic StringBuffer sql = new StringBuffer("UPDATE topics SET archived = "); @@ -381,6 +406,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -394,11 +420,12 @@ class TopicUserContextImpl implements TopicContext return; // no-op Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;"); try @@ -434,8 +461,7 @@ class TopicUserContextImpl implements TopicContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -448,6 +474,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -491,11 +518,12 @@ class TopicUserContextImpl implements TopicContext int last_msg = top_message - count; Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;"); try @@ -530,6 +558,8 @@ class TopicUserContextImpl implements TopicContext } // end if + SQLUtil.shutdown(rs); + // OK, just insert a new row into topicsettings, why dontcha... sql.setLength(0); sql.append("INSERT INTO topicsettings (topicid, uid, last_message, last_read) VALUES ("); @@ -544,8 +574,7 @@ class TopicUserContextImpl implements TopicContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -558,6 +587,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -674,13 +704,14 @@ class TopicUserContextImpl implements TopicContext long new_post_id; java.util.Date posted_date; Connection conn = null; + Statement stmt = null; AuditRecord ar = null; ArrayList mailto_addrs = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ArrayList mailto_uids = null; StringBuffer sql = new StringBuffer(); ResultSet rs; @@ -735,6 +766,7 @@ class TopicUserContextImpl implements TopicContext new_post_id = rs.getLong(1); if (logger.isDebugEnabled()) logger.debug("New post ID: " + new_post_id); + SQLUtil.shutdown(rs); // Touch the topic values to reflect the added post. sql.setLength(0); @@ -788,6 +820,8 @@ class TopicUserContextImpl implements TopicContext } // end while + SQLUtil.shutdown(rs); + // Fill in our own local variables to reflect the update. This includes the recalculation // of "unread" based on the new value of "top_message". int tmp_last_msg = top_message - unread; @@ -800,8 +834,7 @@ class TopicUserContextImpl implements TopicContext } // end try finally { // make sure we unlock the tables when we're done - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -835,6 +868,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -882,6 +916,7 @@ class TopicUserContextImpl implements TopicContext return; // an exercise in futility... Connection conn = null; + Statement stmt = null; AuditRecord ar = null; int post_count; long post_max; @@ -889,7 +924,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // lock some tables while we do the critical parts of the delete stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, topicsettings WRITE, topicbozo WRITE, " @@ -928,8 +963,7 @@ class TopicUserContextImpl implements TopicContext } // end try finally { // make sure and unlock before we're done - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -945,6 +979,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -967,12 +1002,13 @@ class TopicUserContextImpl implements TopicContext public List getActivePosters(int skip, int limit) throws DataException { Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to retrieve all posters StringBuffer sql = @@ -1003,6 +1039,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1026,12 +1063,13 @@ class TopicUserContextImpl implements TopicContext public List getActiveReaders(int skip, int limit) throws DataException, AccessError { Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement to retrieve all readers StringBuffer sql = @@ -1062,6 +1100,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1120,6 +1159,7 @@ class TopicUserContextImpl implements TopicContext return; // no-op Connection conn = null; + Statement stmt = null; try { // figure out what to do here conn = env.getConnection(); @@ -1130,7 +1170,6 @@ class TopicUserContextImpl implements TopicContext loadBozo(conn); // load the bozo filter if we don't already have it Integer uid_key = new Integer(other_uid); - Statement stmt; StringBuffer sql; if (bozo) { // this user is a bozo... @@ -1171,6 +1210,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1230,11 +1270,12 @@ class TopicUserContextImpl implements TopicContext return; // no-op Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;"); try @@ -1260,6 +1301,8 @@ class TopicUserContextImpl implements TopicContext } // end if + SQLUtil.shutdown(rs); + // OK, just insert a new row into topicsettings, why dontcha... sql.setLength(0); sql.append("INSERT INTO topicsettings (topicid, uid, subscribe) VALUES (").append(topicid); @@ -1270,8 +1313,7 @@ class TopicUserContextImpl implements TopicContext } // end try finally { // unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1284,6 +1326,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1337,12 +1380,13 @@ class TopicUserContextImpl implements TopicContext } // end if Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build the SQL statement. StringBuffer sql = new StringBuffer("SELECT c.email, "); @@ -1390,6 +1434,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1428,13 +1473,14 @@ class TopicUserContextImpl implements TopicContext throw new AccessError("You are not permitted to search for posts within this topic."); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // get a database connection conn = env.getConnection(); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1461,6 +1507,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1482,11 +1529,12 @@ class TopicUserContextImpl implements TopicContext throw new AccessError("You are not permitted to search for posts within this topic."); Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1510,6 +1558,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1535,17 +1584,18 @@ class TopicUserContextImpl implements TopicContext *-------------------------------------------------------------------------------- */ - static List getTopicList(EnvConference env, int get_option, int sort_option) throws DataException + static final List getTopicList(EnvConference env, int get_option, int sort_option) throws DataException { if (logger.isDebugEnabled()) logger.debug("getTopicList for conf # " + env.getConfID() + ", user #" + env.getUserID()); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Figure out what the "where" clause of the SQL statement will be. This is in addition to a // WHERE t.confid = (confid) that is always present. (Some of these WHERE specifiers refer to @@ -1687,6 +1737,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1695,17 +1746,18 @@ class TopicUserContextImpl implements TopicContext } // end getTopicList - static TopicContext getTopicByID(EnvConference env, int topicid) throws DataException + static final TopicContext getTopicByID(EnvConference env, int topicid) throws DataException { if (logger.isDebugEnabled()) logger.debug("getTopicByID for topic # " + topicid + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Query the dtabase by topic ID. ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); @@ -1725,6 +1777,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1733,18 +1786,19 @@ class TopicUserContextImpl implements TopicContext } // end getTopicByID - static TopicContext getTopicByNumber(EnvConference env, short topicnum) throws DataException + static final TopicContext getTopicByNumber(EnvConference env, short topicnum) throws DataException { if (logger.isDebugEnabled()) logger.debug("getTopicByNumber for topic # " + topicnum + ", conf # " + env.getConfID() + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // Build the database query. StringBuffer sql = @@ -1776,6 +1830,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/UserContextImpl.java b/src/com/silverwrist/venice/core/impl/UserContextImpl.java index b772a2e..8a6e116 100644 --- a/src/com/silverwrist/venice/core/impl/UserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/UserContextImpl.java @@ -92,7 +92,7 @@ class UserContextImpl implements UserContext, UserBackend *-------------------------------------------------------------------------------- */ - private void loadUserData(ResultSet rs) throws SQLException + private final void loadUserData(ResultSet rs) throws SQLException { uid = rs.getInt("uid"); username = rs.getString("username"); @@ -125,14 +125,15 @@ class UserContextImpl implements UserContext, UserBackend } // end loadUserData - private void loadPrefs() throws DataException + private final void loadPrefs() throws DataException { Connection conn = null; + Statement stmt = null; try { // call through to lower level function conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM userprefs WHERE uid = " + uid + ";"); if (!(rs.next())) @@ -170,13 +171,14 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end loadPrefs - private void sendEmailConfirmation() throws DataException, EmailException + private final void sendEmailConfirmation() throws DataException, EmailException { if (logger.isDebugEnabled()) logger.debug("sendEmailConfirmation(): sending to \"" + my_email + "\""); @@ -211,72 +213,84 @@ class UserContextImpl implements UserContext, UserBackend } // end sendEmailConfirmation - private void autoJoinCommunities(Connection conn) throws SQLException + private final void autoJoinCommunities(Connection conn) throws SQLException { if (logger.isDebugEnabled()) logger.debug("autoJoinCommunities (uid " + uid + ", level " + level + ")"); - // See which communities we are eligible to autojoin. - Statement stmt = conn.createStatement(); - StringBuffer sql = - new StringBuffer("SELECT sigmember.sigid, sigmember.locked FROM users, sigmember, sigs " - + "WHERE sigmember.uid = users.uid AND sigmember.sigid = sigs.sigid " - + "AND users.is_anon = 1 AND sigs.join_lvl <= "); - sql.append(level).append(';'); - if (logger.isDebugEnabled()) - logger.debug("SQL: " + sql.toString()); - ResultSet rs = stmt.executeQuery(sql.toString()); + Statement stmt = null; - // Save the community IDs returned into temporary array lists. - ArrayList tmp_cid = new ArrayList(); - ArrayList tmp_locked = new ArrayList(); - while (rs.next()) - { // save off the "cid" and "locked" column pairs - tmp_cid.add(new Integer(rs.getInt(1))); - tmp_locked.add(new Boolean(rs.getBoolean(2))); - - } // end while - - // Figure out which of those communities we haven't joined yet and set up to autojoin them. - sql.setLength(0); - int new_level = env.getCommunityDefaultRole("Community.NewUser").getLevel(); - for (int i=0; i0) - { // execute the big update - sql.append(';'); + try + { // See which communities we are eligible to autojoin. + stmt = conn.createStatement(); + StringBuffer sql = + new StringBuffer("SELECT sigmember.sigid, sigmember.locked FROM users, sigmember, sigs " + + "WHERE sigmember.uid = users.uid AND sigmember.sigid = sigs.sigid " + + "AND users.is_anon = 1 AND sigs.join_lvl <= "); + sql.append(level).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); - stmt.executeUpdate(sql.toString()); + ResultSet rs = stmt.executeQuery(sql.toString()); - } // end if + // Save the community IDs returned into temporary array lists. + ArrayList tmp_cid = new ArrayList(); + ArrayList tmp_locked = new ArrayList(); + while (rs.next()) + { // save off the "cid" and "locked" column pairs + tmp_cid.add(new Integer(rs.getInt(1))); + tmp_locked.add(new Boolean(rs.getBoolean(2))); + + } // end while + + // Figure out which of those communities we haven't joined yet and set up to autojoin them. + sql.setLength(0); + int new_level = env.getCommunityDefaultRole("Community.NewUser").getLevel(); + for (int i=0; i0) + { // execute the big update + sql.append(';'); + if (logger.isDebugEnabled()) + logger.debug("SQL: " + sql.toString()); + stmt.executeUpdate(sql.toString()); + + } // end if + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end autoJoinCommunities - private void updateProperties(BitSet delta) throws DataException + private final void updateProperties(BitSet delta) throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a connection and create a statement conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (delta.get(PROP_FLAGS)) @@ -297,13 +311,14 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end updateProperties - private void updateProperties() throws DataException + private final void updateProperties() throws DataException { updateProperties(ALL_PROPS); @@ -387,12 +402,13 @@ class UserContextImpl implements UserContext, UserBackend logger.debug("authenticate(): authenticating user \"" + username + "\"..."); Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // look for a user name matching this user record conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + SQLUtil.encodeString(username) + "';"); @@ -463,6 +479,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -494,12 +511,13 @@ class UserContextImpl implements UserContext, UserBackend } // end if Connection conn = null; + Statement stmt = null; Role new_role = env.getDefaultRole("Global.AfterVerify"); try { // get a connection and set the user's status to reflect the verification conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 1, base_lvl = "); sql.append(new_role.getLevel()).append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -521,6 +539,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -544,11 +563,13 @@ class UserContextImpl implements UserContext, UserBackend getContactInfo(); // forces my_email to be updated Connection conn = null; + Statement stmt = null; AuditRecord ar = null; + try { // need to change the user's email confirmation number first conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // generate new confirmation number int new_confirm_num = env.getEngine().getNewConfirmationNumber(); @@ -575,6 +596,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -665,12 +687,21 @@ class UserContextImpl implements UserContext, UserBackend int new_confirm_num = env.getEngine().getNewConfirmationNumber(); Role new_role = env.getDefaultRole("Global.Unverified"); - // create an SQL statement to reset the user account information, and execute it - StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = "); - sql.append(new_confirm_num).append(", base_lvl = ").append(new_role.getLevel()); - sql.append(" WHERE uid = ").append(uid).append(';'); - Statement stmt = conn.createStatement(); - stmt.executeUpdate(sql.toString()); + Statement stmt = null; + try + { // create an SQL statement to reset the user account information, and execute it + StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = "); + sql.append(new_confirm_num).append(", base_lvl = ").append(new_role.getLevel()); + sql.append(" WHERE uid = ").append(uid).append(';'); + stmt = conn.createStatement(); + stmt.executeUpdate(sql.toString()); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally // save off changed data email_verified = false; @@ -778,12 +809,13 @@ class UserContextImpl implements UserContext, UserBackend } // end if Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); PasswordHash phash = new PasswordHash(password); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder)); @@ -802,6 +834,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -819,11 +852,12 @@ class UserContextImpl implements UserContext, UserBackend } // end if Connection conn = null; + Statement stmt = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -839,6 +873,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -976,12 +1011,13 @@ class UserContextImpl implements UserContext, UserBackend public List getSideBoxList() throws DataException { Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // retrieve the necessary rows from the sideboxes table ResultSet rs = stmt.executeQuery("SELECT boxid, sequence FROM sideboxes WHERE uid = " + uid @@ -1004,6 +1040,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1018,11 +1055,12 @@ class UserContextImpl implements UserContext, UserBackend throw new DataException("invalid sidebox ID: " + id); Connection conn = null; + Statement stmt = null; try { // retrieve a connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES sideboxes WRITE;"); try @@ -1050,8 +1088,7 @@ class UserContextImpl implements UserContext, UserBackend } // end try finally { // make sure the table is unlocked before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1064,6 +1101,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1101,11 +1139,12 @@ class UserContextImpl implements UserContext, UserBackend public void setLocale(Locale locale) throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the update statement StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '"); @@ -1126,6 +1165,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1144,11 +1184,12 @@ class UserContextImpl implements UserContext, UserBackend public void setTimeZone(TimeZone timezone) throws DataException { Connection conn = null; + Statement stmt = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the update statement StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '"); @@ -1169,6 +1210,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1187,11 +1229,12 @@ class UserContextImpl implements UserContext, UserBackend // Generate a random authentication string and poke it into the database for this user. String tokenauth = env.getEngine().generateRandomAuthString(); Connection conn = null; + Statement stmt = null; try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET tokenauth = '"); sql.append(tokenauth).append("' WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -1205,6 +1248,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1312,12 +1356,13 @@ class UserContextImpl implements UserContext, UserBackend logger.debug("Authenticating user ID#" + pending_uid); Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // look for a user record matching this user ID conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE uid = " + pending_uid + ";"); if (!(rs.next())) @@ -1382,6 +1427,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); @@ -1461,13 +1507,14 @@ class UserContextImpl implements UserContext, UserBackend ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference"); Connection conn = null; + Statement stmt = null; ArrayList rc = new ArrayList(); try { // get a database connection conn = env.getConnection(); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1500,6 +1547,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1520,11 +1568,12 @@ class UserContextImpl implements UserContext, UserBackend ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference"); Connection conn = null; + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create the SQL statement StringBuffer sql = @@ -1554,6 +1603,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1635,13 +1685,14 @@ class UserContextImpl implements UserContext, UserBackend void loadAnonymous(String remote_addr) throws DataException { Connection conn = null; + Statement stmt = null; if (logger.isDebugEnabled()) logger.debug("loadAnonymous() on UserContext: addr " + remote_addr); try { // retrieve a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE is_anon = 1;"); if (!(rs.next())) { // could not find the anonymous user - this is an internal error @@ -1663,6 +1714,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1716,21 +1768,22 @@ class UserContextImpl implements UserContext, UserBackend *-------------------------------------------------------------------------------- */ - static ReturnNewUser createAccount(EnvEngine env, String remote_addr, String username, String password, - String reminder, boolean verify_email, boolean lockout, int confirm_num, - Role base_role, String description) + static final ReturnNewUser createAccount(EnvEngine env, String remote_addr, String username, String password, + String reminder, boolean verify_email, boolean lockout, + int confirm_num, Role base_role, String description) throws AccessError, DataException { String encode_username = SQLUtil.encodeString(username); int new_uid; // new user ID - return from this function java.util.Date created; // date created - return from this function Connection conn = null; + Statement stmt = null; AuditRecord ar = null; try { // first, lock a bunch of tables for the purpose of this operation conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES users WRITE, userprefs WRITE, propuser WRITE, sigmember WRITE, " + "sideboxes WRITE, confhotlist WRITE;"); @@ -1744,6 +1797,8 @@ class UserContextImpl implements UserContext, UserBackend } // end if + SQLUtil.shutdown(rs); + // Insert a new record for this user PasswordHash phash = new PasswordHash(password); StringBuffer sql = @@ -1770,6 +1825,7 @@ class UserContextImpl implements UserContext, UserBackend new_uid = rs.getInt(1); if (logger.isDebugEnabled()) logger.debug("...created user \"" + username + "\" with UID " + new_uid); + SQLUtil.shutdown(rs); // add a UserPrefs record for this user, too sql.setLength(0); @@ -1857,8 +1913,7 @@ class UserContextImpl implements UserContext, UserBackend } // end try finally { // make sure the tables get unlocked before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + SQLUtil.unlockTables(conn); } // end finally @@ -1874,6 +1929,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); AuditRecord.store(conn,ar); env.releaseConnection(conn); diff --git a/src/com/silverwrist/venice/core/impl/UserProfileImpl.java b/src/com/silverwrist/venice/core/impl/UserProfileImpl.java index 42ca437..be11eb6 100644 --- a/src/com/silverwrist/venice/core/impl/UserProfileImpl.java +++ b/src/com/silverwrist/venice/core/impl/UserProfileImpl.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -79,27 +79,38 @@ class UserProfileImpl implements UserProfile logger.debug("load UserProfileImpl by name: " + username); this.env = env; - // first retrieve from the users table - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, " - + "is_anon FROM users WHERE username = '"); - sql.append(SQLUtil.encodeString(username)).append("';"); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (!(rs.next())) - { // we didn't find the user - logger.error("unable to find user with username '" + username + "'"); - throw new DataException("User '" + username + "' not found."); + Statement stmt = null; + int contact_id = -1; - } // end if + try + { // first retrieve from the users table + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, " + + "is_anon FROM users WHERE username = '"); + sql.append(SQLUtil.encodeString(username)).append("';"); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (!(rs.next())) + { // we didn't find the user + logger.error("unable to find user with username '" + username + "'"); + throw new DataException("User '" + username + "' not found."); - // load the "elementary" fields - this.uid = rs.getInt(1); - this.username = rs.getString(2); - int contact_id = rs.getInt(3); - created = SQLUtil.getFullDateTime(rs,4); - last_login = SQLUtil.getFullDateTime(rs,5); - descr = rs.getString(6); - is_anon = rs.getBoolean(7); + } // end if + + // load the "elementary" fields + this.uid = rs.getInt(1); + this.username = rs.getString(2); + contact_id = rs.getInt(3); + created = SQLUtil.getFullDateTime(rs,4); + last_login = SQLUtil.getFullDateTime(rs,5); + descr = rs.getString(6); + is_anon = rs.getBoolean(7); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally loadContact(conn,contact_id); @@ -111,27 +122,38 @@ class UserProfileImpl implements UserProfile logger.debug("load UserProfileImpl by UID: " + uid); this.env = env; - // first retrieve from the users table - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, " - + "is_anon FROM users WHERE uid = "); - sql.append(uid).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (!(rs.next())) - { // we didn't find user - logger.error("unable to find user with uid " + uid); - throw new DataException("User #" + String.valueOf(uid) + " not found."); + Statement stmt = null; + int contact_id = -1; - } // end if + try + { // first retrieve from the users table + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, " + + "is_anon FROM users WHERE uid = "); + sql.append(uid).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (!(rs.next())) + { // we didn't find user + logger.error("unable to find user with uid " + uid); + throw new DataException("User #" + String.valueOf(uid) + " not found."); - // load the "elementary" fields - this.uid = rs.getInt(1); - this.username = rs.getString(2); - int contact_id = rs.getInt(3); - created = SQLUtil.getFullDateTime(rs,4); - last_login = SQLUtil.getFullDateTime(rs,5); - descr = rs.getString(6); - is_anon = rs.getBoolean(7); + } // end if + + // load the "elementary" fields + this.uid = rs.getInt(1); + this.username = rs.getString(2); + contact_id = rs.getInt(3); + created = SQLUtil.getFullDateTime(rs,4); + last_login = SQLUtil.getFullDateTime(rs,5); + descr = rs.getString(6); + is_anon = rs.getBoolean(7); + + } // end try + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally loadContact(conn,contact_id); @@ -142,100 +164,111 @@ class UserProfileImpl implements UserProfile *-------------------------------------------------------------------------------- */ - private void loadContact(Connection conn, int contact_id) throws SQLException + private final void loadContact(Connection conn, int contact_id) throws SQLException { if (logger.isDebugEnabled()) logger.debug("loadContact for contact ID " + contact_id); boolean override = env.testPermission(EnvUser.PERM_SEEHIDDENCONTACTINFO); - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = "); - sql.append(contact_id).append(';'); + Statement stmt = null; - ResultSet rs = stmt.executeQuery(sql.toString()); - if (rs.next()) - { // load all the record data - boolean me_anon = env.getUser().userIsAnonymous(); - given_name = rs.getString("given_name"); - family_name = rs.getString("family_name"); - String blort = rs.getString("middle_init"); - if ((blort==null) || (blort.length()<1)) - middle_initial = ' '; + try + { // look up the contact information + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = "); + sql.append(contact_id).append(';'); + + ResultSet rs = stmt.executeQuery(sql.toString()); + if (rs.next()) + { // load all the record data + boolean me_anon = env.getUser().userIsAnonymous(); + given_name = rs.getString("given_name"); + family_name = rs.getString("family_name"); + String blort = rs.getString("middle_init"); + if ((blort==null) || (blort.length()<1)) + middle_initial = ' '; + else + middle_initial = blort.charAt(0); + prefix = rs.getString("prefix"); + suffix = rs.getString("suffix"); + company = rs.getString("company"); + if (!override && (me_anon || rs.getBoolean("pvt_addr"))) + { // enforce address privacy + addr1 = null; + addr2 = null; + + } // end if + else + { // load the address strings + addr1 = rs.getString("addr1"); + addr2 = rs.getString("addr2"); + + } // end else + + locality = rs.getString("locality"); + region = rs.getString("region"); + postal_code = rs.getString("pcode"); + country = rs.getString("country"); + if (!override && (me_anon || rs.getBoolean("pvt_phone"))) + { // enforce phone privacy + phone = null; + mobile = null; + + } // end if + else + { // load the phone strings + phone = rs.getString("phone"); + mobile = rs.getString("mobile"); + + } // end else + + if (!override && (me_anon || rs.getBoolean("pvt_fax"))) + fax = null; + else + fax = rs.getString("fax"); + + real_email = rs.getString("email"); + if (!override && (me_anon || rs.getBoolean("pvt_email"))) + email = null; + else + email = real_email; + + photo_url = rs.getString("photo_url"); + url = rs.getString("url"); + last_update = SQLUtil.getFullDateTime(rs,"lastupdate"); + + } // end if else - middle_initial = blort.charAt(0); - prefix = rs.getString("prefix"); - suffix = rs.getString("suffix"); - company = rs.getString("company"); - if (!override && (me_anon || rs.getBoolean("pvt_addr"))) - { // enforce address privacy + { // no contact ID - just default all the data + given_name = null; + family_name = null; + middle_initial = ' '; + prefix = null; + suffix = null; + company = null; addr1 = null; addr2 = null; - - } // end if - else - { // load the address strings - addr1 = rs.getString("addr1"); - addr2 = rs.getString("addr2"); - - } // end else - - locality = rs.getString("locality"); - region = rs.getString("region"); - postal_code = rs.getString("pcode"); - country = rs.getString("country"); - if (!override && (me_anon || rs.getBoolean("pvt_phone"))) - { // enforce phone privacy + locality = null; + region = null; + postal_code = null; + country = null; phone = null; + fax = null; mobile = null; - - } // end if - else - { // load the phone strings - phone = rs.getString("phone"); - mobile = rs.getString("mobile"); - + email = null; + photo_url = null; + url = null; + last_update = null; + real_email = null; + } // end else - if (!override && (me_anon || rs.getBoolean("pvt_fax"))) - fax = null; - else - fax = rs.getString("fax"); + } // end try + finally + { // shut down statement to conserve resources + SQLUtil.shutdown(stmt); - real_email = rs.getString("email"); - if (!override && (me_anon || rs.getBoolean("pvt_email"))) - email = null; - else - email = real_email; - - photo_url = rs.getString("photo_url"); - url = rs.getString("url"); - last_update = SQLUtil.getFullDateTime(rs,"lastupdate"); - - } // end if - else - { // no contact ID - just default all the data - given_name = null; - family_name = null; - middle_initial = ' '; - prefix = null; - suffix = null; - company = null; - addr1 = null; - addr2 = null; - locality = null; - region = null; - postal_code = null; - country = null; - phone = null; - fax = null; - mobile = null; - email = null; - photo_url = null; - url = null; - last_update = null; - real_email = null; - - } // end else + } // end finally } // end loadContact diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java index 82ed7b3..edc052b 100644 --- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java +++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java @@ -292,7 +292,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend *-------------------------------------------------------------------------------- */ - private static Collection getDictionaryNames(Element sect, String app_root) + private static final Collection getDictionaryNames(Element sect, String app_root) { ArrayList rc = new ArrayList(); NodeList nl = sect.getChildNodes(); @@ -317,14 +317,14 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end getDictionaryNames - private void checkInitialized() + private final void checkInitialized() { if (env==null) throw new InternalStateError("Venice engine not initialized!"); } // end checkInitialized - private void loadDefaults(Statement stmt) throws SQLException, DataException + private final void loadDefaults(Statement stmt) throws SQLException, DataException { final String query1 = "SELECT ndx, data FROM propglobal;"; ResultSet rs = stmt.executeQuery(query1); @@ -343,6 +343,8 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end while + SQLUtil.shutdown(rs); + final String query2 = "SELECT posts_per_page, old_posts_at_top, max_search_page, max_sig_mbr_page, max_conf_mbr_page, " + "fp_posts, num_audit_page, sig_create_lvl FROM globals;"; @@ -360,15 +362,19 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend gp_ints[IP_NUMAUDITRECSPERPAGE] = rs.getInt(7); gp_ints[IP_CREATECOMMUNITYLVL] = rs.getInt(8); + SQLUtil.shutdown(rs); + } // end loadDefaults - private synchronized void updateDefaults(BitSet delta) throws DataException + private final synchronized void updateDefaults(BitSet delta) throws DataException { Connection conn = null; + Statement stmt = null; + try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (delta.get(PROP_FLAGS)) @@ -417,13 +423,14 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally } // end updateDefaults - private synchronized void updateDefaults() throws DataException + private final synchronized void updateDefaults() throws DataException { updateDefaults(ALL_PROPS); @@ -695,10 +702,11 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend // initialize anything that requires us to pull from the database Connection conn = null; + Statement stmt = null; try { // get a connection from the data pool conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // load the global defaults loadDefaults(stmt); @@ -712,6 +720,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -834,11 +843,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend { checkInitialized(); Connection conn = null; + Statement stmt = null; try { // look for a user name matching this user record conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT c.email FROM users u, contacts c WHERE u.contactid = " + "c.contactid AND u.username = '" + SQLUtil.encodeString(username) + "';"); @@ -864,6 +874,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -874,11 +885,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend { checkInitialized(); Connection conn = null; + Statement stmt = null; try { // look for a user name matching this user record conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT c.email, u.uid, u.passreminder FROM users u, contacts c " + "WHERE u.contactid = c.contactid AND u.username = '"); sql.append(SQLUtil.encodeString(username)).append("';"); @@ -939,6 +951,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -972,10 +985,11 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend PasswordGenerator pgen = new PasswordGenerator(); PasswordHash phash = new PasswordHash(pgen.toString()); Connection conn = null; + Statement stmt = null; try { // perform the database update conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); sql.append(phash.toString()).append("' WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); @@ -989,6 +1003,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1054,11 +1069,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend { checkInitialized(); Connection conn = null; + Statement stmt = null; try { // do a SELECT on the sigs table conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid FROM sigs WHERE alias = '"); sql.append(alias).append("'"); if (exist_cid>0) @@ -1075,6 +1091,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1091,11 +1108,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend if (global_flags.get(BP_NOCATEGORIES)) return (catid==0); // EJB 1/16/2001 - if categories are disabled, the only valid one is "unclassified" Connection conn = null; + Statement stmt = null; try { // do a SELECT on the category table conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE catid = "); sql.append(catid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -1109,6 +1127,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1125,11 +1144,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " + "c.family_name, c.locality, c.region, c.country FROM users u, " + "contacts c WHERE u.contactid = c.contactid AND "); @@ -1202,6 +1222,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1216,11 +1237,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend logger.debug("User search: field = " + field + ", mode = " + mode + ", term '" + term + "'"); Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c WHERE u.contactid = " + "c.contactid AND "); @@ -1289,6 +1311,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1304,11 +1327,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend public boolean isEmailAddressBanned(String email) { Connection conn = null; // pooled database connection + Statement stmt = null; try { // get a database connection conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); // create and execute the right SQL statement StringBuffer sql = new StringBuffer("SELECT by_uid FROM emailban WHERE address = '"); @@ -1324,6 +1348,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1336,11 +1361,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend { checkInitialized(); Connection conn = null; + Statement stmt = null; try { // do a SELECT on the confalias table conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '"); sql.append(alias).append("';"); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -1354,6 +1380,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally @@ -1639,11 +1666,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend public void forceParamReload() throws DataException { Connection conn = null; // data pooled connection + Statement stmt = null; try { // get a connection and use it to reload conn = env.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); loadDefaults(stmt); } // end try @@ -1655,6 +1683,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure the connection is released before we go + SQLUtil.shutdown(stmt); env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/internals/EnvEngine.java b/src/com/silverwrist/venice/core/internals/EnvEngine.java index d6830e9..56cc6ee 100644 --- a/src/com/silverwrist/venice/core/internals/EnvEngine.java +++ b/src/com/silverwrist/venice/core/internals/EnvEngine.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -108,8 +108,7 @@ public class EnvEngine public final void releaseConnection(Connection c) { - if (c!=null) - datapool.releaseConnection(c); + datapool.releaseConnection(c); } // end releaseConnection diff --git a/src/com/silverwrist/venice/db/DataPool.java b/src/com/silverwrist/venice/db/DataPool.java index c432a88..d822a7c 100644 --- a/src/com/silverwrist/venice/db/DataPool.java +++ b/src/com/silverwrist/venice/db/DataPool.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -233,7 +233,7 @@ public class DataPool implements Runnable * @return The new database connection object. * @exception java.sql.SQLException An error prevented the creation of the connection. */ - private Connection makeNewConnection() throws SQLException + private final Connection makeNewConnection() throws SQLException { try { // make the connection and return it @@ -268,7 +268,7 @@ public class DataPool implements Runnable * * @see #run() */ - private void makeBackgroundConnection() + private final void makeBackgroundConnection() { pending = true; try @@ -291,7 +291,7 @@ public class DataPool implements Runnable * * @param vconn Vector of connections to be closed. */ - private static void closeConnections(Vector vconn) + private final static void closeConnections(Vector vconn) { if (logger.isDebugEnabled()) logger.debug("closeConnections(" + String.valueOf(vconn.size()) + " to be closed)"); diff --git a/src/com/silverwrist/venice/db/PostLinkDecoder.java b/src/com/silverwrist/venice/db/PostLinkDecoder.java index 7a60e70..96e5cd4 100644 --- a/src/com/silverwrist/venice/db/PostLinkDecoder.java +++ b/src/com/silverwrist/venice/db/PostLinkDecoder.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -170,7 +170,7 @@ public class PostLinkDecoder *-------------------------------------------------------------------------------- */ - private static boolean isAllDigits(String str) + private static final boolean isAllDigits(String str) { for (int i=0; iMAX_COMM_LEN) throw new ValidationException("community alias is too long"); @@ -193,7 +193,7 @@ public class PostLinkDecoder } // end setCommunityName - private void setConferenceName(String name) throws ValidationException + private final void setConferenceName(String name) throws ValidationException { if (name.length()>MAX_CONF_LEN) throw new ValidationException("conference alias is too long"); @@ -203,7 +203,7 @@ public class PostLinkDecoder } // end setConferenceName - private void setTopicNumber(String val) throws ValidationException + private final void setTopicNumber(String val) throws ValidationException { if (!isAllDigits(val)) throw new ValidationException("invalid topic number reference"); @@ -223,7 +223,7 @@ public class PostLinkDecoder } // end setTopicNumber - private void setPostRange(StringBuffer buf) throws ValidationException + private final void setPostRange(StringBuffer buf) throws ValidationException { int pos = buf.toString().indexOf('-'); String temp = null; @@ -293,37 +293,37 @@ public class PostLinkDecoder *-------------------------------------------------------------------------------- */ - public String getCommunity() + public final String getCommunity() { return commname; } // end getCommunity - public String getConference() + public final String getConference() { return confname; } // end getConference - public short getTopic() + public final short getTopic() { return topicnum; } // end getTopic - public int getFirstPost() + public final int getFirstPost() { return first_post; } // end getFirstPost - public int getLastPost() + public final int getLastPost() { return last_post; } // end getFirstPost - public boolean needDatabaseVerification() + public final boolean needDatabaseVerification() { return ((commname!=null) || (confname!=null)); @@ -331,9 +331,11 @@ public class PostLinkDecoder public void verifyNames(Connection conn) throws ValidationException { + Statement stmt = null; + try { // do the necessary database stuff - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); ResultSet rs; @@ -364,6 +366,11 @@ public class PostLinkDecoder throw new ValidationException("unable to verify names in post link"); } // end catch + finally + { // shut down the statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end verifyNames diff --git a/src/com/silverwrist/venice/db/PostLinkDecoderContext.java b/src/com/silverwrist/venice/db/PostLinkDecoderContext.java index 8de2b96..9982c61 100644 --- a/src/com/silverwrist/venice/db/PostLinkDecoderContext.java +++ b/src/com/silverwrist/venice/db/PostLinkDecoderContext.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ diff --git a/src/com/silverwrist/venice/db/PostLinkRewriter.java b/src/com/silverwrist/venice/db/PostLinkRewriter.java index 34774e6..c9f4d28 100644 --- a/src/com/silverwrist/venice/db/PostLinkRewriter.java +++ b/src/com/silverwrist/venice/db/PostLinkRewriter.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -57,7 +57,7 @@ public class PostLinkRewriter implements Rewriter *-------------------------------------------------------------------------------- */ - private static String buildPostLink(PostLinkDecoder pl, PostLinkDecoderContext ctxt) + private static final String buildPostLink(PostLinkDecoder pl, PostLinkDecoderContext ctxt) { StringBuffer b = new StringBuffer(URI_PREFIX); boolean started = false; @@ -115,7 +115,6 @@ public class PostLinkRewriter implements Rewriter } // end buildPostLink - /*-------------------------------------------------------------------------------- * Implementations from interface Rewriter *-------------------------------------------------------------------------------- @@ -167,8 +166,7 @@ public class PostLinkRewriter implements Rewriter } // end catch finally { // release the connection when we're done - if (conn!=null) - datapool.releaseConnection(conn); + datapool.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/db/SQLUtil.java b/src/com/silverwrist/venice/db/SQLUtil.java index a38bbaf..d49c87e 100644 --- a/src/com/silverwrist/venice/db/SQLUtil.java +++ b/src/com/silverwrist/venice/db/SQLUtil.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -19,6 +19,7 @@ package com.silverwrist.venice.db; import java.sql.*; import java.util.*; +import org.apache.log4j.*; import com.silverwrist.util.AnyCharMatcher; import com.silverwrist.util.StringUtil; @@ -36,6 +37,8 @@ public class SQLUtil *-------------------------------------------------------------------------------- */ + private static Category logger = Category.getInstance(SQLUtil.class); + private static final String SQL_WILDCARD_CHARS = "%_'"; // used to convert dates and times to UTC for sending to SQL @@ -53,7 +56,7 @@ public class SQLUtil * @return The converted date and time. * @exception java.sql.SQLException The date and time string was in an invalid format. */ - private static java.util.Date convertDateTimeString(String dstr) throws SQLException + private static final java.util.Date convertDateTimeString(String dstr) throws SQLException { if (dstr==null) return null; // null values are the same @@ -92,7 +95,7 @@ public class SQLUtil * null, returns null. * @see com.silverwrist.util.StringUtil#encodeStringSQL(java.lang.String) */ - public static String encodeString(String str) + public static final String encodeString(String str) { return StringUtil.encodeStringSQL(str); @@ -108,7 +111,7 @@ public class SQLUtil * null, returns "NULL". * @see com.silverwrist.util.StringUtil#encodeStringSQL(java.lang.String) */ - public static String encodeStringArg(String str) + public static final String encodeStringArg(String str) { if (str==null) return "NULL"; @@ -127,7 +130,7 @@ public class SQLUtil * @return The SQL-encoded equivalent of str. If str is * null, returns null. */ - public static String encodeStringWildcards(String str) + public static final String encodeStringWildcards(String str) { if (str==null) return null; // safety feature @@ -174,7 +177,7 @@ public class SQLUtil * @param d The date to be encoded. * @return The string equivalent of that date. */ - public static String encodeDate(java.util.Date d) + public static final String encodeDate(java.util.Date d) { // Break down the date as a UTC value. GregorianCalendar cal = new GregorianCalendar(utc); @@ -233,7 +236,7 @@ public class SQLUtil * @return The value of the specified column, expressed as a date. * @exception java.sql.SQLException If the column could not be retrieved or converted. */ - public static java.util.Date getFullDateTime(ResultSet rs, String column) throws SQLException + public static final java.util.Date getFullDateTime(ResultSet rs, String column) throws SQLException { return convertDateTimeString(rs.getString(column)); @@ -247,10 +250,55 @@ public class SQLUtil * @return The value of the specified column, expressed as a date. * @exception java.sql.SQLException If the column could not be retrieved or converted. */ - public static java.util.Date getFullDateTime(ResultSet rs, int column) throws SQLException + public static final java.util.Date getFullDateTime(ResultSet rs, int column) throws SQLException { return convertDateTimeString(rs.getString(column)); } // end getFullDateTime + public static final void shutdown(ResultSet rs) + { + try + { // close the ResultSet + if (rs!=null) + rs.close(); + + } // end try + catch (SQLException e) + { // ignore any SQL errors + } // end catch + + } // end shutdown + + public static final void shutdown(Statement stmt) + { + try + { // close the Statement + if (stmt!=null) + stmt.close(); + + } // end try + catch (SQLException e) + { // ignore any SQL errors + } // end catch + + } // end shutdown + + public static final void unlockTables(Connection conn) + { + try + { // do the update + Statement stmt = conn.createStatement(); + stmt.executeUpdate("UNLOCK TABLES;"); + shutdown(stmt); + + } // end try + catch (SQLException e) + { // warn if there was an error here + logger.warn("DB error in unlockTables()",e); + + } // end catch + + } // end unlockTables + } // end class SQLUtil diff --git a/src/com/silverwrist/venice/db/UserNameRewriter.java b/src/com/silverwrist/venice/db/UserNameRewriter.java index 6f02077..b32435f 100644 --- a/src/com/silverwrist/venice/db/UserNameRewriter.java +++ b/src/com/silverwrist/venice/db/UserNameRewriter.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -68,11 +68,12 @@ public class UserNameRewriter implements Rewriter return null; Connection conn = null; + Statement stmt = null; try { // get a database connection and create a statement conn = datapool.getConnection(); - Statement stmt = conn.createStatement(); + stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT uid FROM users WHERE username = '"); sql.append(SQLUtil.encodeString(data)).append("';"); ResultSet rs = stmt.executeQuery(sql.toString()); @@ -87,8 +88,8 @@ public class UserNameRewriter implements Rewriter } // end catch finally { // make sure and release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + SQLUtil.shutdown(stmt); + datapool.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/security/AuditRecord.java b/src/com/silverwrist/venice/security/AuditRecord.java index abe58bc..463fc49 100644 --- a/src/com/silverwrist/venice/security/AuditRecord.java +++ b/src/com/silverwrist/venice/security/AuditRecord.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -55,6 +55,7 @@ public class AuditRecord implements AuditData if (!(rs.next())) throw new DataException("description string not found for code " + code); rc = rs.getString(1); + SQLUtil.shutdown(rs); descr_cache.put(code_x,rc); } // end if @@ -76,6 +77,7 @@ public class AuditRecord implements AuditData rc = rs.getString(1); else rc = "(UID #" + uid + ")"; + SQLUtil.shutdown(rs); uname_cache.put(uid_x,rc); } // end if @@ -97,6 +99,7 @@ public class AuditRecord implements AuditData rc = rs.getString(1); else rc = "(CID #" + cid + ")"; + SQLUtil.shutdown(rs); commname_cache.put(cid_x,rc); } // end if @@ -105,6 +108,12 @@ public class AuditRecord implements AuditData } // end getCommunityName + void shutdown() + { + SQLUtil.shutdown(stmt); + + } // end shutdown + } // end class DescrStringCache /*-------------------------------------------------------------------------------- @@ -240,7 +249,7 @@ public class AuditRecord implements AuditData *-------------------------------------------------------------------------------- */ - private void setBaseData(int type, int uid, String ip) + private final void setBaseData(int type, int uid, String ip) { this.record = 0; this.when = null; @@ -250,7 +259,7 @@ public class AuditRecord implements AuditData } // end setBaseData - private void setData(String data1, String data2, String data3, String data4) + private final void setData(String data1, String data2, String data3, String data4) { data = new String[DATA_COUNT]; data[0] = data1; @@ -265,61 +274,61 @@ public class AuditRecord implements AuditData *-------------------------------------------------------------------------------- */ - public long getRecord() + public final long getRecord() { return record; } // end getRecord - public java.util.Date getDateTime() + public final java.util.Date getDateTime() { return when; } // end getDateTime - public int getType() + public final int getType() { return type; } // end getType - public int getUID() + public final int getUID() { return uid; } // end getType - public int getCommunityID() + public final int getCommunityID() { return cid; } // end getCommunityID - public String getIPAddress() + public final String getIPAddress() { return ip; } // end getIPAddress - public String getData(int ndx) + public final String getData(int ndx) { return data[ndx]; } // end getData - public String getDescription() + public final String getDescription() { return descr; } // end getDescription - public String getUserName() + public final String getUserName() { return uname; } // end getUserName - public String getCommunityName() + public final String getCommunityName() { return commname; @@ -335,32 +344,42 @@ public class AuditRecord implements AuditData if (record!=0) throw new InternalStateError("audit record " + String.valueOf(record) + " already stored!"); - Statement stmt = conn.createStatement(); - stmt.executeUpdate("LOCK TABLES audit WRITE;"); + Statement stmt = null; + try - { // attempt to insert a record into the audit table - StringBuffer sql = new StringBuffer("INSERT INTO audit (on_date, event, uid, sigid, ip, data1, data2, " - + "data3, data4) VALUES ('"); - java.util.Date now = new java.util.Date(); - sql.append(SQLUtil.encodeDate(now)).append("', ").append(type).append(", ").append(uid).append(", "); - sql.append(cid).append(", '").append(SQLUtil.encodeString(ip)).append("', "); - sql.append(SQLUtil.encodeStringArg(data[0])).append(", ").append(SQLUtil.encodeStringArg(data[1])); - sql.append(", ").append(SQLUtil.encodeStringArg(data[2])).append(", "); - sql.append(SQLUtil.encodeStringArg(data[3])).append(");"); + { // begin updating the database + stmt = conn.createStatement(); + stmt.executeUpdate("LOCK TABLES audit WRITE;"); + try + { // attempt to insert a record into the audit table + StringBuffer sql = new StringBuffer("INSERT INTO audit (on_date, event, uid, sigid, ip, data1, data2, " + + "data3, data4) VALUES ('"); + java.util.Date now = new java.util.Date(); + sql.append(SQLUtil.encodeDate(now)).append("', ").append(type).append(", ").append(uid).append(", "); + sql.append(cid).append(", '").append(SQLUtil.encodeString(ip)).append("', "); + sql.append(SQLUtil.encodeStringArg(data[0])).append(", ").append(SQLUtil.encodeStringArg(data[1])); + sql.append(", ").append(SQLUtil.encodeStringArg(data[2])).append(", "); + sql.append(SQLUtil.encodeStringArg(data[3])).append(");"); - stmt.executeUpdate(sql.toString()); + stmt.executeUpdate(sql.toString()); - ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();"); - if (!(rs.next())) - throw new InternalStateError("AuditRecord.store bogus query - must return at least 1 row!"); - record = rs.getLong(1); - when = now; + ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();"); + if (!(rs.next())) + throw new InternalStateError("AuditRecord.store bogus query - must return at least 1 row!"); + record = rs.getLong(1); + when = now; + + } // end try + finally + { // make sure we unlock the tables before we go + SQLUtil.unlockTables(conn); + + } // end finally } // end try finally - { // make sure we unlock the tables before we go - Statement ulk_stmt = conn.createStatement(); - ulk_stmt.executeUpdate("UNLOCK TABLES;"); + { // close down to conserve resources + SQLUtil.shutdown(stmt); } // end finally @@ -376,20 +395,31 @@ public class AuditRecord implements AuditData { ArrayList rc = new ArrayList(); DescrStringCache cache = new DescrStringCache(conn); + Statement stmt = null; - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT * FROM audit"); - if (cid>0) - sql.append(" WHERE sigid = ").append(cid); - sql.append(" ORDER BY on_date DESC LIMIT ").append(offset).append(", ").append(count).append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); + try + { // query for audit records + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT * FROM audit"); + if (cid>0) + sql.append(" WHERE sigid = ").append(cid); + sql.append(" ORDER BY on_date DESC LIMIT ").append(offset).append(", ").append(count).append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); - while (rs.next()) - { // load the results - AuditData dta = new AuditRecord(rs,cache); - rc.add(dta); + while (rs.next()) + { // load the results + AuditData dta = new AuditRecord(rs,cache); + rc.add(dta); - } // end while + } // end while + + } // end try + finally + { // shut down things + SQLUtil.shutdown(stmt); + cache.shutdown(); + + } // end finally return Collections.unmodifiableList(rc); @@ -397,15 +427,26 @@ public class AuditRecord implements AuditData public static int getAuditRecordCount(Connection conn, int cid) throws SQLException { - Statement stmt = conn.createStatement(); - StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM audit"); - if (cid>0) - sql.append(" WHERE sigid = ").append(cid); - sql.append(';'); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (!(rs.next())) - throw new InternalStateError("query failure on getAuditRecordCount"); - return rs.getInt(1); + Statement stmt = null; + + try + { // look up the count + stmt = conn.createStatement(); + StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM audit"); + if (cid>0) + sql.append(" WHERE sigid = ").append(cid); + sql.append(';'); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (!(rs.next())) + throw new InternalStateError("query failure on getAuditRecordCount"); + return rs.getInt(1); + + } // end try + finally + { // close statement to conserve resources + SQLUtil.shutdown(stmt); + + } // end finally } // end getAuditRecordCount diff --git a/src/com/silverwrist/venice/security/PrimordialSecurityMonitor.java b/src/com/silverwrist/venice/security/PrimordialSecurityMonitor.java index 795553d..0cf4c38 100644 --- a/src/com/silverwrist/venice/security/PrimordialSecurityMonitor.java +++ b/src/com/silverwrist/venice/security/PrimordialSecurityMonitor.java @@ -11,7 +11,7 @@ * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -24,7 +24,7 @@ import com.silverwrist.venice.except.AccessError; /** * The security monitor "below the root" of the security monitor tree, which defines the three roles - * which are "outside the standard scopes." Calls delegated to this instance of SEcurityMonitor + * which are "outside the standard scopes." Calls delegated to this instance of SecurityMonitor * generally fail or return null, except when returning the three defined roles. * * @author Eric J. Bowersox <erbo@silcom.com>