all Statements must be closed properly, to conserve resources after each

database operation (as per PreciseJava.com)
This commit is contained in:
Eric J. Bowersox 2002-03-04 04:50:43 +00:00
parent a404987a42
commit 54081b79e9
32 changed files with 1784 additions and 989 deletions

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -76,22 +76,33 @@ class AdminUserContextImpl implements AdminUserContext
this.my_locale = International.get().createLocale(rs.getString("localeid")); this.my_locale = International.get().createLocale(rs.getString("localeid"));
this.my_tz = TimeZone.getTimeZone(rs.getString("tzid")); this.my_tz = TimeZone.getTimeZone(rs.getString("tzid"));
Statement stmt = conn.createStatement(); Statement stmt = null;
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;
default: try
break; { // 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 } // end constructor
@ -103,10 +114,11 @@ class AdminUserContextImpl implements AdminUserContext
private final void updateProperties(BitSet delta) throws DataException private final void updateProperties(BitSet delta) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (delta.get(UserContextImpl.PROP_FLAGS)) if (delta.get(UserContextImpl.PROP_FLAGS))
@ -127,6 +139,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -196,6 +209,7 @@ class AdminUserContextImpl implements AdminUserContext
public void setDescription(String new_descr) throws DataException public void setDescription(String new_descr) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
if (new_descr.equals(description)) if (new_descr.equals(description))
@ -204,7 +218,7 @@ class AdminUserContextImpl implements AdminUserContext
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); StringBuffer sql = new StringBuffer("UPDATE users SET description = '");
sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -221,6 +235,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -237,6 +252,7 @@ class AdminUserContextImpl implements AdminUserContext
public void setBaseLevel(int new_level) throws DataException public void setBaseLevel(int new_level) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
if (level==new_level) if (level==new_level)
@ -245,7 +261,7 @@ class AdminUserContextImpl implements AdminUserContext
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET base_lvl = "); StringBuffer sql = new StringBuffer("UPDATE users SET base_lvl = ");
sql.append(new_level).append(" WHERE uid = ").append(uid).append(';'); sql.append(new_level).append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -262,6 +278,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -290,6 +307,7 @@ class AdminUserContextImpl implements AdminUserContext
public void setEmailVerified(boolean flag) throws DataException public void setEmailVerified(boolean flag) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
if (flag==email_verified) if (flag==email_verified)
@ -298,7 +316,7 @@ class AdminUserContextImpl implements AdminUserContext
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = "); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = ");
sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -315,6 +333,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -331,6 +350,7 @@ class AdminUserContextImpl implements AdminUserContext
public void setLockedOut(boolean flag) throws DataException public void setLockedOut(boolean flag) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
if (flag==lockout) if (flag==lockout)
@ -339,7 +359,7 @@ class AdminUserContextImpl implements AdminUserContext
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET lockout = "); StringBuffer sql = new StringBuffer("UPDATE users SET lockout = ");
sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -356,6 +376,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -436,12 +457,13 @@ class AdminUserContextImpl implements AdminUserContext
public void setPassword(String password, String reminder) throws DataException public void setPassword(String password, String reminder) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
PasswordHash phash = new PasswordHash(password); PasswordHash phash = new PasswordHash(password);
StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '");
sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder)); sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder));
@ -460,6 +482,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -476,12 +499,13 @@ class AdminUserContextImpl implements AdminUserContext
public void setLocale(Locale locale) throws DataException public void setLocale(Locale locale) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the update statement // create the update statement
StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '"); StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '");
@ -503,6 +527,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -519,12 +544,13 @@ class AdminUserContextImpl implements AdminUserContext
public void setTimeZone(TimeZone timezone) throws DataException public void setTimeZone(TimeZone timezone) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the update statement // create the update statement
StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '"); StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '");
@ -546,6 +572,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -602,11 +629,12 @@ class AdminUserContextImpl implements AdminUserContext
static AdminUserContext getAdminUserContext(EnvUser env, int uid) throws DataException static AdminUserContext getAdminUserContext(EnvUser env, int uid) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs "
+ "ON users.uid = userprefs.uid WHERE users.uid = " + uid + ";"); + "ON users.uid = userprefs.uid WHERE users.uid = " + uid + ";");
if (!(rs.next())) if (!(rs.next()))
@ -625,6 +653,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // release the connection where necessary { // release the connection where necessary
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -634,11 +663,12 @@ class AdminUserContextImpl implements AdminUserContext
static AdminUserContext getAdminUserContext(EnvUser env, String username) throws DataException static AdminUserContext getAdminUserContext(EnvUser env, String username) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs "
+ "ON users.uid = userprefs.uid WHERE users.username = '" + "ON users.uid = userprefs.uid WHERE users.username = '"
+ SQLUtil.encodeString(username) + "';"); + SQLUtil.encodeString(username) + "';");
@ -658,6 +688,7 @@ class AdminUserContextImpl implements AdminUserContext
} // end catch } // end catch
finally finally
{ // release the connection where necessary { // release the connection where necessary
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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); Integer my_ad_id = new Integer(ad_id);
Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id)); Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id));
if (rc!=null) if (rc!=null)
return rc; 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())) if (!(rs.next()))
return null; return null;
rc = new AdvertisementImpl(env,rs); rc = new AdvertisementImpl(env,rs);
SQLUtil.shutdown(rs);
ad_cache.put(my_ad_id,rc); ad_cache.put(my_ad_id,rc);
return rc; return rc;
@ -131,11 +132,12 @@ class AdvertisementImpl implements Advertisement
static Advertisement getAdByID(EnvEngine env, int id) static Advertisement getAdByID(EnvEngine env, int id)
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection and call the internal function { // get a database connection and call the internal function
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
return getTheAd(env,stmt,id); return getTheAd(env,stmt,id);
} // end try } // end try
@ -146,6 +148,7 @@ class AdvertisementImpl implements Advertisement
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -155,11 +158,12 @@ class AdvertisementImpl implements Advertisement
static Advertisement getRandomAd(EnvEngine env) static Advertisement getRandomAd(EnvEngine env)
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection and call the internal function { // get a database connection and call the internal function
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;"); ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;");
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!"); throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!");
@ -184,6 +188,7 @@ class AdvertisementImpl implements Advertisement
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -73,12 +73,13 @@ class BackgroundCommunityPurge implements Runnable
logger.debug("BackgroundCommunityPurge running on community #" + cid); logger.debug("BackgroundCommunityPurge running on community #" + cid);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
ParallelRunQueue rq = new ParallelRunQueue(2); ParallelRunQueue rq = new ParallelRunQueue(2);
try try
{ // get a database connection from the pool { // get a database connection from the pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// run some "lower priority" deletes // run some "lower priority" deletes
stmt.executeUpdate("DELETE FROM contacts WHERE owner_sigid = " + cid + ";"); stmt.executeUpdate("DELETE FROM contacts WHERE owner_sigid = " + cid + ";");
@ -94,6 +95,7 @@ class BackgroundCommunityPurge implements Runnable
int conferences = 0; int conferences = 0;
while (rs.next()) while (rs.next())
conf_ids[conferences++] = rs.getInt(1); conf_ids[conferences++] = rs.getInt(1);
SQLUtil.shutdown(rs);
for (int i=0; i<conferences; i++) for (int i=0; i<conferences; i++)
{ // look to see if there's a conference community object first { // look to see if there's a conference community object first
@ -117,6 +119,7 @@ class BackgroundCommunityPurge implements Runnable
rs = stmt.executeQuery(sql.toString()); rs = stmt.executeQuery(sql.toString());
if (rs.next()) if (rs.next())
delete_core = false; delete_core = false;
SQLUtil.shutdown(rs);
// delete the sigtoconf record // delete the sigtoconf record
sql.setLength(0); sql.setLength(0);
@ -139,6 +142,7 @@ class BackgroundCommunityPurge implements Runnable
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("BackgroundCommunityPurge.run screwup on conference SELECT"); throw new InternalStateError("BackgroundCommunityPurge.run screwup on conference SELECT");
rq.queue(new BackgroundConferencePurge(env,key.intValue(),rs.getInt(1),rs.getInt(2))); rq.queue(new BackgroundConferencePurge(env,key.intValue(),rs.getInt(1),rs.getInt(2)));
SQLUtil.shutdown(rs);
} // end if (have to delete conference data) } // end if (have to delete conference data)
@ -164,6 +168,7 @@ class BackgroundCommunityPurge implements Runnable
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -39,9 +39,9 @@ class BackgroundConferencePurge implements Runnable
*/ */
private EnvEngine env; // the environment private EnvEngine env; // the environment
private int confid; private int confid; // the conference ID
private int num_topics; private int num_topics; // the number of topics
private int max_topicid; private int max_topicid; // the maximum topic ID
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -68,12 +68,13 @@ class BackgroundConferencePurge implements Runnable
logger.debug("BackgroundConferencePurge running on conference #" + confid); logger.debug("BackgroundConferencePurge running on conference #" + confid);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
ParallelRunQueue rq = new ParallelRunQueue(2); ParallelRunQueue rq = new ParallelRunQueue(2);
try try
{ // get a database connection from the pool { // get a database connection from the pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// purge out some auxiliary tables first // purge out some auxiliary tables first
stmt.executeUpdate("DELETE FROM confmember WHERE confid = " + confid + ";"); stmt.executeUpdate("DELETE FROM confmember WHERE confid = " + confid + ";");
@ -90,6 +91,7 @@ class BackgroundConferencePurge implements Runnable
int topics = 0; int topics = 0;
while (rs.next()) while (rs.next())
topicids[topics++] = rs.getInt(1); topicids[topics++] = rs.getInt(1);
SQLUtil.shutdown(rs);
for (int i=0; i<topics; i++) for (int i=0; i<topics; i++)
{ // delete the topic header and settings rows first { // delete the topic header and settings rows first
@ -104,6 +106,7 @@ class BackgroundConferencePurge implements Runnable
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("BackgroundConferencePurge.run screwup on post SELECT"); throw new InternalStateError("BackgroundConferencePurge.run screwup on post SELECT");
rq.queue(new BackgroundTopicPurge(env,topicids[i],rs.getInt(1),rs.getLong(2))); rq.queue(new BackgroundTopicPurge(env,topicids[i],rs.getInt(1),rs.getLong(2)));
SQLUtil.shutdown(rs);
} // end for } // end for
@ -119,6 +122,7 @@ class BackgroundConferencePurge implements Runnable
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -37,9 +37,9 @@ class BackgroundTopicPurge implements Runnable
*/ */
private EnvEngine env; // the environment block private EnvEngine env; // the environment block
private int topicid; private int topicid; // the topic ID
private int num_posts; private int num_posts; // the number of posts in this topic
private long max_postid; private long max_postid; // the maximum post ID
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
@ -67,11 +67,12 @@ class BackgroundTopicPurge implements Runnable
long[] postids = new long[num_posts]; // stores the post IDs long[] postids = new long[num_posts]; // stores the post IDs
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection from the pool { // get a database connection from the pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// look up all the post IDs that are present for this topic // look up all the post IDs that are present for this topic
StringBuffer sql = new StringBuffer("SELECT postid FROM posts WHERE topicid = "); StringBuffer sql = new StringBuffer("SELECT postid FROM posts WHERE topicid = ");
@ -80,6 +81,7 @@ class BackgroundTopicPurge implements Runnable
int posts = 0; int posts = 0;
while (rs.next()) while (rs.next())
postids[posts++] = rs.getLong(1); postids[posts++] = rs.getLong(1);
SQLUtil.shutdown(rs);
for (int i=0; i<posts; i++) for (int i=0; i<posts; i++)
{ // remove all references to the posts in question { // remove all references to the posts in question
@ -104,6 +106,7 @@ class BackgroundTopicPurge implements Runnable
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -34,8 +34,8 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
static class CatSegment static class CatSegment
{ {
private int id; private int id; // ID of this category
private String name; private String name; // name of this segment
CatSegment(int id, String name) CatSegment(int id, String name)
{ {
@ -44,13 +44,13 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end constructor } // end constructor
public int getID() public final int getID()
{ {
return id; return id;
} // end getID } // end getID
public String getName() public final String getName()
{ {
return name; return name;
@ -154,13 +154,11 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int id, int symlink, String name) protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int id, int symlink, String name)
{ {
this.env = other.env; this.env = other.env;
this.cats = new LinkedList(); this.cats = (LinkedList)(other.cats.clone());
this.symlink = symlink; this.symlink = symlink;
this.do_hide = other.do_hide; this.do_hide = other.do_hide;
// copy the references to the objects directly // add the extra segment
for (int i=0; i<other.cats.size(); i++)
this.cats.add(other.cats.get(i));
this.cats.add(new CatSegment(id,name)); this.cats.add(new CatSegment(id,name));
} // end constructor } // end constructor
@ -170,34 +168,46 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
private void doFillFromTop(Connection conn, int catid) throws SQLException, DataException private final void doFillFromTop(Connection conn, int catid) throws SQLException, DataException
{ {
PreparedStatement stmt = conn.prepareStatement("SELECT parent, symlink, name " PreparedStatement stmt = null;
+ "FROM refcategory WHERE catid = ?;");
int curr_catid = catid; int curr_catid = catid;
while (curr_catid!=-1)
{ // get the category reference for this level
stmt.setInt(1,curr_catid);
ResultSet rs = stmt.executeQuery();
if (!(rs.next())) // unable to read database try
throw new DataException("category #" + String.valueOf(catid) + " could not be resolved"); { // prepare a statement
stmt = conn.prepareStatement("SELECT parent, symlink, name FROM refcategory WHERE catid = ?;");
// Save off the symbolic link value, if this category is a symlink. while (curr_catid!=-1)
int symlink_field = rs.getInt("symlink"); { // get the category reference for this level
if (symlink_field!=-1) stmt.setInt(1,curr_catid);
{ // handle saving our symlink value - can only occur at END of path ResultSet rs = stmt.executeQuery();
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 if (!(rs.next())) // unable to read database
throw new DataException("category #" + String.valueOf(catid) + " could not be resolved");
cats.addFirst(new CatSegment(curr_catid,rs.getString("name"))); // Save off the symbolic link value, if this category is a symlink.
curr_catid = rs.getInt("parent"); 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 while } // end if
cats.addFirst(new CatSegment(curr_catid,rs.getString("name")));
curr_catid = rs.getInt("parent");
SQLUtil.shutdown(rs);
} // end while
} // end try
finally
{ // close down the statement when we're done
SQLUtil.shutdown(stmt);
} // end finally
} // end doFillFromTop } // end doFillFromTop
@ -243,11 +253,12 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = "); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = ");
sql.append(getCategoryID()); sql.append(getCategoryID());
if (do_hide) if (do_hide)
@ -272,6 +283,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end catch } // end catch
finally finally
{ // make sure and release the connection before we go { // make sure and release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = -1"); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = -1");
if (!show_all) if (!show_all)
sql.append(" AND hide_dir = 0"); sql.append(" AND hide_dir = 0");
@ -402,6 +416,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end catch } // end catch
finally finally
{ // make sure and release the connection before we go { // make sure and release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -410,8 +425,8 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end getTopLevelCategoryList } // end getTopLevelCategoryList
static List searchForCategories(EnvEngine env, boolean show_all, boolean search_all, int mode, static final List searchForCategories(EnvEngine env, boolean show_all, boolean search_all, int mode,
String term, int offset, int count) throws DataException String term, int offset, int count) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "', offset = " logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "', offset = "
@ -419,11 +434,12 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE name "); StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE name ");
switch (mode) switch (mode)
@ -462,6 +478,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
while (rs.next()) // just read off the matching CATIDs for now while (rs.next()) // just read off the matching CATIDs for now
rc_raw[n++] = rs.getInt("catid"); rc_raw[n++] = rs.getInt("catid");
SQLUtil.shutdown(rs);
for (int i=0; i<n; i++) for (int i=0; i<n; i++)
{ // convert all the simple category IDs into full-blown CategoryDescriptor objects { // convert all the simple category IDs into full-blown CategoryDescriptor objects
@ -479,6 +496,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -494,11 +512,12 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "'"); logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "'");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM refcategory WHERE name "); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM refcategory WHERE name ");
switch (mode) switch (mode)
@ -546,6 +565,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -120,13 +120,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
this.cid = cid; this.cid = cid;
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection from this object { // get a database connection from this object
conn = env.getConnection(); conn = env.getConnection();
// get the community basic data from the database // get the community basic data from the database
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM sigs WHERE sigid = "); StringBuffer sql = new StringBuffer("SELECT * FROM sigs WHERE sigid = ");
sql.append(cid).append(';'); sql.append(cid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); 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."); throw new DataException("community #" + cid + " does not exist in the database.");
loadData(rs); // load the community data loadData(rs); // load the community data
SQLUtil.shutdown(rs);
sql.setLength(0); sql.setLength(0);
sql.append("SELECT ndx, data FROM propcomm WHERE cid = ").append(cid).append(';'); sql.append("SELECT ndx, data FROM propcomm WHERE cid = ").append(cid).append(';');
@ -153,6 +155,8 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end while } // end while
SQLUtil.shutdown(rs);
// get the set of community services // get the set of community services
services = new HashSet(); services = new HashSet();
sql.setLength(0); sql.setLength(0);
@ -175,6 +179,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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 // "cid" field is skipped
created = SQLUtil.getFullDateTime(rs,"createdate"); created = SQLUtil.getFullDateTime(rs,"createdate");
@ -264,40 +269,63 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end loadData } // end loadData
private synchronized void touchUpdate(Connection conn) throws SQLException private final synchronized void touchUpdate(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("UPDATE sigs SET lastupdate = '");
java.util.Date now = new java.util.Date(); try
sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); { // create and execute the Update statement
stmt.executeUpdate(sql.toString()); stmt = conn.createStatement();
last_update = now; 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 } // end touchUpdate
private void newProperties(Connection conn) throws SQLException private final void newProperties(Connection conn) throws SQLException
{ {
// generate start of SQL statement Statement stmt = null;
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("INSERT INTO propcomm (cid, ndx, data) VALUES ");
// append Property 0: flags try
sql.append('(').append(cid).append(", ").append(PROP_FLAGS).append(", '"); { // generate start of SQL statement
sql.append(flags.asString()).append("')"); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("INSERT INTO propcomm (cid, ndx, data) VALUES ");
// finish up // append Property 0: flags
sql.append(';'); sql.append('(').append(cid).append(", ").append(PROP_FLAGS).append(", '");
stmt.executeUpdate(sql.toString()); 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 } // end newProperties
private synchronized void updateProperties(BitSet delta) throws DataException private final synchronized void updateProperties(BitSet delta) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (delta.get(PROP_FLAGS)) if (delta.get(PROP_FLAGS))
@ -318,13 +346,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end updateProperties } // end updateProperties
private synchronized void updateProperties() throws DataException private final synchronized void updateProperties() throws DataException
{ {
updateProperties(ALL_PROPS); updateProperties(ALL_PROPS);
@ -495,11 +524,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
return false; // rejected on a level basis return false; // rejected on a level basis
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// check to see if the UID is listed in "sigban" table... // check to see if the UID is listed in "sigban" table...
StringBuffer sql = new StringBuffer("SELECT by_uid FROM sigban WHERE sigid = "); StringBuffer sql = new StringBuffer("SELECT by_uid FROM sigban WHERE sigid = ");
@ -516,6 +546,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -621,12 +652,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
return; return;
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES sigftrs WRITE;"); stmt.executeUpdate("LOCK TABLES sigftrs WRITE;");
try try
@ -654,8 +686,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end try } // end try
finally finally
{ // make sure we unlock the tables before we go { // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -671,6 +702,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -684,12 +716,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET signame = '"); StringBuffer sql = new StringBuffer("UPDATE sigs SET signame = '");
sql.append(SQLUtil.encodeString(name)).append("', lastupdate = '"); sql.append(SQLUtil.encodeString(name)).append("', lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -708,6 +741,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -721,12 +755,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET alias = '"); StringBuffer sql = new StringBuffer("UPDATE sigs SET alias = '");
sql.append(alias).append("', lastupdate = '"); sql.append(alias).append("', lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -745,6 +780,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -758,12 +794,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET catid = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET catid = ");
sql.append(catid).append(", lastupdate = '"); sql.append(catid).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -782,6 +819,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -795,11 +833,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET synopsis = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET synopsis = ");
sql.append(SQLUtil.encodeStringArg(synopsis)).append(", lastupdate = '"); sql.append(SQLUtil.encodeStringArg(synopsis)).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -817,6 +856,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -829,11 +869,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET language = '"); StringBuffer sql = new StringBuffer("UPDATE sigs SET language = '");
sql.append(SQLUtil.encodeString(language)).append("', lastupdate = '"); sql.append(SQLUtil.encodeString(language)).append("', lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -851,6 +892,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -863,11 +905,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET rules = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET rules = ");
sql.append(SQLUtil.encodeStringArg(rules)).append(", lastupdate = '"); sql.append(SQLUtil.encodeStringArg(rules)).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -885,6 +928,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -897,11 +941,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
return; // no need to touch anything return; // no need to touch anything
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET lastaccess = '"); StringBuffer sql = new StringBuffer("UPDATE sigs SET lastaccess = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';');
@ -917,6 +962,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -942,12 +988,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET hide_dir = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET hide_dir = ");
sql.append(directory ? '1' : '0').append(", hide_search = ").append(search ? '1' : '0'); sql.append(directory ? '1' : '0').append(", hide_search = ").append(search ? '1' : '0');
sql.append(", lastupdate = '"); sql.append(", lastupdate = '");
@ -968,6 +1015,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -987,12 +1035,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET membersonly = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET membersonly = ");
sql.append(flag ? '1' : '0').append(", lastupdate = '"); sql.append(flag ? '1' : '0').append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -1011,6 +1060,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1030,11 +1080,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = ");
sql.append(token.getIndex()).append(", lastupdate = '"); sql.append(token.getIndex()).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -1052,6 +1103,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1064,11 +1116,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT joinkey FROM sigs WHERE sigid = "); StringBuffer sql = new StringBuffer("SELECT joinkey FROM sigs WHERE sigid = ");
sql.append(cid).append(';'); sql.append(cid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -1090,6 +1143,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1102,12 +1156,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET joinkey = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET joinkey = ");
sql.append(SQLUtil.encodeStringArg(key)).append(", lastupdate = '"); sql.append(SQLUtil.encodeStringArg(key)).append(", lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -1126,6 +1181,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1170,6 +1226,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -1177,7 +1234,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigs SET read_lvl = "); StringBuffer sql = new StringBuffer("UPDATE sigs SET read_lvl = ");
sql.append(read).append(", write_lvl = ").append(write).append(", create_lvl = ").append(create); sql.append(read).append(", write_lvl = ").append(write).append(", create_lvl = ").append(create);
sql.append(", delete_lvl = ").append(delete).append(", join_lvl = ").append(join); sql.append(", delete_lvl = ").append(delete).append(", join_lvl = ").append(join);
@ -1208,6 +1265,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1228,14 +1286,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // successful audit record AuditRecord ar = null; // successful audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
boolean did_it = false;
stmt.executeUpdate("LOCK TABLES sigmember WRITE;"); stmt.executeUpdate("LOCK TABLES sigmember WRITE;");
boolean did_it = false;
try try
{ // perform the actual manipulation of the SIGMEMBER table... { // perform the actual manipulation of the SIGMEMBER table...
@ -1262,6 +1321,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end else } // end else
SQLUtil.shutdown(rs);
stmt.executeUpdate(sql.toString()); // update me! stmt.executeUpdate(sql.toString()); // update me!
did_it = true; did_it = true;
@ -1277,8 +1337,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end try } // end try
finally finally
{ // make sure the tables are unlocked before we go { // make sure the tables are unlocked before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1298,6 +1357,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1311,11 +1371,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection and create the appropriate SELECT statement { // get a database connection and create the appropriate SELECT statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigmember WHERE sigid = "); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigmember WHERE sigid = ");
sql.append(cid); sql.append(cid);
if (!include_hidden) if (!include_hidden)
@ -1338,6 +1399,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1424,11 +1486,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create a new SQL statement // create a new SQL statement
StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1527,11 +1591,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
+ term + "'"); + term + "'");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c, sigmember m WHERE " 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 = "); + "u.contactid = c.contactid AND u.uid = m.uid AND m.sigid = ");
sql.append(cid).append(" AND "); sql.append(cid).append(" AND ");
@ -1602,6 +1667,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1618,11 +1684,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create a new SQL statement // create a new SQL statement
StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1676,11 +1744,12 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
logger.debug("Member level: community = " + cid + ", user = " + uid); logger.debug("Member level: community = " + cid + ", user = " + uid);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// a relatively simple search // a relatively simple search
StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM sigmember WHERE sigid = "); StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM sigmember WHERE sigid = ");
@ -1702,6 +1771,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1717,13 +1787,14 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
logger.debug("Delete community: community = " + cid); logger.debug("Delete community: community = " + cid);
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
int conf_count, conf_max; int conf_count, conf_max;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we need to reference immediately // lock the tables we need to reference immediately
stmt.executeUpdate("LOCK TABLES sigs WRITE, sigmember WRITE, confhotlist WRITE, sigtoconf READ;"); 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"); throw new InternalStateError("CommunityCoreData.delete screwup on conference SELECT");
conf_count = rs.getInt(1); conf_count = rs.getInt(1);
conf_max = rs.getInt(2); conf_max = rs.getInt(2);
SQLUtil.shutdown(rs);
// record that we're now deleted // record that we're now deleted
created = null; created = null;
@ -1761,8 +1833,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end try } // end try
finally finally
{ // make sure to unlock the tables before we go { // make sure to unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1778,6 +1849,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1829,12 +1901,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1860,6 +1933,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1895,6 +1969,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
boolean hide_search) throws DataException, AccessError boolean hide_search) throws DataException, AccessError
{ {
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
int new_cid; // ID of the new community int new_cid; // ID of the new community
java.util.Date creation; // creation date! java.util.Date creation; // creation date!
AuditRecord ar = null; // the audit record AuditRecord ar = null; // the audit record
@ -1903,7 +1978,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
try try
{ // get a database connection and create the appropriate SELECT statement { // get a database connection and create the appropriate SELECT statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES sigs WRITE, sigftrs WRITE, propcomm WRITE, sigmember WRITE;"); stmt.executeUpdate("LOCK TABLES sigs WRITE, sigftrs WRITE, propcomm WRITE, sigmember WRITE;");
try try
@ -1913,6 +1988,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next()) // we should get 0 rows back on this one if (rs.next()) // we should get 0 rows back on this one
throw new AccessError("A community with that alias already exists."); throw new AccessError("A community with that alias already exists.");
SQLUtil.shutdown(rs);
// Now, here comes the BIG INSERT to create the community! // Now, here comes the BIG INSERT to create the community!
sql.setLength(0); sql.setLength(0);
@ -1952,6 +2028,8 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end else } // end else
SQLUtil.shutdown(rs);
// Assign the new community the default services for new communities. // Assign the new community the default services for new communities.
Set default_service = env.getSCM().getDefaultServices(ServiceControl.SVCGRP_COMMUNITY); Set default_service = env.getSCM().getDefaultServices(ServiceControl.SVCGRP_COMMUNITY);
if (default_service.size()>0) if (default_service.size()>0)
@ -1997,8 +2075,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end try } // end try
finally finally
{ // unlock the tables before we bail out { // unlock the tables before we bail out
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -2017,6 +2094,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);

View File

@ -48,13 +48,13 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end constructor } // end constructor
public String getName() public final String getName()
{ {
return name; return name;
} // end getName } // end getName
public String getAlias() public final String getAlias()
{ {
return alias; 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()) if (logger.isDebugEnabled())
logger.debug("setMemberValues(" + String.valueOf(granted_level) + ", " + String.valueOf(member) logger.debug("setMemberValues(" + String.valueOf(granted_level) + ", " + String.valueOf(member)
@ -150,7 +150,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end setMemberValues } // end setMemberValues
private CommunityData getData() throws DataException private final CommunityData getData() throws DataException
{ {
if (data==null) if (data==null)
{ // attempt to load the CommunityData object { // attempt to load the CommunityData object
@ -169,7 +169,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end getData } // end getData
private CommunityData getDataNE() private final CommunityData getDataNE()
{ {
if (data==null) if (data==null)
{ // we need to load the CommunityData... { // we need to load the CommunityData...
@ -198,7 +198,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end getDataNE } // end getDataNE
private void testConferenceAccess() throws DataException, AccessError private final void testConferenceAccess() throws DataException, AccessError
{ {
if (deleted) if (deleted)
throw new DataException("This community has been deleted."); throw new DataException("This community has been deleted.");
@ -234,12 +234,14 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end testConferenceAccess } // 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 throws DataException
{ {
Statement stmt = null;
try try
{ // create the query to find the community in the table { // 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 = "); StringBuffer sql = new StringBuffer("SELECT signame, alias FROM sigs WHERE sigid = ");
sql.append(cid).append(';'); sql.append(cid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -252,6 +254,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
// initialize the object and check membership info // initialize the object and check membership info
CommunityUserContextImpl sc = new CommunityUserContextImpl(env,cid,rs.getString(1),rs.getString(2)); CommunityUserContextImpl sc = new CommunityUserContextImpl(env,cid,rs.getString(1),rs.getString(2));
SQLUtil.shutdown(rs);
sc.checkMembership(conn); sc.checkMembership(conn);
return sc; return sc;
@ -262,6 +265,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
throw new DataException("unable to retrieve community information: " + e.getMessage(),e); throw new DataException("unable to retrieve community information: " + e.getMessage(),e);
} // end catch } // end catch
finally
{ // shut down statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end getCommunityPrivate } // end getCommunityPrivate
@ -1290,8 +1298,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
if (conn!=null) env.releaseConnection(conn);
env.releaseConnection(conn);
} // end finally } // end finally
@ -1327,8 +1334,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
if (conn!=null) env.releaseConnection(conn);
env.releaseConnection(conn);
} // end finally } // end finally
@ -1419,13 +1425,14 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
testConferenceAccess(); testConferenceAccess();
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn);
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1458,6 +1465,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1478,11 +1486,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
testConferenceAccess(); testConferenceAccess();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1512,6 +1521,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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()) if (logger.isDebugEnabled())
logger.debug("getMemberCommunityEntries for user #" + String.valueOf(env.getUserID())); logger.debug("getMemberCommunityEntries for user #" + String.valueOf(env.getUserID()));
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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 " 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 " + "FROM sigmember sm, sigs s WHERE sm.sigid = s.sigid "
+ "AND sm.uid = "); + "AND sm.uid = ");
@ -1663,6 +1674,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1671,7 +1683,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end getMemberCommunityEntries } // 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 Connection conn = null; // pooled database connection
@ -1697,16 +1709,17 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end getCommunityContext } // 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 Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
// create the query to find the community in the table // 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 = '"); StringBuffer sql = new StringBuffer("SELECT sigid, signame FROM sigs WHERE alias = '");
sql.append(SQLUtil.encodeString(alias)).append("';"); sql.append(SQLUtil.encodeString(alias)).append("';");
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -1719,6 +1732,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
// initialize the object and check membership info // initialize the object and check membership info
CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2),alias); CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2),alias);
SQLUtil.shutdown(rs);
c.checkMembership(conn); c.checkMembership(conn);
return c; return c;
@ -1731,19 +1745,20 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end getCommunityContext } // 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); return getCommunityPrivate(env,conn,cid);
} // end getCommunityBackend } // 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 throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
@ -1752,11 +1767,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE "); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE ");
switch (field) switch (field)
@ -1822,6 +1838,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1830,18 +1847,19 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end searchForCommunities } // 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 throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Community search: field = " + field + ", mode = " + mode + ", term '" + term + "'"); logger.debug("Community search: field = " + field + ", mode = " + mode + ", term '" + term + "'");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE "); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE ");
switch (field) switch (field)
@ -1902,24 +1920,27 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end getSearchCommunityCount } // 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()) if (logger.isDebugEnabled())
logger.debug("reading communities in category " + catid + ", offset = " + offset + ", count = " + count); logger.debug("reading communities in category " + catid + ", offset = " + offset + ", count = " + count);
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE catid = "); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE catid = ");
sql.append(catid); sql.append(catid);
if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES))) if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES)))
@ -1951,6 +1972,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1959,17 +1981,18 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end getCommunitiesInCategory } // end getCommunitiesInCategory
static int getNumCommunitiesInCategory(EnvUser env, int catid) throws DataException static final int getNumCommunitiesInCategory(EnvUser env, int catid) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("reading communities in category " + catid); logger.debug("reading communities in category " + catid);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE catid = "); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE catid = ");
sql.append(catid); sql.append(catid);
if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES))) if (!(env.testPermission(EnvUser.PERM_SHOWHIDDENCOMMUNITIES)))
@ -1996,6 +2019,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -2009,24 +2033,35 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
protected void checkMembership(Connection conn) throws SQLException protected void checkMembership(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
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 if try
else { // look up the membership data
{ // we're NOT a member... stmt = conn.createStatement();
if (logger.isDebugEnabled()) StringBuffer sql = new StringBuffer("SELECT granted_lvl, locked FROM sigmember WHERE sigid = ");
logger.debug("we are NOT a member of this community"); sql.append(cid).append(" AND uid = ").append(env.getUserID()).append(';');
setMemberValues(0,false,false); 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 } // end checkMembership

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -104,11 +104,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
this.confid = confid; this.confid = confid;
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Build a monster query! This is like the query for retrieving the ConferenceUserContextImpl // 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. // data, except without the left outer join to the user conference membership table.
@ -140,6 +141,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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) if (confdata==null)
{ // attempt to load the ConferenceCommunityContext { // attempt to load the ConferenceCommunityContext
@ -184,7 +186,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end getConferenceData } // end getConferenceData
private synchronized ConferenceData getConferenceDataNE() private final synchronized ConferenceData getConferenceDataNE()
{ {
if (confdata==null) if (confdata==null)
{ // we need to load the ConferenceCommunityContext... { // we need to load the ConferenceCommunityContext...
@ -420,6 +422,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -427,7 +430,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET granted_lvl = "); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET granted_lvl = ");
sql.append(new_level).append(" WHERE sigid = ").append(this.env.getCommunityID()); sql.append(new_level).append(" WHERE sigid = ").append(this.env.getCommunityID());
sql.append(" AND confid = ").append(confid).append(';'); sql.append(" AND confid = ").append(confid).append(';');
@ -450,6 +453,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -469,13 +473,14 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET sequence = "); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET sequence = ");
sql.append(seq).append(" WHERE sigid = ").append(env.getCommunityID()).append(" AND confid = "); sql.append(seq).append(" WHERE sigid = ").append(env.getCommunityID()).append(" AND confid = ");
sql.append(confid).append(';'); sql.append(confid).append(';');
@ -495,6 +500,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -527,6 +533,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end if } // end if
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -534,7 +541,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET hide_list = "); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET hide_list = ");
sql.append(flag ? '1' : '0').append(" WHERE sigid = ").append(env.getCommunityID()); sql.append(flag ? '1' : '0').append(" WHERE sigid = ").append(env.getCommunityID());
sql.append(" AND confid = ").append(confid).append(';'); sql.append(" AND confid = ").append(confid).append(';');
@ -559,6 +566,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -698,12 +706,13 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
{ {
ConferenceData c = getConferenceData(); ConferenceData c = getConferenceData();
Connection conn = null; Connection conn = null;
Statement stmt = null;
boolean delete_core = true; boolean delete_core = true;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// see if we have to delete the core object as well // see if we have to delete the core object as well
StringBuffer sql = new StringBuffer("SELECT sigid FROM sigtoconf WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT sigid FROM sigtoconf WHERE confid = ");
@ -711,6 +720,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next()) if (rs.next())
delete_core = false; // we don't delete the core yet delete_core = false; // we don't delete the core yet
SQLUtil.shutdown(rs);
// remove the row that links this conference to this community // remove the row that links this conference to this community
sql.setLength(0); sql.setLength(0);
@ -734,6 +744,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -85,13 +85,14 @@ class ConferenceCoreData implements ConferenceData
this.confid = confid; this.confid = confid;
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection from this object { // get a database connection from this object
conn = env.getConnection(); conn = env.getConnection();
// get the conference basic data from the database // get the conference basic data from the database
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM confs WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT * FROM confs WHERE confid = ");
sql.append(confid).append(';'); sql.append(confid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); 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."); throw new DataException("Conference #" + confid + " does not exist in the database.");
loadData(rs); // load the conference data loadData(rs); // load the conference data
SQLUtil.shutdown(rs);
flags = new OptionSet(); flags = new OptionSet();
loadProperties(conn); loadProperties(conn);
loadCustom(conn); loadCustom(conn);
@ -112,6 +114,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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 // "confid" field is skipped
create_date = SQLUtil.getFullDateTime(rs,"createdate"); create_date = SQLUtil.getFullDateTime(rs,"createdate");
@ -167,92 +170,138 @@ class ConferenceCoreData implements ConferenceData
} // end loadData } // end loadData
private synchronized void loadProperties(Connection conn) throws SQLException private synchronized final void loadProperties(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
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;
default: try
break; { // 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 } // end loadProperties
private synchronized void loadCustom(Connection conn) throws SQLException private synchronized final void loadCustom(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("SELECT htmltop, htmlbottom FROM confcustom WHERE confid = ");
sql.append(confid).append(';'); try
ResultSet rs = stmt.executeQuery(sql.toString()); { // retrieve the custom HTML blocks
if (rs.next()) stmt = conn.createStatement();
{ // load the custom data and save it as SoftReferences (so it can be erased StringBuffer sql = new StringBuffer("SELECT htmltop, htmlbottom FROM confcustom WHERE confid = ");
has_custom = true; sql.append(confid).append(';');
String s; ResultSet rs = stmt.executeQuery(sql.toString());
if ((cust_top==null) || (cust_top.get()==null)) if (rs.next())
{ // retrieve the top custom block { // load the custom data and save it as SoftReferences (so it can be erased
s = rs.getString(1); has_custom = true;
if (s!=null) String s;
cust_top = new SoftReference(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 } // end if
if ((cust_bottom==null) || (cust_bottom.get()==null)) } // end try
{ // retrieve the bottom custom block finally
s = rs.getString(2); { // shutdown the statement to conserve resources
if (s!=null) SQLUtil.shutdown(stmt);
cust_bottom = new SoftReference(s);
} // end if } // end finally
} // end if
} // end loadCustom } // end loadCustom
private synchronized void touchUpdate(Connection conn) throws SQLException private synchronized final void touchUpdate(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '");
java.util.Date now = new java.util.Date(); try
sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';'); { // set the last update field
stmt.executeUpdate(sql.toString()); stmt = conn.createStatement();
last_update = now; 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 } // end touchUpdate
private void newProperties(Connection conn) throws SQLException private final void newProperties(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("INSERT INTO propconf (confid, ndx, data) VALUES ");
// Append Property 0 - the "flags" property. try
sql.append('(').append(confid).append(", ").append(PROP_FLAGS).append(", '"); { // store off the properties
sql.append(flags.asString()).append("')"); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("INSERT INTO propconf (confid, ndx, data) VALUES ");
// Finish up. // Append Property 0 - the "flags" property.
sql.append(';'); sql.append('(').append(confid).append(", ").append(PROP_FLAGS).append(", '");
stmt.executeUpdate(sql.toString()); 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 } // end newProperties
private synchronized void updateProperties(BitSet delta) throws DataException private synchronized final void updateProperties(BitSet delta) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (delta.get(PROP_FLAGS)) if (delta.get(PROP_FLAGS))
@ -273,13 +322,14 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end updateProperties } // end updateProperties
private synchronized void updateProperties() throws DataException private synchronized final void updateProperties() throws DataException
{ {
updateProperties(ALL_PROPS); updateProperties(ALL_PROPS);
@ -345,6 +395,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
@ -352,7 +403,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
// get a list of all aliases // get a list of all aliases
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = ");
sql.append(confid).append(" ORDER BY alias;"); sql.append(confid).append(" ORDER BY alias;");
@ -370,6 +421,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -384,6 +436,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
@ -391,7 +444,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
// get a list of all hosts (with user info) // get a list of all hosts (with user info)
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = StringBuffer sql =
new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, c.family_name, " 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 " + "c.locality, c.region, c.country FROM users u, contacts c, confmember m "
@ -418,6 +471,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -507,6 +561,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -514,7 +569,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET read_lvl = "); StringBuffer sql = new StringBuffer("UPDATE confs SET read_lvl = ");
sql.append(read).append(", post_lvl = ").append(post).append(", create_lvl = ").append(create); 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 = "); sql.append(", hide_lvl = ").append(hide).append(", nuke_lvl = ").append(nuke).append(", change_lvl = ");
@ -547,6 +602,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -560,6 +616,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -567,7 +624,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET name = '"); StringBuffer sql = new StringBuffer("UPDATE confs SET name = '");
sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '"); sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -592,6 +649,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -605,13 +663,14 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
// create the SQL statement // create the SQL statement
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET descr = '"); StringBuffer sql = new StringBuffer("UPDATE confs SET descr = '");
sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '"); sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '");
java.util.Date now = new java.util.Date(); java.util.Date now = new java.util.Date();
@ -632,6 +691,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -644,13 +704,14 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confalias WRITE;"); stmt.executeUpdate("LOCK TABLES confalias WRITE;");
try try
{ // first check to see if the alias already exists { // first check to see if the alias already exists
@ -666,6 +727,8 @@ class ConferenceCoreData implements ConferenceData
} // end if } // end if
SQLUtil.shutdown(rs);
// now add it! // now add it!
sql.setLength(0); sql.setLength(0);
sql.append("INSERT INTO confalias (confid, alias) VALUES (").append(confid).append(", '"); sql.append("INSERT INTO confalias (confid, alias) VALUES (").append(confid).append(", '");
@ -675,8 +738,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // make sure we unlock the tables before we go { // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -693,6 +755,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -706,6 +769,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -713,7 +777,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
boolean did_it = false; boolean did_it = false;
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confalias WRITE;"); stmt.executeUpdate("LOCK TABLES confalias WRITE;");
try try
{ // first check to see how many aliases there are { // first check to see how many aliases there are
@ -738,6 +802,8 @@ class ConferenceCoreData implements ConferenceData
} // end if } // end if
SQLUtil.shutdown(rs);
// OK, go delete the row (or not, if this alias is not in the table) // OK, go delete the row (or not, if this alias is not in the table)
sql.setLength(0); sql.setLength(0);
sql.append("DELETE FROM confalias WHERE confid = ").append(confid).append(" AND alias = '"); sql.append("DELETE FROM confalias WHERE confid = ").append(confid).append(" AND alias = '");
@ -747,8 +813,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // make sure we unlock the tables before we go { // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -770,6 +835,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -783,6 +849,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
try try
@ -790,7 +857,7 @@ class ConferenceCoreData implements ConferenceData
conn = env.getConnection(); conn = env.getConnection();
boolean did_it = false; boolean did_it = false;
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confmember WRITE;"); stmt.executeUpdate("LOCK TABLES confmember WRITE;");
try try
{ // how we go about this depends on whether we're adding or removing { // how we go about this depends on whether we're adding or removing
@ -815,6 +882,7 @@ class ConferenceCoreData implements ConferenceData
} // end else } // end else
SQLUtil.shutdown(rs);
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
did_it = true; did_it = true;
@ -830,8 +898,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // make sure we unlock the tables before we go { // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -851,6 +918,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -875,11 +943,12 @@ class ConferenceCoreData implements ConferenceData
return cached_alias; return cached_alias;
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement and execute it // create the SQL statement and execute it
StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = ");
@ -899,6 +968,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -912,6 +982,7 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
short new_topic_num; // sequential number of the new topic short new_topic_num; // sequential number of the new topic
int new_topic_id; // ID of the new topic int new_topic_id; // ID of the new topic
@ -920,7 +991,7 @@ class ConferenceCoreData implements ConferenceData
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we need to use so we can update them // lock the tables we need to use so we can update them
stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, postdata WRITE;"); stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, postdata WRITE;");
@ -946,6 +1017,7 @@ class ConferenceCoreData implements ConferenceData
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("createNewTopic() could not get back inserted Topic ID"); throw new InternalStateError("createNewTopic() could not get back inserted Topic ID");
new_topic_id = rs.getInt(1); new_topic_id = rs.getInt(1);
SQLUtil.shutdown(rs);
// insert the "header" for the "zero post" in the topic // insert the "header" for the "zero post" in the topic
sql.setLength(0); sql.setLength(0);
@ -961,6 +1033,7 @@ class ConferenceCoreData implements ConferenceData
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("createNewTopic() could not get back inserted zero post ID"); throw new InternalStateError("createNewTopic() could not get back inserted zero post ID");
long zero_post_id = rs.getLong(1); long zero_post_id = rs.getLong(1);
SQLUtil.shutdown(rs);
// insert the post data // insert the post data
sql.setLength(0); sql.setLength(0);
@ -987,8 +1060,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // we need to unlock the tables before we go { // we need to unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1001,6 +1073,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1032,9 +1105,11 @@ class ConferenceCoreData implements ConferenceData
if (deleted) if (deleted)
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Statement stmt = null;
try try
{ // update the last update date { // update the last update date
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '"); StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '");
sql.append(SQLUtil.encodeDate(date)).append("' WHERE confid = ").append(confid).append(';'); sql.append(SQLUtil.encodeDate(date)).append("' WHERE confid = ").append(confid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -1046,6 +1121,11 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("Database error updating conference: " + e.getMessage(),e); throw new DataException("Database error updating conference: " + e.getMessage(),e);
} // end catch } // end catch
finally
{ // shut down the statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end touchUpdate } // end touchUpdate
@ -1093,11 +1173,12 @@ class ConferenceCoreData implements ConferenceData
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create a new SQL statement // create a new SQL statement
StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, "
@ -1131,6 +1212,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1145,11 +1227,12 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the statement // create the statement
StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM confmember WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT granted_lvl FROM confmember WHERE confid = ");
@ -1169,6 +1252,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1197,13 +1281,14 @@ class ConferenceCoreData implements ConferenceData
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
int topic_count, topic_max; // count and maximum topic int topic_count, topic_max; // count and maximum topic
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock tables on the critical stuff that MUST be deleted now // lock tables on the critical stuff that MUST be deleted now
stmt.executeUpdate("LOCK TABLES confs WRITE, confalias WRITE, topics READ;"); 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"); throw new InternalStateError("ConferenceCoreData.delete screwup on topic SELECT");
topic_count = rs.getInt(1); topic_count = rs.getInt(1);
topic_max = rs.getInt(2); topic_max = rs.getInt(2);
SQLUtil.shutdown(rs);
// record that we're now deleted // record that we're now deleted
create_date = null; create_date = null;
@ -1239,8 +1325,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1256,6 +1341,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1366,10 +1452,12 @@ class ConferenceCoreData implements ConferenceData
throw new IndexOutOfBoundsException("invalid custom block selector"); throw new IndexOutOfBoundsException("invalid custom block selector");
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection { // get a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// build the right SQL command // build the right SQL command
StringBuffer sql = null; StringBuffer sql = null;
@ -1418,6 +1506,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1427,10 +1516,12 @@ class ConferenceCoreData implements ConferenceData
public synchronized void removeCustomBlocks() throws DataException public synchronized void removeCustomBlocks() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection { // get a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// execute the delete statement // execute the delete statement
stmt.executeUpdate("DELETE FROM confcustom WHERE confid = " + confid + ";"); stmt.executeUpdate("DELETE FROM confcustom WHERE confid = " + confid + ";");
@ -1452,6 +1543,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1468,6 +1560,7 @@ class ConferenceCoreData implements ConferenceData
throws DataException throws DataException
{ {
Connection conn = null; // database connection Connection conn = null; // database connection
Statement stmt = null;
AuditRecord ar = null; // audit record AuditRecord ar = null; // audit record
int new_confid; // new conference ID int new_confid; // new conference ID
short new_sequence; // new sequence number short new_sequence; // new sequence number
@ -1480,7 +1573,7 @@ class ConferenceCoreData implements ConferenceData
try try
{ // start by locking all the tables we need { // start by locking all the tables we need
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confs WRITE, sigtoconf WRITE, confalias WRITE, confmember WRITE, " stmt.executeUpdate("LOCK TABLES confs WRITE, sigtoconf WRITE, confalias WRITE, confmember WRITE, "
+ "propconf WRITE;"); + "propconf WRITE;");
@ -1505,6 +1598,7 @@ class ConferenceCoreData implements ConferenceData
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("bogus query in createConference - must return at least 1 row!"); throw new InternalStateError("bogus query in createConference - must return at least 1 row!");
new_sequence = (short)(rs.getShort(1) + 10); new_sequence = (short)(rs.getShort(1) + 10);
SQLUtil.shutdown(rs);
// insert the record into the conferences table! // insert the record into the conferences table!
sql.setLength(0); sql.setLength(0);
@ -1546,6 +1640,7 @@ class ConferenceCoreData implements ConferenceData
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("bogus query in createConference - must get new confid!"); throw new InternalStateError("bogus query in createConference - must get new confid!");
new_confid = rs.getInt(1); new_confid = rs.getInt(1);
SQLUtil.shutdown(rs);
// Make the insert into the confalias table to give the conference an alias. // Make the insert into the confalias table to give the conference an alias.
sql.setLength(0); sql.setLength(0);
@ -1581,8 +1676,7 @@ class ConferenceCoreData implements ConferenceData
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1600,6 +1694,7 @@ class ConferenceCoreData implements ConferenceData
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -51,25 +51,25 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end constructor } // end constructor
public String getName() public final String getName()
{ {
return name; return name;
} // end getName } // end getName
public String getDescription() public final String getDescription()
{ {
return description; return description;
} // end getDescription } // end getDescription
public java.util.Date getCreated() public final java.util.Date getCreated()
{ {
return created; return created;
} // end getCreated } // end getCreated
public int getGrantsLevel() public final int getGrantsLevel()
{ {
return grants_level; 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) if (confdata==null)
{ // attempt to load the ConferenceCommunityContext { // attempt to load the ConferenceCommunityContext
@ -230,7 +230,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end getConferenceData } // end getConferenceData
private ConferenceCommunityContext getConferenceDataNE() private final ConferenceCommunityContext getConferenceDataNE()
{ {
if (confdata==null) if (confdata==null)
{ // we need to load the ConferenceCommunityContext... { // we need to load the ConferenceCommunityContext...
@ -260,7 +260,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end getConferenceDataNE } // end getConferenceDataNE
private void recalcLevel(int new_level) private final void recalcLevel(int new_level)
{ {
level = env.getCommunity().realCommunityLevel(); level = env.getCommunity().realCommunityLevel();
@ -282,14 +282,16 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end recalcLevel } // end recalcLevel
private void tryLoadSettings(Connection conn) throws DataException private final void tryLoadSettings(Connection conn) throws DataException
{ {
if (deleted) if (deleted)
return; // this is a no-op return; // this is a no-op
Statement stmt = null;
try try
{ // look up the conference settings for this user { // look up the conference settings for this user
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM confsettings WHERE confid = "); StringBuffer sql = new StringBuffer("SELECT * FROM confsettings WHERE confid = ");
sql.append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); sql.append(confid).append(" AND uid = ").append(env.getUserID()).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); 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); throw new DataException("Unable to load conference settings: " + e.getMessage(),e);
} // end catch } // end catch
finally
{ // shutdown the statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end tryLoadSettings } // end tryLoadSettings
@ -769,11 +776,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
throw new DataException("This conference has been deleted."); throw new DataException("This conference has been deleted.");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (settings_loaded) if (settings_loaded)
@ -806,6 +814,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -817,6 +826,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
if (deleted || env.getUser().userIsAnonymous()) if (deleted || env.getUser().userIsAnonymous())
return false; return false;
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // 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 // 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 // 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). // 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 " StringBuffer sql = new StringBuffer("SELECT t.topicid FROM topics t LEFT JOIN topicsettings s "
+ "ON t.topicid = s.topicid AND s.uid = "); + "ON t.topicid = s.topicid AND s.uid = ");
sql.append(env.getUserID()).append(" WHERE t.confid = ").append(confid); sql.append(env.getUserID()).append(" WHERE t.confid = ").append(confid);
@ -849,6 +859,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -934,12 +945,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
// now we need to reset our last post date // now we need to reset our last post date
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection { // get a connection
conn = env.getConnection(); conn = env.getConnection();
// create a new record in topicsettings (we WERE the first to post in the topic after all!) // 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 ("); 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(new_topic_inf.getTopicID()).append(", ").append(env.getUserID()).append(", '");
sql.append(SQLUtil.encodeDate(new_topic_inf.getCreateDate())).append("');"); sql.append(SQLUtil.encodeDate(new_topic_inf.getCreateDate())).append("');");
@ -959,6 +972,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1009,11 +1023,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
return; // anonymous user can't fixseen return; // anonymous user can't fixseen
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables that we need // lock the tables that we need
stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;"); stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;");
@ -1031,6 +1046,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
ArrayList tmp = new ArrayList(); ArrayList tmp = new ArrayList();
while (rs.next()) while (rs.next())
tmp.add(new FixSeenHelper(rs.getInt(1),rs.getInt(2),rs.getBoolean(3))); 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 // now iterate over the list and call doFix on each one
Iterator it = tmp.iterator(); Iterator it = tmp.iterator();
@ -1048,8 +1064,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end try } // end try
finally finally
{ // make sure we unlock everything before we go { // make sure we unlock everything before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1062,6 +1077,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1078,12 +1094,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to retrieve all posters // create the SQL statement to retrieve all posters
StringBuffer sql = StringBuffer sql =
@ -1114,6 +1131,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1144,12 +1162,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to retrieve all readers // create the SQL statement to retrieve all readers
StringBuffer sql = StringBuffer sql =
@ -1180,6 +1199,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1271,11 +1291,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
public boolean isInHotlist() public boolean isInHotlist()
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// do a quickie query // do a quickie query
StringBuffer sql = new StringBuffer("SELECT sequence FROM confhotlist WHERE uid = "); StringBuffer sql = new StringBuffer("SELECT sequence FROM confhotlist WHERE uid = ");
@ -1293,6 +1314,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1302,11 +1324,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
public void addToHotlist() throws DataException public void addToHotlist() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confhotlist WRITE;"); stmt.executeUpdate("LOCK TABLES confhotlist WRITE;");
try try
@ -1325,6 +1348,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("bogus query result on addToHotlist"); throw new InternalStateError("bogus query result on addToHotlist");
int new_sequence = rs.getInt(1) + 100; int new_sequence = rs.getInt(1) + 100;
SQLUtil.shutdown(rs);
// add the new record // add the new record
sql.setLength(0); sql.setLength(0);
@ -1336,8 +1360,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end try } // end try
finally finally
{ // make sure the table is unlocked before we go { // make sure the table is unlocked before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1350,6 +1373,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1373,11 +1397,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
public void removeFromHotlist() throws DataException public void removeFromHotlist() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); 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, // create the DELETE statement and just execute it blind (if this conference is not in the hotlist,
// the DELETE is a no-op). // the DELETE is a no-op).
@ -1395,6 +1420,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1404,11 +1430,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
public void setHotlistSequence(int seq) throws DataException public void setHotlistSequence(int seq) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); 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, // create the UPDATE statement and just execute it blind (if this conference is not in the hotlist,
// the UPDATE is a no-op). // the UPDATE is a no-op).
@ -1426,6 +1453,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1521,12 +1549,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Build the SQL statement. // Build the SQL statement.
StringBuffer sql = new StringBuffer("SELECT c.email, "); StringBuffer sql = new StringBuffer("SELECT c.email, ");
@ -1574,6 +1603,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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."); throw new AccessError("You are not permitted to search for posts within this conference.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn);
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1679,6 +1710,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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."); throw new AccessError("You are not permitted to search for posts within this conference.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1730,6 +1763,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1777,30 +1811,42 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
if (deleted || env.getUser().userIsAnonymous()) if (deleted || env.getUser().userIsAnonymous())
return; // anonymous user can't update squat return; // anonymous user can't update squat
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer();
java.util.Date now = new java.util.Date(); try
if (settings_loaded) { // create the SQL statement
{ // generate an update statement stmt = conn.createStatement();
sql.append("UPDATE confsettings SET last_read = '").append(SQLUtil.encodeDate(now)); StringBuffer sql = new StringBuffer();
sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';');
} // end if java.util.Date now = new java.util.Date();
else if (settings_loaded)
{ // need to insert a confsettings row { // generate an update statement
sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); sql.append("UPDATE confsettings SET last_read = '").append(SQLUtil.encodeDate(now));
sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID());
sql.append("', '").append(SQLUtil.encodeDate(now)).append("');"); 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 } // end else
stmt.executeUpdate(sql.toString());
// save off the values to our local fields // execute the statement
last_read = now; stmt.executeUpdate(sql.toString());
settings_loaded = true;
// 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 } // end touchRead
@ -1809,29 +1855,41 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
if (deleted || env.getUser().userIsAnonymous()) if (deleted || env.getUser().userIsAnonymous())
return; // anonymous user can't update squat return; // anonymous user can't update squat
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer();
if (settings_loaded) try
{ // generate an update statement { // create the statement
sql.append("UPDATE confsettings SET last_post = '").append(SQLUtil.encodeDate(post_date)); stmt = conn.createStatement();
sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); StringBuffer sql = new StringBuffer();
} // end if if (settings_loaded)
else { // generate an update statement
{ // need to insert a confsettings row sql.append("UPDATE confsettings SET last_post = '").append(SQLUtil.encodeDate(post_date));
sql.append("INSERT INTO confsettings (confid, uid, default_pseud, last_read) VALUES (").append(confid); sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID());
sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); sql.append(';');
sql.append("', '").append(SQLUtil.encodeDate(post_date)).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 } // end else
stmt.executeUpdate(sql.toString());
// save off the values to our local fields // execute the statement
last_post = post_date; stmt.executeUpdate(sql.toString());
settings_loaded = true;
// 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 } // 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()) if (logger.isDebugEnabled())
logger.debug("getCommunityConferences for community # " + env.getCommunityID() + ", user #" logger.debug("getCommunityConferences for community # " + env.getCommunityID() + ", user #"
+ env.getUserID()); + env.getUserID());
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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 // 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 // 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1973,18 +2033,19 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
} // end getCommunityConferences } // end getCommunityConferences
static ConferenceContext getConference(EnvCommunity env, int confid) throws DataException static final ConferenceContext getConference(EnvCommunity env, int confid) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getConference(#" + confid + ") for community # " + env.getCommunityID() + ", user #" logger.debug("getConference(#" + confid + ") for community # " + env.getCommunityID() + ", user #"
+ env.getUserID()); + env.getUserID());
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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 // 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). // 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end getConference } // end getConference
static ConferenceContext getConference(EnvCommunity env, String alias) throws DataException static final ConferenceContext getConference(EnvCommunity env, String alias) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getConference(\"" + alias + "\") for community # " + env.getCommunityID() logger.debug("getConference(\"" + alias + "\") for community # " + env.getCommunityID()
+ ", user #" + env.getUserID()); + ", user #" + env.getUserID());
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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 // 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 // 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end getConference } // end getConference
static List getUserHotlist(EnvUser env) throws DataException static final List getUserHotlist(EnvUser env) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getUserHotlist for user #" + env.getUserID()); logger.debug("getUserHotlist for user #" + env.getUserID());
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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, // 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 // 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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.contactid = -1;
this.given_name = null; this.given_name = null;
@ -244,11 +244,13 @@ class ContactInfoImpl implements ContactInfo, Stashable
} // end makeEmpty } // 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 try
{ // do a simple SELECT in contacts to look this up { // 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 = "); StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
sql.append(contactid).append(';'); sql.append(contactid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); 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); throw new DataException("Unable to look up contact info: " + e.getMessage(),e);
} // end catch } // end catch
finally
{ // shut down the statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end loadData } // end loadData
@ -938,141 +945,151 @@ class ContactInfoImpl implements ContactInfo, Stashable
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("stashing contact ID " + contactid); logger.debug("stashing contact ID " + contactid);
java.util.Date update = null; java.util.Date update = null;
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer buf;
if (image_hook!=null) try
{ // call the image hook to store an image and get a new photo URL (where applicable) { // start updating the contact in the database
String new_photo_url = image_hook.doImage(conn); stmt = conn.createStatement();
if (new_photo_url!=null) StringBuffer buf;
photo_url = new_photo_url;
image_hook = null;
} // 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) } // end if
{ // 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()); if (contactid>=0)
{ // this involves updating an existing record
} // end if buf = new StringBuffer("UPDATE contacts SET given_name = ");
else buf.append(SQLUtil.encodeStringArg(given_name)).append(", family_name = ");
{ // this involves creating a new record buf.append(SQLUtil.encodeStringArg(family_name)).append(", middle_init = ");
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==' ') if (middle_initial==' ')
buf.append("NULL, "); buf.append("NULL");
else else
buf.append('\'').append(middle_initial).append("', "); buf.append('\'').append(middle_initial).append('\'');
buf.append(SQLUtil.encodeStringArg(prefix)).append(", "); buf.append(", prefix = ").append(SQLUtil.encodeStringArg(prefix));
buf.append(SQLUtil.encodeStringArg(suffix)).append(", "); buf.append(", suffix = ").append(SQLUtil.encodeStringArg(suffix));
buf.append(SQLUtil.encodeStringArg(company)).append(", "); buf.append(", company = ").append(SQLUtil.encodeStringArg(company));
buf.append(SQLUtil.encodeStringArg(addr1)).append(", "); buf.append(", addr1 = ").append(SQLUtil.encodeStringArg(addr1));
buf.append(SQLUtil.encodeStringArg(addr2)).append(", "); buf.append(", addr2 = ").append(SQLUtil.encodeStringArg(addr2));
buf.append(SQLUtil.encodeStringArg(locality)).append(", "); buf.append(", locality = ").append(SQLUtil.encodeStringArg(locality));
buf.append(SQLUtil.encodeStringArg(region)).append(", "); buf.append(", region = ").append(SQLUtil.encodeStringArg(region));
buf.append(SQLUtil.encodeStringArg(postal_code)).append(", "); buf.append(", pcode = ").append(SQLUtil.encodeStringArg(postal_code));
buf.append(SQLUtil.encodeStringArg(country)).append(", "); buf.append(", country = ").append(SQLUtil.encodeStringArg(country));
buf.append(SQLUtil.encodeStringArg(phone)).append(", "); buf.append(", phone = ").append(SQLUtil.encodeStringArg(phone));
buf.append(SQLUtil.encodeStringArg(fax)).append(", "); buf.append(", fax = ").append(SQLUtil.encodeStringArg(fax));
buf.append(SQLUtil.encodeStringArg(mobile)).append(", "); buf.append(", mobile = ").append(SQLUtil.encodeStringArg(mobile));
buf.append(SQLUtil.encodeStringArg(email)).append(", "); buf.append(", email = ").append(SQLUtil.encodeStringArg(email));
buf.append(private_addr ? '1' : '0').append(", "); buf.append(", pvt_addr = ").append(private_addr ? '1' : '0');
buf.append(private_phone ? '1' : '0').append(", "); buf.append(", pvt_phone = ").append(private_phone ? '1' : '0');
buf.append(private_fax ? '1' : '0').append(", "); buf.append(", pvt_fax = ").append(private_fax ? '1' : '0');
buf.append(private_email ? '1' : '0').append(", "); buf.append(", pvt_email = ").append(private_email ? '1' : '0');
buf.append(owner_uid).append(", ").append(owner_cid).append(", "); buf.append(", photo_url = ").append(SQLUtil.encodeStringArg(photo_url));
buf.append(SQLUtil.encodeStringArg(photo_url)).append(", "); buf.append(", url = ").append(SQLUtil.encodeStringArg(url)).append(", lastupdate = '");
buf.append(SQLUtil.encodeStringArg(url)).append(", '");
update = new java.util.Date(); update = new java.util.Date();
buf.append(SQLUtil.encodeDate(update)).append("');"); buf.append(SQLUtil.encodeDate(update)).append("' WHERE contactid = ").append(contactid).append(';');
stmt.executeUpdate(buf.toString()); stmt.executeUpdate(buf.toString());
// now read back the contact ID we just added } // end if
int new_contactid; else
ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();"); { // this involves creating a new record
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) if (owner_cid>=0)
{ // update the SIGS table stmt.executeUpdate("LOCK TABLES contacts WRITE, sigs WRITE;");
buf.append("UPDATE sigs SET contactid = ").append(new_contactid).append(" WHERE sigid = ");
buf.append(owner_cid).append(';');
} // end if
else else
{ // update the USERS table stmt.executeUpdate("LOCK TABLES contacts WRITE, users WRITE;");
buf.append("UPDATE users SET contactid = ").append(new_contactid).append(" WHERE uid = ");
buf.append(owner_uid).append(';');
} // end else 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()); stmt.executeUpdate(buf.toString());
contactid = new_contactid; // save link // 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 try } // end if
finally else
{ // make sure the tables get unlocked { // error reading back the contact ID
Statement ulk_stmt = conn.createStatement(); logger.error("unable to read back contact ID");
ulk_stmt.executeUpdate("UNLOCK TABLES;"); throw new DataException("unable to read back new contact ID");
} // end finally } // end else
} // 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 last_update = update; // save last update date
is_modified = false; is_modified = false;

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -89,12 +89,13 @@ class ImageStore implements BinaryData
public InputStream getData() throws DataException public InputStream getData() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
InputStream rc = null; InputStream rc = null;
try try
{ // open up a database connection { // open up a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Create the SQL we need to retrieve the image. // Create the SQL we need to retrieve the image.
StringBuffer sql = new StringBuffer("SELECT data FROM imagestore WHERE imgid = "); StringBuffer sql = new StringBuffer("SELECT data FROM imagestore WHERE imgid = ");
@ -128,6 +129,7 @@ class ImageStore implements BinaryData
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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()) if (logger.isDebugEnabled())
logger.debug("loadImageByID # " + id); logger.debug("loadImageByID # " + id);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT mimetype, length FROM imagestore WHERE imgid = "); StringBuffer sql = new StringBuffer("SELECT mimetype, length FROM imagestore WHERE imgid = ");
sql.append(id).append(';'); sql.append(id).append(';');
@ -173,14 +176,15 @@ class ImageStore implements BinaryData
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end loadImageByID } // end loadImageByID
static int storeNewImage(Connection conn, short type, int owner, String mime, int length, InputStream data) static final int storeNewImage(Connection conn, short type, int owner, String mime, int length,
throws SQLException InputStream data) throws SQLException
{ {
// Create the SQL statement that inserts the image into the store. // Create the SQL statement that inserts the image into the store.
StringBuffer sql = StringBuffer sql =
@ -190,22 +194,34 @@ class ImageStore implements BinaryData
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString()); logger.debug("SQL: " + sql.toString());
// Prepare the statement, set the BLOB parameter, and execute it. PreparedStatement stmt = null;
PreparedStatement stmt = conn.prepareStatement(sql.toString()); Statement stmt2 = null;
stmt.setBinaryStream(1,data,length);
stmt.executeUpdate();
// Get the ID of the new image and return it. try
Statement stmt2 = conn.createStatement(); { // Prepare the statement, set the BLOB parameter, and execute it.
ResultSet rs = stmt2.executeQuery("SELECT LAST_INSERT_ID();"); stmt = conn.prepareStatement(sql.toString());
if (!(rs.next())) stmt.setBinaryStream(1,data,length);
throw new InternalStateError("storeNewImage(): Unable to get new image ID!"); stmt.executeUpdate();
return rs.getInt(1);
// 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 } // end storeNewImage
static int storeNewImage(EnvEngine env, short type, int owner, String mime, int length, InputStream data) static final int storeNewImage(EnvEngine env, short type, int owner, String mime, int length,
throws DataException InputStream data) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("storeNewImage: type " + type + ", owner " + owner + ", mime " + mime + ", len " + length); logger.debug("storeNewImage: type " + type + ", owner " + owner + ", mime " + mime + ", len " + length);
@ -232,7 +248,7 @@ class ImageStore implements BinaryData
} // end storeNewImage } // 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 throws SQLException
{ {
// Create the SQL statement that inserts the image into the store. // Create the SQL statement that inserts the image into the store.
@ -242,14 +258,24 @@ class ImageStore implements BinaryData
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString()); logger.debug("SQL: " + sql.toString());
// Prepare the statement, set the BLOB parameter, and execute it. PreparedStatement stmt = null;
PreparedStatement stmt = conn.prepareStatement(sql.toString());
stmt.setBinaryStream(1,data,length); try
stmt.executeUpdate(); { // 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 } // 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 throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + String.valueOf(uid) + ";");
if (rs.next()) try
return rs.getString(1); { // run the quick select
else stmt = conn.createStatement();
return "(unknown)"; 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 } // end quickGetUserName
@ -217,12 +228,12 @@ class PublishedMessageImpl implements TopicMessageContext
if (text_cache==null) if (text_cache==null)
{ // we don't have the body text yet, go get it { // we don't have the body text yet, go get it
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // use a database connection to get the body text { // use a database connection to get the body text
conn = env.getConnection(); conn = env.getConnection();
stmt = conn.createStatement();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = "
+ String.valueOf(postid) + ";"); + String.valueOf(postid) + ";");
if (rs.next()) if (rs.next())
@ -239,6 +250,7 @@ class PublishedMessageImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -323,6 +335,12 @@ class PublishedMessageImpl implements TopicMessageContext
} // end attachData } // 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() public boolean canPublish()
{ {
return false; return false;
@ -349,19 +367,32 @@ class PublishedMessageImpl implements TopicMessageContext
} // end getPostLink } // 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 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; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the statement to retrieve the post information // create the statement to retrieve the post information
StringBuffer sql = StringBuffer sql =
@ -390,6 +421,7 @@ class PublishedMessageImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -399,11 +431,12 @@ class PublishedMessageImpl implements TopicMessageContext
static void backfillReturn(List return_list, EnvEngine env) throws DataException static void backfillReturn(List return_list, EnvEngine env) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// How many posts have been published anyway? // How many posts have been published anyway?
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM postpublish;"); ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM postpublish;");
@ -443,6 +476,7 @@ class PublishedMessageImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -61,10 +61,12 @@ class PublishedMessageTopicImpl implements TopicContext
PublishedMessageTopicImpl(EnvEngine env, int cid, int topicid) throws DataException PublishedMessageTopicImpl(EnvEngine env, int cid, int topicid) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// query the topics table for information // query the topics table for information
StringBuffer sql = StringBuffer sql =
@ -110,6 +112,7 @@ class PublishedMessageTopicImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // release the connection { // release the connection
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -98,11 +98,12 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor
public void setSequence(int seq) throws DataException public void setSequence(int seq) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); 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, // create the UPDATE statement and just execute it blind (if this sidebox is not in the list,
// the UPDATE is a no-op). // the UPDATE is a no-op).
@ -121,6 +122,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -130,11 +132,12 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor
public void remove() throws DataException public void remove() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); 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, // create the DELETE statement and just execute it blind (if this conference is not in the hotlist,
// the DELETE is a no-op). // the DELETE is a no-op).
@ -151,6 +154,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -19,6 +19,7 @@ package com.silverwrist.venice.core.impl;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import com.silverwrist.venice.db.SQLUtil;
class TopicMessageFoundHelper class TopicMessageFoundHelper
{ {
@ -54,12 +55,23 @@ class TopicMessageFoundHelper
String rc = (String)(comm_aliases.get(key)); String rc = (String)(comm_aliases.get(key));
if (rc==null) if (rc==null)
{ // create an SQL statement to find the alias { // create an SQL statement to find the alias
Statement stmt = conn.createStatement(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT alias FROM sigs WHERE sigid = " + cid + ";");
if (rs.next()) try
rc = rs.getString(1); { // use the statement
else stmt = conn.createStatement();
rc = "(unknown)"; 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); comm_aliases.put(key,rc);
@ -75,12 +87,23 @@ class TopicMessageFoundHelper
String rc = (String)(conf_aliases.get(key)); String rc = (String)(conf_aliases.get(key));
if (rc==null) if (rc==null)
{ // create an SQL statement to find the alias { // create an SQL statement to find the alias
Statement stmt = conn.createStatement(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT alias FROM confalias WHERE confid = " + confid + " LIMIT 1;");
if (rs.next()) try
rc = rs.getString(1); { // use the SQL statement
else stmt = conn.createStatement();
rc = "(unknown)"; 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); conf_aliases.put(key,rc);
@ -96,12 +119,23 @@ class TopicMessageFoundHelper
String rc = (String)(user_names.get(key)); String rc = (String)(user_names.get(key));
if (rc==null) if (rc==null)
{ // create an SQL statement to find the username { // create an SQL statement to find the username
Statement stmt = conn.createStatement(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";");
if (rs.next()) try
rc = rs.getString(1); { // use the statement
else stmt = conn.createStatement();
rc = "(unknown)"; 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); user_names.put(key,rc);
@ -112,4 +146,3 @@ class TopicMessageFoundHelper
} // end getUserName } // end getUserName
} // end TopicMessageFoundHelper } // end TopicMessageFoundHelper

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE uid = " + uid + ";");
if (rs.next()) try
return rs.getString(1); { // do a quick search
else stmt = conn.createStatement();
return "(unknown)"; 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 } // end quickGetUserName
private void refresh(Connection conn) throws SQLException private final void refresh(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("SELECT posts.hidden, posts.scribble_uid, posts.scribble_date, "
+ "posts.pseud, postattach.datalen, postattach.filename, " try
+ "postattach.mimetype, postattach.stgmethod FROM posts " { // run against the database
+ "LEFT JOIN postattach ON posts.postid = postattach.postid " stmt = conn.createStatement();
+ "WHERE posts.postid = "); StringBuffer sql = new StringBuffer("SELECT posts.hidden, posts.scribble_uid, posts.scribble_date, "
sql.append(postid).append(';'); + "posts.pseud, postattach.datalen, postattach.filename, "
ResultSet rs = stmt.executeQuery(sql.toString()); + "postattach.mimetype, postattach.stgmethod FROM posts "
if (rs.next()) + "LEFT JOIN postattach ON posts.postid = postattach.postid "
{ // update a variety of fields + "WHERE posts.postid = ");
hidden = rs.getBoolean(1); sql.append(postid).append(';');
scribble_uid = rs.getInt(2); ResultSet rs = stmt.executeQuery(sql.toString());
scribble_date = SQLUtil.getFullDateTime(rs,3); if (rs.next())
pseud = rs.getString(4); { // update a variety of fields
datalen = rs.getInt(5); hidden = rs.getBoolean(1);
filename = rs.getString(6); scribble_uid = rs.getInt(2);
mimetype = rs.getString(7); scribble_date = SQLUtil.getFullDateTime(rs,3);
stgmethod = rs.getInt(8); pseud = rs.getString(4);
if (rs.wasNull()) 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; stgmethod = -1;
nuked = true;
creator_cache = null;
text_cache = null;
} // end if } // end else
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 try
finally
{ // shut down the statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end refresh } // end refresh
@ -302,12 +324,23 @@ class TopicMessageUserContextImpl implements TopicMessageContext
if (scribble_date==null) if (scribble_date==null)
{ // let's go get the body text! { // let's go get the body text!
Statement stmt = conn.createStatement(); Statement stmt = null;
ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " + postid + ";");
if (rs.next()) try
text_cache = rs.getString(1); { // retrieve the body text
else stmt = conn.createStatement();
return "Data Missing"; // FUTURE: throw an exception? 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 } // end if
else // for scribbled posts, we return the scribbler's name only else // for scribbled posts, we return the scribbler's name only
@ -366,6 +399,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
InputStream rc = null; InputStream rc = null;
try try
{ // open up a database connection { // open up a database connection
@ -388,7 +422,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end if } // end if
// This will cause a "hit" on the attachment data. Update that record. // 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 = '"); 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(SQLUtil.encodeDate(new java.util.Date())).append("' WHERE postid = ").append(postid);
sql.append(';'); sql.append(';');
@ -445,6 +479,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -488,12 +523,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext
return; // changing the status of a nuked or scribbled post is futile return; // changing the status of a nuked or scribbled post is futile
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // open up a database connection { // open up a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we reference // lock the tables we reference
stmt.executeUpdate("LOCK TABLES posts WRITE, postattach READ;"); stmt.executeUpdate("LOCK TABLES posts WRITE, postattach READ;");
@ -515,8 +551,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -533,6 +568,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -555,12 +591,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext
return; // scribbling a nuked or scribbled post is futile return; // scribbling a nuked or scribbled post is futile
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // open up a database connection { // open up a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we reference // lock the tables we reference
stmt.executeUpdate("LOCK TABLES posts WRITE, postdata WRITE, postattach WRITE, postpublish WRITE;"); stmt.executeUpdate("LOCK TABLES posts WRITE, postdata WRITE, postattach WRITE, postpublish WRITE;");
@ -606,6 +643,8 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end if } // end if
// else don't try...we're deleting the row anyway // else don't try...we're deleting the row anyway
SQLUtil.shutdown(rs);
// Delete the actual post data row. // Delete the actual post data row.
sql.setLength(0); sql.setLength(0);
sql.append("DELETE FROM postdata WHERE postid = ").append(postid).append(';'); sql.append("DELETE FROM postdata WHERE postid = ").append(postid).append(';');
@ -634,8 +673,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -651,6 +689,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -671,12 +710,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext
return; // nuking a nuked post is futile return; // nuking a nuked post is futile
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // open up a database connection { // open up a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we reference // lock the tables we reference
stmt.executeUpdate("LOCK TABLES posts WRITE, postdata WRITE, postattach WRITE, postdogear WRITE, " 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?"); throw new InternalStateError("lost the post to be nuked after refresh?");
int x_topic_id = rs.getInt(1); int x_topic_id = rs.getInt(1);
int x_post_num = rs.getInt(2); int x_post_num = rs.getInt(2);
SQLUtil.shutdown(rs);
// Delete any and all references to this post! // Delete any and all references to this post!
stmt.executeUpdate("DELETE FROM posts WHERE postid = " + postid + ";"); stmt.executeUpdate("DELETE FROM posts WHERE postid = " + postid + ";");
@ -730,8 +771,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -747,6 +787,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -866,6 +907,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
Connection conn = null; Connection conn = null;
AuditRecord ar = null; AuditRecord ar = null;
PreparedStatement stmt = null;
try try
{ // open up a database connection { // open up a database connection
@ -892,7 +934,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
logger.debug("SQL: " + sql.toString()); logger.debug("SQL: " + sql.toString());
// Prepare the statement, set the BLOB parameter, and execute it. // 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.setBinaryStream(1,real_data,real_length);
stmt.executeUpdate(); stmt.executeUpdate();
@ -916,6 +958,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -938,15 +981,17 @@ class TopicMessageUserContextImpl implements TopicMessageContext
return false; return false;
} // end if } // end if
if ((scribble_date!=null) || nuked) if ((scribble_date!=null) || nuked)
return false; // cannot publish a scribbled or nuked message return false; // cannot publish a scribbled or nuked message
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// see if the post has already been published // see if the post has already been published
ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid
@ -961,6 +1006,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -987,12 +1033,13 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// see if post has already been published // see if post has already been published
ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid ResultSet rs = stmt.executeQuery("SELECT by_uid FROM postpublish WHERE postid = " + postid
@ -1038,6 +1085,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1058,11 +1106,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext
String prefix = env.getConference().selfConference().getPostLink(); String prefix = env.getConference().selfConference().getPostLink();
short topicnum = -1; short topicnum = -1;
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT num FROM topics WHERE topicid = " + topicid + ";"); ResultSet rs = stmt.executeQuery("SELECT num FROM topics WHERE topicid = " + topicid + ";");
if (!(rs.next())) if (!(rs.next()))
@ -1078,6 +1127,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1114,6 +1164,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
ArrayList mailto_addrs = null; ArrayList mailto_addrs = null;
int new_topic_num = -1; int new_topic_num = -1;
@ -1124,7 +1175,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock the tables we reference // lock the tables we reference
stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, topicsettings READ;"); stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, posts WRITE, topicsettings READ;");
@ -1216,8 +1267,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1254,6 +1304,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); 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 throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
@ -1289,11 +1340,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// run a query to get all the posts in a particular topic // run a query to get all the posts in a particular topic
StringBuffer sql = StringBuffer sql =
@ -1327,6 +1379,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1335,18 +1388,20 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end loadMessageRange } // 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()) if (logger.isDebugEnabled())
logger.debug("loadMessage for conf # " + env.getConfID() + ", topic #" + topicid + ", message " logger.debug("loadMessage for conf # " + env.getConfID() + ", topic #" + topicid + ", message "
+ message_num); + message_num);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// run a query to get all the posts in a particular topic // run a query to get all the posts in a particular topic
StringBuffer sql = StringBuffer sql =
@ -1378,23 +1433,25 @@ class TopicMessageUserContextImpl implements TopicMessageContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end loadMessage } // end loadMessage
static TopicMessageContext getMessage(EnvConference env, long postid) throws DataException static final TopicMessageContext getMessage(EnvConference env, long postid) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getMessage for conf # " + env.getConfID() + ", post #" + postid); logger.debug("getMessage for conf # " + env.getConfID() + ", post #" + postid);
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = StringBuffer sql =
new StringBuffer("SELECT p.postid, p.parent, p.topicid, p.num, p.linecount, p.creator_uid, " 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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 = StringBuffer sql =
new StringBuffer("SELECT topics.topicid, topics.num, topics.creator_uid, topics.top_message, " new StringBuffer("SELECT topics.topicid, topics.num, topics.creator_uid, topics.top_message, "
@ -126,7 +126,7 @@ class TopicUserContextImpl implements TopicContext
} // end queryByTopic } // end queryByTopic
private void makeDeleted() private final void makeDeleted()
{ {
top_message = -1; top_message = -1;
frozen = false; frozen = false;
@ -141,39 +141,61 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
private void refresh(Connection conn) throws SQLException private final void refresh(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
// perform a requery of the database try
ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); { // use database to refresh object
if (rs.next()) stmt = conn.createStatement();
{ // 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 // perform a requery of the database
else // this topic must have been deleted - fsck it ResultSet rs = queryByTopic(stmt,topicid,env.getUserID());
makeDeleted(); 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 } // end refresh
private void loadBozo(Connection conn) throws SQLException private final void loadBozo(Connection conn) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("SELECT bozo_uid FROM topicbozo WHERE topicid = ");
sql.append(topicid).append(" AND uid = ").append(env.getUserID()).append(';'); try
ResultSet rs = stmt.executeQuery(sql.toString()); { // load the bozo UIDs list
bozo_uids = new HashSet(); stmt = conn.createStatement();
while (rs.next()) StringBuffer sql = new StringBuffer("SELECT bozo_uid FROM topicbozo WHERE topicid = ");
bozo_uids.add(new Integer(rs.getInt(1))); 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 } // end loadBozo
@ -304,12 +326,13 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
AuditRecord ar = null; // audit record indicating success AuditRecord ar = null; // audit record indicating success
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to freeze or unfreeze the topic // create the SQL statement to freeze or unfreeze the topic
StringBuffer sql = new StringBuffer("UPDATE topics SET frozen = "); StringBuffer sql = new StringBuffer("UPDATE topics SET frozen = ");
@ -333,6 +356,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -352,12 +376,13 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
AuditRecord ar = null; // audit record indicating success AuditRecord ar = null; // audit record indicating success
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to freeze or unfreeze the topic // create the SQL statement to freeze or unfreeze the topic
StringBuffer sql = new StringBuffer("UPDATE topics SET archived = "); StringBuffer sql = new StringBuffer("UPDATE topics SET archived = ");
@ -381,6 +406,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -394,11 +420,12 @@ class TopicUserContextImpl implements TopicContext
return; // no-op return; // no-op
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;"); stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;");
try try
@ -434,8 +461,7 @@ class TopicUserContextImpl implements TopicContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -448,6 +474,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -491,11 +518,12 @@ class TopicUserContextImpl implements TopicContext
int last_msg = top_message - count; int last_msg = top_message - count;
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;"); stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;");
try try
@ -530,6 +558,8 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
SQLUtil.shutdown(rs);
// OK, just insert a new row into topicsettings, why dontcha... // OK, just insert a new row into topicsettings, why dontcha...
sql.setLength(0); sql.setLength(0);
sql.append("INSERT INTO topicsettings (topicid, uid, last_message, last_read) VALUES ("); sql.append("INSERT INTO topicsettings (topicid, uid, last_message, last_read) VALUES (");
@ -544,8 +574,7 @@ class TopicUserContextImpl implements TopicContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -558,6 +587,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -674,13 +704,14 @@ class TopicUserContextImpl implements TopicContext
long new_post_id; long new_post_id;
java.util.Date posted_date; java.util.Date posted_date;
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
ArrayList mailto_addrs = null; ArrayList mailto_addrs = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ArrayList mailto_uids = null; ArrayList mailto_uids = null;
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
ResultSet rs; ResultSet rs;
@ -735,6 +766,7 @@ class TopicUserContextImpl implements TopicContext
new_post_id = rs.getLong(1); new_post_id = rs.getLong(1);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("New post ID: " + new_post_id); logger.debug("New post ID: " + new_post_id);
SQLUtil.shutdown(rs);
// Touch the topic values to reflect the added post. // Touch the topic values to reflect the added post.
sql.setLength(0); sql.setLength(0);
@ -788,6 +820,8 @@ class TopicUserContextImpl implements TopicContext
} // end while } // end while
SQLUtil.shutdown(rs);
// Fill in our own local variables to reflect the update. This includes the recalculation // Fill in our own local variables to reflect the update. This includes the recalculation
// of "unread" based on the new value of "top_message". // of "unread" based on the new value of "top_message".
int tmp_last_msg = top_message - unread; int tmp_last_msg = top_message - unread;
@ -800,8 +834,7 @@ class TopicUserContextImpl implements TopicContext
} // end try } // end try
finally finally
{ // make sure we unlock the tables when we're done { // make sure we unlock the tables when we're done
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -835,6 +868,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -882,6 +916,7 @@ class TopicUserContextImpl implements TopicContext
return; // an exercise in futility... return; // an exercise in futility...
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
int post_count; int post_count;
long post_max; long post_max;
@ -889,7 +924,7 @@ class TopicUserContextImpl implements TopicContext
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// lock some tables while we do the critical parts of the delete // lock some tables while we do the critical parts of the delete
stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, topicsettings WRITE, topicbozo WRITE, " stmt.executeUpdate("LOCK TABLES confs WRITE, topics WRITE, topicsettings WRITE, topicbozo WRITE, "
@ -928,8 +963,7 @@ class TopicUserContextImpl implements TopicContext
} // end try } // end try
finally finally
{ // make sure and unlock before we're done { // make sure and unlock before we're done
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -945,6 +979,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -967,12 +1002,13 @@ class TopicUserContextImpl implements TopicContext
public List getActivePosters(int skip, int limit) throws DataException public List getActivePosters(int skip, int limit) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to retrieve all posters // create the SQL statement to retrieve all posters
StringBuffer sql = StringBuffer sql =
@ -1003,6 +1039,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1026,12 +1063,13 @@ class TopicUserContextImpl implements TopicContext
public List getActiveReaders(int skip, int limit) throws DataException, AccessError public List getActiveReaders(int skip, int limit) throws DataException, AccessError
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement to retrieve all readers // create the SQL statement to retrieve all readers
StringBuffer sql = StringBuffer sql =
@ -1062,6 +1100,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1120,6 +1159,7 @@ class TopicUserContextImpl implements TopicContext
return; // no-op return; // no-op
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // figure out what to do here { // figure out what to do here
conn = env.getConnection(); conn = env.getConnection();
@ -1130,7 +1170,6 @@ class TopicUserContextImpl implements TopicContext
loadBozo(conn); // load the bozo filter if we don't already have it loadBozo(conn); // load the bozo filter if we don't already have it
Integer uid_key = new Integer(other_uid); Integer uid_key = new Integer(other_uid);
Statement stmt;
StringBuffer sql; StringBuffer sql;
if (bozo) if (bozo)
{ // this user is a bozo... { // this user is a bozo...
@ -1171,6 +1210,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1230,11 +1270,12 @@ class TopicUserContextImpl implements TopicContext
return; // no-op return; // no-op
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;"); stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;");
try try
@ -1260,6 +1301,8 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
SQLUtil.shutdown(rs);
// OK, just insert a new row into topicsettings, why dontcha... // OK, just insert a new row into topicsettings, why dontcha...
sql.setLength(0); sql.setLength(0);
sql.append("INSERT INTO topicsettings (topicid, uid, subscribe) VALUES (").append(topicid); sql.append("INSERT INTO topicsettings (topicid, uid, subscribe) VALUES (").append(topicid);
@ -1270,8 +1313,7 @@ class TopicUserContextImpl implements TopicContext
} // end try } // end try
finally finally
{ // unlock the tables before we go { // unlock the tables before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1284,6 +1326,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1337,12 +1380,13 @@ class TopicUserContextImpl implements TopicContext
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Build the SQL statement. // Build the SQL statement.
StringBuffer sql = new StringBuffer("SELECT c.email, "); StringBuffer sql = new StringBuffer("SELECT c.email, ");
@ -1390,6 +1434,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1428,13 +1473,14 @@ class TopicUserContextImpl implements TopicContext
throw new AccessError("You are not permitted to search for posts within this topic."); throw new AccessError("You are not permitted to search for posts within this topic.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn);
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1461,6 +1507,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1482,11 +1529,12 @@ class TopicUserContextImpl implements TopicContext
throw new AccessError("You are not permitted to search for posts within this topic."); throw new AccessError("You are not permitted to search for posts within this topic.");
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1510,6 +1558,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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()) if (logger.isDebugEnabled())
logger.debug("getTopicList for conf # " + env.getConfID() + ", user #" + env.getUserID()); logger.debug("getTopicList for conf # " + env.getConfID() + ", user #" + env.getUserID());
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); 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 // 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 // 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 } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1695,17 +1746,18 @@ class TopicUserContextImpl implements TopicContext
} // end getTopicList } // end getTopicList
static TopicContext getTopicByID(EnvConference env, int topicid) throws DataException static final TopicContext getTopicByID(EnvConference env, int topicid) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getTopicByID for topic # " + topicid + ", user #" + env.getUserID()); logger.debug("getTopicByID for topic # " + topicid + ", user #" + env.getUserID());
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Query the dtabase by topic ID. // Query the dtabase by topic ID.
ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); ResultSet rs = queryByTopic(stmt,topicid,env.getUserID());
@ -1725,6 +1777,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1733,18 +1786,19 @@ class TopicUserContextImpl implements TopicContext
} // end getTopicByID } // end getTopicByID
static TopicContext getTopicByNumber(EnvConference env, short topicnum) throws DataException static final TopicContext getTopicByNumber(EnvConference env, short topicnum) throws DataException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("getTopicByNumber for topic # " + topicnum + ", conf # " + env.getConfID() + ", user #" logger.debug("getTopicByNumber for topic # " + topicnum + ", conf # " + env.getConfID() + ", user #"
+ env.getUserID()); + env.getUserID());
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// Build the database query. // Build the database query.
StringBuffer sql = StringBuffer sql =
@ -1776,6 +1830,7 @@ class TopicUserContextImpl implements TopicContext
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -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"); uid = rs.getInt("uid");
username = rs.getString("username"); username = rs.getString("username");
@ -125,14 +125,15 @@ class UserContextImpl implements UserContext, UserBackend
} // end loadUserData } // end loadUserData
private void loadPrefs() throws DataException private final void loadPrefs() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // call through to lower level function { // call through to lower level function
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM userprefs WHERE uid = " + uid + ";"); ResultSet rs = stmt.executeQuery("SELECT * FROM userprefs WHERE uid = " + uid + ";");
if (!(rs.next())) if (!(rs.next()))
@ -170,13 +171,14 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection { // make sure we release the connection
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end loadPrefs } // end loadPrefs
private void sendEmailConfirmation() throws DataException, EmailException private final void sendEmailConfirmation() throws DataException, EmailException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("sendEmailConfirmation(): sending to \"" + my_email + "\""); logger.debug("sendEmailConfirmation(): sending to \"" + my_email + "\"");
@ -211,72 +213,84 @@ class UserContextImpl implements UserContext, UserBackend
} // end sendEmailConfirmation } // end sendEmailConfirmation
private void autoJoinCommunities(Connection conn) throws SQLException private final void autoJoinCommunities(Connection conn) throws SQLException
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("autoJoinCommunities (uid " + uid + ", level " + level + ")"); logger.debug("autoJoinCommunities (uid " + uid + ", level " + level + ")");
// See which communities we are eligible to autojoin. Statement stmt = null;
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());
// Save the community IDs returned into temporary array lists. try
ArrayList tmp_cid = new ArrayList(); { // See which communities we are eligible to autojoin.
ArrayList tmp_locked = new ArrayList(); stmt = conn.createStatement();
while (rs.next()) StringBuffer sql =
{ // save off the "cid" and "locked" column pairs new StringBuffer("SELECT sigmember.sigid, sigmember.locked FROM users, sigmember, sigs "
tmp_cid.add(new Integer(rs.getInt(1))); + "WHERE sigmember.uid = users.uid AND sigmember.sigid = sigs.sigid "
tmp_locked.add(new Boolean(rs.getBoolean(2))); + "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());
} // end while // 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)));
// Figure out which of those communities we haven't joined yet and set up to autojoin them. } // end while
sql.setLength(0);
int new_level = env.getCommunityDefaultRole("Community.NewUser").getLevel(); // Figure out which of those communities we haven't joined yet and set up to autojoin them.
for (int i=0; i<tmp_cid.size(); i++) sql.setLength(0);
{ // see if the user is already a member of this community int new_level = env.getCommunityDefaultRole("Community.NewUser").getLevel();
Integer x_cid = (Integer)(tmp_cid.get(i)); for (int i=0; i<tmp_cid.size(); i++)
rs = stmt.executeQuery("SELECT sigid FROM sigmember WHERE sigid = " + x_cid + " AND uid = " + uid { // see if the user is already a member of this community
+ ";"); Integer x_cid = (Integer)(tmp_cid.get(i));
if (!(rs.next())) rs = stmt.executeQuery("SELECT sigid FROM sigmember WHERE sigid = " + x_cid + " AND uid = " + uid
{ // tack this information onto the end of our big "INSERT" command + ";");
Boolean x_locked = (Boolean)(tmp_locked.get(i)); if (!(rs.next()))
if (sql.length()==0) { // tack this information onto the end of our big "INSERT" command
sql.append("INSERT INTO sigmember (sigid, uid, granted_lvl, locked) VALUES "); Boolean x_locked = (Boolean)(tmp_locked.get(i));
else if (sql.length()==0)
sql.append(", "); sql.append("INSERT INTO sigmember (sigid, uid, granted_lvl, locked) VALUES ");
sql.append("(").append(x_cid).append(", ").append(uid).append(", ").append(new_level).append(", "); else
sql.append(x_locked.booleanValue() ? '1' : '0').append(")"); sql.append(", ");
sql.append("(").append(x_cid).append(", ").append(uid).append(", ").append(new_level).append(", ");
sql.append(x_locked.booleanValue() ? '1' : '0').append(")");
} // end if
} // end for
if (sql.length()>0)
{ // execute the big update
sql.append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
} // end if } // end if
} // end for } // end try
finally
{ // shut down the statement to conserve resources
SQLUtil.shutdown(stmt);
if (sql.length()>0) } // end finally
{ // execute the big update
sql.append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
} // end if
} // end autoJoinCommunities } // end autoJoinCommunities
private void updateProperties(BitSet delta) throws DataException private final void updateProperties(BitSet delta) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection and create a statement { // get a connection and create a statement
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (delta.get(PROP_FLAGS)) if (delta.get(PROP_FLAGS))
@ -297,13 +311,14 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end updateProperties } // end updateProperties
private void updateProperties() throws DataException private final void updateProperties() throws DataException
{ {
updateProperties(ALL_PROPS); updateProperties(ALL_PROPS);
@ -387,12 +402,13 @@ class UserContextImpl implements UserContext, UserBackend
logger.debug("authenticate(): authenticating user \"" + username + "\"..."); logger.debug("authenticate(): authenticating user \"" + username + "\"...");
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // look for a user name matching this user record { // look for a user name matching this user record
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '"
+ SQLUtil.encodeString(username) + "';"); + SQLUtil.encodeString(username) + "';");
@ -463,6 +479,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -494,12 +511,13 @@ class UserContextImpl implements UserContext, UserBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
Role new_role = env.getDefaultRole("Global.AfterVerify"); Role new_role = env.getDefaultRole("Global.AfterVerify");
try try
{ // get a connection and set the user's status to reflect the verification { // get a connection and set the user's status to reflect the verification
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 1, base_lvl = "); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 1, base_lvl = ");
sql.append(new_role.getLevel()).append(" WHERE uid = ").append(uid).append(';'); sql.append(new_role.getLevel()).append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -521,6 +539,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -544,11 +563,13 @@ class UserContextImpl implements UserContext, UserBackend
getContactInfo(); // forces my_email to be updated getContactInfo(); // forces my_email to be updated
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // need to change the user's email confirmation number first { // need to change the user's email confirmation number first
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// generate new confirmation number // generate new confirmation number
int new_confirm_num = env.getEngine().getNewConfirmationNumber(); int new_confirm_num = env.getEngine().getNewConfirmationNumber();
@ -575,6 +596,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -665,12 +687,21 @@ class UserContextImpl implements UserContext, UserBackend
int new_confirm_num = env.getEngine().getNewConfirmationNumber(); int new_confirm_num = env.getEngine().getNewConfirmationNumber();
Role new_role = env.getDefaultRole("Global.Unverified"); Role new_role = env.getDefaultRole("Global.Unverified");
// create an SQL statement to reset the user account information, and execute it Statement stmt = null;
StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = "); try
sql.append(new_confirm_num).append(", base_lvl = ").append(new_role.getLevel()); { // create an SQL statement to reset the user account information, and execute it
sql.append(" WHERE uid = ").append(uid).append(';'); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = ");
Statement stmt = conn.createStatement(); sql.append(new_confirm_num).append(", base_lvl = ").append(new_role.getLevel());
stmt.executeUpdate(sql.toString()); 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 // save off changed data
email_verified = false; email_verified = false;
@ -778,12 +809,13 @@ class UserContextImpl implements UserContext, UserBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
PasswordHash phash = new PasswordHash(password); PasswordHash phash = new PasswordHash(password);
StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '");
sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder)); sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder));
@ -802,6 +834,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -819,11 +852,12 @@ class UserContextImpl implements UserContext, UserBackend
} // end if } // end if
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); StringBuffer sql = new StringBuffer("UPDATE users SET description = '");
sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -839,6 +873,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -976,12 +1011,13 @@ class UserContextImpl implements UserContext, UserBackend
public List getSideBoxList() throws DataException public List getSideBoxList() throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// retrieve the necessary rows from the sideboxes table // retrieve the necessary rows from the sideboxes table
ResultSet rs = stmt.executeQuery("SELECT boxid, sequence FROM sideboxes WHERE uid = " + uid ResultSet rs = stmt.executeQuery("SELECT boxid, sequence FROM sideboxes WHERE uid = " + uid
@ -1004,6 +1040,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1018,11 +1055,12 @@ class UserContextImpl implements UserContext, UserBackend
throw new DataException("invalid sidebox ID: " + id); throw new DataException("invalid sidebox ID: " + id);
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection { // retrieve a connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES sideboxes WRITE;"); stmt.executeUpdate("LOCK TABLES sideboxes WRITE;");
try try
@ -1050,8 +1088,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end try } // end try
finally finally
{ // make sure the table is unlocked before we go { // make sure the table is unlocked before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1064,6 +1101,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1101,11 +1139,12 @@ class UserContextImpl implements UserContext, UserBackend
public void setLocale(Locale locale) throws DataException public void setLocale(Locale locale) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the update statement // create the update statement
StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '"); StringBuffer sql = new StringBuffer("UPDATE userprefs SET localeid = '");
@ -1126,6 +1165,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1144,11 +1184,12 @@ class UserContextImpl implements UserContext, UserBackend
public void setTimeZone(TimeZone timezone) throws DataException public void setTimeZone(TimeZone timezone) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the update statement // create the update statement
StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '"); StringBuffer sql = new StringBuffer("UPDATE userprefs SET tzid = '");
@ -1169,6 +1210,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // 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. // Generate a random authentication string and poke it into the database for this user.
String tokenauth = env.getEngine().generateRandomAuthString(); String tokenauth = env.getEngine().generateRandomAuthString();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET tokenauth = '"); StringBuffer sql = new StringBuffer("UPDATE users SET tokenauth = '");
sql.append(tokenauth).append("' WHERE uid = ").append(uid).append(';'); sql.append(tokenauth).append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -1205,6 +1248,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1312,12 +1356,13 @@ class UserContextImpl implements UserContext, UserBackend
logger.debug("Authenticating user ID#" + pending_uid); logger.debug("Authenticating user ID#" + pending_uid);
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // look for a user record matching this user ID { // look for a user record matching this user ID
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE uid = " + pending_uid + ";"); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE uid = " + pending_uid + ";");
if (!(rs.next())) if (!(rs.next()))
@ -1382,6 +1427,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);
@ -1461,13 +1507,14 @@ class UserContextImpl implements UserContext, UserBackend
ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference"); ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
Connection conn = null; Connection conn = null;
Statement stmt = null;
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn); TopicMessageFoundHelper helper = new TopicMessageFoundHelper(conn);
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1500,6 +1547,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1520,11 +1568,12 @@ class UserContextImpl implements UserContext, UserBackend
ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference"); ServiceToken conf_token = env.getSCM().getTokenForSymbol(ServiceControl.SVCGRP_COMMUNITY,"Conference");
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create the SQL statement // create the SQL statement
StringBuffer sql = StringBuffer sql =
@ -1554,6 +1603,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1635,13 +1685,14 @@ class UserContextImpl implements UserContext, UserBackend
void loadAnonymous(String remote_addr) throws DataException void loadAnonymous(String remote_addr) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("loadAnonymous() on UserContext: addr " + remote_addr); logger.debug("loadAnonymous() on UserContext: addr " + remote_addr);
try try
{ // retrieve a connection from the data pool { // retrieve a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE is_anon = 1;"); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE is_anon = 1;");
if (!(rs.next())) if (!(rs.next()))
{ // could not find the anonymous user - this is an internal error { // could not find the anonymous user - this is an internal error
@ -1663,6 +1714,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1716,21 +1768,22 @@ class UserContextImpl implements UserContext, UserBackend
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
static ReturnNewUser createAccount(EnvEngine env, String remote_addr, String username, String password, static final ReturnNewUser createAccount(EnvEngine env, String remote_addr, String username, String password,
String reminder, boolean verify_email, boolean lockout, int confirm_num, String reminder, boolean verify_email, boolean lockout,
Role base_role, String description) int confirm_num, Role base_role, String description)
throws AccessError, DataException throws AccessError, DataException
{ {
String encode_username = SQLUtil.encodeString(username); String encode_username = SQLUtil.encodeString(username);
int new_uid; // new user ID - return from this function int new_uid; // new user ID - return from this function
java.util.Date created; // date created - return from this function java.util.Date created; // date created - return from this function
Connection conn = null; Connection conn = null;
Statement stmt = null;
AuditRecord ar = null; AuditRecord ar = null;
try try
{ // first, lock a bunch of tables for the purpose of this operation { // first, lock a bunch of tables for the purpose of this operation
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES users WRITE, userprefs WRITE, propuser WRITE, sigmember WRITE, " stmt.executeUpdate("LOCK TABLES users WRITE, userprefs WRITE, propuser WRITE, sigmember WRITE, "
+ "sideboxes WRITE, confhotlist WRITE;"); + "sideboxes WRITE, confhotlist WRITE;");
@ -1744,6 +1797,8 @@ class UserContextImpl implements UserContext, UserBackend
} // end if } // end if
SQLUtil.shutdown(rs);
// Insert a new record for this user // Insert a new record for this user
PasswordHash phash = new PasswordHash(password); PasswordHash phash = new PasswordHash(password);
StringBuffer sql = StringBuffer sql =
@ -1770,6 +1825,7 @@ class UserContextImpl implements UserContext, UserBackend
new_uid = rs.getInt(1); new_uid = rs.getInt(1);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("...created user \"" + username + "\" with UID " + new_uid); logger.debug("...created user \"" + username + "\" with UID " + new_uid);
SQLUtil.shutdown(rs);
// add a UserPrefs record for this user, too // add a UserPrefs record for this user, too
sql.setLength(0); sql.setLength(0);
@ -1857,8 +1913,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end try } // end try
finally finally
{ // make sure the tables get unlocked before we go { // make sure the tables get unlocked before we go
Statement ulk_stmt = conn.createStatement(); SQLUtil.unlockTables(conn);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -1874,6 +1929,7 @@ class UserContextImpl implements UserContext, UserBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
AuditRecord.store(conn,ar); AuditRecord.store(conn,ar);
env.releaseConnection(conn); env.releaseConnection(conn);

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -79,27 +79,38 @@ class UserProfileImpl implements UserProfile
logger.debug("load UserProfileImpl by name: " + username); logger.debug("load UserProfileImpl by name: " + username);
this.env = env; this.env = env;
// first retrieve from the users table Statement stmt = null;
Statement stmt = conn.createStatement(); int contact_id = -1;
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.");
} // 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 } // end if
this.uid = rs.getInt(1);
this.username = rs.getString(2); // load the "elementary" fields
int contact_id = rs.getInt(3); this.uid = rs.getInt(1);
created = SQLUtil.getFullDateTime(rs,4); this.username = rs.getString(2);
last_login = SQLUtil.getFullDateTime(rs,5); contact_id = rs.getInt(3);
descr = rs.getString(6); created = SQLUtil.getFullDateTime(rs,4);
is_anon = rs.getBoolean(7); 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); loadContact(conn,contact_id);
@ -111,27 +122,38 @@ class UserProfileImpl implements UserProfile
logger.debug("load UserProfileImpl by UID: " + uid); logger.debug("load UserProfileImpl by UID: " + uid);
this.env = env; this.env = env;
// first retrieve from the users table Statement stmt = null;
Statement stmt = conn.createStatement(); int contact_id = -1;
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.");
} // 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 } // end if
this.uid = rs.getInt(1);
this.username = rs.getString(2); // load the "elementary" fields
int contact_id = rs.getInt(3); this.uid = rs.getInt(1);
created = SQLUtil.getFullDateTime(rs,4); this.username = rs.getString(2);
last_login = SQLUtil.getFullDateTime(rs,5); contact_id = rs.getInt(3);
descr = rs.getString(6); created = SQLUtil.getFullDateTime(rs,4);
is_anon = rs.getBoolean(7); 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); 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()) if (logger.isDebugEnabled())
logger.debug("loadContact for contact ID " + contact_id); logger.debug("loadContact for contact ID " + contact_id);
boolean override = env.testPermission(EnvUser.PERM_SEEHIDDENCONTACTINFO); boolean override = env.testPermission(EnvUser.PERM_SEEHIDDENCONTACTINFO);
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
sql.append(contact_id).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); try
if (rs.next()) { // look up the contact information
{ // load all the record data stmt = conn.createStatement();
boolean me_anon = env.getUser().userIsAnonymous(); StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
given_name = rs.getString("given_name"); sql.append(contact_id).append(';');
family_name = rs.getString("family_name");
String blort = rs.getString("middle_init"); ResultSet rs = stmt.executeQuery(sql.toString());
if ((blort==null) || (blort.length()<1)) if (rs.next())
middle_initial = ' '; { // 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 else
middle_initial = blort.charAt(0); { // no contact ID - just default all the data
prefix = rs.getString("prefix"); given_name = null;
suffix = rs.getString("suffix"); family_name = null;
company = rs.getString("company"); middle_initial = ' ';
if (!override && (me_anon || rs.getBoolean("pvt_addr"))) prefix = null;
{ // enforce address privacy suffix = null;
company = null;
addr1 = null; addr1 = null;
addr2 = null; addr2 = null;
locality = null;
} // end if region = null;
else postal_code = null;
{ // load the address strings country = null;
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; phone = null;
fax = null;
mobile = null; mobile = null;
email = null;
} // end if photo_url = null;
else url = null;
{ // load the phone strings last_update = null;
phone = rs.getString("phone"); real_email = null;
mobile = rs.getString("mobile");
} // end else } // end else
if (!override && (me_anon || rs.getBoolean("pvt_fax"))) } // end try
fax = null; finally
else { // shut down statement to conserve resources
fax = rs.getString("fax"); SQLUtil.shutdown(stmt);
real_email = rs.getString("email"); } // end finally
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 loadContact } // end loadContact

View File

@ -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(); ArrayList rc = new ArrayList();
NodeList nl = sect.getChildNodes(); NodeList nl = sect.getChildNodes();
@ -317,14 +317,14 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end getDictionaryNames } // end getDictionaryNames
private void checkInitialized() private final void checkInitialized()
{ {
if (env==null) if (env==null)
throw new InternalStateError("Venice engine not initialized!"); throw new InternalStateError("Venice engine not initialized!");
} // end checkInitialized } // 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;"; final String query1 = "SELECT ndx, data FROM propglobal;";
ResultSet rs = stmt.executeQuery(query1); ResultSet rs = stmt.executeQuery(query1);
@ -343,6 +343,8 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end while } // end while
SQLUtil.shutdown(rs);
final String query2 = final String query2 =
"SELECT posts_per_page, old_posts_at_top, max_search_page, max_sig_mbr_page, max_conf_mbr_page, " "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;"; + "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_NUMAUDITRECSPERPAGE] = rs.getInt(7);
gp_ints[IP_CREATECOMMUNITYLVL] = rs.getInt(8); gp_ints[IP_CREATECOMMUNITYLVL] = rs.getInt(8);
SQLUtil.shutdown(rs);
} // end loadDefaults } // end loadDefaults
private synchronized void updateDefaults(BitSet delta) throws DataException private final synchronized void updateDefaults(BitSet delta) throws DataException
{ {
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
if (delta.get(PROP_FLAGS)) if (delta.get(PROP_FLAGS))
@ -417,13 +423,14 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
} // end updateDefaults } // end updateDefaults
private synchronized void updateDefaults() throws DataException private final synchronized void updateDefaults() throws DataException
{ {
updateDefaults(ALL_PROPS); updateDefaults(ALL_PROPS);
@ -695,10 +702,11 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
// initialize anything that requires us to pull from the database // initialize anything that requires us to pull from the database
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a connection from the data pool { // get a connection from the data pool
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// load the global defaults // load the global defaults
loadDefaults(stmt); loadDefaults(stmt);
@ -712,6 +720,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -834,11 +843,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
{ {
checkInitialized(); checkInitialized();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // look for a user name matching this user record { // look for a user name matching this user record
conn = env.getConnection(); 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 = " ResultSet rs = stmt.executeQuery("SELECT c.email FROM users u, contacts c WHERE u.contactid = "
+ "c.contactid AND u.username = '" + SQLUtil.encodeString(username) + "c.contactid AND u.username = '" + SQLUtil.encodeString(username)
+ "';"); + "';");
@ -864,6 +874,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -874,11 +885,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
{ {
checkInitialized(); checkInitialized();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // look for a user name matching this user record { // look for a user name matching this user record
conn = env.getConnection(); 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 " StringBuffer sql = new StringBuffer("SELECT c.email, u.uid, u.passreminder FROM users u, contacts c "
+ "WHERE u.contactid = c.contactid AND u.username = '"); + "WHERE u.contactid = c.contactid AND u.username = '");
sql.append(SQLUtil.encodeString(username)).append("';"); sql.append(SQLUtil.encodeString(username)).append("';");
@ -939,6 +951,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -972,10 +985,11 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
PasswordGenerator pgen = new PasswordGenerator(); PasswordGenerator pgen = new PasswordGenerator();
PasswordHash phash = new PasswordHash(pgen.toString()); PasswordHash phash = new PasswordHash(pgen.toString());
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // perform the database update { // perform the database update
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '");
sql.append(phash.toString()).append("' WHERE uid = ").append(uid).append(';'); sql.append(phash.toString()).append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString()); stmt.executeUpdate(sql.toString());
@ -989,6 +1003,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1054,11 +1069,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
{ {
checkInitialized(); checkInitialized();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // do a SELECT on the sigs table { // do a SELECT on the sigs table
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT sigid FROM sigs WHERE alias = '"); StringBuffer sql = new StringBuffer("SELECT sigid FROM sigs WHERE alias = '");
sql.append(alias).append("'"); sql.append(alias).append("'");
if (exist_cid>0) if (exist_cid>0)
@ -1075,6 +1091,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1091,11 +1108,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
if (global_flags.get(BP_NOCATEGORIES)) if (global_flags.get(BP_NOCATEGORIES))
return (catid==0); // EJB 1/16/2001 - if categories are disabled, the only valid one is "unclassified" return (catid==0); // EJB 1/16/2001 - if categories are disabled, the only valid one is "unclassified"
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // do a SELECT on the category table { // do a SELECT on the category table
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE catid = "); StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE catid = ");
sql.append(catid).append(';'); sql.append(catid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -1109,6 +1127,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1125,11 +1144,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
ArrayList rc = new ArrayList(); // return from this function ArrayList rc = new ArrayList(); // return from this function
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, " 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, " + "c.family_name, c.locality, c.region, c.country FROM users u, "
+ "contacts c WHERE u.contactid = c.contactid AND "); + "contacts c WHERE u.contactid = c.contactid AND ");
@ -1202,6 +1222,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1216,11 +1237,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
logger.debug("User search: field = " + field + ", mode = " + mode + ", term '" + term + "'"); logger.debug("User search: field = " + field + ", mode = " + mode + ", term '" + term + "'");
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c WHERE u.contactid = " StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM users u, contacts c WHERE u.contactid = "
+ "c.contactid AND "); + "c.contactid AND ");
@ -1289,6 +1311,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1304,11 +1327,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
public boolean isEmailAddressBanned(String email) public boolean isEmailAddressBanned(String email)
{ {
Connection conn = null; // pooled database connection Connection conn = null; // pooled database connection
Statement stmt = null;
try try
{ // get a database connection { // get a database connection
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
// create and execute the right SQL statement // create and execute the right SQL statement
StringBuffer sql = new StringBuffer("SELECT by_uid FROM emailban WHERE address = '"); StringBuffer sql = new StringBuffer("SELECT by_uid FROM emailban WHERE address = '");
@ -1324,6 +1348,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure we release the connection before we go { // make sure we release the connection before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1336,11 +1361,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
{ {
checkInitialized(); checkInitialized();
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // do a SELECT on the confalias table { // do a SELECT on the confalias table
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '"); StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '");
sql.append(alias).append("';"); sql.append(alias).append("';");
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -1354,6 +1380,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally
@ -1639,11 +1666,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
public void forceParamReload() throws DataException public void forceParamReload() throws DataException
{ {
Connection conn = null; // data pooled connection Connection conn = null; // data pooled connection
Statement stmt = null;
try try
{ // get a connection and use it to reload { // get a connection and use it to reload
conn = env.getConnection(); conn = env.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
loadDefaults(stmt); loadDefaults(stmt);
} // end try } // end try
@ -1655,6 +1683,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end catch } // end catch
finally finally
{ // make sure the connection is released before we go { // make sure the connection is released before we go
SQLUtil.shutdown(stmt);
env.releaseConnection(conn); env.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -108,8 +108,7 @@ public class EnvEngine
public final void releaseConnection(Connection c) public final void releaseConnection(Connection c)
{ {
if (c!=null) datapool.releaseConnection(c);
datapool.releaseConnection(c);
} // end releaseConnection } // end releaseConnection

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -233,7 +233,7 @@ public class DataPool implements Runnable
* @return The new database connection object. * @return The new database connection object.
* @exception java.sql.SQLException An error prevented the creation of the connection. * @exception java.sql.SQLException An error prevented the creation of the connection.
*/ */
private Connection makeNewConnection() throws SQLException private final Connection makeNewConnection() throws SQLException
{ {
try try
{ // make the connection and return it { // make the connection and return it
@ -268,7 +268,7 @@ public class DataPool implements Runnable
* *
* @see #run() * @see #run()
*/ */
private void makeBackgroundConnection() private final void makeBackgroundConnection()
{ {
pending = true; pending = true;
try try
@ -291,7 +291,7 @@ public class DataPool implements Runnable
* *
* @param vconn Vector of connections to be closed. * @param vconn Vector of connections to be closed.
*/ */
private static void closeConnections(Vector vconn) private final static void closeConnections(Vector vconn)
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("closeConnections(" + String.valueOf(vconn.size()) + " to be closed)"); logger.debug("closeConnections(" + String.valueOf(vconn.size()) + " to be closed)");

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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; i<str.length(); i++) for (int i=0; i<str.length(); i++)
{ // if any character is not a digit, bail out! { // if any character is not a digit, bail out!
@ -183,7 +183,7 @@ public class PostLinkDecoder
} // end isAllDigits } // end isAllDigits
private void setCommunityName(String name) throws ValidationException private final void setCommunityName(String name) throws ValidationException
{ {
if (name.length()>MAX_COMM_LEN) if (name.length()>MAX_COMM_LEN)
throw new ValidationException("community alias is too long"); throw new ValidationException("community alias is too long");
@ -193,7 +193,7 @@ public class PostLinkDecoder
} // end setCommunityName } // end setCommunityName
private void setConferenceName(String name) throws ValidationException private final void setConferenceName(String name) throws ValidationException
{ {
if (name.length()>MAX_CONF_LEN) if (name.length()>MAX_CONF_LEN)
throw new ValidationException("conference alias is too long"); throw new ValidationException("conference alias is too long");
@ -203,7 +203,7 @@ public class PostLinkDecoder
} // end setConferenceName } // end setConferenceName
private void setTopicNumber(String val) throws ValidationException private final void setTopicNumber(String val) throws ValidationException
{ {
if (!isAllDigits(val)) if (!isAllDigits(val))
throw new ValidationException("invalid topic number reference"); throw new ValidationException("invalid topic number reference");
@ -223,7 +223,7 @@ public class PostLinkDecoder
} // end setTopicNumber } // end setTopicNumber
private void setPostRange(StringBuffer buf) throws ValidationException private final void setPostRange(StringBuffer buf) throws ValidationException
{ {
int pos = buf.toString().indexOf('-'); int pos = buf.toString().indexOf('-');
String temp = null; String temp = null;
@ -293,37 +293,37 @@ public class PostLinkDecoder
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
public String getCommunity() public final String getCommunity()
{ {
return commname; return commname;
} // end getCommunity } // end getCommunity
public String getConference() public final String getConference()
{ {
return confname; return confname;
} // end getConference } // end getConference
public short getTopic() public final short getTopic()
{ {
return topicnum; return topicnum;
} // end getTopic } // end getTopic
public int getFirstPost() public final int getFirstPost()
{ {
return first_post; return first_post;
} // end getFirstPost } // end getFirstPost
public int getLastPost() public final int getLastPost()
{ {
return last_post; return last_post;
} // end getFirstPost } // end getFirstPost
public boolean needDatabaseVerification() public final boolean needDatabaseVerification()
{ {
return ((commname!=null) || (confname!=null)); return ((commname!=null) || (confname!=null));
@ -331,9 +331,11 @@ public class PostLinkDecoder
public void verifyNames(Connection conn) throws ValidationException public void verifyNames(Connection conn) throws ValidationException
{ {
Statement stmt = null;
try try
{ // do the necessary database stuff { // do the necessary database stuff
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
ResultSet rs; ResultSet rs;
@ -364,6 +366,11 @@ public class PostLinkDecoder
throw new ValidationException("unable to verify names in post link"); throw new ValidationException("unable to verify names in post link");
} // end catch } // end catch
finally
{ // shut down the statement to conserve resources
SQLUtil.shutdown(stmt);
} // end finally
} // end verifyNames } // end verifyNames

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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); StringBuffer b = new StringBuffer(URI_PREFIX);
boolean started = false; boolean started = false;
@ -115,7 +115,6 @@ public class PostLinkRewriter implements Rewriter
} // end buildPostLink } // end buildPostLink
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Implementations from interface Rewriter * Implementations from interface Rewriter
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -167,8 +166,7 @@ public class PostLinkRewriter implements Rewriter
} // end catch } // end catch
finally finally
{ // release the connection when we're done { // release the connection when we're done
if (conn!=null) datapool.releaseConnection(conn);
datapool.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -19,6 +19,7 @@ package com.silverwrist.venice.db;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.util.AnyCharMatcher; import com.silverwrist.util.AnyCharMatcher;
import com.silverwrist.util.StringUtil; 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 = "%_'"; private static final String SQL_WILDCARD_CHARS = "%_'";
// used to convert dates and times to UTC for sending to SQL // 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. * @return The converted date and time.
* @exception java.sql.SQLException The date and time string was in an invalid format. * @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) if (dstr==null)
return null; // null values are the same return null; // null values are the same
@ -92,7 +95,7 @@ public class SQLUtil
* <CODE>null</CODE>, returns <CODE>null</CODE>. * <CODE>null</CODE>, returns <CODE>null</CODE>.
* @see com.silverwrist.util.StringUtil#encodeStringSQL(java.lang.String) * @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); return StringUtil.encodeStringSQL(str);
@ -108,7 +111,7 @@ public class SQLUtil
* <CODE>null</CODE>, returns "NULL". * <CODE>null</CODE>, returns "NULL".
* @see com.silverwrist.util.StringUtil#encodeStringSQL(java.lang.String) * @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) if (str==null)
return "NULL"; return "NULL";
@ -127,7 +130,7 @@ public class SQLUtil
* @return The SQL-encoded equivalent of <CODE>str</CODE>. If <CODE>str</CODE> is * @return The SQL-encoded equivalent of <CODE>str</CODE>. If <CODE>str</CODE> is
* <CODE>null</CODE>, returns <CODE>null</CODE>. * <CODE>null</CODE>, returns <CODE>null</CODE>.
*/ */
public static String encodeStringWildcards(String str) public static final String encodeStringWildcards(String str)
{ {
if (str==null) if (str==null)
return null; // safety feature return null; // safety feature
@ -174,7 +177,7 @@ public class SQLUtil
* @param d The date to be encoded. * @param d The date to be encoded.
* @return The string equivalent of that date. * @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. // Break down the date as a UTC value.
GregorianCalendar cal = new GregorianCalendar(utc); GregorianCalendar cal = new GregorianCalendar(utc);
@ -233,7 +236,7 @@ public class SQLUtil
* @return The value of the specified column, expressed as a date. * @return The value of the specified column, expressed as a date.
* @exception java.sql.SQLException If the column could not be retrieved or converted. * @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)); return convertDateTimeString(rs.getString(column));
@ -247,10 +250,55 @@ public class SQLUtil
* @return The value of the specified column, expressed as a date. * @return The value of the specified column, expressed as a date.
* @exception java.sql.SQLException If the column could not be retrieved or converted. * @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)); return convertDateTimeString(rs.getString(column));
} // end getFullDateTime } // 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 } // end class SQLUtil

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -68,11 +68,12 @@ public class UserNameRewriter implements Rewriter
return null; return null;
Connection conn = null; Connection conn = null;
Statement stmt = null;
try try
{ // get a database connection and create a statement { // get a database connection and create a statement
conn = datapool.getConnection(); conn = datapool.getConnection();
Statement stmt = conn.createStatement(); stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT uid FROM users WHERE username = '"); StringBuffer sql = new StringBuffer("SELECT uid FROM users WHERE username = '");
sql.append(SQLUtil.encodeString(data)).append("';"); sql.append(SQLUtil.encodeString(data)).append("';");
ResultSet rs = stmt.executeQuery(sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString());
@ -87,8 +88,8 @@ public class UserNameRewriter implements Rewriter
} // end catch } // end catch
finally finally
{ // make sure and release the connection before we go { // make sure and release the connection before we go
if (conn!=null) SQLUtil.shutdown(stmt);
datapool.releaseConnection(conn); datapool.releaseConnection(conn);
} // end finally } // end finally

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * Contributor(s):
*/ */
@ -55,6 +55,7 @@ public class AuditRecord implements AuditData
if (!(rs.next())) if (!(rs.next()))
throw new DataException("description string not found for code " + code); throw new DataException("description string not found for code " + code);
rc = rs.getString(1); rc = rs.getString(1);
SQLUtil.shutdown(rs);
descr_cache.put(code_x,rc); descr_cache.put(code_x,rc);
} // end if } // end if
@ -76,6 +77,7 @@ public class AuditRecord implements AuditData
rc = rs.getString(1); rc = rs.getString(1);
else else
rc = "(UID #" + uid + ")"; rc = "(UID #" + uid + ")";
SQLUtil.shutdown(rs);
uname_cache.put(uid_x,rc); uname_cache.put(uid_x,rc);
} // end if } // end if
@ -97,6 +99,7 @@ public class AuditRecord implements AuditData
rc = rs.getString(1); rc = rs.getString(1);
else else
rc = "(CID #" + cid + ")"; rc = "(CID #" + cid + ")";
SQLUtil.shutdown(rs);
commname_cache.put(cid_x,rc); commname_cache.put(cid_x,rc);
} // end if } // end if
@ -105,6 +108,12 @@ public class AuditRecord implements AuditData
} // end getCommunityName } // end getCommunityName
void shutdown()
{
SQLUtil.shutdown(stmt);
} // end shutdown
} // end class DescrStringCache } // 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.record = 0;
this.when = null; this.when = null;
@ -250,7 +259,7 @@ public class AuditRecord implements AuditData
} // end setBaseData } // 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 = new String[DATA_COUNT];
data[0] = data1; data[0] = data1;
@ -265,61 +274,61 @@ public class AuditRecord implements AuditData
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
public long getRecord() public final long getRecord()
{ {
return record; return record;
} // end getRecord } // end getRecord
public java.util.Date getDateTime() public final java.util.Date getDateTime()
{ {
return when; return when;
} // end getDateTime } // end getDateTime
public int getType() public final int getType()
{ {
return type; return type;
} // end getType } // end getType
public int getUID() public final int getUID()
{ {
return uid; return uid;
} // end getType } // end getType
public int getCommunityID() public final int getCommunityID()
{ {
return cid; return cid;
} // end getCommunityID } // end getCommunityID
public String getIPAddress() public final String getIPAddress()
{ {
return ip; return ip;
} // end getIPAddress } // end getIPAddress
public String getData(int ndx) public final String getData(int ndx)
{ {
return data[ndx]; return data[ndx];
} // end getData } // end getData
public String getDescription() public final String getDescription()
{ {
return descr; return descr;
} // end getDescription } // end getDescription
public String getUserName() public final String getUserName()
{ {
return uname; return uname;
} // end getUserName } // end getUserName
public String getCommunityName() public final String getCommunityName()
{ {
return commname; return commname;
@ -335,32 +344,42 @@ public class AuditRecord implements AuditData
if (record!=0) if (record!=0)
throw new InternalStateError("audit record " + String.valueOf(record) + " already stored!"); throw new InternalStateError("audit record " + String.valueOf(record) + " already stored!");
Statement stmt = conn.createStatement(); Statement stmt = null;
stmt.executeUpdate("LOCK TABLES audit WRITE;");
try try
{ // attempt to insert a record into the audit table { // begin updating the database
StringBuffer sql = new StringBuffer("INSERT INTO audit (on_date, event, uid, sigid, ip, data1, data2, " stmt = conn.createStatement();
+ "data3, data4) VALUES ('"); stmt.executeUpdate("LOCK TABLES audit WRITE;");
java.util.Date now = new java.util.Date(); try
sql.append(SQLUtil.encodeDate(now)).append("', ").append(type).append(", ").append(uid).append(", "); { // attempt to insert a record into the audit table
sql.append(cid).append(", '").append(SQLUtil.encodeString(ip)).append("', "); StringBuffer sql = new StringBuffer("INSERT INTO audit (on_date, event, uid, sigid, ip, data1, data2, "
sql.append(SQLUtil.encodeStringArg(data[0])).append(", ").append(SQLUtil.encodeStringArg(data[1])); + "data3, data4) VALUES ('");
sql.append(", ").append(SQLUtil.encodeStringArg(data[2])).append(", "); java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeStringArg(data[3])).append(");"); 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();"); ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID();");
if (!(rs.next())) if (!(rs.next()))
throw new InternalStateError("AuditRecord.store bogus query - must return at least 1 row!"); throw new InternalStateError("AuditRecord.store bogus query - must return at least 1 row!");
record = rs.getLong(1); record = rs.getLong(1);
when = now; when = now;
} // end try
finally
{ // make sure we unlock the tables before we go
SQLUtil.unlockTables(conn);
} // end finally
} // end try } // end try
finally finally
{ // make sure we unlock the tables before we go { // close down to conserve resources
Statement ulk_stmt = conn.createStatement(); SQLUtil.shutdown(stmt);
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally } // end finally
@ -376,20 +395,31 @@ public class AuditRecord implements AuditData
{ {
ArrayList rc = new ArrayList(); ArrayList rc = new ArrayList();
DescrStringCache cache = new DescrStringCache(conn); DescrStringCache cache = new DescrStringCache(conn);
Statement stmt = null;
Statement stmt = conn.createStatement(); try
StringBuffer sql = new StringBuffer("SELECT * FROM audit"); { // query for audit records
if (cid>0) stmt = conn.createStatement();
sql.append(" WHERE sigid = ").append(cid); StringBuffer sql = new StringBuffer("SELECT * FROM audit");
sql.append(" ORDER BY on_date DESC LIMIT ").append(offset).append(", ").append(count).append(';'); if (cid>0)
ResultSet rs = stmt.executeQuery(sql.toString()); 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()) while (rs.next())
{ // load the results { // load the results
AuditData dta = new AuditRecord(rs,cache); AuditData dta = new AuditRecord(rs,cache);
rc.add(dta); rc.add(dta);
} // end while } // end while
} // end try
finally
{ // shut down things
SQLUtil.shutdown(stmt);
cache.shutdown();
} // end finally
return Collections.unmodifiableList(rc); return Collections.unmodifiableList(rc);
@ -397,15 +427,26 @@ public class AuditRecord implements AuditData
public static int getAuditRecordCount(Connection conn, int cid) throws SQLException public static int getAuditRecordCount(Connection conn, int cid) throws SQLException
{ {
Statement stmt = conn.createStatement(); Statement stmt = null;
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM audit");
if (cid>0) try
sql.append(" WHERE sigid = ").append(cid); { // look up the count
sql.append(';'); stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql.toString()); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM audit");
if (!(rs.next())) if (cid>0)
throw new InternalStateError("query failure on getAuditRecordCount"); sql.append(" WHERE sigid = ").append(cid);
return rs.getInt(1); 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 } // end getAuditRecordCount

View File

@ -11,7 +11,7 @@
* *
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * 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): * 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 * 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 <CODE>SEcurityMonitor</CODE> * which are "outside the standard scopes." Calls delegated to this instance of <CODE>SecurityMonitor</CODE>
* generally fail or return <CODE>null</CODE>, except when returning the three defined roles. * generally fail or return <CODE>null</CODE>, except when returning the three defined roles.
* *
* @author Eric J. Bowersox &lt;erbo@silcom.com&gt; * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;