From 47b88efd7535b2bf1de72ede359ce4d9fc6b7925 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Sat, 17 Nov 2001 06:37:30 +0000 Subject: [PATCH] MAJOR restructuring of the engine code to get the execution environment info separated from the internal objects (as well as separating the internal interfaces), some prep work for modularizing the SIG-to-service interface so it'll be easier to add chat and stuff. Also fixed up a display issue with 1-character CDTextFormFields. --- .../venice/core/impl/AdminOperationsImpl.java | 31 +- .../core/impl/AdminUserContextImpl.java | 98 ++-- .../venice/core/impl/AdvertisementImpl.java | 29 +- .../core/impl/BackgroundCommunityPurge.java | 23 +- .../core/impl/BackgroundConferencePurge.java | 19 +- .../core/impl/BackgroundTopicPurge.java | 18 +- .../core/impl/CategoryDescriptorImpl.java | 74 ++- .../venice/core/impl/CommunityCoreData.java | 262 +++++------ .../core/impl/CommunityUserContextImpl.java | 294 +++++------- .../impl/ConferenceCommunityContextImpl.java | 115 ++--- .../venice/core/impl/ConferenceCoreData.java | 162 +++---- .../core/impl/ConferenceUserContextImpl.java | 435 ++++++------------ .../venice/core/impl/ContactInfoImpl.java | 10 +- .../venice/core/impl/ImageStore.java | 35 +- .../core/impl/PublishedMessageImpl.java | 48 +- .../core/impl/SideBoxDescriptorImpl.java | 29 +- .../venice/core/impl/SimpleEmailer.java | 5 +- .../impl/TopicMessageUserContextImpl.java | 197 ++++---- .../core/impl/TopicUserContextImpl.java | 267 +++++------ .../venice/core/impl/UserContextImpl.java | 171 +++---- .../venice/core/impl/UserProfileImpl.java | 30 +- .../venice/core/impl/VeniceEngineImpl.java | 119 +++-- .../{impl => internals}/CommunityBackend.java | 4 +- .../{impl => internals}/CommunityData.java | 27 +- .../CommunityDataBackend.java | 4 +- .../ConferenceBackend.java | 4 +- .../ConferenceCommunityContext.java | 20 +- .../{impl => internals}/ConferenceData.java | 16 +- .../venice/core/internals/Emailer.java | 34 ++ .../{impl => internals}/EngineBackend.java | 7 +- .../venice/core/internals/EnvCommunity.java | 105 +++++ .../core/internals/EnvCommunityData.java | 65 +++ .../venice/core/internals/EnvConference.java | 66 +++ .../internals/EnvConferenceCommunity.java | 39 ++ .../core/internals/EnvConferenceData.java | 39 ++ .../venice/core/internals/EnvEngine.java | 83 ++++ .../venice/core/internals/EnvUser.java | 97 ++++ .../{impl => internals}/ReturnConfSeq.java | 14 +- .../{impl => internals}/ReturnTopicInfo.java | 16 +- .../core/{impl => internals}/UserBackend.java | 2 +- .../format/CDEmailAddressFormField.java | 18 +- .../servlets/format/CDIntegerFormField.java | 1 + .../servlets/format/CDTextFormField.java | 13 +- .../servlets/format/CDVeniceIDFormField.java | 6 + 44 files changed, 1616 insertions(+), 1535 deletions(-) rename src/com/silverwrist/venice/core/{impl => internals}/CommunityBackend.java (94%) rename src/com/silverwrist/venice/core/{impl => internals}/CommunityData.java (79%) rename src/com/silverwrist/venice/core/{impl => internals}/CommunityDataBackend.java (90%) rename src/com/silverwrist/venice/core/{impl => internals}/ConferenceBackend.java (94%) rename src/com/silverwrist/venice/core/{impl => internals}/ConferenceCommunityContext.java (79%) rename src/com/silverwrist/venice/core/{impl => internals}/ConferenceData.java (82%) create mode 100644 src/com/silverwrist/venice/core/internals/Emailer.java rename src/com/silverwrist/venice/core/{impl => internals}/EngineBackend.java (94%) create mode 100644 src/com/silverwrist/venice/core/internals/EnvCommunity.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvCommunityData.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvConference.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvConferenceCommunity.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvConferenceData.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvEngine.java create mode 100644 src/com/silverwrist/venice/core/internals/EnvUser.java rename src/com/silverwrist/venice/core/{impl => internals}/ReturnConfSeq.java (82%) rename src/com/silverwrist/venice/core/{impl => internals}/ReturnTopicInfo.java (83%) rename src/com/silverwrist/venice/core/{impl => internals}/UserBackend.java (96%) diff --git a/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java b/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java index c96143f..40c28c1 100644 --- a/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdminOperationsImpl.java @@ -21,6 +21,7 @@ import java.sql.*; import java.util.*; import org.apache.log4j.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.security.AuditRecord; import com.silverwrist.venice.security.SecLevels; @@ -39,20 +40,16 @@ class AdminOperationsImpl implements AdminOperations *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // the back end of the engine - private UserBackend user; // the UserContext that created this object - private DataPool datapool; // the data pool used by this object + private EnvUser env; // the execution environment /*-------------------------------------------------------------------------------- * Constructor *-------------------------------------------------------------------------------- */ - AdminOperationsImpl(EngineBackend engine, UserBackend user, DataPool datapool) + AdminOperationsImpl(EnvUser env) { - this.engine = engine; - this.user = user; - this.datapool = datapool; + this.env = env; } // end constructor @@ -63,7 +60,7 @@ class AdminOperationsImpl implements AdminOperations public boolean isGlobalAdmin() { - return (user.realBaseLevel()==SecLevels.GLOBAL_BOFH); + return (env.getUser().realBaseLevel()==SecLevels.GLOBAL_BOFH); } // end isGlobalAdmin @@ -74,7 +71,7 @@ class AdminOperationsImpl implements AdminOperations try { // retrieve a connection from the data pool and get the audit records - conn = datapool.getConnection(); + conn = env.getConnection(); rc = AuditRecord.getAuditRecords(conn,-1,offset,count); } // end try @@ -86,8 +83,7 @@ class AdminOperationsImpl implements AdminOperations } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -102,7 +98,7 @@ class AdminOperationsImpl implements AdminOperations try { // retrieve a connection from the data pool and get the audit records - conn = datapool.getConnection(); + conn = env.getConnection(); rc = AuditRecord.getAuditRecordCount(conn,-1); } // end try @@ -114,8 +110,7 @@ class AdminOperationsImpl implements AdminOperations } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -125,25 +120,25 @@ class AdminOperationsImpl implements AdminOperations public AdminUserContext getUserContext(int uid) throws DataException { - return AdminUserContextImpl.getAdminUserContext(engine,user,datapool,uid); + return AdminUserContextImpl.getAdminUserContext(env,uid); } // end getUserContext public AdminUserContext getUserContext(String username) throws DataException { - return AdminUserContextImpl.getAdminUserContext(engine,user,datapool,username); + return AdminUserContextImpl.getAdminUserContext(env,username); } // end getUserContext public GlobalProperties getProperties() { - return engine.getProperties(); + return env.getEngine().getProperties(); } // end getProperties public void setProperties(GlobalProperties props) throws DataException { - engine.setProperties(props); + env.getEngine().setProperties(props); } // end setProperties diff --git a/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java b/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java index a27d4bf..3a0440e 100644 --- a/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdminUserContextImpl.java @@ -22,6 +22,7 @@ import java.util.*; import org.apache.log4j.*; import com.silverwrist.util.International; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.security.PasswordHash; import com.silverwrist.venice.security.AuditRecord; @@ -40,9 +41,7 @@ class AdminUserContextImpl implements AdminUserContext *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // the back end of the engine - private UserBackend user; // the controlling administrative user - private DataPool datapool; // the data pool used by this object + private EnvUser env; // the local environment private int uid; // the user ID of this user private int contactid; // ID of associated contact information private int level; // base security level for this user @@ -60,12 +59,9 @@ class AdminUserContextImpl implements AdminUserContext *-------------------------------------------------------------------------------- */ - protected AdminUserContextImpl(EngineBackend engine, UserBackend user, DataPool datapool, ResultSet rs) - throws SQLException + protected AdminUserContextImpl(EnvUser env, ResultSet rs) throws SQLException { - this.engine = engine; - this.user = user; - this.datapool = datapool; + this.env = env; this.uid = rs.getInt("uid"); this.contactid = rs.getInt("contactid"); this.level = rs.getInt("base_lvl"); @@ -119,15 +115,14 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); description = new_descr; // change stored information - ar = new AuditRecord(AuditRecord.ADMIN_ACCOUNT_CHANGE,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,"field=description"); + ar = env.newAudit(AuditRecord.ADMIN_ACCOUNT_CHANGE,"uid=" + uid,"field=description"); } // end try catch (SQLException e) @@ -150,8 +145,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -173,15 +167,14 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET base_lvl = "); sql.append(new_level).append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); level = new_level; - ar = new AuditRecord(AuditRecord.ADMIN_SET_SECURITY,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,"level=" + new_level); + ar = env.newAudit(AuditRecord.ADMIN_SET_SECURITY,"uid=" + uid,"level=" + new_level); } // end try catch (SQLException e) @@ -204,8 +197,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -227,15 +219,14 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = "); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); email_verified = flag; - ar = new AuditRecord(AuditRecord.ADMIN_ACCOUNT_CHANGE,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,"field=verify_email"); + ar = env.newAudit(AuditRecord.ADMIN_ACCOUNT_CHANGE,"uid=" + uid,"field=verify_email"); } // end try catch (SQLException e) @@ -258,8 +249,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -281,15 +271,14 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET lockout = "); sql.append(flag ? '1' : '0').append(" WHERE uid = ").append(uid).append(';'); stmt.executeUpdate(sql.toString()); lockout = flag; - ar = new AuditRecord(AuditRecord.ADMIN_LOCK_OUT,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,flag ? "locked" : "unlocked"); + ar = env.newAudit(AuditRecord.ADMIN_LOCK_OUT,"uid=" + uid,flag ? "locked" : "unlocked"); } // end try catch (SQLException e) @@ -312,8 +301,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -326,7 +314,7 @@ class AdminUserContextImpl implements AdminUserContext ContactInfoImpl rc; if (contactid>=0) - rc = new ContactInfoImpl(datapool,contactid); + rc = new ContactInfoImpl(env,contactid); else rc = new ContactInfoImpl(uid); return rc; @@ -351,7 +339,7 @@ class AdminUserContextImpl implements AdminUserContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Stashable obj = (Stashable)ci; // save the contact information @@ -365,8 +353,7 @@ class AdminUserContextImpl implements AdminUserContext } // end if - ar = new AuditRecord(AuditRecord.ADMIN_USER_CONTACT_INFO,user.realUID(),user.userRemoteAddress(), - "uid=" + uid,"contactid=" + contactid); + ar = env.newAudit(AuditRecord.ADMIN_USER_CONTACT_INFO,"uid=" + uid,"contactid=" + contactid); } // end try catch (ClassCastException cce) @@ -395,8 +382,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -409,7 +395,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); PasswordHash phash = new PasswordHash(password); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); @@ -418,8 +404,7 @@ class AdminUserContextImpl implements AdminUserContext stmt.executeUpdate(sql.toString()); // record an audit record for this user - ar = new AuditRecord(AuditRecord.ADMIN_PASSWORD_CHANGE,user.realUID(),user.userRemoteAddress(), - "uid=" + uid); + ar = env.newAudit(AuditRecord.ADMIN_PASSWORD_CHANGE,"uid=" + uid); } // end try catch (SQLException e) @@ -442,8 +427,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -462,7 +446,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the update statement @@ -474,8 +458,7 @@ class AdminUserContextImpl implements AdminUserContext // replace the locale here my_locale = locale; - ar = new AuditRecord(AuditRecord.ADMIN_ACCOUNT_CHANGE,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,"field=localeid"); + ar = env.newAudit(AuditRecord.ADMIN_ACCOUNT_CHANGE,"uid=" + uid,"field=localeid"); } // end try catch (SQLException e) @@ -498,8 +481,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -518,7 +500,7 @@ class AdminUserContextImpl implements AdminUserContext try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the update statement @@ -530,8 +512,7 @@ class AdminUserContextImpl implements AdminUserContext // replace the locale here my_tz = timezone; - ar = new AuditRecord(AuditRecord.ADMIN_ACCOUNT_CHANGE,user.realUID(),user.userRemoteAddress(),0, - "uid=" + uid,"field=tzid"); + ar = env.newAudit(AuditRecord.ADMIN_ACCOUNT_CHANGE,"uid=" + uid,"field=tzid"); } // end try catch (SQLException e) @@ -554,8 +535,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -578,14 +558,13 @@ class AdminUserContextImpl implements AdminUserContext *-------------------------------------------------------------------------------- */ - static AdminUserContext getAdminUserContext(EngineBackend engine, UserBackend user, DataPool datapool, - int uid) throws DataException + static AdminUserContext getAdminUserContext(EnvUser env, int uid) throws DataException { Connection conn = null; try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " + "ON users.uid = userprefs.uid WHERE users.uid = " + uid + ";"); @@ -594,7 +573,7 @@ class AdminUserContextImpl implements AdminUserContext if (rs.getBoolean("is_anon")) throw new DataException("Cannot modify the defaults for the anonymous user."); - return new AdminUserContextImpl(engine,user,datapool,rs); + return new AdminUserContextImpl(env,rs); } // end try catch (SQLException e) @@ -605,21 +584,19 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // release the connection where necessary - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getAdminUserContext - static AdminUserContext getAdminUserContext(EngineBackend engine, UserBackend user, DataPool datapool, - String username) throws DataException + static AdminUserContext getAdminUserContext(EnvUser env, String username) throws DataException { Connection conn = null; try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users INNER JOIN userprefs " + "ON users.uid = userprefs.uid WHERE users.username = '" @@ -629,7 +606,7 @@ class AdminUserContextImpl implements AdminUserContext if (rs.getBoolean("is_anon")) throw new DataException("Cannot modify the defaults for the anonymous user."); - return new AdminUserContextImpl(engine,user,datapool,rs); + return new AdminUserContextImpl(env,rs); } // end try catch (SQLException e) @@ -640,8 +617,7 @@ class AdminUserContextImpl implements AdminUserContext } // end catch finally { // release the connection where necessary - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java b/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java index 3bdf37b..8d93088 100644 --- a/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java +++ b/src/com/silverwrist/venice/core/impl/AdvertisementImpl.java @@ -21,6 +21,7 @@ import java.sql.*; import java.util.Random; import com.silverwrist.util.cache.CacheMap; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.EnvEngine; import com.silverwrist.venice.db.*; class AdvertisementImpl implements Advertisement @@ -38,7 +39,7 @@ class AdvertisementImpl implements Advertisement *-------------------------------------------------------------------------------- */ - private DataPool datapool; // data pool reference + private EnvEngine env; // execution environment private int adid; // ad ID private String imagepath; // image path private short style; // ad style @@ -50,9 +51,9 @@ class AdvertisementImpl implements Advertisement *-------------------------------------------------------------------------------- */ - protected AdvertisementImpl(DataPool datapool, ResultSet rs) throws SQLException + protected AdvertisementImpl(EnvEngine env, ResultSet rs) throws SQLException { - this.datapool = datapool; + this.env = env; this.adid = rs.getInt("adid"); this.imagepath = rs.getString("imagepath"); this.style = rs.getShort("pathstyle"); @@ -66,7 +67,7 @@ class AdvertisementImpl implements Advertisement *-------------------------------------------------------------------------------- */ - private static Advertisement getTheAd(DataPool datapool, Statement stmt, int ad_id) throws SQLException + private static Advertisement getTheAd(EnvEngine env, Statement stmt, int ad_id) throws SQLException { Integer my_ad_id = new Integer(ad_id); Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id)); @@ -76,7 +77,7 @@ class AdvertisementImpl implements Advertisement ResultSet rs = stmt.executeQuery("SELECT * From adverts WHERE adid = " + ad_id + ";"); if (!(rs.next())) return null; - rc = new AdvertisementImpl(datapool,rs); + rc = new AdvertisementImpl(env,rs); ad_cache.put(my_ad_id,rc); return rc; @@ -126,15 +127,15 @@ class AdvertisementImpl implements Advertisement *-------------------------------------------------------------------------------- */ - static Advertisement getAdByID(DataPool datapool, int id) + static Advertisement getAdByID(EnvEngine env, int id) { Connection conn = null; try { // get a database connection and call the internal function - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); - return getTheAd(datapool,stmt,id); + return getTheAd(env,stmt,id); } // end try catch (SQLException e) @@ -144,20 +145,19 @@ class AdvertisementImpl implements Advertisement } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getAdByID - static Advertisement getRandomAd(DataPool datapool) + static Advertisement getRandomAd(EnvEngine env) { Connection conn = null; try { // get a database connection and call the internal function - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;"); if (!(rs.next())) @@ -167,7 +167,7 @@ class AdvertisementImpl implements Advertisement for (int i=0; i<100; i++) { // select an ad ID int ad_id = rng.nextInt(maximum) + 1; - Advertisement rc = getTheAd(datapool,stmt,ad_id); + Advertisement rc = getTheAd(env,stmt,ad_id); if (rc!=null) return rc; @@ -183,8 +183,7 @@ class AdvertisementImpl implements Advertisement } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java index 1fd1fa9..d2d76df 100644 --- a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java +++ b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java @@ -22,9 +22,10 @@ import java.util.*; import org.apache.log4j.*; import com.silverwrist.util.ParallelRunQueue; import com.silverwrist.util.cache.ObjectCache; -import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.DataException; import com.silverwrist.venice.core.InternalStateError; +import com.silverwrist.venice.core.internals.*; +import com.silverwrist.venice.db.*; class BackgroundCommunityPurge implements Runnable { @@ -40,9 +41,7 @@ class BackgroundCommunityPurge implements Runnable *-------------------------------------------------------------------------------- */ - private EngineBackend engine; - private DataPool datapool; - private UserBackend user; + private EnvCommunity env; private int cid; private int num_confs; private int max_confid; @@ -53,12 +52,9 @@ class BackgroundCommunityPurge implements Runnable *-------------------------------------------------------------------------------- */ - BackgroundCommunityPurge(EngineBackend engine, DataPool datapool, UserBackend user, int cid, int num_confs, - int max_confid, ObjectCache conf_objcache) + BackgroundCommunityPurge(EnvCommunity env, int cid, int num_confs, int max_confid, ObjectCache conf_objcache) { - this.engine = engine; - this.datapool = datapool; - this.user = user; + this.env = env; this.cid = cid; this.num_confs = num_confs; this.max_confid = max_confid; @@ -81,7 +77,7 @@ class BackgroundCommunityPurge implements Runnable try { // get a database connection from the pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // run some "lower priority" deletes @@ -106,7 +102,7 @@ class BackgroundCommunityPurge implements Runnable if (confobj!=null) { // OK, there's an object - do the delete internally and release the object conf_objcache.detach(key); - confobj.delete(user); + confobj.delete(env); } // end if else @@ -141,7 +137,7 @@ class BackgroundCommunityPurge implements Runnable rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new InternalStateError("BackgroundCommunityPurge.run screwup on conference SELECT"); - rq.queue(new BackgroundConferencePurge(engine,datapool,key.intValue(),rs.getInt(1),rs.getInt(2))); + rq.queue(new BackgroundConferencePurge(env,key.intValue(),rs.getInt(1),rs.getInt(2))); } // end if (have to delete conference data) @@ -167,8 +163,7 @@ class BackgroundCommunityPurge implements Runnable } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/BackgroundConferencePurge.java b/src/com/silverwrist/venice/core/impl/BackgroundConferencePurge.java index bdb0410..3b59d0e 100644 --- a/src/com/silverwrist/venice/core/impl/BackgroundConferencePurge.java +++ b/src/com/silverwrist/venice/core/impl/BackgroundConferencePurge.java @@ -22,6 +22,7 @@ import org.apache.log4j.*; import com.silverwrist.util.ParallelRunQueue; import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.InternalStateError; +import com.silverwrist.venice.core.internals.*; class BackgroundConferencePurge implements Runnable { @@ -30,15 +31,14 @@ class BackgroundConferencePurge implements Runnable *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(BackgroundConferencePurge.class.getName()); + private static Category logger = Category.getInstance(BackgroundConferencePurge.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private EngineBackend engine; - private DataPool datapool; + private EnvEngine env; // the environment private int confid; private int num_topics; private int max_topicid; @@ -48,11 +48,9 @@ class BackgroundConferencePurge implements Runnable *-------------------------------------------------------------------------------- */ - BackgroundConferencePurge(EngineBackend engine, DataPool datapool, int confid, int num_topics, - int max_topicid) + BackgroundConferencePurge(EnvEngine env, int confid, int num_topics, int max_topicid) { - this.engine = engine; - this.datapool = datapool; + this.env = env; this.confid = confid; this.num_topics = num_topics; this.max_topicid = max_topicid; @@ -74,7 +72,7 @@ class BackgroundConferencePurge implements Runnable try { // get a database connection from the pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // purge out some auxiliary tables first @@ -104,7 +102,7 @@ class BackgroundConferencePurge implements Runnable rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new InternalStateError("BackgroundConferencePurge.run screwup on post SELECT"); - rq.queue(new BackgroundTopicPurge(engine,datapool,topicids[i],rs.getInt(1),rs.getLong(2))); + rq.queue(new BackgroundTopicPurge(env,topicids[i],rs.getInt(1),rs.getLong(2))); } // end for @@ -120,8 +118,7 @@ class BackgroundConferencePurge implements Runnable } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/BackgroundTopicPurge.java b/src/com/silverwrist/venice/core/impl/BackgroundTopicPurge.java index 407c87d..8902b05 100644 --- a/src/com/silverwrist/venice/core/impl/BackgroundTopicPurge.java +++ b/src/com/silverwrist/venice/core/impl/BackgroundTopicPurge.java @@ -20,6 +20,7 @@ package com.silverwrist.venice.core.impl; import java.sql.*; import org.apache.log4j.*; import com.silverwrist.venice.db.*; +import com.silverwrist.venice.core.internals.*; class BackgroundTopicPurge implements Runnable { @@ -28,15 +29,14 @@ class BackgroundTopicPurge implements Runnable *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(BackgroundTopicPurge.class.getName()); + private static Category logger = Category.getInstance(BackgroundTopicPurge.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private EngineBackend engine; - private DataPool datapool; + private EnvEngine env; // the environment block private int topicid; private int num_posts; private long max_postid; @@ -46,10 +46,9 @@ class BackgroundTopicPurge implements Runnable *-------------------------------------------------------------------------------- */ - BackgroundTopicPurge(EngineBackend engine, DataPool datapool, int topicid, int num_posts, long max_postid) + BackgroundTopicPurge(EnvEngine env, int topicid, int num_posts, long max_postid) { - this.engine = engine; - this.datapool = datapool; + this.env = env; this.topicid = topicid; this.num_posts = num_posts; this.max_postid = max_postid; @@ -71,7 +70,7 @@ class BackgroundTopicPurge implements Runnable try { // get a database connection from the pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // look up all the post IDs that are present for this topic @@ -89,7 +88,7 @@ class BackgroundTopicPurge implements Runnable stmt.executeUpdate("DELETE FROM postattach WHERE postid = " + postids[i] + ";"); stmt.executeUpdate("DELETE FROM postdogear WHERE postid = " + postids[i] + ";"); if (stmt.executeUpdate("DELETE FROM postpublish WHERE postid = " + postids[i] + ";")>0) - engine.unpublish(postids[i]); + env.getEngine().unpublish(postids[i]); } // end for @@ -105,8 +104,7 @@ class BackgroundTopicPurge implements Runnable } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/CategoryDescriptorImpl.java b/src/com/silverwrist/venice/core/impl/CategoryDescriptorImpl.java index 403df88..9afd950 100644 --- a/src/com/silverwrist/venice/core/impl/CategoryDescriptorImpl.java +++ b/src/com/silverwrist/venice/core/impl/CategoryDescriptorImpl.java @@ -22,6 +22,7 @@ import java.util.*; import org.apache.log4j.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.EnvEngine; class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable { @@ -61,14 +62,14 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(CategoryDescriptorImpl.class.getName()); + private static Category logger = Category.getInstance(CategoryDescriptorImpl.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private DataPool datapool; // used for doing database lookups + private EnvEngine env; // the execution environment private LinkedList cats; // the actual category segments private int symlink = -1; // if our category is actually a symlink private boolean do_hide = true; // do we hide subcategories marked hide_dir? @@ -78,9 +79,9 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable *-------------------------------------------------------------------------------- */ - CategoryDescriptorImpl(DataPool datapool, int catid, boolean do_hide) throws DataException + CategoryDescriptorImpl(EnvEngine env, int catid, boolean do_hide) throws DataException { - this.datapool = datapool; + this.env = env; cats = new LinkedList(); this.do_hide = do_hide; @@ -91,7 +92,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable try { // get a connection and a prepared statement - conn = datapool.getConnection(); + conn = env.getConnection(); doFillFromTop(conn,catid); } // end try @@ -102,17 +103,16 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end catch finally { // make sure and release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end constructor - protected CategoryDescriptorImpl(DataPool datapool, Connection conn, int catid, boolean do_hide) + protected CategoryDescriptorImpl(EnvEngine env, Connection conn, int catid, boolean do_hide) throws SQLException, DataException { - this.datapool = datapool; + this.env = env; cats = new LinkedList(); this.do_hide = do_hide; @@ -123,9 +123,9 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end constructor - protected CategoryDescriptorImpl(DataPool datapool, int id, int symlink, String name, boolean do_hide) + protected CategoryDescriptorImpl(EnvEngine env, int id, int symlink, String name, boolean do_hide) { - this.datapool = datapool; + this.env = env; this.cats = new LinkedList(); this.symlink = symlink; this.do_hide = do_hide; @@ -136,7 +136,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int copy_levels) { - this.datapool = other.datapool; + this.env = other.env; this.cats = new LinkedList(); this.symlink = ((copy_levels==other.cats.size()) ? other.symlink : -1); this.do_hide = other.do_hide; @@ -152,7 +152,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int id, int symlink, String name) { - this.datapool = other.datapool; + this.env = other.env; this.cats = new LinkedList(); this.symlink = symlink; this.do_hide = other.do_hide; @@ -164,18 +164,6 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end constructor - /*-------------------------------------------------------------------------------- - * finalize() function - *-------------------------------------------------------------------------------- - */ - - protected void finalize() - { - datapool = null; - cats = null; - - } // end finalize - /*-------------------------------------------------------------------------------- * Internal functions *-------------------------------------------------------------------------------- @@ -248,7 +236,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable { if (symlink!=-1) { // "snap" the symlink before getting subcategories - CategoryDescriptorImpl real_obj = new CategoryDescriptorImpl(datapool,symlink,do_hide); + CategoryDescriptorImpl real_obj = new CategoryDescriptorImpl(env,symlink,do_hide); return real_obj.getSubCategories(); } // end if @@ -257,7 +245,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable ArrayList rc = new ArrayList(); try { // get a connection and create a statement - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = "); sql.append(getCategoryID()); @@ -283,8 +271,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end catch finally { // make sure and release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -324,7 +311,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable public CategoryDescriptor getLinkedCategory() throws DataException { if (symlink!=-1) - return new CategoryDescriptorImpl(datapool,symlink,do_hide); + return new CategoryDescriptorImpl(env,symlink,do_hide); else return this; @@ -383,13 +370,13 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable *-------------------------------------------------------------------------------- */ - static List getTopLevelCategoryList(DataPool datapool, boolean do_hide) throws DataException + static List getTopLevelCategoryList(EnvEngine env, boolean do_hide) throws DataException { Connection conn = null; ArrayList rc = new ArrayList(); try { // get a connection and create a statement - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = -1"); if (do_hide) @@ -400,8 +387,8 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable ResultSet rs = stmt.executeQuery(sql.toString()); while (rs.next()) { // turn data values into CategoryDescriptor objects - CategoryDescriptor ncd = new CategoryDescriptorImpl(datapool,rs.getInt("catid"),rs.getInt("symlink"), - rs.getString("name"),do_hide); + CategoryDescriptor ncd = new CategoryDescriptorImpl(env,rs.getInt(1),rs.getInt(2),rs.getString(3), + do_hide); rc.add(ncd); } // end while @@ -414,8 +401,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end catch finally { // make sure and release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -423,7 +409,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable } // end getTopLevelCategoryList - static List searchForCategories(DataPool datapool, boolean do_hide, boolean search_all, int mode, + static List searchForCategories(EnvEngine env, boolean do_hide, boolean search_all, int mode, String term, int offset, int count) throws DataException { if (logger.isDebugEnabled()) @@ -435,7 +421,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE name "); @@ -478,7 +464,7 @@ class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable for (int i=0; igranted_level) - this.level = user.realBaseLevel(); - else - this.level = granted_level; + this.level = Math.max(env.getUser().realBaseLevel(),granted_level); this.is_member = member; this.show_admin = Capability.isCommunityAdmin(granted_level); this.locked = locked; @@ -161,9 +150,9 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend { // attempt to load the CommunityData object if (deleted) throw new DataException("This community has been deleted."); - data = engine.getCommunityDataObject(cid); + data = env.getEngine().getCommunityDataObject(cid); if (data!=null) - user.saveMRU("community",data); + env.getUser().saveMRU("community",data); // clear cache when we get the real data cache = null; @@ -182,9 +171,9 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend return null; // we're deleted try { // attempt to load the CommunityDataObject - data = engine.getCommunityDataObject(cid); + data = env.getEngine().getCommunityDataObject(cid); if (data!=null) - user.saveMRU("community",data); + env.getUser().saveMRU("community",data); } // end try catch (DataException e) @@ -216,7 +205,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if getData().testMembership(level,is_member); - if (!(engine.canAccessFeature("CONF",level,getData().canReadCommunitySubObjects(level)))) + if (!(env.getEngine().canAccessFeature("CONF",level,getData().canReadCommunitySubObjects(level)))) { // you can't access the conferences! logger.error("user not permitted to read confs from this community"); throw new AccessError("You are not permitted to access this community's conferences."); @@ -225,8 +214,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end testConferenceAccess - private static CommunityUserContextImpl getCommunityPrivate(EngineBackend engine, UserBackend user, - DataPool datapool, Connection conn, int cid) + private static CommunityUserContextImpl getCommunityPrivate(EnvUser env, Connection conn, int cid) throws DataException { try @@ -243,8 +231,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // initialize the object and check membership info - CommunityUserContextImpl sc = new CommunityUserContextImpl(engine,user,datapool,cid, - rs.getString(1),rs.getString(2)); + CommunityUserContextImpl sc = new CommunityUserContextImpl(env,cid,rs.getString(1),rs.getString(2)); sc.checkMembership(conn); return sc; @@ -339,8 +326,8 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend { if (deleted) throw new DataException("This community has been deleted."); - return new CategoryDescriptorImpl(datapool,getData().getCategoryID(), - Capability.hideHiddenCategories(user.realBaseLevel())); + return new CategoryDescriptorImpl(env,getData().getCategoryID(), + Capability.hideHiddenCategories(env.getUser().realBaseLevel())); } // end getCategory @@ -373,11 +360,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // load the profile for the user - return new UserProfileImpl(engine,user,conn,getData().getHostUID(), - Capability.canSeeHiddenContactFields(user.realBaseLevel())); + return new UserProfileImpl(env,conn,getData().getHostUID(), + Capability.canSeeHiddenContactFields(env.getUser().realBaseLevel())); } // end try catch (SQLException e) @@ -387,8 +374,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -463,7 +449,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend int id = getData().getContactID(); ContactInfo rc; if (id>=0) - rc = new ContactInfoImpl(datapool,id); + rc = new ContactInfoImpl(env,id); else rc = new ContactInfoImpl(getData().getHostUID(),cid); getData().touch(); @@ -489,7 +475,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().putContactInfo(user,ci); + getData().putContactInfo(env,ci); } // end putContactInfo @@ -515,7 +501,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // Adjust the "mask"...this function cannot affect the set of "locked" features. BitSet real_mask = (BitSet)(mask.clone()); - real_mask.andNot(engine.getLockedFeaturesMask()); + real_mask.andNot(env.getEngine().getLockedFeaturesMask()); // Figure out which bits are being carried over from the old feature set. BitSet new_features = getData().getFeatureSet(); @@ -528,7 +514,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // Put the features together to result in the final feature set, which we set down in // the "back end" class. new_features.or(update_bits); - getData().putFeatureSet(user,new_features); + getData().putFeatureSet(env,new_features); } // end setFeatures @@ -562,7 +548,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setName(user,name); + getData().setName(env,name); } // end setName @@ -576,7 +562,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setAlias(user,alias); + getData().setAlias(env,alias); } // end setAlias @@ -597,7 +583,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setCategoryID(user,catid); + getData().setCategoryID(env,catid); } // end setCategoryID @@ -689,7 +675,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend boolean hide_dir = (mode!=HIDE_NONE); boolean hide_search = (mode==HIDE_BOTH); - getData().setHideFlags(user,hide_dir,hide_search); + getData().setHideFlags(env,hide_dir,hide_search); } // end setHideMode @@ -720,7 +706,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setMembersOnly(user,flag); + getData().setMembersOnly(env,flag); } // end setMembersOnly @@ -736,7 +722,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend public void setInitialFeatureIndex(short ndx) throws DataException, AccessError { - if (!(engine.isValidInitialFeatureIndex(ndx))) + if (!(env.getEngine().isValidInitialFeatureIndex(ndx))) { // the mode is not valid logger.error("feature index value " + String.valueOf(ndx) + " is not valid"); throw new IllegalArgumentException("invalid initial feature index"); @@ -786,7 +772,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setJoinKey(user,key); + getData().setJoinKey(env,key); } // end setJoinKey @@ -905,7 +891,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - getData().setSecurityLevels(user,read,write,create,delete,join); + getData().setSecurityLevels(env,read,write,create,delete,join); } // end setSecurityLevels @@ -958,7 +944,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if - if (!(getData().canJoinCommunity(user.realUID(),level))) + if (!(getData().canJoinCommunity(env.getUserID(),level))) { // this user can't join up! logger.error("user not permitted to join community"); throw new AccessError("You are not permitted to join this community."); @@ -984,7 +970,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // else we can join without specifying a key // actually set the data in the database - getData().setMembership(user,user.realUID(),DefaultLevels.memberCommunity(),false,false); + getData().setMembership(env,env.getUserID(),DefaultLevels.memberCommunity(),false,false); // and update our internal data store setMemberValues(DefaultLevels.memberCommunity(),true,false); @@ -1013,7 +999,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // actually set the data in the database - getData().setMembership(user,user.realUID(),-1,false,false); + getData().setMembership(env,env.getUserID(),-1,false,false); // and update our internal data store setMemberValues(-1,false,false); @@ -1038,7 +1024,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend return false; CommunityData d = getDataNE(); if (d!=null) - return d.canJoinCommunity(user.realUID(),level); + return d.canJoinCommunity(env.getUserID(),level); else return false; @@ -1047,21 +1033,21 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend public List getConferences() throws DataException, AccessError { testConferenceAccess(); - return ConferenceUserContextImpl.getCommunityConferences(engine,this,datapool); + return ConferenceUserContextImpl.getCommunityConferences(env); } // end getConferences public ConferenceContext getConferenceContext(int confid) throws DataException, AccessError { testConferenceAccess(); - return ConferenceUserContextImpl.getConference(engine,this,datapool,confid); + return ConferenceUserContextImpl.getConference(env,confid); } // end getConferenceContext public ConferenceContext getConferenceContext(String alias) throws DataException, AccessError { testConferenceAccess(); - return ConferenceUserContextImpl.getConference(engine,this,datapool,alias); + return ConferenceUserContextImpl.getConference(env,alias); } // end getConferenceContext @@ -1084,10 +1070,10 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // call down to the community core data to create the conference - ConferenceCommunityContext cdata = getData().createConference(this,name,alias,description,pvt,hide_list); + ConferenceCommunityContext cdata = getData().createConference(env,name,alias,description,pvt,hide_list); // wrap the returned object in a conference user context object and release the extra reference - return new ConferenceUserContextImpl(engine,this,datapool,cdata); + return new ConferenceUserContextImpl(env,cdata); } // end createConference @@ -1160,9 +1146,9 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // actually set the data in the database - getData().setMembership(user,uid,new_level,false,false); + getData().setMembership(env,uid,new_level,false,false); - if (uid==user.realUID()) // and update our internal data store + if (uid==env.getUserID()) // and update our internal data store setMemberValues(new_level,(new_level>0),false); } // end setMembership @@ -1190,8 +1176,8 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // call the methods required to delete the community - my_comm.delete(user); - engine.detachCommunityDataObject(cid); + my_comm.delete(env); + env.getEngine().detachCommunityDataObject(cid); // flag that we've been deleted cache = null; @@ -1205,14 +1191,14 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend public void sendInvitation(String address, String personal_message) throws AccessError, DataException, EmailException { - if (user.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) throw new AccessError("You must be logged in to send an invitation."); CommunityData my_comm = getData(); my_comm.testMembership(level,is_member); // Prepare the subject line to be sent to the user. - String subject = engine.getStockMessage("subj-invite"); + String subject = env.getEngine().getStockMessage("subj-invite"); HashMap vars = new HashMap(5); vars.put("community.name",my_comm.getName()); subject = StringUtil.replaceAllVariables(subject,vars); @@ -1220,10 +1206,10 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // Prepare the message text to be sent to the user. String msg; if (my_comm.isPublicCommunity()) - msg = engine.getStockMessage("invite-public"); + msg = env.getEngine().getStockMessage("invite-public"); else { // get the private invite message and set the join key variable - msg = engine.getStockMessage("invite-private"); + msg = env.getEngine().getStockMessage("invite-private"); vars.put("joinkey",my_comm.getJoinKey()); } // end else @@ -1231,16 +1217,16 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend // Set the remaining variables and replace them. vars.put("community.alias",my_comm.getAlias()); vars.put("personal",personal_message); - vars.put("fullname",user.realFullName()); - String uname = user.realUserName(); + vars.put("fullname",env.getUser().realFullName()); + String uname = env.getUser().realUserName(); vars.put("username",uname); msg = StringUtil.replaceAllVariables(msg,vars); StringBuffer msg_buf = new StringBuffer(msg); - msg_buf.append("\n\n--\n").append(engine.getStockMessage("signature")); + msg_buf.append("\n\n--\n").append(env.getEngine().getStockMessage("signature")); - // Get a SimpleEmailer object, set it up, and send it. - SimpleEmailer em = engine.createEmailer(); - em.setFrom(uname,user.realEmailAddress()); + // Get a Emailer object, set it up, and send it. + Emailer em = env.getEngine().createEmailer(); + em.setFrom(uname,env.getUser().realEmailAddress()); em.setTo(address); em.setSubject(subject); em.setText(msg_buf.toString()); @@ -1250,7 +1236,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend public boolean canSendInvitation() { - if (user.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return false; CommunityData d = getDataNE(); if (d==null) @@ -1275,7 +1261,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // retrieve a connection from the data pool and get the audit records - conn = datapool.getConnection(); + conn = env.getConnection(); rc = AuditRecord.getAuditRecords(conn,cid,offset,count); } // end try @@ -1288,7 +1274,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend finally { // make sure the connection is released before we go if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1312,7 +1298,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // retrieve a connection from the data pool and get the audit records - conn = datapool.getConnection(); + conn = env.getConnection(); rc = AuditRecord.getAuditRecordCount(conn,cid); } // end try @@ -1325,7 +1311,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend finally { // make sure the connection is released before we go if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1363,65 +1349,6 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end setProperties - /*-------------------------------------------------------------------------------- - * Implementations from interface UserBackend - *-------------------------------------------------------------------------------- - */ - - public int realUID() - { - return user.realUID(); - - } // end realUID - - public int realBaseLevel() - { - return user.realBaseLevel(); - - } // end realBaseLevel - - public String userRemoteAddress() - { - return user.userRemoteAddress(); - - } // end userRemoteAddress - - public String userDefaultPseud() throws DataException - { - return user.userDefaultPseud(); - - } // end userDefaultPseud - - public boolean userIsAnonymous() - { - return user.userIsAnonymous(); - - } // end userIsAnonymous - - public String realUserName() - { - return user.realUserName(); - - } // end realUserName - - public String realEmailAddress() throws DataException - { - return user.realEmailAddress(); - - } // end realEmailAddress - - public String realFullName() throws DataException - { - return user.realFullName(); - - } // end realFullName - - public void saveMRU(String tag, Object data) - { - user.saveMRU(tag,data); - - } // end saveMRU - /*-------------------------------------------------------------------------------- * Implementations from interface CommunityBackend *-------------------------------------------------------------------------------- @@ -1498,30 +1425,29 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend *-------------------------------------------------------------------------------- */ - static List getMemberCommunityEntries(EngineBackend engine, UserBackend user, DataPool datapool) - throws DataException + static List getMemberCommunityEntries(EnvUser env) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getMemberCommunityEntries for user #" + String.valueOf(user.realUID())); + logger.debug("getMemberCommunityEntries for user #" + String.valueOf(env.getUserID())); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sm.sigid, sm.granted_lvl, sm.locked, s.signame, s.alias " + "FROM sigmember sm, sigs s WHERE sm.sigid = s.sigid " + "AND sm.uid = "); - sql.append(user.realUID()).append(" ORDER BY s.signame;"); + sql.append(env.getUserID()).append(" ORDER BY s.signame;"); ResultSet rs = stmt.executeQuery(sql.toString()); while (rs.next()) { // create the user contexts and add them to the return vector int the_cid = rs.getInt(1); if (logger.isDebugEnabled()) logger.debug("...found community #" + the_cid); - CommunityContext tmp = new CommunityUserContextImpl(engine,user,datapool,the_cid,rs.getInt(2), - rs.getBoolean(3),rs.getString(4),rs.getString(5)); + CommunityContext tmp = new CommunityUserContextImpl(env,the_cid,rs.getInt(2),rs.getBoolean(3), + rs.getString(4),rs.getString(5)); rc.add(tmp); } // end while @@ -1535,8 +1461,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1544,17 +1469,16 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getMemberCommunityEntries - static CommunityContext getCommunityContext(EngineBackend engine, UserBackend user, DataPool datapool, - int cid) throws DataException + static CommunityContext getCommunityContext(EnvUser env, int cid) throws DataException { Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // return the community we want - return getCommunityPrivate(engine,user,datapool,conn,cid); + return getCommunityPrivate(env,conn,cid); } // end try catch (SQLException e) @@ -1565,21 +1489,19 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getCommunityContext - static CommunityContext getCommunityContext(EngineBackend engine, UserBackend user, DataPool datapool, - String alias) throws DataException + static CommunityContext getCommunityContext(EnvUser env, String alias) throws DataException { Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the query to find the community in the table Statement stmt = conn.createStatement(); @@ -1594,8 +1516,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end if // initialize the object and check membership info - CommunityUserContextImpl c = new CommunityUserContextImpl(engine,user,datapool,rs.getInt(1), - rs.getString(2),alias); + CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2),alias); c.checkMembership(conn); return c; @@ -1608,22 +1529,20 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getCommunityContext - static CommunityBackend getCommunityBackend(EngineBackend engine, UserBackend user, DataPool datapool, - Connection conn, int cid) throws DataException + static CommunityBackend getCommunityBackend(EnvUser env, Connection conn, int cid) throws DataException { - return getCommunityPrivate(engine,user,datapool,conn,cid); + return getCommunityPrivate(env,conn,cid); } // end getCommunityBackend - static List searchForCommunities(EngineBackend engine, UserBackend user, DataPool datapool, int field, - int mode, String term, int offset, int count) throws DataException + static List searchForCommunities(EnvUser env, int field, int mode, String term, int offset, int count) + throws DataException { if (logger.isDebugEnabled()) logger.debug("Community search: field = " + field + ", mode = " + mode + ", term '" + term @@ -1634,7 +1553,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE "); @@ -1672,7 +1591,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end switch - if (Capability.hideHiddenSearchCommunities(user.realBaseLevel())) + if (Capability.hideHiddenSearchCommunities(env.getUser().realBaseLevel())) sql.append(" AND hide_search = 0"); sql.append(" ORDER BY signame LIMIT ").append(offset).append(", ").append(count+1).append(';'); @@ -1684,8 +1603,8 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend while (rs.next()) { // load all matching communities into the recordset - CommunityUserContextImpl c = new CommunityUserContextImpl(engine,user,datapool,rs.getInt(1), - rs.getString(2),rs.getString(3)); + CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2), + rs.getString(3)); c.checkMembership(conn); CommunityContext tmp = c; rc.add(tmp); @@ -1701,8 +1620,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1710,7 +1628,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end searchForCommunities - static int getSearchCommunityCount(UserBackend user, DataPool datapool, int field, int mode, String term) + static int getSearchCommunityCount(EnvUser env, int field, int mode, String term) throws DataException { if (logger.isDebugEnabled()) @@ -1720,7 +1638,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE "); @@ -1758,7 +1676,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end switch - if (Capability.hideHiddenSearchCommunities(user.realBaseLevel())) + if (Capability.hideHiddenSearchCommunities(env.getUser().realBaseLevel())) sql.append(" AND hide_search = 0"); sql.append(';'); @@ -1782,15 +1700,13 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getSearchCommunityCount - static List getCommunitiesInCategory(EngineBackend engine, UserBackend user, DataPool datapool, int catid, - int offset, int count) throws DataException + static List getCommunitiesInCategory(EnvUser env, int catid, int offset, int count) throws DataException { if (logger.isDebugEnabled()) logger.debug("reading communities in category " + catid + ", offset = " + offset + ", count = " + count); @@ -1800,11 +1716,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT sigid, signame, alias FROM sigs WHERE catid = "); sql.append(catid); - if (Capability.hideHiddenDirectoryCommunities(user.realBaseLevel())) + if (Capability.hideHiddenDirectoryCommunities(env.getUser().realBaseLevel())) sql.append(" AND hide_dir = 0"); sql.append(" ORDER BY signame LIMIT ").append(offset).append(", ").append(count+1).append(';'); @@ -1816,8 +1732,8 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend while (rs.next()) { // load all matching communities into the recordset - CommunityUserContextImpl c = new CommunityUserContextImpl(engine,user,datapool,rs.getInt(1), - rs.getString(2),rs.getString(3)); + CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2), + rs.getString(3)); c.checkMembership(conn); CommunityContext tmp = c; rc.add(tmp); @@ -1833,8 +1749,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1842,7 +1757,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end getCommunitiesInCategory - static int getNumCommunitiesInCategory(UserBackend user, DataPool datapool, int catid) throws DataException + static int getNumCommunitiesInCategory(EnvUser env, int catid) throws DataException { if (logger.isDebugEnabled()) logger.debug("reading communities in category " + catid); @@ -1851,11 +1766,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM sigs WHERE catid = "); sql.append(catid); - if (Capability.hideHiddenDirectoryCommunities(user.realBaseLevel())) + if (Capability.hideHiddenDirectoryCommunities(env.getUser().realBaseLevel())) sql.append(" AND hide_dir = 0"); sql.append(';'); @@ -1879,8 +1794,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1895,7 +1809,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend { Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT granted_lvl, locked FROM sigmember WHERE sigid = "); - sql.append(cid).append(" AND uid = ").append(user.realUID()).append(';'); + sql.append(cid).append(" AND uid = ").append(env.getUserID()).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) { // we are a member... diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java index 20631c1..7dc7a86 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceCommunityContextImpl.java @@ -20,10 +20,11 @@ package com.silverwrist.venice.core.impl; import java.sql.*; import java.util.*; import org.apache.log4j.*; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.htmlcheck.*; import com.silverwrist.venice.security.AuditRecord; -import com.silverwrist.venice.core.*; class ConferenceCommunityContextImpl implements ConferenceCommunityContext { @@ -78,9 +79,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // engine object reference - private CommunityDataBackend comm; // community object reference - private DataPool datapool; // data pool object + private EnvConferenceCommunity env; // the environment private int confid; // ID of this conference private int level; // level granted in conference to members of the community private short sequence; // sequence number this conference appears in list @@ -94,23 +93,20 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext *-------------------------------------------------------------------------------- */ - ConferenceCommunityContextImpl(EngineBackend engine, CommunityDataBackend comm, DataPool datapool, - int confid) throws DataException + ConferenceCommunityContextImpl(EnvCommunityData env, int confid) throws DataException { if (logger.isDebugEnabled()) - logger.debug("new ConferenceCommunityContextImpl(#" + String.valueOf(confid) + ") for community # " - + comm.realCommunityID()); + logger.debug("new ConferenceCommunityContextImpl(#" + confid + ") for community # " + + env.getCommunityID()); - this.engine = engine; - this.comm = comm; - this.datapool = datapool; + this.env = new EnvConferenceCommunity(env); this.confid = confid; Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build a monster query! This is like the query for retrieving the ConferenceUserContextImpl @@ -118,7 +114,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext StringBuffer sql = new StringBuffer("SELECT c.createdate, c.name, c.descr, s.granted_lvl, s.sequence, s.hide_list " + "FROM sigtoconf s, confs c WHERE s.confid = c.confid AND s.sigid = "); - sql.append(comm.realCommunityID()).append(" AND c.confid = ").append(confid).append(';'); + sql.append(env.getCommunityID()).append(" AND c.confid = ").append(confid).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -126,7 +122,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext ResultSet rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new DataException("conference ID#" + confid + " not found in community#" - + comm.realCommunityID()); + + env.getCommunityID()); // fill in the "cache" and "level" indicators this.cache = new ConfCache(rs.getString(2),rs.getString(3),SQLUtil.getFullDateTime(rs,1)); @@ -143,23 +139,19 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end constructor - ConferenceCommunityContextImpl(EngineBackend engine, CommunityDataBackend comm, DataPool datapool, - short sequence, boolean hide_list, ConferenceData cdata) + ConferenceCommunityContextImpl(EnvCommunityData env, short sequence, boolean hide_list, ConferenceData cdata) { if (logger.isDebugEnabled()) logger.debug("new ConferenceCommunityContextImpl(NEW#" + confid + ") for community # " - + comm.realCommunityID()); + + env.getCommunityID()); - this.engine = engine; - this.comm = comm; - this.datapool = datapool; + this.env = new EnvConferenceCommunity(env); this.confid = cdata.getID(); this.level = 0; this.sequence = sequence; @@ -180,7 +172,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext { // attempt to load the ConferenceCommunityContext if (deleted) throw new DataException("This conference has been deleted."); - confdata = engine.getConferenceDataObject(confid); + confdata = env.getEngine().getConferenceDataObject(confid); // clear cache when we get the real confdata cache = null; @@ -200,7 +192,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // attempt to load the ConferenceCommunityContext - confdata = engine.getConferenceDataObject(confid); + confdata = env.getEngine().getConferenceDataObject(confid); } // end try catch (DataException e) @@ -384,16 +376,16 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end getDeleteLevel - public synchronized void setSecurityLevels(CommunityBackend comm, int read, int post, int create, int hide, + public synchronized void setSecurityLevels(EnvCommunity outer, int read, int post, int create, int hide, int nuke, int change, int delete) throws DataException { - getConferenceData().setSecurityLevels(comm,read,post,create,hide,nuke,change,delete); + getConferenceData().setSecurityLevels(outer,read,post,create,hide,nuke,change,delete); } // end setSecurityLevels - public synchronized void setName(CommunityBackend comm, String val) throws DataException + public synchronized void setName(EnvCommunity outer, String val) throws DataException { - getConferenceData().setName(comm,val); + getConferenceData().setName(outer,val); } // end setName @@ -403,25 +395,25 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end setDescription - public synchronized void addAlias(CommunityBackend comm, String alias) throws DataException + public synchronized void addAlias(EnvCommunity outer, String alias) throws DataException { - getConferenceData().addAlias(comm,alias); + getConferenceData().addAlias(outer,alias); } // end addAlias - public synchronized void removeAlias(CommunityBackend comm, String alias) throws DataException + public synchronized void removeAlias(EnvCommunity outer, String alias) throws DataException { - getConferenceData().removeAlias(comm,alias); + getConferenceData().removeAlias(outer,alias); } // end removeAlias - public synchronized void setMembership(CommunityBackend comm, int uid, int grant_level) throws DataException + public synchronized void setMembership(EnvCommunity outer, int uid, int grant_level) throws DataException { - getConferenceData().setMembership(comm,uid,grant_level); + getConferenceData().setMembership(outer,uid,grant_level); } // end setMembership - public synchronized void setCommunityGrantedLevel(CommunityBackend comm, int new_level) throws DataException + public synchronized void setCommunityGrantedLevel(EnvCommunity outer, int new_level) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -431,12 +423,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET granted_lvl = "); - sql.append(new_level).append(" WHERE sigid = ").append(this.comm.realCommunityID()); + sql.append(new_level).append(" WHERE sigid = ").append(this.env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); // execute the update @@ -446,8 +438,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext level = new_level; // create an audit record reflecting the change - ar = new AuditRecord(AuditRecord.CONF_SECURITY,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid); + ar = outer.newAudit(AuditRecord.CONF_SECURITY,"conf=" + confid); } // end try catch (SQLException e) @@ -470,8 +461,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -492,12 +482,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET sequence = "); - sql.append(seq).append(" WHERE sigid = ").append(this.comm.realCommunityID()).append(" AND confid = "); + sql.append(seq).append(" WHERE sigid = ").append(env.getCommunityID()).append(" AND confid = "); sql.append(confid).append(';'); // execute the update @@ -515,8 +505,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -528,7 +517,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end getHideList - public void setHideList(CommunityBackend comm, boolean flag) throws DataException + public void setHideList(EnvCommunity outer, boolean flag) throws DataException { if (logger.isDebugEnabled()) logger.debug("setHideList(conf #" + confid + ", " + flag + ")"); @@ -552,12 +541,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET hide_list = "); - sql.append(flag ? '1' : '0').append(" WHERE sigid = ").append(this.comm.realCommunityID()); + sql.append(flag ? '1' : '0').append(" WHERE sigid = ").append(env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -569,8 +558,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext hide_list = flag; // create an audit record reflecting the change - ar = new AuditRecord(AuditRecord.CONF_SECURITY,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid); + ar = outer.newAudit(AuditRecord.CONF_SECURITY,"conf=" + confid); } // end try catch (SQLException e) @@ -593,8 +581,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -618,7 +605,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end getAnAlias - public ReturnTopicInfo createNewTopic(CommunityBackend comm, String title, String pseud, String body) + public ReturnTopicInfo createNewTopic(EnvCommunity outer, String title, String pseud, String body) throws DataException { ConferenceData d = getConferenceData(); @@ -627,9 +614,10 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // preprocess the body argument through the HTML checker - HTMLChecker text_ch = engine.createCheckerObject(engine.HTMLC_POST_BODY); + HTMLChecker text_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_BODY); text_ch.setContextValue("PostLinkDecoderContext", - new PostLinkDecoderContext(comm.realCommunityAlias(),conf_alias,new_topic)); + new PostLinkDecoderContext(outer.getCommunity().realCommunityAlias(),conf_alias, + new_topic)); try { // run through the HTML checker @@ -645,7 +633,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // call down to create the new topic! - return d.createNewTopic(comm,title,pseud,text_ch.getValue(),text_ch.getLines()); + return d.createNewTopic(outer,title,pseud,text_ch.getValue(),text_ch.getLines()); } // end try catch (NotYetFinishedException e) @@ -727,7 +715,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end canDeleteConference - public void delete(UserBackend user) throws DataException + public void delete(EnvCommunity outer) throws DataException { ConferenceData c = getConferenceData(); Connection conn = null; @@ -735,12 +723,12 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // see if we have to delete the core object as well StringBuffer sql = new StringBuffer("SELECT sigid FROM sigtoconf WHERE confid = "); - sql.append(confid).append(" AND sigid <> ").append(comm.realCommunityID()).append(" LIMIT 1;"); + sql.append(confid).append(" AND sigid <> ").append(env.getCommunityID()).append(" LIMIT 1;"); ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) delete_core = false; // we don't delete the core yet @@ -748,7 +736,7 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext // remove the row that links this conference to this community sql.setLength(0); sql.append("DELETE FROM sigtoconf WHERE confid = ").append(confid).append(" AND sigid = "); - sql.append(comm.realCommunityID()).append(';'); + sql.append(env.getCommunityID()).append(';'); stmt.executeUpdate(sql.toString()); // record that we've been deleted @@ -767,15 +755,14 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally if (delete_core) { // the conference is not linked to any other communities - we need to delete the core as well - c.delete(user,comm.realCommunityID()); - engine.detachConferenceDataObject(confid); + c.delete(outer); + env.getEngine().detachConferenceDataObject(confid); } // end if diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java b/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java index 034c60e..c33c733 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceCoreData.java @@ -21,10 +21,11 @@ import java.sql.*; import java.util.*; import org.apache.log4j.*; import com.silverwrist.util.OptionSet; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.security.AuditRecord; import com.silverwrist.venice.security.DefaultLevels; -import com.silverwrist.venice.core.*; class ConferenceCoreData implements ConferenceData { @@ -48,8 +49,7 @@ class ConferenceCoreData implements ConferenceData *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // pointer to engine back end - private DataPool datapool; // pointer to data pool + private EnvConferenceData env; // the environment private int confid; // ID of this conference private java.util.Date create_date; // creation date of this conference private java.util.Date last_update; // last update date of conference @@ -73,19 +73,18 @@ class ConferenceCoreData implements ConferenceData *-------------------------------------------------------------------------------- */ - ConferenceCoreData(EngineBackend engine, DataPool datapool, int confid) throws DataException + ConferenceCoreData(EnvEngine env, int confid) throws DataException { if (logger.isDebugEnabled()) logger.debug("new ConferenceCoreData for conference " + confid); - this.engine = engine; - this.datapool = datapool; + this.env = new EnvConferenceData(env); this.confid = confid; Connection conn = null; try { // get a database connection from this object - conn = datapool.getConnection(); + conn = env.getConnection(); // get the conference basic data from the database Statement stmt = conn.createStatement(); @@ -108,20 +107,18 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end constructor - protected ConferenceCoreData(EngineBackend engine, CommunityDataBackend comm, DataPool datapool, int confid, - java.util.Date created, boolean pvt, String name, String descr) + protected ConferenceCoreData(EnvCommunityData env, int confid, java.util.Date created, boolean pvt, + String name, String descr) { if (logger.isDebugEnabled()) logger.debug("new ConferenceCoreData for NEW conference " + confid); - this.engine = engine; - this.datapool = datapool; + this.env = new EnvConferenceData(env); this.confid = confid; this.create_date = created; this.last_update = null; @@ -136,7 +133,7 @@ class ConferenceCoreData implements ConferenceData this.name = name; this.description = descr; this.flags = new OptionSet(); - if (comm.getParamBoolean(CommunityDataBackend.BP_POSTPICTURES)) + if (env.getCommunityData().getParamBoolean(CommunityDataBackend.BP_POSTPICTURES)) flags.set(BP_POSTPICTURES); } // end constructor @@ -219,7 +216,7 @@ class ConferenceCoreData implements ConferenceData Connection conn = null; try { // get a connection and create a statement - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); @@ -241,8 +238,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -318,7 +314,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection from this object - conn = datapool.getConnection(); + conn = env.getConnection(); // get a list of all aliases Statement stmt = conn.createStatement(); @@ -339,8 +335,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -358,7 +353,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection from this object - conn = datapool.getConnection(); + conn = env.getConnection(); // get a list of all hosts (with user info) Statement stmt = conn.createStatement(); @@ -388,8 +383,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -471,7 +465,7 @@ class ConferenceCoreData implements ConferenceData } // end getDeleteLevel - public synchronized void setSecurityLevels(CommunityBackend comm, int read, int post, int create, int hide, + public synchronized void setSecurityLevels(EnvCommunity outer, int read, int post, int create, int hide, int nuke, int change, int delete) throws DataException { if (deleted) @@ -482,7 +476,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); @@ -507,8 +501,7 @@ class ConferenceCoreData implements ConferenceData last_update = now; // create an audit record reflecting the change - ar = new AuditRecord(AuditRecord.CONF_SECURITY,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid); + ar = outer.newAudit(AuditRecord.CONF_SECURITY,"conf=" + confid); } // end try catch (SQLException e) @@ -531,14 +524,13 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end setSecurityLevels - public synchronized void setName(CommunityBackend comm, String val) throws DataException + public synchronized void setName(EnvCommunity outer, String val) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -548,7 +540,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); @@ -565,8 +557,7 @@ class ConferenceCoreData implements ConferenceData last_update = now; // create an audit record reflecting the change - ar = new AuditRecord(AuditRecord.CONF_SECURITY,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid); + ar = outer.newAudit(AuditRecord.CONF_SECURITY,"conf=" + confid); } // end try catch (SQLException e) @@ -589,8 +580,7 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -605,7 +595,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create the SQL statement Statement stmt = conn.createStatement(); @@ -629,14 +619,13 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end setDescription - public synchronized void addAlias(CommunityBackend comm, String alias) throws DataException + public synchronized void addAlias(EnvCommunity outer, String alias) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -646,7 +635,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confalias WRITE;"); @@ -680,8 +669,7 @@ class ConferenceCoreData implements ConferenceData // set the database's update date and generate a new audit record touchUpdate(conn); - ar = new AuditRecord(AuditRecord.CONF_ALIAS,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid,"add=" + alias); + ar = outer.newAudit(AuditRecord.CONF_ALIAS,"conf=" + confid,"add=" + alias); } // end try catch (SQLException e) @@ -704,14 +692,13 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end addAlias - public synchronized void removeAlias(CommunityBackend comm, String alias) throws DataException + public synchronized void removeAlias(EnvCommunity outer, String alias) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -721,7 +708,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); boolean did_it = false; Statement stmt = conn.createStatement(); @@ -768,8 +755,7 @@ class ConferenceCoreData implements ConferenceData touchUpdate(conn); if ((cached_alias!=null) && cached_alias.equals(alias)) cached_alias = null; // also release the cached alias and force a re-get - ar = new AuditRecord(AuditRecord.CONF_ALIAS,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid,"remove=" + alias); + ar = outer.newAudit(AuditRecord.CONF_ALIAS,"conf=" + confid,"remove=" + alias); } // end if @@ -794,14 +780,13 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end removeAlias - public synchronized void setMembership(CommunityBackend comm, int uid, int grant_level) throws DataException + public synchronized void setMembership(EnvCommunity outer, int uid, int grant_level) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -811,7 +796,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); boolean did_it = false; Statement stmt = conn.createStatement(); @@ -862,8 +847,7 @@ class ConferenceCoreData implements ConferenceData if (did_it) { // set the database's update date and generate a new audit record touchUpdate(conn); - ar = new AuditRecord(AuditRecord.CONF_MEMBERSHIP,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"conf=" + confid,"uid=" + uid,"level=" + grant_level); + ar = outer.newAudit(AuditRecord.CONF_MEMBERSHIP,"conf=" + confid,"uid=" + uid,"level=" + grant_level); } // end if @@ -888,8 +872,7 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -915,7 +898,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement and execute it @@ -936,14 +919,13 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getAnAlias - public synchronized ReturnTopicInfo createNewTopic(CommunityBackend comm, String title, String pseud, + public synchronized ReturnTopicInfo createNewTopic(EnvCommunity outer, String title, String pseud, String body, int body_lines) throws DataException { if (deleted) @@ -957,7 +939,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock the tables we need to use so we can update them @@ -970,7 +952,7 @@ class ConferenceCoreData implements ConferenceData // add the topic row to the database StringBuffer sql = new StringBuffer("INSERT INTO topics (confid, num, creator_uid, createdate, " + "lastupdate, name) VALUES ("); - sql.append(confid).append(", ").append(new_topic_num).append(", ").append(comm.realUID()); + sql.append(confid).append(", ").append(new_topic_num).append(", ").append(outer.getUserID()); creation = new java.util.Date(); String now_str = SQLUtil.encodeDate(creation); sql.append(", '").append(now_str).append("', '").append(now_str).append("', '").append(title); @@ -988,7 +970,7 @@ class ConferenceCoreData implements ConferenceData // insert the "header" for the "zero post" in the topic sql.setLength(0); sql.append("INSERT INTO posts (topicid, num, linecount, creator_uid, posted, pseud) VALUES ("); - sql.append(new_topic_id).append(", 0, ").append(body_lines).append(", ").append(comm.realUID()); + sql.append(new_topic_id).append(", 0, ").append(body_lines).append(", ").append(outer.getUserID()); sql.append(", '").append(now_str).append("', '").append(pseud).append("');"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1019,9 +1001,8 @@ class ConferenceCoreData implements ConferenceData last_update = creation; // create an audit record indicating we were successful - ar = new AuditRecord(AuditRecord.CREATE_TOPIC,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"confid=" + confid,"num=" + new_topic_num, - "title=" + title); + ar = outer.newAudit(AuditRecord.CREATE_TOPIC,"confid=" + confid,"num=" + new_topic_num, + "title=" + title); } // end try finally @@ -1052,8 +1033,7 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1147,7 +1127,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create a new SQL statement @@ -1182,8 +1162,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1200,7 +1179,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the statement @@ -1221,8 +1200,7 @@ class ConferenceCoreData implements ConferenceData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1244,7 +1222,7 @@ class ConferenceCoreData implements ConferenceData } // end canDeleteConference - public synchronized void delete(UserBackend user, int the_cid) throws DataException + public synchronized void delete(EnvCommunity outer) throws DataException { if (deleted) throw new DataException("This conference has been deleted."); @@ -1255,7 +1233,7 @@ class ConferenceCoreData implements ConferenceData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock tables on the critical stuff that MUST be deleted now @@ -1298,8 +1276,7 @@ class ConferenceCoreData implements ConferenceData } // end finally // create an audit record indicating we were successful - ar = new AuditRecord(AuditRecord.DELETE_CONF,user.realUID(),user.userRemoteAddress(),the_cid, - "confid=" + confid); + ar = outer.newAudit(AuditRecord.DELETE_CONF,"confid=" + confid); } // end try catch (SQLException e) @@ -1322,14 +1299,12 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally // Delete the rest of the gunk in the background; spin off another thread to handle it. - BackgroundConferencePurge purger = new BackgroundConferencePurge(engine,datapool,confid,topic_count, - topic_max); + BackgroundConferencePurge purger = new BackgroundConferencePurge(env,confid,topic_count,topic_max); Thread thrd = new Thread(purger); thrd.setPriority(Thread.NORM_PRIORITY-1); thrd.start(); @@ -1376,11 +1351,10 @@ class ConferenceCoreData implements ConferenceData *-------------------------------------------------------------------------------- */ - static ReturnConfSeq createConference(EngineBackend engine, CommunityBackend comm, DataPool datapool, - String name, String alias, String description, boolean pvt, - boolean hide_list, int host_uid) throws DataException + static ReturnConfSeq createConference(EnvCommunity outer, EnvCommunityData env, String name, String alias, + String description, boolean pvt, boolean hide_list, int host_uid) + throws DataException { - CommunityDataBackend data_backend = comm.getDataBackend(); Connection conn = null; // database connection AuditRecord ar = null; // audit record int new_confid; // new conference ID @@ -1393,7 +1367,7 @@ class ConferenceCoreData implements ConferenceData try { // start by locking all the tables we need - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confs WRITE, sigtoconf WRITE, confalias WRITE, confmember WRITE, " + "propconf WRITE;"); @@ -1411,7 +1385,7 @@ class ConferenceCoreData implements ConferenceData // compute our new sequence number sql.setLength(0); - sql.append("SELECT MAX(sequence) FROM sigtoconf WHERE sigid = ").append(comm.realCommunityID()); + sql.append("SELECT MAX(sequence) FROM sigtoconf WHERE sigid = ").append(env.getCommunityID()); sql.append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1453,7 +1427,7 @@ class ConferenceCoreData implements ConferenceData // Link the community to the conference by adding a row to sigtoconf. sql.setLength(0); sql.append("INSERT INTO sigtoconf (sigid, confid, sequence, hide_list) VALUES ("); - sql.append(comm.realCommunityID()).append(", ").append(new_confid).append(", ").append(new_sequence); + sql.append(env.getCommunityID()).append(", ").append(new_confid).append(", ").append(new_sequence); sql.append(", ").append(hide_list ? '1' : '0').append(");"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1469,7 +1443,7 @@ class ConferenceCoreData implements ConferenceData // Create a new ConferenceCoreData object representing this conference and register it with the // engine's conference data object cache. - conf = new ConferenceCoreData(engine,data_backend,datapool,new_confid,created,pvt,name,description); + conf = new ConferenceCoreData(env,new_confid,created,pvt,name,description); conf.newProperties(conn); } // end try @@ -1480,11 +1454,10 @@ class ConferenceCoreData implements ConferenceData } // end finally - engine.registerNewConference(conf); + env.getEngine().registerNewConference(conf); // create an audit record indicating we were successful - ar = new AuditRecord(AuditRecord.CREATE_CONF,comm.realUID(),comm.userRemoteAddress(), - comm.realCommunityID(),"confid=" + new_confid,"name=" + name,"alias=" + alias); + ar = outer.newAudit(AuditRecord.CREATE_CONF,"confid=" + new_confid,"name=" + name,"alias=" + alias); } // end try catch (SQLException e) @@ -1507,8 +1480,7 @@ class ConferenceCoreData implements ConferenceData } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java index efff60e..cae68ee 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/ConferenceUserContextImpl.java @@ -20,10 +20,11 @@ package com.silverwrist.venice.core.impl; import java.sql.*; import java.util.*; import org.apache.log4j.*; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.htmlcheck.*; import com.silverwrist.venice.security.DefaultLevels; -import com.silverwrist.venice.core.*; class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend { @@ -161,9 +162,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // pointer to the engine back end - private CommunityBackend comm; // pointer to the community back end - private DataPool datapool; // pointer to the data pool + private EnvConference env; // the environment private int confid; // the conference ID private int level; // access level I have within this conference private ConfCache cache; // cached internal data for the conference @@ -179,13 +178,11 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend *-------------------------------------------------------------------------------- */ - protected ConferenceUserContextImpl(EngineBackend engine, CommunityBackend comm, DataPool datapool, - int confid, String name, String description, java.util.Date created, - int comm_level, int user_level, Connection conn) throws DataException + protected ConferenceUserContextImpl(EnvCommunity env, int confid, String name, String description, + java.util.Date created, int comm_level, int user_level, + Connection conn) throws DataException { - this.engine = engine; - this.comm = comm; - this.datapool = datapool; + this.env = new EnvConference(env,this); this.confid = confid; this.cache = new ConfCache(name,description,created,comm_level); recalcLevel(user_level); @@ -193,17 +190,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end constructor - ConferenceUserContextImpl(EngineBackend engine, CommunityBackend comm, DataPool datapool, - ConferenceCommunityContext cdata) throws DataException + ConferenceUserContextImpl(EnvCommunity env, ConferenceCommunityContext cdata) throws DataException { - this.engine = engine; - this.comm = comm; - this.datapool = datapool; + this.env = new EnvConference(env,this); this.confid = cdata.getConfID(); this.cache = null; this.confdata = cdata; recalcLevel(DefaultLevels.hostConference()); - this.pseud = comm.userDefaultPseud(); + this.pseud = env.getUser().userDefaultPseud(); this.last_read = null; this.last_post = null; @@ -220,9 +214,9 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend { // attempt to load the ConferenceCommunityContext if (deleted) throw new DataException("This conference has been deleted."); - confdata = comm.getConferenceDataObject(confid); + confdata = env.getCommunity().getConferenceDataObject(confid); if (confdata!=null) - comm.saveMRU("conf",confdata); + env.getUser().saveMRU("conf",confdata); // clear cache when we get the real confdata cache = null; @@ -242,9 +236,9 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend try { // attempt to load the ConferenceCommunityContext - confdata = comm.getConferenceDataObject(confid); + confdata = env.getCommunity().getConferenceDataObject(confid); if (confdata!=null) - comm.saveMRU("conf",confdata); + env.getUser().saveMRU("conf",confdata); } // end try catch (DataException e) @@ -265,7 +259,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend private void recalcLevel(int new_level) { - level = comm.realCommunityLevel(); + level = env.getCommunity().realCommunityLevel(); int comm_level = -1; if (cache!=null) @@ -294,7 +288,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend { // look up the conference settings for this user Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT * FROM confsettings WHERE confid = "); - sql.append(confid).append(" AND uid = ").append(comm.realUID()).append(';'); + sql.append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) @@ -308,7 +302,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend else { // just default everything settings_loaded = false; - pseud = comm.userDefaultPseud(); + pseud = env.getUser().userDefaultPseud(); last_read = null; last_post = null; @@ -573,7 +567,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // Now call through to set the security levels. - getConferenceData().setSecurityLevels(comm,read,post,create,hide,nuke,change,delete); + getConferenceData().setSecurityLevels(env,read,post,create,hide,nuke,change,delete); } // end setSecurityLevels @@ -587,7 +581,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // Call through to set the name. - getConferenceData().setName(comm,val); + getConferenceData().setName(env,val); } // end setName @@ -615,7 +609,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // Call through to add the alias. - getConferenceData().addAlias(comm,alias); + getConferenceData().addAlias(env,alias); } // end addAlias @@ -629,7 +623,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // Call through to remove the alias. - getConferenceData().removeAlias(comm,alias); + getConferenceData().removeAlias(env,alias); } // end removeAlias @@ -643,10 +637,10 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // call down to set the level - getConferenceData().setMembership(comm,uid,grant_level); + getConferenceData().setMembership(env,uid,grant_level); // If we adjusted our OWN level, reflect that change. - if (uid==comm.realUID()) + if (uid==env.getUserID()) recalcLevel(grant_level); } // end setMembership @@ -666,7 +660,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public int getCommunityGrantedLevel() throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("getCommunityGrantedLevel(): user not permitted to retrieve security info"); throw new AccessError("You are not permitted to retrieve security information for this conference."); @@ -680,21 +674,21 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void setCommunityGrantedLevel(int new_level) throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("setCommunityGrantedLevel(): user not permitted to change security info"); throw new AccessError("You are not permitted to change security information for this conference."); } // end if - c.setCommunityGrantedLevel(comm,new_level); + c.setCommunityGrantedLevel(env,new_level); } // end setCommunityGrantedLevel public short getSequence() throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("getSequence(): user not permitted to retrieve layout info"); throw new AccessError("You are not permitted to retrieve layout information for this conference."); @@ -708,7 +702,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void setSequence(short seq) throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("setSequence(): user not permitted to set layout info"); throw new AccessError("You are not permitted to set layout information for this conference."); @@ -722,7 +716,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public boolean getHideList() throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("getHideList(): user not permitted to retrieve security info"); throw new AccessError("You are not permitted to retrieve security information for this conference."); @@ -736,20 +730,20 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void setHideList(boolean flag) throws DataException, AccessError { ConferenceCommunityContext c = getConferenceData(); - if (!(comm.userCanCreateSubobjects())) + if (!(env.getCommunity().userCanCreateSubobjects())) { // this user can't modify the conference security logger.error("setHideList(): user not permitted to change security info"); throw new AccessError("You are not permitted to change security information for this conference."); } // end if - c.setHideList(comm,flag); + c.setHideList(env,flag); } // end setHideList public boolean canSetHideList() { - return comm.userCanCreateSubobjects(); + return env.getCommunity().userCanCreateSubobjects(); } // end canSetHideList @@ -761,7 +755,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void setDefaultPseud(String val) throws DataException { - if (comm.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return; // anonymous user can't change pseud if (deleted) throw new DataException("This conference has been deleted."); @@ -770,21 +764,21 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); if (settings_loaded) { // generate an update statement sql.append("UPDATE confsettings SET default_pseud = '").append(SQLUtil.encodeString(val)); - sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(comm.realUID()); + sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()); sql.append(';'); } // end if else { // need to insert a confsettings row sql.append("INSERT INTO confsettings (confid, uid, default_pseud) VALUES (").append(confid); - sql.append(", ").append(comm.realUID()).append(", '").append(SQLUtil.encodeString(val)).append("');"); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(val)).append("');"); } // end else @@ -804,8 +798,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -813,13 +806,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public boolean anyUnread() { - if (deleted || comm.userIsAnonymous()) + if (deleted || env.getUser().userIsAnonymous()) return false; Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // Build a query. The idea here is that we want to see the topic IDs of all topics within the // conference which (a) are not archived, (b) are not hidden and (c) have one or more messages unread @@ -830,7 +823,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT t.topicid FROM topics t LEFT JOIN topicsettings s " + "ON t.topicid = s.topicid AND s.uid = "); - sql.append(comm.realUID()).append(" WHERE t.confid = ").append(confid); + sql.append(env.getUserID()).append(" WHERE t.confid = ").append(confid); sql.append(" AND t.archived = 0 AND IFNULL(s.hidden,0) = 0 " + "AND (t.top_message - IFNULL(s.last_message,-1)) > 0 LIMIT 1;"); if (logger.isDebugEnabled()) @@ -848,8 +841,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -867,7 +859,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // palm it all off on the big static function - return TopicUserContextImpl.getTopicList(engine,this,datapool,get_option,sort_option); + return TopicUserContextImpl.getTopicList(env,get_option,sort_option); } // end getTopicList @@ -881,7 +873,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // call down to the TopicUserContextImpl implementation - return TopicUserContextImpl.getTopicByNumber(engine,this,datapool,number); + return TopicUserContextImpl.getTopicByNumber(env,number); } // end getTopic @@ -896,8 +888,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // preprocess the pseud and title arguments through HTML checkers - HTMLChecker title_ch = engine.createCheckerObject(engine.HTMLC_POST_PSEUD); - HTMLChecker zp_pseud_ch = engine.createCheckerObject(engine.HTMLC_POST_PSEUD); + HTMLChecker title_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_PSEUD); + HTMLChecker zp_pseud_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_PSEUD); try { // run arguments through the HTML checker @@ -919,7 +911,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend try { // call down to create the new topic! real_title = title_ch.getValue(); - new_topic_inf = getConferenceData().createNewTopic(comm,real_title,zp_pseud_ch.getValue(),zp_text); + new_topic_inf = getConferenceData().createNewTopic(env,real_title,zp_pseud_ch.getValue(),zp_text); } // end try catch (NotYetFinishedException e) @@ -932,12 +924,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Connection conn = null; try { // get a connection - conn = datapool.getConnection(); + conn = env.getConnection(); // create a new record in topicsettings (we WERE the first to post in the topic after all!) Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("INSERT INTO topicsettings (topicid, uid, last_post) VALUES ("); - sql.append(new_topic_inf.getTopicID()).append(", ").append(comm.realUID()).append(", '"); + sql.append(new_topic_inf.getTopicID()).append(", ").append(env.getUserID()).append(", '"); sql.append(SQLUtil.encodeDate(new_topic_inf.getCreateDate())).append("');"); stmt.executeUpdate(sql.toString()); @@ -953,13 +945,12 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally // create the topic context to return to the user - return new TopicUserContextImpl(engine,this,datapool,new_topic_inf,real_title); + return new TopicUserContextImpl(env,new_topic_inf,real_title); } // end addTopic @@ -973,7 +964,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // call down to the static function level - return TopicMessageUserContextImpl.getMessage(engine,this,datapool,postid); + return TopicMessageUserContextImpl.getMessage(env,postid); } // end getMessageByPostID @@ -985,7 +976,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend new_topic = 0; else new_topic = (short)(c.getTopTopic() + 1); - HTMLChecker rc = engine.createCheckerObject(engine.HTMLC_PREVIEW_BODY); + HTMLChecker rc = env.getEngine().createCheckerObject(EngineBackend.HTMLC_PREVIEW_BODY); rc.setContextValue("PostLinkDecoderContext",createDecoderContext(new_topic)); return rc; @@ -1000,14 +991,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if - if (comm.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return; // anonymous user can't fixseen Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock the tables that we need @@ -1019,7 +1010,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend new StringBuffer("SELECT topics.topicid, topics.top_message, ISNULL(topicsettings.last_message) " + "FROM topics LEFT JOIN topicsettings ON topics.topicid = topicsettings.topicid " + "AND topicsettings.uid = "); - sql.append(comm.realUID()).append(" WHERE topics.confid = ").append(confid).append(';'); + sql.append(env.getUserID()).append(" WHERE topics.confid = ").append(confid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); // use the results to build up a list of FixSeenHelpers @@ -1033,7 +1024,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend while (it.hasNext()) { // just hit each one in turn FixSeenHelper fsh = (FixSeenHelper)(it.next()); - fsh.doFix(stmt,comm.realUID(),now); + fsh.doFix(stmt,env.getUserID(),now); } // end while @@ -1057,8 +1048,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1077,8 +1067,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ArrayList rc = new ArrayList(); try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to retrieve all posters @@ -1110,8 +1100,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1144,8 +1133,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ArrayList rc = new ArrayList(); try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to retrieve all readers @@ -1177,8 +1166,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1227,7 +1215,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void delete() throws DataException, AccessError { ConferenceCommunityContext ctxt = getConferenceData(); - if (!(ctxt.canDeleteConference(level)) || !(comm.userCanDeleteSubobjects())) + if (!(ctxt.canDeleteConference(level)) || !(env.getCommunity().userCanDeleteSubobjects())) { // no way can we delete this conference, not NO way! logger.error("delete(): user not permitted to delete conference"); throw new AccessError("You are not permitted to delete this conference."); @@ -1235,8 +1223,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end if // call the methods required to delete the conference - ctxt.delete(comm); - comm.detachConferenceDataObject(confid); + ctxt.delete(env); + env.getCommunity().detachConferenceDataObject(confid); // flag that we've been deleted cache = null; @@ -1256,7 +1244,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ConferenceCommunityContext c = getConferenceDataNE(); if (c==null) return false; - return (c.canDeleteConference(level) && comm.userCanDeleteSubobjects()); + return (c.canDeleteConference(level) && env.getCommunity().userCanDeleteSubobjects()); } // end canDeleteConference @@ -1265,13 +1253,13 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // do a quickie query StringBuffer sql = new StringBuffer("SELECT sequence FROM confhotlist WHERE uid = "); - sql.append(comm.realUID()).append(" AND sigid = ").append(comm.realCommunityID()); + sql.append(env.getUserID()).append(" AND sigid = ").append(env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); return rs.next(); @@ -1285,8 +1273,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1297,15 +1284,15 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confhotlist WRITE;"); try { // do a quickie query to see if we're already in the hotlist StringBuffer sql = new StringBuffer("SELECT sequence FROM confhotlist WHERE uid = "); - sql.append(comm.realUID()).append(" AND sigid = ").append(comm.realCommunityID()); + sql.append(env.getUserID()).append(" AND sigid = ").append(env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) @@ -1313,7 +1300,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend // find a sequence number for the new entry sql.setLength(0); - sql.append("SELECT MAX(sequence) FROM confhotlist WHERE uid = ").append(comm.realUID()).append(';'); + sql.append("SELECT MAX(sequence) FROM confhotlist WHERE uid = ").append(env.getUserID()).append(';'); rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new InternalStateError("bogus query result on addToHotlist"); @@ -1321,8 +1308,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend // add the new record sql.setLength(0); - sql.append("INSERT INTO confhotlist (uid, sequence, sigid, confid) VALUES (").append(comm.realUID()); - sql.append(", ").append(new_sequence).append(", ").append(comm.realCommunityID()).append(", "); + sql.append("INSERT INTO confhotlist (uid, sequence, sigid, confid) VALUES (").append(env.getUserID()); + sql.append(", ").append(new_sequence).append(", ").append(env.getCommunityID()).append(", "); sql.append(confid).append(");"); stmt.executeUpdate(sql.toString()); @@ -1343,8 +1330,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1352,7 +1338,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public boolean canAddToHotlist() { - if (comm.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return false; return !(isInHotlist()); @@ -1360,7 +1346,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public CommunityContext getEnclosingCommunity() { - return comm.selfCommunity(); + return env.getCommunity().selfCommunity(); } // end getEnclosingCommunity @@ -1369,14 +1355,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the DELETE statement and just execute it blind (if this conference is not in the hotlist, // the DELETE is a no-op). StringBuffer sql = new StringBuffer("DELETE FROM confhotlist WHERE uid = "); - sql.append(comm.realUID()).append(" AND sigid = ").append(comm.realCommunityID()); + sql.append(env.getUserID()).append(" AND sigid = ").append(env.getCommunityID()); sql.append(" AND confid = ").append(confid).append(';'); stmt.executeUpdate(sql.toString()); @@ -1389,8 +1375,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1401,15 +1386,15 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the UPDATE statement and just execute it blind (if this conference is not in the hotlist, // the UPDATE is a no-op). StringBuffer sql = new StringBuffer("UPDATE confhotlist SET sequence = "); - sql.append(seq).append(" WHERE uid = ").append(comm.realUID()).append(" AND sigid = "); - sql.append(comm.realCommunityID()).append(" AND confid = ").append(confid).append(';'); + sql.append(seq).append(" WHERE uid = ").append(env.getUserID()).append(" AND sigid = "); + sql.append(env.getCommunityID()).append(" AND confid = ").append(confid).append(';'); stmt.executeUpdate(sql.toString()); } // end try @@ -1421,8 +1406,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1465,130 +1449,6 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end setProperties - /*-------------------------------------------------------------------------------- - * Implementations from interface UserBackend - *-------------------------------------------------------------------------------- - */ - - public int realUID() - { - return comm.realUID(); - - } // end realUID - - public int realBaseLevel() - { - return comm.realBaseLevel(); - - } // end realBaseLevel - - public String userRemoteAddress() - { - return comm.userRemoteAddress(); - - } // end userRemoteAddress - - public String userDefaultPseud() throws DataException - { - return comm.userDefaultPseud(); - - } // end userDefaultPseud - - public boolean userIsAnonymous() - { - return comm.userIsAnonymous(); - - } // end userIsAnonymous - - public String realUserName() - { - return comm.realUserName(); - - } // end realUserName - - public String realEmailAddress() throws DataException - { - return comm.realEmailAddress(); - - } // end realEmailAddress - - public String realFullName() throws DataException - { - return comm.realFullName(); - - } // end realFullName - - public void saveMRU(String tag, Object data) - { - comm.saveMRU(tag,data); - - } // end saveMRU - - /*-------------------------------------------------------------------------------- - * Implementations from interface CommunityBackend - *-------------------------------------------------------------------------------- - */ - - public CommunityContext selfCommunity() - { - return comm.selfCommunity(); - - } // end selfCommunity - - public int realCommunityID() - { - return comm.realCommunityID(); - - } // end realCommunityID - - public boolean userHideHiddenConferences() - { - return comm.userHideHiddenConferences(); - - } // end userHideHiddenConferences - - public int realCommunityLevel() - { - return comm.realCommunityLevel(); - - } // end realCommunityLevel - - public ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException - { - return comm.getConferenceDataObject(confid); - - } // end getConferenceDataObject - - public boolean userCanCreateSubobjects() - { - return comm.userCanCreateSubobjects(); - - } // end userCanCreateSubobjects - - public String realCommunityAlias() - { - return comm.realCommunityAlias(); - - } // end realCommunityAlias - - public void detachConferenceDataObject(int confid) throws DataException - { - comm.detachConferenceDataObject(confid); - - } // end detachConferenceDataObject - - public boolean userCanDeleteSubobjects() - { - return comm.userCanDeleteSubobjects(); - - } // end userCanDeleteSubobjects - - public CommunityDataBackend getDataBackend() throws DataException - { - return comm.getDataBackend(); - - } // end getDataBackend - /*-------------------------------------------------------------------------------- * Implementations from interface ConferenceBackend *-------------------------------------------------------------------------------- @@ -1611,7 +1471,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void touchRead(Connection conn) throws SQLException { - if (deleted || comm.userIsAnonymous()) + if (deleted || env.getUser().userIsAnonymous()) return; // anonymous user can't update squat Statement stmt = conn.createStatement(); @@ -1621,14 +1481,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (settings_loaded) { // generate an update statement sql.append("UPDATE confsettings SET last_read = '").append(SQLUtil.encodeDate(now)); - sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(comm.realUID()).append(';'); + sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); } // 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(comm.realUID()).append(", '").append(SQLUtil.encodeString(pseud)).append("', '"); - sql.append(SQLUtil.encodeDate(now)).append("');"); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); + sql.append("', '").append(SQLUtil.encodeDate(now)).append("');"); } // end else @@ -1643,7 +1503,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public void touchPost(Connection conn, java.util.Date post_date) throws SQLException { - if (deleted || comm.userIsAnonymous()) + if (deleted || env.getUser().userIsAnonymous()) return; // anonymous user can't update squat Statement stmt = conn.createStatement(); @@ -1652,14 +1512,14 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend if (settings_loaded) { // generate an update statement sql.append("UPDATE confsettings SET last_post = '").append(SQLUtil.encodeDate(post_date)); - sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(comm.realUID()).append(';'); + sql.append("' WHERE confid = ").append(confid).append(" AND uid = ").append(env.getUserID()).append(';'); } // 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(comm.realUID()).append(", '").append(SQLUtil.encodeString(pseud)).append("', '"); - sql.append(SQLUtil.encodeDate(post_date)).append("');"); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeString(pseud)); + sql.append("', '").append(SQLUtil.encodeDate(post_date)).append("');"); } // end else @@ -1729,7 +1589,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend public PostLinkDecoderContext createDecoderContext(short topicid) { - return new PostLinkDecoderContext(comm.realCommunityAlias(),realConfAlias(),topicid); + return new PostLinkDecoderContext(env.getCommunity().realCommunityAlias(),realConfAlias(),topicid); } // end createDecoderContext @@ -1738,18 +1598,17 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend *-------------------------------------------------------------------------------- */ - static List getCommunityConferences(EngineBackend engine, CommunityBackend comm, DataPool datapool) - throws DataException + static List getCommunityConferences(EnvCommunity env) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getCommunityConferences for community # " + comm.realCommunityID() + ", user #" - + comm.realUID()); + logger.debug("getCommunityConferences for community # " + env.getCommunityID() + ", user #" + + env.getUserID()); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build a monster query! The idea is that we get the basic info of all conferences linked to the @@ -1762,9 +1621,9 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend new StringBuffer("SELECT c.confid, c.createdate, c.name, c.descr, s.granted_lvl, m.granted_lvl " + "FROM sigtoconf s, confs c LEFT JOIN confmember m ON c.confid = m.confid " + "AND m.uid = "); - sql.append(comm.realUID()).append(" WHERE s.confid = c.confid AND s.sigid = "); - sql.append(comm.realCommunityID()); - if (comm.userHideHiddenConferences()) + sql.append(env.getUserID()).append(" WHERE s.confid = c.confid AND s.sigid = "); + sql.append(env.getCommunityID()); + if (env.getCommunity().userHideHiddenConferences()) sql.append(" AND s.hide_list = 0"); sql.append(" ORDER BY s.sequence, c.name;"); if (logger.isDebugEnabled()) @@ -1775,9 +1634,9 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend while (rs.next()) { // create the appropriate objects to return - ConferenceContext cc = new ConferenceUserContextImpl(engine,comm,datapool,rs.getInt(1),rs.getString(3), - rs.getString(4),SQLUtil.getFullDateTime(rs,2), - rs.getInt(5),rs.getInt(6),conn); + ConferenceContext cc = new ConferenceUserContextImpl(env,rs.getInt(1),rs.getString(3),rs.getString(4), + SQLUtil.getFullDateTime(rs,2),rs.getInt(5), + rs.getInt(6),conn); rc.add(cc); } // end while @@ -1791,8 +1650,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1800,18 +1658,17 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end getCommunityConferences - static ConferenceContext getConference(EngineBackend engine, CommunityBackend comm, DataPool datapool, - int confid) throws DataException + static ConferenceContext getConference(EnvCommunity env, int confid) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getConference(#" + confid + ") for community # " + comm.realCommunityID() + ", user #" - + comm.realUID()); + logger.debug("getConference(#" + confid + ") for community # " + env.getCommunityID() + ", user #" + + env.getUserID()); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build a monster query! This is like the query in getCommunityConferences, except that we add the @@ -1820,8 +1677,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend new StringBuffer("SELECT c.createdate, c.name, c.descr, s.granted_lvl, m.granted_lvl " + "FROM sigtoconf s, confs c LEFT JOIN confmember m ON c.confid = m.confid " + "AND m.uid = "); - sql.append(comm.realUID()).append(" WHERE s.confid = c.confid AND s.sigid = "); - sql.append(comm.realCommunityID()).append(" AND c.confid = ").append(confid).append(';'); + sql.append(env.getUserID()).append(" WHERE s.confid = c.confid AND s.sigid = "); + sql.append(env.getCommunityID()).append(" AND c.confid = ").append(confid).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1829,12 +1686,11 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ResultSet rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new DataException("conference ID#" + confid + " not found in community#" - + comm.realCommunityID()); + + env.getCommunityID()); // pass back the new object - return new ConferenceUserContextImpl(engine,comm,datapool,confid,rs.getString(2), - rs.getString(3),SQLUtil.getFullDateTime(rs,1), - rs.getInt(4),rs.getInt(5),conn); + return new ConferenceUserContextImpl(env,confid,rs.getString(2),rs.getString(3), + SQLUtil.getFullDateTime(rs,1),rs.getInt(4),rs.getInt(5),conn); } // end try catch (SQLException e) @@ -1845,25 +1701,23 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getConference - static ConferenceContext getConference(EngineBackend engine, CommunityBackend comm, DataPool datapool, - String alias) throws DataException + static ConferenceContext getConference(EnvCommunity env, String alias) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getConference(\"" + alias + "\") for community # " + comm.realCommunityID() + ", user #" - + comm.realUID()); + logger.debug("getConference(\"" + alias + "\") for community # " + env.getCommunityID() + + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build a monster query! This is similar to the other getConference query, except that now we @@ -1873,8 +1727,8 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend new StringBuffer("SELECT c.confid, c.createdate, c.name, c.descr, s.granted_lvl, m.granted_lvl " + "FROM sigtoconf s, confalias a, confs c LEFT JOIN confmember m ON " + "c.confid = m.confid AND m.uid = "); - sql.append(comm.realUID()).append(" WHERE s.confid = c.confid AND a.confid = c.confid AND s.sigid = "); - sql.append(comm.realCommunityID()).append(" AND a.alias = '").append(SQLUtil.encodeString(alias)); + sql.append(env.getUserID()).append(" WHERE s.confid = c.confid AND a.confid = c.confid AND s.sigid = "); + sql.append(env.getCommunityID()).append(" AND a.alias = '").append(SQLUtil.encodeString(alias)); sql.append("';"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1883,10 +1737,10 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ResultSet rs = stmt.executeQuery(sql.toString()); if (!(rs.next())) throw new DataException("conference \"" + alias + "\" not found in community#" - + comm.realCommunityID()); + + env.getCommunityID()); // pass back the new object - return new ConferenceUserContextImpl(engine,comm,datapool,rs.getInt(1),rs.getString(3),rs.getString(4), + return new ConferenceUserContextImpl(env,rs.getInt(1),rs.getString(3),rs.getString(4), SQLUtil.getFullDateTime(rs,2),rs.getInt(5),rs.getInt(6),conn); } // end try @@ -1898,24 +1752,23 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end getConference - static List getUserHotlist(EngineBackend engine, UserBackend user, DataPool datapool) throws DataException + static List getUserHotlist(EnvUser env) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getUserHotlist for user #" + user.realUID()); + logger.debug("getUserHotlist for user #" + env.getUserID()); Connection conn = null; // pooled database connection ArrayList rc = new ArrayList(); // return from this function try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build a monster query! We pull the CommunityID and ConfID entries from the confhotlist table, @@ -1926,7 +1779,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend + "f.granted_lvl, h.sequence FROM confhotlist h, sigtoconf s, confs c " + "LEFT JOIN confmember f ON h.confid = f.confid AND h.uid = f.uid " + "WHERE h.confid = s.confid AND c.confid = h.confid AND h.uid = "); - sql.append(user.realUID()).append(" ORDER BY h.sequence ASC;"); + sql.append(env.getUserID()).append(" ORDER BY h.sequence ASC;"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1934,24 +1787,25 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend ResultSet rs = stmt.executeQuery(sql.toString()); // Create some temporary data structures to assist us in building the return list. - HashMap comm_backend_cache = new HashMap(); + HashMap env_cache = new HashMap(); while (rs.next()) { // retrieve the community id from the resultset first Integer cid = new Integer(rs.getInt(1)); - // we need a community backend for our conference, so make sure we have one - CommunityBackend comm = (CommunityBackend)(comm_backend_cache.get(cid)); - if (comm==null) - { // get it and make sure it's in the cache for next time - comm = CommunityUserContextImpl.getCommunityBackend(engine,user,datapool,conn,cid.intValue()); - comm_backend_cache.put(cid,comm); - + // we need a community environment for our conference, so make sure we have one + EnvCommunity ecomm = (EnvCommunity)(env_cache.get(cid)); + if (ecomm==null) + { // get the backend for this community and cache it + CommunityBackend cb = CommunityUserContextImpl.getCommunityBackend(env,conn,cid.intValue()); + ecomm = new EnvCommunity(env,cb); + env_cache.put(cid,ecomm); + } // end if // make the new ConferenceContext ConferenceContext conf = - new ConferenceUserContextImpl(engine,comm,datapool,rs.getInt(2),rs.getString(3),rs.getString(4), + new ConferenceUserContextImpl(ecomm,rs.getInt(2),rs.getString(3),rs.getString(4), SQLUtil.getFullDateTime(rs,5),rs.getInt(6),rs.getInt(7),conn); // and create the actual return value @@ -1969,8 +1823,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java b/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java index 4ef4eb5..bb02e1f 100644 --- a/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java +++ b/src/com/silverwrist/venice/core/impl/ContactInfoImpl.java @@ -22,6 +22,7 @@ import java.sql.*; import java.util.*; import org.apache.log4j.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.EnvEngine; import com.silverwrist.venice.db.*; class ContactInfoImpl implements ContactInfo, Stashable @@ -170,11 +171,11 @@ class ContactInfoImpl implements ContactInfo, Stashable /** * Loads a ContactInfoImpl object out of the database. * - * @param dp Database connection pool to get a Venice database connection from. + * @param env Engine environment to get a database connection from. * @param contactid ID of the contact to load. * @exception DataException The contact could not be loaded for some reason. */ - ContactInfoImpl(DataPool dp, int contactid) throws DataException + ContactInfoImpl(EnvEngine env, int contactid) throws DataException { if (logger.isDebugEnabled()) logger.debug("new ContactInfoImpl (loading CID " + contactid + ")"); @@ -182,7 +183,7 @@ class ContactInfoImpl implements ContactInfo, Stashable try { // get a connection and call loadData - conn = dp.getConnection(); + conn = env.getConnection(); loadData(conn,contactid); } // end try @@ -194,8 +195,7 @@ class ContactInfoImpl implements ContactInfo, Stashable } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - dp.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/ImageStore.java b/src/com/silverwrist/venice/core/impl/ImageStore.java index 73b25a9..82c9ee8 100644 --- a/src/com/silverwrist/venice/core/impl/ImageStore.java +++ b/src/com/silverwrist/venice/core/impl/ImageStore.java @@ -24,6 +24,7 @@ import org.apache.log4j.*; import com.silverwrist.util.IOUtil; import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.EnvEngine; class ImageStore implements BinaryData { @@ -42,7 +43,7 @@ class ImageStore implements BinaryData *-------------------------------------------------------------------------------- */ - private DataPool datapool; + private EnvEngine env; // the execution environment private int imgid; private String type; private int length; @@ -52,9 +53,9 @@ class ImageStore implements BinaryData *-------------------------------------------------------------------------------- */ - protected ImageStore(DataPool datapool, int imgid, String type, int length) + protected ImageStore(EnvEngine env, int imgid, String type, int length) { - this.datapool = datapool; + this.env = env; this.imgid = imgid; this.type = type; this.length = length; @@ -91,7 +92,7 @@ class ImageStore implements BinaryData try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Create the SQL we need to retrieve the image. @@ -126,8 +127,7 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -140,7 +140,7 @@ class ImageStore implements BinaryData *-------------------------------------------------------------------------------- */ - static ImageStore loadImageByID(DataPool datapool, int id) throws DataException + static ImageStore loadImageByID(EnvEngine env, int id) throws DataException { if (logger.isDebugEnabled()) logger.debug("loadImageByID # " + id); @@ -149,7 +149,7 @@ class ImageStore implements BinaryData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT mimetype, length FROM imagestore WHERE imgid = "); @@ -159,7 +159,7 @@ class ImageStore implements BinaryData ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) // create an object reference and return it - return new ImageStore(datapool,id,rs.getString(1),rs.getInt(2)); + return new ImageStore(env,id,rs.getString(1),rs.getInt(2)); return null; // no such image @@ -172,8 +172,7 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -204,7 +203,7 @@ class ImageStore implements BinaryData } // end storeNewImage - static int storeNewImage(DataPool datapool, short type, int owner, String mime, int length, InputStream data) + static int storeNewImage(EnvEngine env, short type, int owner, String mime, int length, InputStream data) throws DataException { if (logger.isDebugEnabled()) @@ -214,7 +213,7 @@ class ImageStore implements BinaryData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); return storeNewImage(conn,type,owner,mime,length,data); } // end try @@ -226,8 +225,7 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -250,7 +248,7 @@ class ImageStore implements BinaryData } // end replaceImage - static void replaceImage(DataPool datapool, int imgid, String mime, int length, InputStream data) + static void replaceImage(EnvEngine env, int imgid, String mime, int length, InputStream data) throws DataException { if (logger.isDebugEnabled()) @@ -260,7 +258,7 @@ class ImageStore implements BinaryData try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); replaceImage(conn,imgid,mime,length,data); } // end try @@ -272,8 +270,7 @@ class ImageStore implements BinaryData } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java b/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java index 0f1fa3a..bac13e6 100644 --- a/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java +++ b/src/com/silverwrist/venice/core/impl/PublishedMessageImpl.java @@ -24,6 +24,7 @@ import org.apache.log4j.*; import com.silverwrist.util.StringUtil; import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.EnvEngine; class PublishedMessageImpl implements TopicMessageContext { @@ -32,14 +33,14 @@ class PublishedMessageImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(PublishedMessageImpl.class.getName()); + private static Category logger = Category.getInstance(PublishedMessageImpl.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private DataPool datapool; + private EnvEngine env; // the execution environment private long postid; private long parent; private int num; @@ -55,10 +56,10 @@ class PublishedMessageImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - PublishedMessageImpl(DataPool datapool, long postid, long parent, int num, int linecount, int creator_uid, + PublishedMessageImpl(EnvEngine env, long postid, long parent, int num, int linecount, int creator_uid, java.util.Date posted, String pseud, String creator_cache, String text_cache) { - this.datapool = datapool; + this.env = env; this.postid = postid; this.parent = parent; this.num = num; @@ -71,10 +72,10 @@ class PublishedMessageImpl implements TopicMessageContext } // end constructor - protected PublishedMessageImpl(DataPool datapool, long postid, long parent, int num, int linecount, + protected PublishedMessageImpl(EnvEngine env, long postid, long parent, int num, int linecount, int creator_uid, java.util.Date posted, String pseud) { - this.datapool = datapool; + this.env = env; this.postid = postid; this.parent = parent; this.num = num; @@ -144,7 +145,7 @@ class PublishedMessageImpl implements TopicMessageContext try { // use a database connection to get the user name - conn = datapool.getConnection(); + conn = env.getConnection(); creator_cache = quickGetUserName(conn,creator_uid); } // end try @@ -156,8 +157,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -211,7 +211,7 @@ class PublishedMessageImpl implements TopicMessageContext try { // use a database connection to get the body text - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT data FROM postdata WHERE postid = " @@ -230,8 +230,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -332,13 +331,13 @@ class PublishedMessageImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - static void backfillCache(List cache_list, int desired_size, DataPool datapool) throws DataException + static void backfillCache(List cache_list, int desired_size, EnvEngine env) throws DataException { Connection conn = null; try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the statement to retrieve the post information @@ -351,8 +350,13 @@ class PublishedMessageImpl implements TopicMessageContext // execute the statement! ResultSet rs = stmt.executeQuery(sql.toString()); while (rs.next()) - cache_list.add(new PublishedMessageImpl(datapool,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), - rs.getInt(5),SQLUtil.getFullDateTime(rs,6),rs.getString(7))); + { // create PublishedMessageImpl objects to backfill the cache + TopicMessageContext tmc = new PublishedMessageImpl(env,rs.getLong(1),rs.getLong(2),rs.getInt(3), + rs.getInt(4),rs.getInt(5), + SQLUtil.getFullDateTime(rs,6),rs.getString(7)); + cache_list.add(tmc); + + } // end while } // end try catch (SQLException e) @@ -363,20 +367,19 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end backfillCache - static void backfillReturn(List return_list, DataPool datapool) throws DataException + static void backfillReturn(List return_list, EnvEngine env) throws DataException { Connection conn = null; try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // How many posts have been published anyway? @@ -399,7 +402,7 @@ class PublishedMessageImpl implements TopicMessageContext if ((ctr--)<=0) { // append context, please TopicMessageContext ctxt = - new PublishedMessageImpl(datapool,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), + new PublishedMessageImpl(env,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), rs.getInt(5),SQLUtil.getFullDateTime(rs,6),rs.getString(7)); return_list.add(ctxt); @@ -416,8 +419,7 @@ class PublishedMessageImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java b/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java index 777c7dc..649ba06 100644 --- a/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java +++ b/src/com/silverwrist/venice/core/impl/SideBoxDescriptorImpl.java @@ -21,6 +21,7 @@ import java.sql.*; import org.apache.log4j.*; import com.silverwrist.venice.core.*; import com.silverwrist.venice.db.*; +import com.silverwrist.venice.core.internals.*; class SideBoxDescriptorImpl implements UserSideBoxDescriptor { @@ -36,9 +37,8 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor *-------------------------------------------------------------------------------- */ - private int uid; // the user ID + private EnvUser env; // the execution environment private SideBoxDescriptor parent; // the master side box descriptor - private DataPool datapool; // the data pool used by this object private int sequence; // the sequence number /*-------------------------------------------------------------------------------- @@ -46,11 +46,10 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor *-------------------------------------------------------------------------------- */ - SideBoxDescriptorImpl(int uid, SideBoxDescriptor parent, DataPool datapool, int sequence) + SideBoxDescriptorImpl(EnvUser env, SideBoxDescriptor parent, int sequence) { - this.uid = uid; + this.env = env; this.parent = parent; - this.datapool = datapool; this.sequence = sequence; } // end constructor @@ -94,15 +93,15 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the UPDATE statement and just execute it blind (if this sidebox is not in the list, // the UPDATE is a no-op). StringBuffer sql = new StringBuffer("UPDATE sideboxes SET sequence = "); - sql.append(seq).append(" WHERE uid = ").append(uid).append(" AND boxid = ").append(parent.getID()); - sql.append(';'); + sql.append(seq).append(" WHERE uid = ").append(env.getUserID()).append(" AND boxid = "); + sql.append(parent.getID()).append(';'); stmt.executeUpdate(sql.toString()); this.sequence = seq; @@ -115,8 +114,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -127,14 +125,14 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the DELETE statement and just execute it blind (if this conference is not in the hotlist, // the DELETE is a no-op). StringBuffer sql = new StringBuffer("DELETE FROM sideboxes WHERE uid = "); - sql.append(uid).append(" AND boxid = ").append(parent.getID()).append(';'); + sql.append(env.getUserID()).append(" AND boxid = ").append(parent.getID()).append(';'); stmt.executeUpdate(sql.toString()); } // end try @@ -146,8 +144,7 @@ class SideBoxDescriptorImpl implements UserSideBoxDescriptor } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/SimpleEmailer.java b/src/com/silverwrist/venice/core/impl/SimpleEmailer.java index 48982df..0706156 100644 --- a/src/com/silverwrist/venice/core/impl/SimpleEmailer.java +++ b/src/com/silverwrist/venice/core/impl/SimpleEmailer.java @@ -22,8 +22,9 @@ import javax.mail.*; import javax.mail.internet.*; import com.silverwrist.venice.core.EmailException; import com.silverwrist.venice.core.InternalStateError; +import com.silverwrist.venice.core.internals.Emailer; -class SimpleEmailer +class SimpleEmailer implements Emailer { /*-------------------------------------------------------------------------------- * Attributes @@ -65,7 +66,7 @@ class SimpleEmailer } // end constructor /*-------------------------------------------------------------------------------- - * External operations + * Implementations from interface Emailer *-------------------------------------------------------------------------------- */ diff --git a/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java b/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java index 85b3515..ac52840 100644 --- a/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/TopicMessageUserContextImpl.java @@ -24,10 +24,11 @@ import java.util.zip.*; import org.apache.log4j.*; import com.silverwrist.util.IOUtil; import com.silverwrist.util.StringUtil; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.security.AuditRecord; import com.silverwrist.venice.security.Capability; -import com.silverwrist.venice.core.*; class TopicMessageUserContextImpl implements TopicMessageContext { @@ -45,9 +46,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - private EngineBackend engine; - private ConferenceBackend conf; - private DataPool datapool; + private EnvConference env; // the conference environment private long postid; private long parent; private int num; @@ -71,15 +70,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - protected TopicMessageUserContextImpl(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - long postid, long parent, int num, int linecount, int creator_uid, - java.util.Date posted, boolean hidden, int scribble_uid, - java.util.Date scribble_date, String pseud, int datalen, - String filename, String mimetype, int stgmethod) + protected TopicMessageUserContextImpl(EnvConference env, long postid, long parent, int num, int linecount, + int creator_uid, java.util.Date posted, boolean hidden, + int scribble_uid, java.util.Date scribble_date, String pseud, + int datalen, String filename, String mimetype, int stgmethod) { - this.engine = engine; - this.conf = conf; - this.datapool = datapool; + this.env = env; this.postid = postid; this.parent = parent; this.num = num; @@ -97,13 +93,10 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end constructor - TopicMessageUserContextImpl(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - long postid, long parent, int num, int linecount, int creator_uid, - java.util.Date posted, String pseud) + TopicMessageUserContextImpl(EnvConference env, long postid, long parent, int num, int linecount, + int creator_uid, java.util.Date posted, String pseud) { - this.engine = engine; - this.conf = conf; - this.datapool = datapool; + this.env = env; this.postid = postid; this.parent = parent; this.num = num; @@ -227,7 +220,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // use a database connection to get the user name - conn = datapool.getConnection(); + conn = env.getConnection(); refresh(conn); if (nuked) return null; // post nuked! @@ -242,8 +235,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -299,7 +291,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // use a database connection to get the body text - conn = datapool.getConnection(); + conn = env.getConnection(); refresh(conn); if (nuked) @@ -327,8 +319,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -375,7 +366,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext InputStream rc = null; try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // make sure we have current data refresh(conn); @@ -451,8 +442,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -462,27 +452,29 @@ class TopicMessageUserContextImpl implements TopicMessageContext public boolean canHide() { - return (((creator_uid==conf.realUID()) && (!conf.userIsAnonymous())) || conf.userCanHide()); + return ( ((creator_uid==env.getUserID()) && (!env.getUser().userIsAnonymous())) + || env.getConference().userCanHide()); } // end canHide public boolean canScribble() { - return (((creator_uid==conf.realUID()) && (!conf.userIsAnonymous())) || conf.userCanScribble()); + return ( ((creator_uid==env.getUserID()) && (!env.getUser().userIsAnonymous())) + || env.getConference().userCanScribble()); } // end canScribble public boolean canNuke() { - return conf.userCanNuke(); + return env.getConference().userCanNuke(); } // end canNuke public void setHidden(boolean flag) throws DataException, AccessError { - if (conf.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return; // no-op - if ((creator_uid!=conf.realUID()) && !(conf.userCanHide())) + if ((creator_uid!=env.getUserID()) && !(env.getConference().userCanHide())) { // we can't change the hidden status! logger.error("trying to set hidden status of post w/o permission!"); throw new AccessError("You are not permitted to change the hidden status of this message."); @@ -497,7 +489,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock the tables we reference @@ -526,9 +518,8 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end finally // record what we did in an audit record - ar = new AuditRecord(AuditRecord.HIDE_MESSAGE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + conf.realConfID() + ",post=" + postid, - flag ? "hide" : "unhide"); + ar = env.newAudit(AuditRecord.HIDE_MESSAGE,"conf=" + env.getConfID() + ",post=" + postid, + flag ? "hide" : "unhide"); } // end try catch (SQLException e) @@ -551,8 +542,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -560,9 +550,9 @@ class TopicMessageUserContextImpl implements TopicMessageContext public void scribble() throws DataException, AccessError { - if (conf.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) return; // no-op - if ((creator_uid!=conf.realUID()) && !(conf.userCanScribble())) + if ((creator_uid!=env.getUserID()) && !(env.getConference().userCanScribble())) { // we can't scribble this post logger.error("trying to scribble post w/o permission!"); throw new AccessError("You are not permitted to scribble this message."); @@ -577,7 +567,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock the tables we reference @@ -590,7 +580,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext // First, set the appropriate "scribbled" information in the "header". StringBuffer sql = new StringBuffer("UPDATE posts SET linecount = 0, hidden = 0, scribble_uid = "); - sql.append(conf.realUID()).append(", scribble_date = '"); + sql.append(env.getUserID()).append(", scribble_date = '"); java.util.Date now = new java.util.Date(); final String scribble_pseud = "(Scribbled)"; // TODO: configurable option sql.append(SQLUtil.encodeDate(now)).append("', pseud = '").append(scribble_pseud); @@ -639,12 +629,12 @@ class TopicMessageUserContextImpl implements TopicMessageContext sql.setLength(0); sql.append("DELETE FROM postpublish WHERE postid = ").append(postid).append(';'); if (stmt.executeUpdate(sql.toString())>0) - engine.unpublish(postid); + env.getEngine().unpublish(postid); // Update our internal data fields. linecount = 0; hidden = false; - scribble_uid = conf.realUID(); + scribble_uid = env.getUserID(); scribble_date = now; pseud = scribble_pseud; text_cache = null; @@ -658,8 +648,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end finally // record what we did in an audit record - ar = new AuditRecord(AuditRecord.SCRIBBLE_MESSAGE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + conf.realConfID() + ",post=" + postid); + ar = env.newAudit(AuditRecord.SCRIBBLE_MESSAGE,"conf=" + env.getConfID() + ",post=" + postid); } // end try catch (SQLException e) @@ -682,8 +671,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -691,7 +679,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext public void nuke() throws DataException, AccessError { - if (!(conf.userCanNuke())) + if (!(env.getConference().userCanNuke())) { // we can't scribble this post logger.error("trying to nuke post w/o permission!"); throw new AccessError("You are not permitted to nuke this message."); @@ -706,7 +694,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock the tables we reference @@ -732,7 +720,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext stmt.executeUpdate("DELETE FROM postattach WHERE postid = " + postid + ";"); stmt.executeUpdate("DELETE FROM postdogear WHERE postid = " + postid + ";"); if (stmt.executeUpdate("DELETE FROM postpublish WHERE postid = " + postid + ";")>0) - engine.unpublish(postid); + env.getEngine().unpublish(postid); // Phase 1 of renumber - Renumber all posts IN THIS TOPIC that had a number higher than the one // we just blew to hell. (Must have the "topicid =" clause in there - see Bug #415473) @@ -767,8 +755,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end finally // record what we did in an audit record - ar = new AuditRecord(AuditRecord.NUKE_MESSAGE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + conf.realConfID() + ",post=" + postid); + ar = env.newAudit(AuditRecord.NUKE_MESSAGE,"conf=" + env.getConfID() + ",post=" + postid); } // end try catch (SQLException e) @@ -791,8 +778,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -811,7 +797,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end if - if (creator_uid!=conf.realUID()) + if (creator_uid!=env.getUserID()) { // you can't attach to this message! logger.error("tried to attach data to a message that's not yours!"); throw new AccessError("You are not permitted to add an attachment to this message."); @@ -858,7 +844,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext int real_length = 0; int tmp_stgmethod; - if (engine.isNoCompressMimeType(m_type)) + if (env.getEngine().isNoCompressMimeType(m_type)) { // don't compress me, just store me normally logger.debug("stored as NORMAL data (no compression)"); real_data = data; @@ -913,7 +899,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // open up a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); // make sure we have the right status to upload refresh(conn); @@ -948,9 +934,8 @@ class TopicMessageUserContextImpl implements TopicMessageContext stgmethod = tmp_stgmethod; // Generate an audit record indicating what we did. - ar = new AuditRecord(AuditRecord.UPLOAD_ATTACHMENT,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + conf.realConfID() + ",post=" + postid, - "len=" + length + ",type=" + m_type + ",name=" + file + ",method=" + tmp_stgmethod); + ar = env.newAudit(AuditRecord.UPLOAD_ATTACHMENT,"conf=" + env.getConfID() + ",post=" + postid, + "len=" + length + ",type=" + m_type + ",name=" + file + ",method=" + tmp_stgmethod); } // end try catch (SQLException e) @@ -973,8 +958,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -982,7 +966,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext public boolean canPublish() { - if (!(Capability.canPublishToFrontPage(conf.realBaseLevel()))) + if (!(Capability.canPublishToFrontPage(env.getUser().realBaseLevel()))) return false; // must be a sysadmin to publish if ((scribble_date!=null) || nuked) return false; // cannot publish a scribbled or nuked message @@ -991,7 +975,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // see if the post has already been published @@ -1007,8 +991,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1018,7 +1001,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext public void publish() throws DataException, AccessError { - if (!(Capability.canPublishToFrontPage(conf.realBaseLevel()))) + if (!(Capability.canPublishToFrontPage(env.getUser().realBaseLevel()))) { // you aren't allowed to publish - naughty naughty! logger.error("unable to publish because we're not allowed"); throw new AccessError("You are not permitted to publish postings to the front page."); @@ -1044,7 +1027,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // see if post has already been published @@ -1054,31 +1037,30 @@ class TopicMessageUserContextImpl implements TopicMessageContext throw new DataException("This posting has already been published."); boolean done = false; - engine.startPublish(); + env.getEngine().startPublish(); try { // insert the post reference into the database StringBuffer sql = new StringBuffer("INSERT INTO postpublish (sigid, postid, by_uid, on_date) VALUES ("); - sql.append(conf.realCommunityID()).append(", ").append(postid).append(", ").append(conf.realUID()); + sql.append(env.getCommunityID()).append(", ").append(postid).append(", ").append(env.getUserID()); java.util.Date now = new java.util.Date(); sql.append(", '").append(SQLUtil.encodeDate(now)).append("');"); stmt.executeUpdate(sql.toString()); // generate an audit record indicating what we've done - ar = new AuditRecord(AuditRecord.PUBLISH_POST,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + conf.realConfID() + ",post=" + postid); + ar = env.newAudit(AuditRecord.PUBLISH_POST,"conf=" + env.getConfID() + ",post=" + postid); // establish cached data object for front page - engine.publishNew(new PublishedMessageImpl(datapool,postid,parent,num,linecount,creator_uid, - posted,pseud,creator_cache,text_cache)); + env.getEngine().publishNew(new PublishedMessageImpl(env,postid,parent,num,linecount,creator_uid, + posted,pseud,creator_cache,text_cache)); done = true; } // end try finally { // make sure to release the lock if we goofed in here if (!done) - engine.publishNew(null); + env.getEngine().publishNew(null); } // end finally @@ -1103,8 +1085,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1115,11 +1096,11 @@ class TopicMessageUserContextImpl implements TopicMessageContext *-------------------------------------------------------------------------------- */ - static List loadMessageRange(EngineBackend engine, ConferenceBackend conf, DataPool datapool, int topicid, - int post_low, int post_high) throws DataException + static List loadMessageRange(EnvConference env, int topicid, int post_low, int post_high) + throws DataException { if (logger.isDebugEnabled()) - logger.debug("loadMessageRange for conf # " + conf.realConfID() + ", topic #" + topicid + ", range [" + logger.debug("loadMessageRange for conf # " + env.getConfID() + ", topic #" + topicid + ", range [" + post_low + ", " + post_high + "]"); ArrayList rc = new ArrayList(); @@ -1127,7 +1108,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // run a query to get all the posts in a particular topic @@ -1145,11 +1126,10 @@ class TopicMessageUserContextImpl implements TopicMessageContext while (rs.next()) { // create implementation objects and shove them into the return vector TopicMessageContext val = - new TopicMessageUserContextImpl(engine,conf,datapool,rs.getLong(1),rs.getLong(2),rs.getInt(3), - rs.getInt(4),rs.getInt(5),SQLUtil.getFullDateTime(rs,6), - rs.getBoolean(7),rs.getInt(8),SQLUtil.getFullDateTime(rs,9), - rs.getString(10),rs.getInt(11),rs.getString(12),rs.getString(13), - rs.getInt(14)); + new TopicMessageUserContextImpl(env,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), + rs.getInt(5),SQLUtil.getFullDateTime(rs,6),rs.getBoolean(7), + rs.getInt(8),SQLUtil.getFullDateTime(rs,9),rs.getString(10), + rs.getInt(11),rs.getString(12),rs.getString(13),rs.getInt(14)); rc.add(val); } // end while @@ -1163,8 +1143,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1172,18 +1151,17 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end loadMessageRange - static TopicMessageContext loadMessage(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - int topicid, int message_num) throws DataException + static TopicMessageContext loadMessage(EnvConference env, int topicid, int message_num) throws DataException { if (logger.isDebugEnabled()) - logger.debug("loadMessage for conf # " + conf.realConfID() + ", topic #" + topicid + ", message " + logger.debug("loadMessage for conf # " + env.getConfID() + ", topic #" + topicid + ", message " + message_num); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // run a query to get all the posts in a particular topic @@ -1198,11 +1176,10 @@ class TopicMessageUserContextImpl implements TopicMessageContext ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) // create an object reference and return it - return new TopicMessageUserContextImpl(engine,conf,datapool,rs.getLong(1),rs.getLong(2),rs.getInt(3), - rs.getInt(4),rs.getInt(5),SQLUtil.getFullDateTime(rs,6), - rs.getBoolean(7),rs.getInt(8),SQLUtil.getFullDateTime(rs,9), - rs.getString(10),rs.getInt(11),rs.getString(12), - rs.getString(13),rs.getInt(14)); + return new TopicMessageUserContextImpl(env,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), + rs.getInt(5),SQLUtil.getFullDateTime(rs,6),rs.getBoolean(7), + rs.getInt(8),SQLUtil.getFullDateTime(rs,9),rs.getString(10), + rs.getInt(11),rs.getString(12),rs.getString(13),rs.getInt(14)); // indicates an error... throw new DataException("Message not found."); @@ -1216,24 +1193,22 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally } // end loadMessage - static TopicMessageContext getMessage(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - long postid) throws DataException + static TopicMessageContext getMessage(EnvConference env, long postid) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getMessage for conf # " + conf.realConfID() + ", post #" + postid); + logger.debug("getMessage for conf # " + env.getConfID() + ", post #" + postid); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = @@ -1241,17 +1216,16 @@ class TopicMessageUserContextImpl implements TopicMessageContext + "p.hidden, p.scribble_uid, p.scribble_date, p.pseud, a.datalen, a.filename, " + "a.mimetype, a.stgmethod FROM topics t, posts p LEFT JOIN postattach a " + "ON p.postid = a.postid WHERE t.topicid = p.topicid AND t.confid = "); - sql.append(conf.realConfID()).append(" AND p.postid = ").append(postid).append(';'); + sql.append(env.getConfID()).append(" AND p.postid = ").append(postid).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) // create an object reference and return it - return new TopicMessageUserContextImpl(engine,conf,datapool,rs.getLong(1),rs.getLong(2),rs.getInt(3), - rs.getInt(4),rs.getInt(5),SQLUtil.getFullDateTime(rs,6), - rs.getBoolean(7),rs.getInt(8),SQLUtil.getFullDateTime(rs,9), - rs.getString(10),rs.getInt(11),rs.getString(12), - rs.getString(13),rs.getInt(14)); + return new TopicMessageUserContextImpl(env,rs.getLong(1),rs.getLong(2),rs.getInt(3),rs.getInt(4), + rs.getInt(5),SQLUtil.getFullDateTime(rs,6),rs.getBoolean(7), + rs.getInt(8),SQLUtil.getFullDateTime(rs,9),rs.getString(10), + rs.getInt(11),rs.getString(12),rs.getString(13),rs.getInt(14)); // indicates an error... throw new DataException("Message not found."); @@ -1265,8 +1239,7 @@ class TopicMessageUserContextImpl implements TopicMessageContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java index 736f002..352b5ba 100644 --- a/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/TopicUserContextImpl.java @@ -20,10 +20,11 @@ package com.silverwrist.venice.core.impl; import java.sql.*; import java.util.*; import org.apache.log4j.*; +import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.htmlcheck.*; import com.silverwrist.venice.security.AuditRecord; -import com.silverwrist.venice.core.*; class TopicUserContextImpl implements TopicContext { @@ -39,9 +40,7 @@ class TopicUserContextImpl implements TopicContext *-------------------------------------------------------------------------------- */ - private EngineBackend engine; - private ConferenceBackend conf; - private DataPool datapool; + private EnvConference env; // the enclosing environment private int topicid; private short topicnum; private int creator_uid; @@ -61,14 +60,11 @@ class TopicUserContextImpl implements TopicContext *-------------------------------------------------------------------------------- */ - protected TopicUserContextImpl(EngineBackend engine, ConferenceBackend conf, DataPool datapool, int topicid, - short topicnum, int creator_uid, int top_message, boolean frozen, - boolean archived, java.util.Date created, java.util.Date lastupdate, - String name, boolean hidden, int unread) + protected TopicUserContextImpl(EnvConference env, int topicid, short topicnum, int creator_uid, + int top_message, boolean frozen, boolean archived, java.util.Date created, + java.util.Date lastupdate, String name, boolean hidden, int unread) { - this.engine = engine; - this.conf = conf; - this.datapool = datapool; + this.env = env; this.topicid = topicid; this.topicnum = topicnum; this.creator_uid = creator_uid; @@ -83,15 +79,12 @@ class TopicUserContextImpl implements TopicContext } // end constructor - TopicUserContextImpl(EngineBackend engine, ConferenceBackend conf, DataPool datapool, ReturnTopicInfo inf, - String name) + TopicUserContextImpl(EnvConference env, ReturnTopicInfo inf, String name) { - this.engine = engine; - this.conf = conf; - this.datapool = datapool; + this.env = env; this.topicid = inf.getTopicID(); this.topicnum = inf.getTopicNum(); - this.creator_uid = conf.realUID(); + this.creator_uid = env.getUserID(); this.top_message = 0; this.frozen = false; this.archived = false; @@ -144,7 +137,7 @@ class TopicUserContextImpl implements TopicContext Statement stmt = conn.createStatement(); // perform a requery of the database - ResultSet rs = queryByTopic(stmt,topicid,conf.realUID()); + ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); if (rs.next()) { // update the fields that are capable of changing top_message = rs.getInt(4); @@ -166,7 +159,7 @@ class TopicUserContextImpl implements TopicContext { Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("SELECT bozo_uid FROM topicbozo WHERE topicid = "); - sql.append(topicid).append(" AND uid = ").append(conf.realUID()).append(';'); + sql.append(topicid).append(" AND uid = ").append(env.getUserID()).append(';'); ResultSet rs = stmt.executeQuery(sql.toString()); bozo_uids = new HashSet(); while (rs.next()) @@ -187,7 +180,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); refresh(conn); } // end try @@ -199,8 +192,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -280,13 +272,13 @@ class TopicUserContextImpl implements TopicContext public boolean canFreeze() { - return conf.userCanHide(); + return env.getConference().userCanHide(); } // end canFreeze public boolean canArchive() { - return conf.userCanHide(); + return env.getConference().userCanHide(); } // end canArchive @@ -294,7 +286,7 @@ class TopicUserContextImpl implements TopicContext { if ((frozen==flag) || deleted) return; // no-op - if (!(conf.userCanHide())) + if (!(env.getConference().userCanHide())) { // you can't freeze the topic! logger.error("user cannot change frozen status of topic"); throw new AccessError("You are not permitted to freeze or unfreeze this topic."); @@ -306,7 +298,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to freeze or unfreeze the topic @@ -315,9 +307,8 @@ class TopicUserContextImpl implements TopicContext if (stmt.executeUpdate(sql.toString())>0) { // success! save the flag and generate an audit record frozen = flag; - ar = new AuditRecord(AuditRecord.TOPIC_FREEZE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic=" - + String.valueOf(topicid),flag ? "freeze" : "unfreeze"); + ar = env.newAudit(AuditRecord.TOPIC_FREEZE,"conf=" + env.getConfID() + ",topic=" + topicid, + flag ? "freeze" : "unfreeze"); } // end if else // somebody else must have deleted this topic @@ -344,8 +335,7 @@ class TopicUserContextImpl implements TopicContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -355,7 +345,7 @@ class TopicUserContextImpl implements TopicContext { if ((archived==flag) || deleted) return; // no-op - if (!(conf.userCanHide())) + if (!(env.getConference().userCanHide())) { // you can't archive the topic! logger.error("user cannot change archived status of topic"); throw new AccessError("You are not permitted to archive or unarchive this topic."); @@ -367,7 +357,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to freeze or unfreeze the topic @@ -376,9 +366,8 @@ class TopicUserContextImpl implements TopicContext if (stmt.executeUpdate(sql.toString())>0) { // success! save the flag and generate an audit record archived = flag; - ar = new AuditRecord(AuditRecord.TOPIC_ARCHIVE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic=" - + String.valueOf(topicid),flag ? "archive" : "unarchive"); + ar = env.newAudit(AuditRecord.TOPIC_ARCHIVE,"conf=" + env.getConfID() + ",topic=" + topicid, + flag ? "archive" : "unarchive"); } // end if else // somebody else must have deleted this topic @@ -405,8 +394,7 @@ class TopicUserContextImpl implements TopicContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -414,14 +402,14 @@ class TopicUserContextImpl implements TopicContext public void setHidden(boolean flag) throws DataException { - if ((hidden==flag) || deleted || conf.userIsAnonymous()) + if ((hidden==flag) || deleted || env.getUser().userIsAnonymous()) return; // no-op Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;"); @@ -429,7 +417,7 @@ class TopicUserContextImpl implements TopicContext { // start by trying to see if we can update topicsettings directly StringBuffer sql = new StringBuffer("UPDATE topicsettings SET hidden = "); sql.append(flag ? '1' : '0').append(" WHERE topicid = ").append(topicid).append(" AND uid = "); - sql.append(conf.realUID()).append(';'); + sql.append(env.getUserID()).append(';'); if (stmt.executeUpdate(sql.toString())>0) { // that was all we needed - just save the flag and exit hidden = flag; @@ -451,7 +439,7 @@ class TopicUserContextImpl implements TopicContext // OK, just insert a new row into topicsettings, why dontcha... sql.setLength(0); sql.append("INSERT INTO topicsettings (topicid, uid, hidden) VALUES (").append(topicid).append(", "); - sql.append(conf.realUID()).append(", ").append(flag ? '1' : '0').append(");"); + sql.append(env.getUserID()).append(", ").append(flag ? '1' : '0').append(");"); stmt.executeUpdate(sql.toString()); hidden = flag; // successful completion @@ -472,8 +460,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -493,7 +480,7 @@ class TopicUserContextImpl implements TopicContext if (logger.isDebugEnabled()) logger.debug("[raw] setUnreadMessages(" + count + ") entry"); - if (conf.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) { // this is effectively a no-op, but log it logger.debug("reject 1: anonymous user"); return; @@ -519,7 +506,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;"); @@ -529,13 +516,13 @@ class TopicUserContextImpl implements TopicContext sql.append(last_msg).append(", last_read = '"); java.util.Date now = new java.util.Date(); sql.append(SQLUtil.encodeDate(now)).append("' WHERE topicid = ").append(topicid).append(" AND uid = "); - sql.append(conf.realUID()).append(';'); + sql.append(env.getUserID()).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); if (stmt.executeUpdate(sql.toString())>0) { // that was all we needed - just save the flag and exit logger.debug("--> bailed out after update - done with setUnreadMessages{"); - conf.touchRead(conn); + env.getConference().touchRead(conn); unread = count; return; @@ -558,12 +545,12 @@ class TopicUserContextImpl implements TopicContext // OK, just insert a new row into topicsettings, why dontcha... sql.setLength(0); sql.append("INSERT INTO topicsettings (topicid, uid, last_message, last_read) VALUES ("); - sql.append(topicid).append(", ").append(conf.realUID()).append(", ").append(last_msg).append(", '"); + sql.append(topicid).append(", ").append(env.getUserID()).append(", ").append(last_msg).append(", '"); sql.append(SQLUtil.encodeDate(now)).append("');"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); stmt.executeUpdate(sql.toString()); - conf.touchRead(conn); + env.getConference().touchRead(conn); unread = count; // successful completion } // end try @@ -583,8 +570,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -598,7 +584,7 @@ class TopicUserContextImpl implements TopicContext public List getMessages(int low, int high) throws DataException, AccessError { - if (!(conf.userCanRead())) + if (!(env.getConference().userCanRead())) { // they can't read messages in this topic! logger.error("trying to read postings w/o permission!"); throw new AccessError("You do not have permission to read messages in this conference."); @@ -607,15 +593,15 @@ class TopicUserContextImpl implements TopicContext // reorder parameters so they come in the correct order! if (low<=high) - return TopicMessageUserContextImpl.loadMessageRange(engine,conf,datapool,topicid,low,high); + return TopicMessageUserContextImpl.loadMessageRange(env,topicid,low,high); else - return TopicMessageUserContextImpl.loadMessageRange(engine,conf,datapool,topicid,high,low); + return TopicMessageUserContextImpl.loadMessageRange(env,topicid,high,low); } // end getMessages public TopicMessageContext getMessage(int number) throws DataException, AccessError { - if (!(conf.userCanRead())) + if (!(env.getConference().userCanRead())) { // they can't read messages in this topic! logger.error("trying to read postings w/o permission!"); throw new AccessError("You do not have permission to read messages in this conference."); @@ -623,7 +609,7 @@ class TopicUserContextImpl implements TopicContext } // end if // pass down to one of our static functiions to return this - return TopicMessageUserContextImpl.loadMessage(engine,conf,datapool,topicid,number); + return TopicMessageUserContextImpl.loadMessage(env,topicid,number); } // end getMessage @@ -633,7 +619,7 @@ class TopicUserContextImpl implements TopicContext if (logger.isInfoEnabled()) logger.info("postNewMessage(" + parent + ", '" + pseud + "',) entry"); - if (!(conf.userCanPost())) + if (!(env.getConference().userCanPost())) { // they can't post in this topic! logger.error("trying to post w/o permission!"); throw new AccessError("You do not have permission to post messages in this conference."); @@ -647,14 +633,14 @@ class TopicUserContextImpl implements TopicContext } // end if - if (frozen && !(conf.userCanHide())) + if (frozen && !(env.getConference().userCanHide())) { // can't post to a frozen topic! logger.error("can't post to a frozen topic!"); throw new AccessError("The topic is frozen, and you do not have permission to post to it."); } // end if - if (archived && !(conf.userCanHide())) + if (archived && !(env.getConference().userCanHide())) { // can't post to a frozen topic! logger.error("can't post to an archived topic!"); throw new AccessError("The topic is archived, and you do not have permission to post to it."); @@ -662,9 +648,9 @@ class TopicUserContextImpl implements TopicContext } // end if // preprocess the two arguments through HTML checkers - HTMLChecker pseud_ch = engine.createCheckerObject(engine.HTMLC_POST_PSEUD); - HTMLChecker text_ch = engine.createCheckerObject(engine.HTMLC_POST_BODY); - text_ch.setContextValue("PostLinkDecoderContext",conf.createDecoderContext(topicnum)); + HTMLChecker pseud_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_PSEUD); + HTMLChecker text_ch = env.getEngine().createCheckerObject(EngineBackend.HTMLC_POST_BODY); + text_ch.setContextValue("PostLinkDecoderContext",env.getConference().createDecoderContext(topicnum)); try { // run both arguments through the HTML checker pseud_ch.append(pseud); @@ -704,7 +690,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // slap a lock on all the tables we need to touch @@ -721,14 +707,14 @@ class TopicUserContextImpl implements TopicContext } // end if - if (frozen && !(conf.userCanHide())) + if (frozen && !(env.getConference().userCanHide())) { // can't post to a frozen topic! logger.error("can't post to a frozen topic!"); throw new AccessError("The topic is frozen, and you do not have permission to post to it."); } // end if - if (archived && !(conf.userCanHide())) + if (archived && !(env.getConference().userCanHide())) { // can't post to a frozen topic! logger.error("can't post to an archived topic!"); throw new AccessError("The topic is archived, and you do not have permission to post to it."); @@ -744,7 +730,7 @@ class TopicUserContextImpl implements TopicContext StringBuffer sql = new StringBuffer("INSERT INTO posts (parent, topicid, num, linecount, creator_uid, " + "posted, pseud) VALUES ("); sql.append(parent).append(", ").append(topicid).append(", ").append(new_post_num).append(", "); - sql.append(text_linecount).append(", ").append(conf.realUID()).append(", '"); + sql.append(text_linecount).append(", ").append(env.getUserID()).append(", '"); posted_date = new java.util.Date(); sql.append(SQLUtil.encodeDate(posted_date)).append("', '").append(real_pseud).append("');"); if (logger.isDebugEnabled()) @@ -776,7 +762,7 @@ class TopicUserContextImpl implements TopicContext // mark that we posted to the topic sql.setLength(0); sql.append("UPDATE topicsettings SET last_post = '").append(SQLUtil.encodeDate(posted_date)); - sql.append("' WHERE topicid = ").append(topicid).append(" AND uid = ").append(conf.realUID()); + sql.append("' WHERE topicid = ").append(topicid).append(" AND uid = ").append(env.getUserID()); sql.append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -784,7 +770,7 @@ class TopicUserContextImpl implements TopicContext { // we had no topicsettings record, add one sql.setLength(0); sql.append("INSERT INTO topicsettings (topicid, uid, last_post) VALUES (").append(topicid); - sql.append(", ").append(conf.realUID()).append(", '").append(SQLUtil.encodeDate(posted_date)); + sql.append(", ").append(env.getUserID()).append(", '").append(SQLUtil.encodeDate(posted_date)); sql.append("');"); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -793,8 +779,8 @@ class TopicUserContextImpl implements TopicContext } // end if // mark that we posted to the conference - conf.touchUpdate(conn,posted_date); - conf.touchPost(conn,posted_date); + env.getConference().touchUpdate(conn,posted_date); + env.getConference().touchPost(conn,posted_date); // Fill in our own local variables to reflect the update. This includes the recalculation // of "unread" based on the new value of "top_message". @@ -814,10 +800,8 @@ class TopicUserContextImpl implements TopicContext } // end finally // record what we did in an audit record - ar = new AuditRecord(AuditRecord.POST_MESSAGE,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic=" - + String.valueOf(topicid) + ",post=" + String.valueOf(new_post_id), - "pseud=" + real_pseud); + ar = env.newAudit(AuditRecord.POST_MESSAGE,"conf=" + env.getConfID() + ",topic=" + topicid + ",post=" + + new_post_id,"pseud=" + real_pseud); } // end try catch (SQLException e) @@ -840,34 +824,33 @@ class TopicUserContextImpl implements TopicContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally // return the new message context - return new TopicMessageUserContextImpl(engine,conf,datapool,new_post_id,parent,new_post_num, - text_linecount,conf.realUID(),posted_date,real_pseud); + return new TopicMessageUserContextImpl(env,new_post_id,parent,new_post_num,text_linecount,env.getUserID(), + posted_date,real_pseud); } // end postMessage public HTMLChecker getPreviewChecker() { - HTMLChecker rc = engine.createCheckerObject(engine.HTMLC_PREVIEW_BODY); - rc.setContextValue("PostLinkDecoderContext",conf.createDecoderContext(topicnum)); + HTMLChecker rc = env.getEngine().createCheckerObject(EngineBackend.HTMLC_PREVIEW_BODY); + rc.setContextValue("PostLinkDecoderContext",env.getConference().createDecoderContext(topicnum)); return rc; } // end getPreviewChecker public boolean canDelete() { - return conf.userCanNuke(); + return env.getConference().userCanNuke(); } // end canDelete public void delete() throws DataException, AccessError { - if (!(conf.userCanNuke())) + if (!(env.getConference().userCanNuke())) { // we can't delete the topic! logger.error("trying to delete w/o permission!"); throw new AccessError("You do not have permission to delete this topic."); @@ -884,7 +867,7 @@ class TopicUserContextImpl implements TopicContext try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // lock some tables while we do the critical parts of the delete @@ -907,7 +890,7 @@ class TopicUserContextImpl implements TopicContext stmt.executeUpdate(sql.toString()); // and indicate that we updated the conference - conf.touchUpdate(conn,new java.util.Date()); + env.getConference().touchUpdate(conn,new java.util.Date()); // determine the number of posts in this topic, and the maximum post ID sql.setLength(0); @@ -930,9 +913,7 @@ class TopicUserContextImpl implements TopicContext } // end finally // record what we did in an audit record - ar = new AuditRecord(AuditRecord.DELETE_TOPIC,conf.realUID(),conf.userRemoteAddress(), - conf.realCommunityID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic=" - + String.valueOf(topicid)); + ar = env.newAudit(AuditRecord.DELETE_TOPIC,"conf=" + env.getConfID() + ",topic=" + topicid); } // end try catch (SQLException e) @@ -955,13 +936,12 @@ class TopicUserContextImpl implements TopicContext } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally // Delete the rest of the gunk in the background; spin off another thread to handle it. - BackgroundTopicPurge purger = new BackgroundTopicPurge(engine,datapool,topicid,post_count,post_max); + BackgroundTopicPurge purger = new BackgroundTopicPurge(env,topicid,post_count,post_max); Thread thrd = new Thread(purger); thrd.setPriority(Thread.NORM_PRIORITY-1); thrd.start(); @@ -974,8 +954,8 @@ class TopicUserContextImpl implements TopicContext ArrayList rc = new ArrayList(); try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to retrieve all posters @@ -1007,8 +987,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1034,8 +1013,8 @@ class TopicUserContextImpl implements TopicContext ArrayList rc = new ArrayList(); try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the SQL statement to retrieve all readers @@ -1067,8 +1046,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1090,7 +1068,7 @@ class TopicUserContextImpl implements TopicContext public boolean isBozo(int other_uid) throws DataException { - if (deleted || conf.userIsAnonymous() || (other_uid==conf.realUID())) + if (deleted || env.getUser().userIsAnonymous() || (other_uid==env.getUserID())) return false; // no-op if (bozo_uids==null) @@ -1098,7 +1076,7 @@ class TopicUserContextImpl implements TopicContext Connection conn = null; try { // load the bozo filter UIDs from the database - conn = datapool.getConnection(); + conn = env.getConnection(); loadBozo(conn); } // end try @@ -1110,8 +1088,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1123,13 +1100,13 @@ class TopicUserContextImpl implements TopicContext public void setBozo(int other_uid, boolean bozo) throws DataException { - if (deleted || conf.userIsAnonymous() || (other_uid==conf.realUID())) + if (deleted || env.getUser().userIsAnonymous() || (other_uid==env.getUserID())) return; // no-op Connection conn = null; try { // figure out what to do here - conn = datapool.getConnection(); + conn = env.getConnection(); refresh(conn); if (deleted) return; // one more check to make sure we're not deleted @@ -1144,7 +1121,7 @@ class TopicUserContextImpl implements TopicContext if (!(bozo_uids.contains(uid_key))) { // add them to the bozo list sql = new StringBuffer("INSERT INTO topicbozo (topicid, uid, bozo_uid) VALUES ("); - sql.append(topicid).append(", ").append(conf.realUID()).append(", ").append(other_uid).append(");"); + sql.append(topicid).append(", ").append(env.getUserID()).append(", ").append(other_uid).append(");"); stmt = conn.createStatement(); stmt.executeUpdate(sql.toString()); bozo_uids.add(uid_key); @@ -1158,7 +1135,7 @@ class TopicUserContextImpl implements TopicContext if (bozo_uids.contains(uid_key)) { // remove them from the bozo list sql = new StringBuffer("DELETE FROM topicbozo WHERE topicid = "); - sql.append(topicid).append(" AND uid = ").append(conf.realUID()).append(" AND bozo_uid = "); + sql.append(topicid).append(" AND uid = ").append(env.getUserID()).append(" AND bozo_uid = "); sql.append(other_uid).append(';'); stmt = conn.createStatement(); stmt.executeUpdate(sql.toString()); @@ -1178,8 +1155,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1190,13 +1166,13 @@ class TopicUserContextImpl implements TopicContext // 1. You can't set bozo filters on a deleted topic. // 2. You can't set bozo filters if you're the anonymous user. // 3. You can't bozo-filter yourself, silly. - return !(deleted || conf.userIsAnonymous() || (other_uid==conf.realUID())); + return !(deleted || env.getUser().userIsAnonymous() || (other_uid==env.getUserID())); } // end canSetBozoFilter public List getBozos() throws DataException { - if (deleted || conf.userIsAnonymous()) + if (deleted || env.getUser().userIsAnonymous()) return Collections.EMPTY_LIST; // no-op if (bozo_uids==null) @@ -1204,7 +1180,7 @@ class TopicUserContextImpl implements TopicContext Connection conn = null; try { // load the bozo filter UIDs from the database - conn = datapool.getConnection(); + conn = env.getConnection(); loadBozo(conn); } // end try @@ -1216,8 +1192,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1232,18 +1207,16 @@ class TopicUserContextImpl implements TopicContext *-------------------------------------------------------------------------------- */ - static List getTopicList(EngineBackend engine, ConferenceBackend conf, DataPool datapool, int get_option, - int sort_option) throws DataException + static List getTopicList(EnvConference env, int get_option, int sort_option) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getTopicList for conf # " + String.valueOf(conf.realConfID()) + ", user #" - + String.valueOf(conf.realUID())); + logger.debug("getTopicList for conf # " + env.getConfID() + ", user #" + env.getUserID()); ArrayList rc = new ArrayList(); // return from this function Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Figure out what the "where" clause of the SQL statement will be. This is in addition to a @@ -1352,7 +1325,7 @@ class TopicUserContextImpl implements TopicContext if (get_option==ConferenceContext.DISPLAY_ACTIVE) sql.append(", SIGN(t.top_message - IFNULL(s.last_message,-1)) AS newflag"); sql.append(" FROM topics t LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = "); - sql.append(conf.realUID()).append(" WHERE t.confid = ").append(conf.realConfID()); + sql.append(env.getUserID()).append(" WHERE t.confid = ").append(env.getConfID()); if (where_clause!=null) sql.append(" AND ").append(where_clause); sql.append(" ORDER BY "); @@ -1368,10 +1341,10 @@ class TopicUserContextImpl implements TopicContext while (rs.next()) { // create the returned objects and add them to the vector TopicContext top = - new TopicUserContextImpl(engine,conf,datapool,rs.getInt(1),rs.getShort(2),rs.getInt(3), - rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6), - SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8), - rs.getString(9),rs.getBoolean(10),rs.getInt(11)); + new TopicUserContextImpl(env,rs.getInt(1),rs.getShort(2),rs.getInt(3),rs.getInt(4), + rs.getBoolean(5),rs.getBoolean(6),SQLUtil.getFullDateTime(rs,7), + SQLUtil.getFullDateTime(rs,8),rs.getString(9),rs.getBoolean(10), + rs.getInt(11)); rc.add(top); } // end while @@ -1385,8 +1358,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1394,27 +1366,25 @@ class TopicUserContextImpl implements TopicContext } // end getTopicList - static TopicContext getTopicByID(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - int topicid) throws DataException + static TopicContext getTopicByID(EnvConference env, int topicid) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getTopicByID for topic # " + String.valueOf(topicid) + ", user #" - + String.valueOf(conf.realUID())); + logger.debug("getTopicByID for topic # " + topicid + ", user #" + env.getUserID()); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Query the dtabase by topic ID. - ResultSet rs = queryByTopic(stmt,topicid,conf.realUID()); + ResultSet rs = queryByTopic(stmt,topicid,env.getUserID()); if (rs.next()) // found it! - return new TopicUserContextImpl(engine,conf,datapool,topicid,rs.getShort(2),rs.getInt(3), - rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6), - SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8), - rs.getString(9),rs.getBoolean(10),rs.getInt(11)); + return new TopicUserContextImpl(env,topicid,rs.getShort(2),rs.getInt(3),rs.getInt(4),rs.getBoolean(5), + rs.getBoolean(6),SQLUtil.getFullDateTime(rs,7), + SQLUtil.getFullDateTime(rs,8),rs.getString(9),rs.getBoolean(10), + rs.getInt(11)); // else fall out and return null } // end try @@ -1426,8 +1396,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1435,18 +1404,17 @@ class TopicUserContextImpl implements TopicContext } // end getTopicByID - static TopicContext getTopicByNumber(EngineBackend engine, ConferenceBackend conf, DataPool datapool, - short topicnum) throws DataException + static TopicContext getTopicByNumber(EnvConference env, short topicnum) throws DataException { if (logger.isDebugEnabled()) - logger.debug("getTopicByNumber for topic # " + String.valueOf(topicnum) + ", conf # " - + String.valueOf(conf.realConfID()) + ", user #" + String.valueOf(conf.realUID())); + logger.debug("getTopicByNumber for topic # " + topicnum + ", conf # " + env.getConfID() + ", user #" + + env.getUserID()); Connection conn = null; // pooled database connection try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // Build the database query. @@ -1455,7 +1423,7 @@ class TopicUserContextImpl implements TopicContext + "t.createdate, t.lastupdate, t.name, IFNULL(s.hidden,0) AS hidden, " + "(t.top_message - IFNULL(s.last_message,-1)) AS unread FROM topics t " + "LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = "); - sql.append(conf.realUID()).append(" WHERE t.confid = ").append(conf.realConfID()); + sql.append(env.getUserID()).append(" WHERE t.confid = ").append(env.getConfID()); sql.append(" AND t.num = ").append(topicnum).append(';'); if (logger.isDebugEnabled()) logger.debug("SQL: " + sql.toString()); @@ -1463,10 +1431,10 @@ class TopicUserContextImpl implements TopicContext // Now pass this query off to the database! ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) // found it! - return new TopicUserContextImpl(engine,conf,datapool,rs.getInt(1),topicnum,rs.getInt(3), - rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6), - SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8), - rs.getString(9),rs.getBoolean(10),rs.getInt(11)); + return new TopicUserContextImpl(env,rs.getInt(1),topicnum,rs.getInt(3),rs.getInt(4),rs.getBoolean(5), + rs.getBoolean(6),SQLUtil.getFullDateTime(rs,7), + SQLUtil.getFullDateTime(rs,8),rs.getString(9),rs.getBoolean(10), + rs.getInt(11)); // else fall out and return null } // end try @@ -1478,8 +1446,7 @@ class TopicUserContextImpl implements TopicContext } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/UserContextImpl.java b/src/com/silverwrist/venice/core/impl/UserContextImpl.java index e1eb241..b906bc5 100644 --- a/src/com/silverwrist/venice/core/impl/UserContextImpl.java +++ b/src/com/silverwrist/venice/core/impl/UserContextImpl.java @@ -23,6 +23,7 @@ import org.apache.log4j.*; import com.silverwrist.util.*; import com.silverwrist.venice.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.security.PasswordHash; import com.silverwrist.venice.security.Capability; @@ -54,8 +55,7 @@ class UserContextImpl implements UserContext, UserBackend *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // the back end of the engine - private DataPool datapool; // the data pool used by this object + private EnvUser env; // the environment store private String remote_addr; // remote address identifier private int uid = -1; // the user ID we're using private int contactid; // ID of our contact information @@ -80,10 +80,9 @@ class UserContextImpl implements UserContext, UserBackend *-------------------------------------------------------------------------------- */ - UserContextImpl(EngineBackend engine, DataPool datapool) + UserContextImpl(EnvEngine env) { - this.engine = engine; - this.datapool = datapool; + this.env = new EnvUser(env,this); } // end constructor @@ -131,7 +130,7 @@ class UserContextImpl implements UserContext, UserBackend try { // call through to lower level function - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM userprefs WHERE uid = " + uid + ";"); @@ -170,8 +169,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -183,7 +181,7 @@ class UserContextImpl implements UserContext, UserBackend logger.debug("sendEmailConfirmation(): sending to \"" + my_email + "\""); // Create the message to be sent. - String message = engine.getStockMessage("email-confirm"); + String message = env.getEngine().getStockMessage("email-confirm"); if (message==null) { // no message defined? oy! logger.error("internal error condition: email-confirm stock message not defined"); @@ -197,12 +195,12 @@ class UserContextImpl implements UserContext, UserBackend vars.put("confnum",String.valueOf(confirm_num)); message = StringUtil.replaceAllVariables(message,vars); - String subject = engine.getStockMessage("email-confirm-subject"); + String subject = env.getEngine().getStockMessage("email-confirm-subject"); if (subject==null) subject = "Venice Email Confirmation"; // Create the emailer and send the message. - SimpleEmailer emailer = engine.createEmailer(); + Emailer emailer = env.getEngine().createEmailer(); emailer.setTo(my_email); emailer.setSubject(subject); emailer.setText(message); @@ -276,7 +274,7 @@ class UserContextImpl implements UserContext, UserBackend Connection conn = null; try { // get a connection and create a statement - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); @@ -298,8 +296,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -390,7 +387,7 @@ class UserContextImpl implements UserContext, UserBackend try { // look for a user name matching this user record - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '" + SQLUtil.encodeString(username) + "';"); @@ -474,8 +471,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -499,7 +495,7 @@ class UserContextImpl implements UserContext, UserBackend { // the confirmation number is wrong logger.warn("...confirmation number incorrect"); ar = new AuditRecord(AuditRecord.VERIFY_FAIL,uid,remote_addr,"Invalid confirmation number"); - engine.saveAuditRecord(ar); + env.getEngine().saveAuditRecord(ar); throw new AccessError("Confirmation number is incorrect. Please try again."); } // end if @@ -508,7 +504,7 @@ class UserContextImpl implements UserContext, UserBackend try { // get a connection and set the user's status to reflect the verification - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 1, base_lvl = "); sql.append(DefaultLevels.afterEmailVerification()).append(" WHERE uid = ").append(uid).append(';'); @@ -543,8 +539,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -569,11 +564,11 @@ class UserContextImpl implements UserContext, UserBackend AuditRecord ar = null; try { // need to change the user's email confirmation number first - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // generate new confirmation number - int new_confirm_num = engine.getNewConfirmationNumber(); + int new_confirm_num = env.getEngine().getNewConfirmationNumber(); // create an SQL statement to reset the user account information, and execute it StringBuffer sql = new StringBuffer("UPDATE users SET email_confnum = "); @@ -609,8 +604,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -623,7 +617,7 @@ class UserContextImpl implements UserContext, UserBackend ContactInfoImpl rc; if (contactid>=0) - rc = new ContactInfoImpl(datapool,contactid); + rc = new ContactInfoImpl(env,contactid); else rc = new ContactInfoImpl(uid); if (my_email==null) @@ -662,7 +656,7 @@ class UserContextImpl implements UserContext, UserBackend try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Stashable obj = (Stashable)ci; // save the contact information @@ -694,7 +688,7 @@ class UserContextImpl implements UserContext, UserBackend logger.debug("email address changed, need to reconfirm"); // generate new confirmation number - int new_confirm_num = engine.getNewConfirmationNumber(); + int new_confirm_num = env.getEngine().getNewConfirmationNumber(); // create an SQL statement to reset the user account information, and execute it StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = "); @@ -744,8 +738,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -761,8 +754,8 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); - UserProfileImpl prof = new UserProfileImpl(engine,this,conn,xusername, + conn = env.getConnection(); + UserProfileImpl prof = new UserProfileImpl(env,conn,xusername, Capability.canSeeHiddenContactFields(level)); if (logger.isDebugEnabled()) logger.debug("...found it!"); @@ -777,8 +770,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -792,8 +784,8 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); - UserProfileImpl prof = new UserProfileImpl(engine,this,conn,xuid, + conn = env.getConnection(); + UserProfileImpl prof = new UserProfileImpl(env,conn,xuid, Capability.canSeeHiddenContactFields(level)); if (logger.isDebugEnabled()) logger.debug("...found it!"); @@ -808,8 +800,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -829,7 +820,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); PasswordHash phash = new PasswordHash(password); StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '"); @@ -861,8 +852,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -881,7 +871,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET description = '"); sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';'); @@ -898,8 +888,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -907,75 +896,74 @@ class UserContextImpl implements UserContext, UserBackend public List getMemberCommunities() throws DataException { - return CommunityUserContextImpl.getMemberCommunityEntries(engine,this,datapool); + return CommunityUserContextImpl.getMemberCommunityEntries(env); } // end getMemberCommunities public CommunityContext getCommunityContext(int cid) throws DataException { - return CommunityUserContextImpl.getCommunityContext(engine,this,datapool,cid); + return CommunityUserContextImpl.getCommunityContext(env,cid); } // end getCommunityContext public CommunityContext getCommunityContext(String alias) throws DataException { - return CommunityUserContextImpl.getCommunityContext(engine,this,datapool,alias); + return CommunityUserContextImpl.getCommunityContext(env,alias); } // end getCommunityContext public List getRootCategoryList() throws DataException { - return CategoryDescriptorImpl.getTopLevelCategoryList(datapool,Capability.hideHiddenCategories(level)); + return CategoryDescriptorImpl.getTopLevelCategoryList(env,Capability.hideHiddenCategories(level)); } // end getRootCategoryList public CategoryDescriptor getCategoryDescriptor(int catid) throws DataException { - return new CategoryDescriptorImpl(datapool,catid,Capability.hideHiddenCategories(level)); + return new CategoryDescriptorImpl(env,catid,Capability.hideHiddenCategories(level)); } // end getCategoryDescriptor public List searchForCommunities(int field, int mode, String term, int offset, int count) throws DataException { - return CommunityUserContextImpl.searchForCommunities(engine,this,datapool,field,mode,term,offset,count); + return CommunityUserContextImpl.searchForCommunities(env,field,mode,term,offset,count); } // end searchForCommunities public int getSearchCommunityCount(int field, int mode, String term) throws DataException { - return CommunityUserContextImpl.getSearchCommunityCount(this,datapool,field,mode,term); + return CommunityUserContextImpl.getSearchCommunityCount(env,field,mode,term); } // end getSearchCommunityCount public List getCommunitiesInCategory(int catid, int offset, int count) throws DataException { - return CommunityUserContextImpl.getCommunitiesInCategory(engine,this,datapool,catid,offset,count); + return CommunityUserContextImpl.getCommunitiesInCategory(env,catid,offset,count); } // end getCommunitiesInCategory public List getCommunitiesInCategory(CategoryDescriptor cat, int offset, int count) throws DataException { - return CommunityUserContextImpl.getCommunitiesInCategory(engine,this,datapool,cat.getLinkedCategoryID(), - offset,count); + return CommunityUserContextImpl.getCommunitiesInCategory(env,cat.getLinkedCategoryID(),offset,count); } // end getCommunitiesInCategory public int getNumCommunitiesInCategory(int catid) throws DataException { - return CommunityUserContextImpl.getNumCommunitiesInCategory(this,datapool,catid); + return CommunityUserContextImpl.getNumCommunitiesInCategory(env,catid); } // end getNumCommunitiessInCategory public int getNumCommunitiesInCategory(CategoryDescriptor cat) throws DataException { - return CommunityUserContextImpl.getNumCommunitiesInCategory(this,datapool,cat.getLinkedCategoryID()); + return CommunityUserContextImpl.getNumCommunitiesInCategory(env,cat.getLinkedCategoryID()); } // end getNumCommunitiesInCategory public List searchForCategories(int mode, String term, int offset, int count) throws DataException { - return CategoryDescriptorImpl.searchForCategories(datapool,Capability.hideHiddenCategories(level), + return CategoryDescriptorImpl.searchForCategories(env,Capability.hideHiddenCategories(level), Capability.showHiddenSearchCategories(level),mode, term,offset,count); @@ -983,7 +971,7 @@ class UserContextImpl implements UserContext, UserBackend public int getSearchCategoryCount(int mode, String term) throws DataException { - return CategoryDescriptorImpl.getSearchCategoryCount(datapool,Capability.hideHiddenCategories(level), + return CategoryDescriptorImpl.getSearchCategoryCount(env,Capability.hideHiddenCategories(level), Capability.showHiddenSearchCategories(level), mode,term); @@ -1001,11 +989,11 @@ class UserContextImpl implements UserContext, UserBackend boolean hide_search = (hide_mode==CommunityContext.HIDE_BOTH); // Create the new community's database entries and internal data. - CommunityData new_comm = CommunityCoreData.createCommunity(engine,this,datapool,name,alias,uid,language, - synopsis,rules,joinkey,hide_dir,hide_search); + CommunityData new_comm = CommunityCoreData.createCommunity(env,name,alias,uid,language,synopsis,rules, + joinkey,hide_dir,hide_search); // Create the community context we return to the user. - CommunityContext rc = new CommunityUserContextImpl(engine,this,datapool,new_comm); + CommunityContext rc = new CommunityUserContextImpl(env,new_comm); // And that's it! You expected lightning bolts maybe? :-) @@ -1015,7 +1003,7 @@ class UserContextImpl implements UserContext, UserBackend public boolean canCreateCommunity() { - return (level>=engine.getParamInt(EngineBackend.IP_CREATECOMMUNITYLVL)); + return (level>=env.getEngine().getParamInt(EngineBackend.IP_CREATECOMMUNITYLVL)); } // end canCreateCommunity @@ -1026,7 +1014,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // retrieve the necessary rows from the sideboxes table @@ -1034,8 +1022,9 @@ class UserContextImpl implements UserContext, UserBackend + " ORDER BY sequence;"); while (rs.next()) { // create the implementation objects and return them all - SideBoxDescriptor sbd = new SideBoxDescriptorImpl(uid,engine.getMasterSideBoxDescriptor(rs.getInt(1)), - datapool,rs.getInt(2)); + SideBoxDescriptor sbd = + new SideBoxDescriptorImpl(env,env.getEngine().getMasterSideBoxDescriptor(rs.getInt(1)), + rs.getInt(2)); rc.add(sbd); } // end while @@ -1049,8 +1038,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1060,14 +1048,14 @@ class UserContextImpl implements UserContext, UserBackend public void addSideBox(int id) throws DataException { - if (engine.getMasterSideBoxDescriptor(id)==null) + if (env.getEngine().getMasterSideBoxDescriptor(id)==null) throw new DataException("invalid sidebox ID: " + id); Connection conn = null; try - { // retrieve a connection from the datapool - conn = datapool.getConnection(); + { // retrieve a connection + conn = env.getConnection(); Statement stmt = conn.createStatement(); stmt.executeUpdate("LOCK TABLES sideboxes WRITE;"); @@ -1110,8 +1098,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1119,7 +1106,7 @@ class UserContextImpl implements UserContext, UserBackend public List getConferenceHotlist() throws DataException { - return ConferenceUserContextImpl.getUserHotlist(engine,this,datapool); + return ConferenceUserContextImpl.getUserHotlist(env); } // end getConferenceHotlist @@ -1139,7 +1126,7 @@ class UserContextImpl implements UserContext, UserBackend } // end if // create the return object - return new AdminOperationsImpl(engine,this,datapool); + return new AdminOperationsImpl(env); } // end getAdminInterface @@ -1158,7 +1145,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the update statement @@ -1180,8 +1167,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1202,7 +1188,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); // create the update statement @@ -1224,8 +1210,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1241,12 +1226,12 @@ class UserContextImpl implements UserContext, UserBackend } // end if // Generate a random authentication string and poke it into the database for this user. - String tokenauth = engine.generateRandomAuthString(); + String tokenauth = env.getEngine().generateRandomAuthString(); Connection conn = null; try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE users SET tokenauth = '"); sql.append(tokenauth).append("' WHERE uid = ").append(uid).append(';'); @@ -1261,8 +1246,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1327,7 +1311,7 @@ class UserContextImpl implements UserContext, UserBackend } // end if String pending_auth = token.substring(xstart,xend); - if (!(engine.isValidRandomAuthString(pending_auth))) + if (!(env.getEngine().isValidRandomAuthString(pending_auth))) { // the auth string is not valid by the rules under which it was generated logger.error("Token parse error: invalid auth string value"); return false; @@ -1373,7 +1357,7 @@ class UserContextImpl implements UserContext, UserBackend try { // look for a user record matching this user ID - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE uid = " + pending_uid + ";"); @@ -1451,8 +1435,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end if @@ -1463,7 +1446,7 @@ class UserContextImpl implements UserContext, UserBackend public Advertisement selectAd() { // just get a random ad for now - return AdvertisementImpl.getRandomAd(datapool); + return AdvertisementImpl.getRandomAd(env); } // end selectAd @@ -1589,7 +1572,7 @@ class UserContextImpl implements UserContext, UserBackend try { // retrieve a connection from the data pool - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE is_anon = 1;"); if (!(rs.next())) @@ -1612,8 +1595,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -1643,7 +1625,7 @@ class UserContextImpl implements UserContext, UserBackend try { // get a database connection and call the internal function - conn = datapool.getConnection(); + conn = env.getConnection(); autoJoinCommunities(conn); } // end try @@ -1655,8 +1637,7 @@ class UserContextImpl implements UserContext, UserBackend } // end catch finally { // make sure the connection is released before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally diff --git a/src/com/silverwrist/venice/core/impl/UserProfileImpl.java b/src/com/silverwrist/venice/core/impl/UserProfileImpl.java index b572cb3..e2e58b7 100644 --- a/src/com/silverwrist/venice/core/impl/UserProfileImpl.java +++ b/src/com/silverwrist/venice/core/impl/UserProfileImpl.java @@ -22,6 +22,7 @@ import java.util.*; import org.apache.log4j.*; import com.silverwrist.util.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; class UserProfileImpl implements UserProfile @@ -31,15 +32,14 @@ class UserProfileImpl implements UserProfile *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(UserProfileImpl.class.getName()); + private static Category logger = Category.getInstance(UserProfileImpl.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private EngineBackend engine; // the engine back end - private UserBackend user; // the user that generated this profile + private EnvUser env; // the user environment private int uid; // user ID private String username; // user name private String given_name; // given name ("first name") @@ -72,13 +72,12 @@ class UserProfileImpl implements UserProfile *-------------------------------------------------------------------------------- */ - UserProfileImpl(EngineBackend engine, UserBackend user, Connection conn, String username, boolean override) + UserProfileImpl(EnvUser env, Connection conn, String username, boolean override) throws DataException, SQLException { if (logger.isDebugEnabled()) logger.debug("load UserProfileImpl by name: " + username + " (" + override + ")"); - this.engine = engine; - this.user = user; + this.env = env; // first retrieve from the users table Statement stmt = conn.createStatement(); @@ -106,13 +105,12 @@ class UserProfileImpl implements UserProfile } // end constructor - UserProfileImpl(EngineBackend engine, UserBackend user, Connection conn, int uid, boolean override) + UserProfileImpl(EnvUser env, Connection conn, int uid, boolean override) throws DataException, SQLException { if (logger.isDebugEnabled()) logger.debug("load UserProfileImpl by UID: " + uid + " (" + override + ")"); - this.engine = engine; - this.user = user; + this.env = env; // first retrieve from the users table Statement stmt = conn.createStatement(); @@ -157,7 +155,7 @@ class UserProfileImpl implements UserProfile ResultSet rs = stmt.executeQuery(sql.toString()); if (rs.next()) { // load all the record data - boolean me_anon = user.userIsAnonymous(); + boolean me_anon = env.getUser().userIsAnonymous(); given_name = rs.getString("given_name"); family_name = rs.getString("family_name"); String blort = rs.getString("middle_init"); @@ -405,16 +403,16 @@ class UserProfileImpl implements UserProfile public boolean canSendQuickEmail() { - return !is_anon && !(user.userIsAnonymous()); + return !is_anon && !(env.getUser().userIsAnonymous()); } // end canSendQuickEmail public void sendQuickEmail(String subject, String text) throws AccessError, DataException, EmailException { if (logger.isDebugEnabled()) - logger.debug("Send Quick E-Mail (from uid " + user.realUID() + " to uid " + uid + ")"); + logger.debug("Send Quick E-Mail (from uid " + env.getUserID() + " to uid " + uid + ")"); - if (user.userIsAnonymous()) + if (env.getUser().userIsAnonymous()) { // we can't send quick emails if we're anonymous! logger.error("sending user is not logged in."); throw new AccessError("You must be logged in to send a quick E-mail message."); @@ -430,11 +428,11 @@ class UserProfileImpl implements UserProfile // assemble the full text StringBuffer text_buf = new StringBuffer(text); - text_buf.append("\n\n--\n").append(engine.getStockMessage("signature")); + text_buf.append("\n\n--\n").append(env.getEngine().getStockMessage("signature")); // create the emailer object, fill it in, and send it - SimpleEmailer em = engine.createEmailer(); - em.setFrom(user.realUserName(),user.realEmailAddress()); + Emailer em = env.getEngine().createEmailer(); + em.setFrom(env.getUser().realUserName(),env.getUser().realEmailAddress()); em.setTo(real_email); em.setSubject(subject); em.setText(text_buf.toString()); diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java index 309cdc8..8bf70f2 100644 --- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java +++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java @@ -25,6 +25,7 @@ import org.w3c.dom.*; import com.silverwrist.util.*; import com.silverwrist.util.cache.*; import com.silverwrist.venice.core.*; +import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.db.*; import com.silverwrist.venice.htmlcheck.*; import com.silverwrist.venice.htmlcheck.dict.*; @@ -264,7 +265,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend Integer xcid = (Integer)key; try { // create the desired object - return new CommunityCoreData(VeniceEngineImpl.this,datapool,xcid.intValue()); + return new CommunityCoreData(env,xcid.intValue()); } // end try catch (DataException e) @@ -293,7 +294,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend Integer xconf = (Integer)key; try { // create the desired object - return new ConferenceCoreData(VeniceEngineImpl.this,datapool,xconf.intValue()); + return new ConferenceCoreData(env,xconf.intValue()); } // end try catch (DataException e) @@ -392,7 +393,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend */ private Document config = null; // configuration data - private DataPool datapool = null; // database connection pool + private EnvEngine env = null; // my environment private Random rng; // random number generator private Properties email_props = null; // email properties private javax.mail.Session mailsession = null; // email session object @@ -479,7 +480,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend Connection conn = null; try { // get a database connection - conn = datapool.getConnection(); + conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer(); @@ -529,8 +530,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end catch finally { // make sure we release the connection before we go - if (conn!=null) - datapool.releaseConnection(conn); + env.releaseConnection(conn); } // end finally @@ -651,6 +651,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend this.config = config; + DataPool datapool = null; ArrayList dictionary_tmp; try { // first, verify that this is a valid configuration @@ -847,11 +848,15 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend catch (ConfigException ce) { // before we leave on a ConfigException, nuke the important data this.config = null; - datapool = null; + if (datapool!=null) + datapool.closeAllConnections(); throw ce; } // end catch + // Initialize the environment. + env = new EnvEngine(this,datapool); + for (i=0; i, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; public interface CommunityDataBackend { diff --git a/src/com/silverwrist/venice/core/impl/ConferenceBackend.java b/src/com/silverwrist/venice/core/internals/ConferenceBackend.java similarity index 94% rename from src/com/silverwrist/venice/core/impl/ConferenceBackend.java rename to src/com/silverwrist/venice/core/internals/ConferenceBackend.java index 0b172a4..09542ac 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceBackend.java +++ b/src/com/silverwrist/venice/core/internals/ConferenceBackend.java @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import java.sql.Connection; import java.sql.SQLException; @@ -23,7 +23,7 @@ import java.util.Date; import com.silverwrist.venice.db.PostLinkDecoderContext; import com.silverwrist.venice.core.DataException; -public interface ConferenceBackend extends CommunityBackend +public interface ConferenceBackend { public abstract int realConfID(); diff --git a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContext.java b/src/com/silverwrist/venice/core/internals/ConferenceCommunityContext.java similarity index 79% rename from src/com/silverwrist/venice/core/impl/ConferenceCommunityContext.java rename to src/com/silverwrist/venice/core/internals/ConferenceCommunityContext.java index a46dd80..2d7ec69 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceCommunityContext.java +++ b/src/com/silverwrist/venice/core/internals/ConferenceCommunityContext.java @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import java.sql.Connection; import java.util.Date; @@ -63,20 +63,20 @@ public interface ConferenceCommunityContext public abstract int getDeleteLevel() throws DataException; - public abstract void setSecurityLevels(CommunityBackend comm, int read, int post, int create, int hide, + public abstract void setSecurityLevels(EnvCommunity outer, int read, int post, int create, int hide, int nuke, int change, int delete) throws DataException; - public abstract void setName(CommunityBackend comm, String val) throws DataException; + public abstract void setName(EnvCommunity outer, String val) throws DataException; public abstract void setDescription(String val) throws DataException; - public abstract void addAlias(CommunityBackend comm, String alias) throws DataException; + public abstract void addAlias(EnvCommunity outer, String alias) throws DataException; - public abstract void removeAlias(CommunityBackend comm, String alias) throws DataException; + public abstract void removeAlias(EnvCommunity outer, String alias) throws DataException; - public abstract void setMembership(CommunityBackend comm, int uid, int grant_level) throws DataException; + public abstract void setMembership(EnvCommunity outer, int uid, int grant_level) throws DataException; - public abstract void setCommunityGrantedLevel(CommunityBackend comm, int new_level) throws DataException; + public abstract void setCommunityGrantedLevel(EnvCommunity outer, int new_level) throws DataException; public abstract short getSequence(); @@ -84,13 +84,13 @@ public interface ConferenceCommunityContext public abstract boolean getHideList(); - public abstract void setHideList(CommunityBackend comm, boolean flag) throws DataException; + public abstract void setHideList(EnvCommunity outer, boolean flag) throws DataException; public abstract boolean canHideTopics(int level); public abstract String getAnAlias() throws DataException; - public abstract ReturnTopicInfo createNewTopic(CommunityBackend comm, String title, String pseud, + public abstract ReturnTopicInfo createNewTopic(EnvCommunity outer, String title, String pseud, String body) throws DataException; public abstract boolean canScribblePosts(int level); @@ -107,7 +107,7 @@ public interface ConferenceCommunityContext public abstract boolean canDeleteConference(int level); - public abstract void delete(UserBackend user) throws DataException; + public abstract void delete(EnvCommunity outer) throws DataException; public abstract boolean displayPostPictures(); diff --git a/src/com/silverwrist/venice/core/impl/ConferenceData.java b/src/com/silverwrist/venice/core/internals/ConferenceData.java similarity index 82% rename from src/com/silverwrist/venice/core/impl/ConferenceData.java rename to src/com/silverwrist/venice/core/internals/ConferenceData.java index e9f311e..ca4a66c 100644 --- a/src/com/silverwrist/venice/core/impl/ConferenceData.java +++ b/src/com/silverwrist/venice/core/internals/ConferenceData.java @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import java.sql.Connection; import java.util.Date; @@ -61,24 +61,24 @@ public interface ConferenceData public abstract int getDeleteLevel(); - public abstract void setSecurityLevels(CommunityBackend comm, int read, int post, int create, int hide, + public abstract void setSecurityLevels(EnvCommunity outer, int read, int post, int create, int hide, int nuke, int change, int delete) throws DataException; - public abstract void setName(CommunityBackend comm, String val) throws DataException; + public abstract void setName(EnvCommunity outer, String val) throws DataException; public abstract void setDescription(String val) throws DataException; - public abstract void addAlias(CommunityBackend comm, String alias) throws DataException; + public abstract void addAlias(EnvCommunity outer, String alias) throws DataException; - public abstract void removeAlias(CommunityBackend comm, String alias) throws DataException; + public abstract void removeAlias(EnvCommunity outer, String alias) throws DataException; - public abstract void setMembership(CommunityBackend comm, int uid, int grant_level) throws DataException; + public abstract void setMembership(EnvCommunity outer, int uid, int grant_level) throws DataException; public abstract boolean canHideTopics(int level); public abstract String getAnAlias() throws DataException; - public abstract ReturnTopicInfo createNewTopic(CommunityBackend comm, String title, String pseud, + public abstract ReturnTopicInfo createNewTopic(EnvCommunity outer, String title, String pseud, String body, int body_lines) throws DataException; public abstract boolean canScribblePosts(int level); @@ -101,7 +101,7 @@ public interface ConferenceData public abstract boolean canDeleteConference(int level); - public abstract void delete(UserBackend user, int the_cid) throws DataException; + public abstract void delete(EnvCommunity outer) throws DataException; public abstract boolean displayPostPictures(); diff --git a/src/com/silverwrist/venice/core/internals/Emailer.java b/src/com/silverwrist/venice/core/internals/Emailer.java new file mode 100644 index 0000000..fab1597 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/Emailer.java @@ -0,0 +1,34 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +import com.silverwrist.venice.core.EmailException; + +public interface Emailer +{ + public abstract void setTo(String to) throws EmailException; + + public abstract void setFrom(String from_name, String from_addr) throws EmailException; + + public abstract void setSubject(String subject); + + public abstract void setText(String text); + + public abstract void send() throws EmailException; + +} // end interface Emailer diff --git a/src/com/silverwrist/venice/core/impl/EngineBackend.java b/src/com/silverwrist/venice/core/internals/EngineBackend.java similarity index 94% rename from src/com/silverwrist/venice/core/impl/EngineBackend.java rename to src/com/silverwrist/venice/core/internals/EngineBackend.java index 63c9d99..f03f116 100644 --- a/src/com/silverwrist/venice/core/impl/EngineBackend.java +++ b/src/com/silverwrist/venice/core/internals/EngineBackend.java @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import java.util.BitSet; import java.util.List; @@ -24,6 +24,7 @@ import com.silverwrist.venice.htmlcheck.HTMLChecker; import com.silverwrist.venice.core.DataException; import com.silverwrist.venice.core.GlobalProperties; import com.silverwrist.venice.core.SideBoxDescriptor; +import com.silverwrist.venice.core.TopicMessageContext; public interface EngineBackend { @@ -47,7 +48,7 @@ public interface EngineBackend // Boolean parameter indexes public static final int BP_POSTPICTURES = 0; - public abstract SimpleEmailer createEmailer(); + public abstract Emailer createEmailer(); public abstract String getStockMessage(String key); @@ -93,7 +94,7 @@ public interface EngineBackend public abstract void startPublish(); - public abstract void publishNew(PublishedMessageImpl pubmsg); + public abstract void publishNew(TopicMessageContext pubmsg); public abstract void unpublish(long postid); diff --git a/src/com/silverwrist/venice/core/internals/EnvCommunity.java b/src/com/silverwrist/venice/core/internals/EnvCommunity.java new file mode 100644 index 0000000..5604f31 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvCommunity.java @@ -0,0 +1,105 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +import com.silverwrist.venice.security.AuditRecord; + +public class EnvCommunity extends EnvUser +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private CommunityBackend comm; // the community back end + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvCommunity(EnvUser parent, CommunityBackend comm) + { + super(parent); + this.comm = comm; + + } // end constructor + + protected EnvCommunity(EnvCommunity other) + { + super(other); + this.comm = other.comm; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class EnvUser + *-------------------------------------------------------------------------------- + */ + + public AuditRecord newAudit(int type, String data1, String data2, String data3, String data4) + { + return new AuditRecord(type,super.getUserID(),super.getUser().userRemoteAddress(),getCommunityID(),data1, + data2,data3,data4); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1, String data2, String data3) + { + return new AuditRecord(type,super.getUserID(),super.getUser().userRemoteAddress(),getCommunityID(),data1, + data2,data3); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1, String data2) + { + return new AuditRecord(type,super.getUserID(),super.getUser().userRemoteAddress(),getCommunityID(),data1, + data2); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1) + { + return new AuditRecord(type,super.getUserID(),super.getUser().userRemoteAddress(),getCommunityID(),data1); + + } // end newAudit + + public AuditRecord newAudit(int type) + { + return new AuditRecord(type,super.getUserID(),super.getUser().userRemoteAddress(),getCommunityID()); + + } // end newAudit + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final CommunityBackend getCommunity() + { + return comm; + + } // end getCommunity + + public final int getCommunityID() + { + return comm.realCommunityID(); + + } // end getCommunityID() + +} // end class EnvCommunity diff --git a/src/com/silverwrist/venice/core/internals/EnvCommunityData.java b/src/com/silverwrist/venice/core/internals/EnvCommunityData.java new file mode 100644 index 0000000..dd71223 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvCommunityData.java @@ -0,0 +1,65 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +public class EnvCommunityData extends EnvEngine +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private CommunityDataBackend comm; + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvCommunityData(EnvEngine parent, CommunityDataBackend comm) + { + super(parent); + this.comm = comm; + + } // end constructor + + protected EnvCommunityData(EnvCommunityData other) + { + super(other); + this.comm = other.comm; + + } // end EnvCommunityData + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final CommunityDataBackend getCommunityData() + { + return comm; + + } // end getCommunityData + + public final int getCommunityID() + { + return comm.realCommunityID(); + + } // end getCommunityID + +} // end class EnvCommunityData diff --git a/src/com/silverwrist/venice/core/internals/EnvConference.java b/src/com/silverwrist/venice/core/internals/EnvConference.java new file mode 100644 index 0000000..0831a15 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvConference.java @@ -0,0 +1,66 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +public class EnvConference extends EnvCommunity +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private ConferenceBackend conf; + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvConference(EnvCommunity parent, ConferenceBackend conf) + { + super(parent); + this.conf = conf; + + } // end constructor + + protected EnvConference(EnvConference other) + { + super(other); + this.conf = other.conf; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final ConferenceBackend getConference() + { + return conf; + + } // end getConference + + public final int getConfID() + { + return conf.realConfID(); + + } // end getConfID + +} // end class EnvConference + diff --git a/src/com/silverwrist/venice/core/internals/EnvConferenceCommunity.java b/src/com/silverwrist/venice/core/internals/EnvConferenceCommunity.java new file mode 100644 index 0000000..6d147ce --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvConferenceCommunity.java @@ -0,0 +1,39 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +public class EnvConferenceCommunity extends EnvCommunityData +{ + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvConferenceCommunity(EnvCommunityData parent) + { + super(parent); + + } // end constructor + + protected EnvConferenceCommunity(EnvConferenceCommunity other) + { + super(other); + + } // end constructor + +} // end class EnvConferenceCommunity diff --git a/src/com/silverwrist/venice/core/internals/EnvConferenceData.java b/src/com/silverwrist/venice/core/internals/EnvConferenceData.java new file mode 100644 index 0000000..f34e404 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvConferenceData.java @@ -0,0 +1,39 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +public class EnvConferenceData extends EnvEngine +{ + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvConferenceData(EnvEngine parent) + { + super(parent); + + } // end constructor + + protected EnvConferenceData(EnvConferenceData other) + { + super(other); + + } // end constructor + +} // end class EnvConferenceData diff --git a/src/com/silverwrist/venice/core/internals/EnvEngine.java b/src/com/silverwrist/venice/core/internals/EnvEngine.java new file mode 100644 index 0000000..7215147 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvEngine.java @@ -0,0 +1,83 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +import java.sql.Connection; +import java.sql.SQLException; +import com.silverwrist.venice.db.*; + +public class EnvEngine +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private EngineBackend engine; // the engine + private DataPool datapool; // the database pool + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvEngine(EngineBackend engine, DataPool datapool) + { + this.engine = engine; + this.datapool = datapool; + + } // end constructor + + protected EnvEngine(EnvEngine other) + { + this.engine = other.engine; + this.datapool = other.datapool; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final EngineBackend getEngine() + { + return engine; + + } // end getEngine + + public final DataPool getDataPool() + { + return datapool; + + } // end getDataPool + + public final Connection getConnection() throws SQLException + { + return datapool.getConnection(); + + } // end getConnection + + public final void releaseConnection(Connection c) + { + if (c!=null) + datapool.releaseConnection(c); + + } // end releaseConnection + +} // end class EnvEngine diff --git a/src/com/silverwrist/venice/core/internals/EnvUser.java b/src/com/silverwrist/venice/core/internals/EnvUser.java new file mode 100644 index 0000000..839a9f6 --- /dev/null +++ b/src/com/silverwrist/venice/core/internals/EnvUser.java @@ -0,0 +1,97 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core.internals; + +import com.silverwrist.venice.security.AuditRecord; + +public class EnvUser extends EnvEngine +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private UserBackend user; // the user backend object + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + public EnvUser(EnvEngine parent, UserBackend user) + { + super(parent); + this.user = user; + + } // end constructor + + protected EnvUser(EnvUser other) + { + super(other); + this.user = other.user; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final UserBackend getUser() + { + return user; + + } // end getUser + + public final int getUserID() + { + return user.realUID(); + + } // end getUserID + + public AuditRecord newAudit(int type, String data1, String data2, String data3, String data4) + { + return new AuditRecord(type,getUserID(),user.userRemoteAddress(),data1,data2,data3,data4); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1, String data2, String data3) + { + return new AuditRecord(type,getUserID(),user.userRemoteAddress(),data1,data2,data3); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1, String data2) + { + return new AuditRecord(type,getUserID(),user.userRemoteAddress(),data1,data2); + + } // end newAudit + + public AuditRecord newAudit(int type, String data1) + { + return new AuditRecord(type,getUserID(),user.userRemoteAddress(),data1); + + } // end newAudit + + public AuditRecord newAudit(int type) + { + return new AuditRecord(type,getUserID(),user.userRemoteAddress()); + + } // end newAudit + +} // end class EnvUser diff --git a/src/com/silverwrist/venice/core/impl/ReturnConfSeq.java b/src/com/silverwrist/venice/core/internals/ReturnConfSeq.java similarity index 82% rename from src/com/silverwrist/venice/core/impl/ReturnConfSeq.java rename to src/com/silverwrist/venice/core/internals/ReturnConfSeq.java index e404d88..ebd1ceb 100644 --- a/src/com/silverwrist/venice/core/impl/ReturnConfSeq.java +++ b/src/com/silverwrist/venice/core/internals/ReturnConfSeq.java @@ -15,24 +15,24 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; -class ReturnConfSeq +public final class ReturnConfSeq { /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private ConferenceData conf; - private short sequence; + private ConferenceData conf; // conference being returned + private short sequence; // sequence number of conference /*-------------------------------------------------------------------------------- * Constructor *-------------------------------------------------------------------------------- */ - ReturnConfSeq(ConferenceData conf, short sequence) + public ReturnConfSeq(ConferenceData conf, short sequence) { this.conf = conf; this.sequence = sequence; @@ -44,13 +44,13 @@ class ReturnConfSeq *-------------------------------------------------------------------------------- */ - ConferenceData getConference() + public final ConferenceData getConference() { return conf; } // end getConference - short getSequence() + public final short getSequence() { return sequence; diff --git a/src/com/silverwrist/venice/core/impl/ReturnTopicInfo.java b/src/com/silverwrist/venice/core/internals/ReturnTopicInfo.java similarity index 83% rename from src/com/silverwrist/venice/core/impl/ReturnTopicInfo.java rename to src/com/silverwrist/venice/core/internals/ReturnTopicInfo.java index 2235f85..29dafc4 100644 --- a/src/com/silverwrist/venice/core/impl/ReturnTopicInfo.java +++ b/src/com/silverwrist/venice/core/internals/ReturnTopicInfo.java @@ -15,20 +15,20 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import java.util.Date; -public class ReturnTopicInfo +public final class ReturnTopicInfo { /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private int topic_id; - private short topic_num; - private Date create_date; + private int topic_id; // the topic ID + private short topic_num; // the topic number + private Date create_date; // the creation date /*-------------------------------------------------------------------------------- * Constructor @@ -48,19 +48,19 @@ public class ReturnTopicInfo *-------------------------------------------------------------------------------- */ - public int getTopicID() + public final int getTopicID() { return topic_id; } // end getTopicID - public short getTopicNum() + public final short getTopicNum() { return topic_num; } // end getTopicNum - public Date getCreateDate() + public final Date getCreateDate() { return create_date; diff --git a/src/com/silverwrist/venice/core/impl/UserBackend.java b/src/com/silverwrist/venice/core/internals/UserBackend.java similarity index 96% rename from src/com/silverwrist/venice/core/impl/UserBackend.java rename to src/com/silverwrist/venice/core/internals/UserBackend.java index c80c20b..5c6e841 100644 --- a/src/com/silverwrist/venice/core/impl/UserBackend.java +++ b/src/com/silverwrist/venice/core/internals/UserBackend.java @@ -15,7 +15,7 @@ * * Contributor(s): */ -package com.silverwrist.venice.core.impl; +package com.silverwrist.venice.core.internals; import com.silverwrist.venice.core.DataException; diff --git a/src/com/silverwrist/venice/servlets/format/CDEmailAddressFormField.java b/src/com/silverwrist/venice/servlets/format/CDEmailAddressFormField.java index 1447442..93248d3 100644 --- a/src/com/silverwrist/venice/servlets/format/CDEmailAddressFormField.java +++ b/src/com/silverwrist/venice/servlets/format/CDEmailAddressFormField.java @@ -7,7 +7,7 @@ * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * - * The Original Code is the Venice Web Community System. + * The Original Code is the Venice Web Communities System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are @@ -22,6 +22,11 @@ import com.silverwrist.venice.ValidationException; public class CDEmailAddressFormField extends CDTextFormField { + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + public CDEmailAddressFormField(String name, String caption, String caption2, boolean required, int size, int maxlength) { @@ -35,13 +40,24 @@ public class CDEmailAddressFormField extends CDTextFormField } // end constructor + /*-------------------------------------------------------------------------------- + * Overrides from class CDTextFormField + *-------------------------------------------------------------------------------- + */ + protected void validateContents(String value) throws ValidationException { + super.validateContents(value); if (!IDUtils.isValidEmailAddress(value)) throw new ValidationException("The value of '" + getCaption() + "' must be a correct Internet address."); } // end validateContents + /*-------------------------------------------------------------------------------- + * Implementations from interface CDFormField + *-------------------------------------------------------------------------------- + */ + public Object clone() { return new CDEmailAddressFormField(this); diff --git a/src/com/silverwrist/venice/servlets/format/CDIntegerFormField.java b/src/com/silverwrist/venice/servlets/format/CDIntegerFormField.java index 5e54ad3..339752d 100644 --- a/src/com/silverwrist/venice/servlets/format/CDIntegerFormField.java +++ b/src/com/silverwrist/venice/servlets/format/CDIntegerFormField.java @@ -94,6 +94,7 @@ public class CDIntegerFormField extends CDTextFormField protected void validateContents(String value) throws ValidationException { + super.validateContents(value); try { // convert to an integer and check against range int x = Integer.parseInt(value); diff --git a/src/com/silverwrist/venice/servlets/format/CDTextFormField.java b/src/com/silverwrist/venice/servlets/format/CDTextFormField.java index 04dddcd..24864ba 100644 --- a/src/com/silverwrist/venice/servlets/format/CDTextFormField.java +++ b/src/com/silverwrist/venice/servlets/format/CDTextFormField.java @@ -30,6 +30,7 @@ public class CDTextFormField extends CDBaseFormField private int size; private int maxlength; + private int real_maxlength; /*-------------------------------------------------------------------------------- * Constructors @@ -40,8 +41,9 @@ public class CDTextFormField extends CDBaseFormField int size, int maxlength) { super(name,caption,caption2,required); - this.size = size; - this.maxlength = maxlength; + this.size = Math.max(size,2); + this.maxlength = Math.max(maxlength,2); + this.real_maxlength = maxlength; } // end constructor @@ -50,6 +52,7 @@ public class CDTextFormField extends CDBaseFormField super(other); this.size = other.size; this.maxlength = other.maxlength; + this.real_maxlength = other.real_maxlength; } // end constructor @@ -73,7 +76,11 @@ public class CDTextFormField extends CDBaseFormField } // end renderActualField protected void validateContents(String value) throws ValidationException - { // this is a do-nothing value + { + if (value.length()>real_maxlength) + throw new ValidationException("The value of the '" + getCaption() + "' field must be no longer than " + + real_maxlength + " characters."); + } // end validateContents /*-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/servlets/format/CDVeniceIDFormField.java b/src/com/silverwrist/venice/servlets/format/CDVeniceIDFormField.java index 9de3488..4739eeb 100644 --- a/src/com/silverwrist/venice/servlets/format/CDVeniceIDFormField.java +++ b/src/com/silverwrist/venice/servlets/format/CDVeniceIDFormField.java @@ -47,12 +47,18 @@ public class CDVeniceIDFormField extends CDTextFormField protected void validateContents(String value) throws ValidationException { + super.validateContents(value); if (!IDUtils.isValidVeniceID(value)) throw new ValidationException("There is an invalid character in the '" + getCaption() + "'field. " + "Valid characters are letters, digits, -, _, !, ~, *, ', and $."); } // end validateContents + /*-------------------------------------------------------------------------------- + * Implementations from interface CDFormField + *-------------------------------------------------------------------------------- + */ + public CDFormField duplicate() { return new CDVeniceIDFormField(this);