cmlenz 2002/08/08 14:12:12
Modified: src/stores/org/apache/slide/store/impl/rdbms
J2EEDescriptorsStore.java J2EEStore.java
J2EEContentStore.java
Log:
- Moved the methods for handling the URI/URI-ID mapping cache into
the common base class J2EEStore
- Various cleanup
Revision Changes Path
1.3 +52 -136
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEDescriptorsStore.java
Index: J2EEDescriptorsStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEDescriptorsStore.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- J2EEDescriptorsStore.java 8 Aug 2002 15:21:51 -0000 1.2
+++ J2EEDescriptorsStore.java 8 Aug 2002 21:12:12 -0000 1.3
@@ -128,7 +128,7 @@
try {
- long currentUriID = this.getURIID(uri.toString());
+ long currentUriID = this.getUriId(uri.toString());
statement = connection.createStatement();
if (currentUriID == 0) {
@@ -252,7 +252,7 @@
try {
- long uriid = this.getURIID( uri.toString());
+ long uriid = this.getUriId( uri.toString());
statement = connection.createStatement();
StringBuffer theSQL = new StringBuffer
@@ -268,7 +268,7 @@
}
- long parent = this.getURIID(object.getUri());
+ long parent = this.getUriId(object.getUri());
Enumeration children =
getNewChildren(parent,object.enumerateChildren());
if (children != null) {
@@ -276,7 +276,7 @@
theSQL = new StringBuffer("insert into
CHILDREN ");
theSQL.append("(URI_ID,CHILD_URI_ID) values(
");
theSQL.append(parent).append(" , ")
-
.append(this.getURIID((String)children.nextElement()))
+
.append(this.getUriId((String)children.nextElement()))
.append(")");
statement.execute(theSQL.toString());
}
@@ -284,7 +284,7 @@
// Updating link
if (object instanceof LinkNode) {
- long link_to = this.getURIID
+ long link_to = this.getUriId
(((LinkNode) object).getLinkedUri());
if (! this.isLinkExist(parent,link_to)) {
theSQL = new StringBuffer("insert into LINKS (URI_ID,");
@@ -326,8 +326,8 @@
Connection connection = getCurrentConnection();
try {
- this.setURIID(uri.toString());
- long uriid = this.getURIID( uri.toString());
+ this.setUriId(uri.toString());
+ long uriid = this.getUriId( uri.toString());
String className = object.getClass().getName();
@@ -360,7 +360,7 @@
theSQL = new StringBuffer("insert into
CHILDREN ");
theSQL.append("(URI_ID,CHILD_URI_ID) values(
");
theSQL.append(uriid).append(" , ")
-
.append(this.getURIID((String)children.nextElement()))
+
.append(this.getUriId((String)children.nextElement()))
.append(" )");
statement.execute(theSQL.toString());
}
@@ -368,7 +368,7 @@
// If the object is a link, also store the link information
if (object instanceof LinkNode) {
- long link_to = this.getURIID
+ long link_to = this.getUriId
(((LinkNode) object).getLinkedUri());
if (! this.isLinkExist(uriid,link_to)) {
theSQL = new StringBuffer("insert into LINKS
(URI_ID,");
@@ -406,7 +406,7 @@
try {
- long uriid = this.getURIID(object.getUri());
+ long uriid = this.getUriId(object.getUri());
Statement statement = null;
Connection connection = getCurrentConnection();
@@ -448,8 +448,8 @@
theSQL.append(uriid);
statement.execute(theSQL.toString());
- super.uriIdLookup.remove(object.getUri());
- super.uriLookup.remove(new Long(uriid));
+ removeUri(object.getUri());
+
statement.close();
} catch (SQLException e) {
@@ -476,12 +476,12 @@
NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
String revisionNumberStr =
(revisionNumber == null) ? "NULL" : revisionNumber.toString();
- this.setURIID(permission.getObjectUri());
- this.setURIID(permission.getSubjectUri());
- this.setURIID(permission.getActionUri());
- long objid = this.getURIID(permission.getObjectUri());
- long subid = this.getURIID(permission.getSubjectUri());
- long actid = this.getURIID(permission.getActionUri());
+ this.setUriId(permission.getObjectUri());
+ this.setUriId(permission.getSubjectUri());
+ this.setUriId(permission.getActionUri());
+ long objid = this.getUriId(permission.getObjectUri());
+ long subid = this.getUriId(permission.getSubjectUri());
+ long actid = this.getUriId(permission.getActionUri());
StringBuffer theSQL = new StringBuffer("select 1 from
PERMISSIONS");
theSQL.append(" where OBJECT_ID = ");
@@ -534,11 +534,11 @@
NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
StringBuffer theSQL = new StringBuffer("delete from
PERMISSIONS ");
theSQL.append("where OBJECT_ID= ");
- theSQL.append(this.getURIID(permission.getObjectUri()))
+ theSQL.append(this.getUriId(permission.getObjectUri()))
.append(" and SUBJECT_ID = ")
- .append(this.getURIID(permission.getSubjectUri()))
+ .append(this.getUriId(permission.getSubjectUri()))
.append(" and ACTION_ID = " )
- .append(this.getURIID(permission.getActionUri()));
+ .append(this.getUriId(permission.getActionUri()));
if(revisionNumber != null) {
statement.execute(theSQL.append(" and VERSION_NO = ")
@@ -580,7 +580,7 @@
statement = connection.createStatement();
StringBuffer theSQL = new StringBuffer("delete from
PERMISSIONS");
theSQL.append(" where OBJECT_ID= ");
- theSQL.append(this.getURIID(uri.toString()));
+ theSQL.append(this.getUriId(uri.toString()));
statement.execute(theSQL.toString());
} catch (SQLException e) {
@@ -616,18 +616,18 @@
StringBuffer theSQL = new StringBuffer("select * from
PERMISSIONS ");
theSQL.append("where OBJECT_ID = ");
- theSQL.append(this.getURIID(uri.toString()));
+ theSQL.append(this.getUriId(uri.toString()));
statement.execute(theSQL.toString());
ResultSet res = statement.executeQuery(theSQL.toString());
String object = null;
while (res.next()) {
if (object == null) {
- object = this.getURIString(res.getLong("OBJECT_ID"));
+ object = this.getUri(res.getLong("OBJECT_ID"));
}
String revision = res.getString("VERSION_NO");
- String subject = this.getURIString(res.getLong("SUBJECT_ID"));
- String action = this.getURIString(res.getLong("ACTION_ID"));
+ String subject = this.getUri(res.getLong("SUBJECT_ID"));
+ String action = this.getUri(res.getLong("ACTION_ID"));
boolean inheritable = res.getBoolean("IS_INHERITABLE");
boolean negative = res.getBoolean("IS_NEGATIVE");
@@ -672,15 +672,15 @@
new StringBuffer("insert into LOCKS
(LOCK_ID,OBJECT_ID,");
theSQL.append("SUBJECT_ID,TYPE_ID,EXPIRATION_DATE,");
theSQL.append("IS_INHERITABLE,IS_EXCLUSIVE) values( ");
- long in_lockid = this.getURIID(lock.getLockId());
+ long in_lockid = this.getUriId(lock.getLockId());
if (in_lockid == 0 ) {
- this.setURIID(lock.getLockId());
- in_lockid = this.getURIID(lock.getLockId());
+ this.setUriId(lock.getLockId());
+ in_lockid = this.getUriId(lock.getLockId());
}
theSQL.append(in_lockid).append(", ");
- theSQL.append(this.getURIID(lock.getObjectUri())).append(", ");
- theSQL.append(this.getURIID(lock.getSubjectUri())).append(",
");
- theSQL.append(this.getURIID(lock.getTypeUri())).append(", ");
+ theSQL.append(this.getUriId(lock.getObjectUri())).append(", ");
+ theSQL.append(this.getUriId(lock.getSubjectUri())).append(",
");
+ theSQL.append(this.getUriId(lock.getTypeUri())).append(", ");
theSQL.append(lock.getExpirationDate().getTime()).append(", ");
theSQL.append(lock.isInheritable()).append(", ");
theSQL.append(lock.isExclusive()).append(" ) ");
@@ -712,7 +712,7 @@
throws ServiceAccessException, LockTokenNotFoundException {
try {
- if (! isLockExist(this.getURIID(lock.getLockId())) ) {
+ if (! isLockExist(this.getUriId(lock.getLockId())) ) {
this.putLock(uri,lock);
}
} catch (SQLException e) {
@@ -746,12 +746,15 @@
StringBuffer theSQL =
new StringBuffer("delete from LOCKS where
LOCK_ID= '");
- long in_lock = this.getURIID(lock.getLockId());
+ long in_lock = this.getUriId(lock.getLockId());
theSQL.append(in_lock).append("'");
statement.execute(theSQL.toString());
statement.execute("delete from URI where URI_ID = " + in_lock);
- super.uriIdLookup.remove(lock.getLockId());
- super.uriLookup.remove(new Long(in_lock));
+
+ // Lock-IDs shouldn't go into the URI table I think, need to fix
+ // that in some other places to
+// super.uriIdLookup.remove(lock.getLockId());
+// super.uriLookup.remove(new Long(in_lock));
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
@@ -802,7 +805,7 @@
StringBuffer theSQL =
new StringBuffer("select * from LOCKS where
OBJECT_ID= ");
- theSQL.append(this.getURIID(uri.toString()));
+ theSQL.append(this.getUriId(uri.toString()));
ResultSet res = statement.executeQuery(theSQL.toString());
@@ -816,10 +819,10 @@
expirationDate = new Date();
}
NodeLock lock =
- new NodeLock(this.getURIString(res.getLong("LOCK_ID")),
- this.getURIString(res.getLong("OBJECT_ID")),
- this.getURIString(res.getLong("SUBJECT_ID")),
- this.getURIString(res.getLong("TYPE_ID")),
+ new NodeLock(this.getUri(res.getLong("LOCK_ID")),
+ this.getUri(res.getLong("OBJECT_ID")),
+ this.getUri(res.getLong("SUBJECT_ID")),
+ this.getUri(res.getLong("TYPE_ID")),
expirationDate,
res.getBoolean("IS_INHERITABLE"),
res.getBoolean("IS_EXCLUSIVE"));
@@ -865,7 +868,7 @@
Hashtable latestRevisionNumbers = new Hashtable();
Hashtable branches = new Hashtable();
boolean isVersioned = false;
- long uriid = this.getURIID( uri.toString());
+ long uriid = this.getUriId( uri.toString());
statement = connection.createStatement();
statement2 = connection.createStatement();
StringBuffer theSQL =
@@ -963,7 +966,7 @@
if (revisionDescriptors.isVersioned()) {
isVersioned = 1;
}
- long urid = this.getURIID(uri.toString());
+ long urid = this.getUriId(uri.toString());
statement = connection.createStatement();
StringBuffer theSQL =
@@ -1053,7 +1056,7 @@
Connection connection = getCurrentConnection();
try {
- long uriid = this.getURIID(uri.toString());
+ long uriid = this.getUriId(uri.toString());
ResultSet res = null;
statement = connection.createStatement();
StringBuffer theSQL = new StringBuffer
@@ -1103,7 +1106,7 @@
try {
ResultSet res = null;
- long uriid = this.getURIID(uri.toString());
+ long uriid = this.getUriId(uri.toString());
String branchName = null;
Vector labels = new Vector();
Hashtable properties = new Hashtable();
@@ -1196,7 +1199,7 @@
try {
ResultSet res = null;
- long uriid = this.getURIID(uri.toString());
+ long uriid = this.getUriId(uri.toString());
long brid =
this.getBranchID(revisionDescriptor.getBranchName());
if (brid == 0 ) {
this.setBranchID(revisionDescriptor.getBranchName());
@@ -1328,7 +1331,7 @@
try {
statement = connection.createStatement();
- long uriid = this.getURIID(uri.toString());
+ long uriid = this.getUriId(uri.toString());
String revisionNumberStr =
(revisionNumber == null) ? "NULL" :
revisionNumber.toString();
String branchStr = null;
@@ -1368,95 +1371,8 @@
// ------------------------------------------------------ Protected Methods
- /**
- * Retrieve the URI ID For the URI.
- */
-
- protected long getURIID(String revisionUri)
- throws SQLException {
-
- Long urivalue = (Long)super.uriIdLookup.get(revisionUri);
- if (urivalue == null) {
- Connection connection = getCurrentConnection();
-
- Statement getStatement = connection.createStatement();
- StringBuffer theSQL = new StringBuffer("select URI_ID from
URI");
- theSQL.append(" where URI_STRING = '");
- theSQL.append(revisionUri).append("'");
- ResultSet rslt = getStatement.executeQuery(theSQL.toString());
- if (rslt.next()) {
- long uriid = rslt.getLong("URI_ID");
- if (super.uriIdLookup.size() == 2000) {
- super.uriIdLookup.clear();
- super.uriLookup.clear();
- }
- rslt.close();
- super.uriIdLookup.put(revisionUri,new Long(uriid));
- super.uriLookup.put(new Long(uriid),revisionUri);
- return uriid;
- } else {
- return 0;
- }
- } else {
- return urivalue.longValue();
- }
- }
-
-
- /**
- * Retrieve the URI Name.
- */
-
- protected String getURIString(long revisionUriID)
- throws SQLException {
-
- Long uri_key = new Long(revisionUriID);
- String URI_String = (String)super.uriLookup.get(uri_key);
-
- if (URI_String == null) {
- Connection connection = getCurrentConnection();
-
- Statement getStatement = connection.createStatement();
- StringBuffer theSQL = new StringBuffer
- ("select URI_STRING from URI where
URI_ID = ");
- theSQL.append(revisionUriID);
- ResultSet rslt = getStatement.executeQuery(theSQL.toString());
- if (rslt.next()) {
- URI_String = rslt.getString("URI_STRING");
- if (super.uriLookup.size() == 2000) {
- super.uriLookup.clear();
- super.uriIdLookup.clear();
- }
- rslt.close();
- super.uriLookup.put(uri_key,URI_String);
- super.uriIdLookup.put(URI_String,uri_key);
- } else {
- return null;
- }
- }
- return URI_String;
- }
-
-
- /**
- * Add the URI.
- */
-
- protected void setURIID(String revisionUri)
- throws SQLException {
-
- if (this.getURIID(revisionUri) == 0 ) {
- Connection connection = getCurrentConnection();
- Statement addStatement = connection.createStatement();
- StringBuffer theSQL = new StringBuffer
- ("insert into URI (URI_STRING)
values ('");
- theSQL.append(revisionUri).append("')");
- addStatement.execute(theSQL.toString());
- addStatement.close();
- }
- }
-
-
+
+
/**
* Retrieve the Branch ID For the given Branch.
*/
1.2 +238 -85
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEStore.java
Index: J2EEStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- J2EEStore.java 7 Aug 2002 18:49:49 -0000 1.1
+++ J2EEStore.java 8 Aug 2002 21:12:12 -0000 1.2
@@ -64,7 +64,9 @@
package org.apache.slide.store.impl.rdbms;
import java.sql.Connection;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Hashtable;
import javax.naming.Context;
@@ -91,17 +93,69 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Smith</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ashok Kumar</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
* @version $Revision$
*/
-
public abstract class J2EEStore
extends AbstractXAService {
+
+
+ // ---------------------------------------------------------- Inner Classes
+
+
+ /**
+ *
+ */
+ private class TransactionId {
+ Xid xid;
+ int status;
+ boolean rollbackOnly;
+ Connection connection;
+
+ /**
+ * Constructor.
+ */
+ TransactionId(Xid xid, int status) {
+ this.xid = xid;
+ this.status = status;
+ this.rollbackOnly = false;
+
+ try {
+ connection = ds.getConnection();
+ if(connection == null) {
+ connection = globalConnection;
+ return;
+ }
+ if (connection.getAutoCommit()) {
+ connection.setAutoCommit(false);
+ }
+ } catch (SQLException e) {
+ getLogger().log("Couldn't get connection " + e.getMessage(),
+ LOG_CHANNEL, Logger.DEBUG);
+ connection = globalConnection;
+ }
+ }
+ }
+
+
// -------------------------------------------------------------- Constants
- public static final int TX_IDLE = 0;
- public static final int TX_PREPARED = 1;
- public static final int TX_SUSPENDED = 1;
+
+ private static final int TX_IDLE = 0;
+
+
+ private static final int TX_PREPARED = 1;
+
+
+ private static final int TX_SUSPENDED = 1;
+
+
+ /**
+ * Size limit for the caches.
+ */
+ private static final int CACHE_SIZE = 200;
+
// ----------------------------------------------------- Instance Variables
@@ -109,60 +163,92 @@
* Database connection source.
*/
protected DataSource ds;
+
+
+ /**
+ * Value of the datasource parameter.
+ */
protected String datasource;
-
- protected Hashtable connectionMap = new Hashtable();
- // New DB Schema lookup cache
- protected static Hashtable uriIdLookup = new Hashtable(2000); //if u change
the numbers change them
- protected static Hashtable uriLookup = new Hashtable(2000); //also in
J2EE*2.java
- /* A connection used when we aren't associated with a transaction correctly. */
- protected static Connection globalConnection;
+
+ /**
+ * A map of the active connections, keyed by thread.
+ */
+ private Hashtable connectionMap =
+ new Hashtable();
+
+
+ /**
+ * Hashtable used to cache the mapping between URI IDs and the actual URIs.
+ */
+ private static Hashtable uriIdLookup =
+ new Hashtable(CACHE_SIZE);
+
+
+ /**
+ * Hashtable used to cache the mapping between URIs and their IDs.
+ */
+ private static Hashtable uriLookup =
+ new Hashtable(CACHE_SIZE);
+
+
+ /**
+ * A connection used when we aren't associated with a transaction correctly.
+ */
+ private static Connection globalConnection;
+
// -------------------------------------------------------- Service Methods
+
/**
* Initializes the data source with a set of parameters.
*
* @param parameters Hashtable containing the parameters' name
- * and associated value
- * @exception ServiceParameterErrorException Incorrect service parameter
+ * and associated value
+ * @exception ServiceParameterErrorException Incorrect service parameter
* @exception ServiceParameterMissingException Service parameter missing
*/
public void setParameters(Hashtable parameters)
throws ServiceParameterErrorException,
ServiceParameterMissingException {
- // Get the datsource lookup name
- datasource = (String) parameters.get("datasource");
+
+ String value = (String)parameters.get("datasource");
+ if (value == null) {
+ throw new ServiceParameterMissingException(this, "datasource");
+ }
+ datasource = value;
}
/**
- * Connects to JDBC and creates the basic table structure.
+ * Establishes the global connection to the data source.
*
- * @exception ServiceConnectionFailedException Connection to the
- * database failed
+ * @exception ServiceConnectionFailedException if the connection failed
*/
public synchronized void connect()
throws ServiceConnectionFailedException {
- getLogger().log("Trying connect to database", LOG_CHANNEL,
- Logger.DEBUG);
+
+ getLogger().log("Trying connect to data source", LOG_CHANNEL,
+ Logger.DEBUG);
try {
globalConnection = ds.getConnection();
- } catch(SQLException e) {
- getLogger().log("Couldn't get global transaction.", LOG_CHANNEL,
- Logger.ERROR);
+ } catch (SQLException e) {
+ throw new ServiceConnectionFailedException(
+ this, "Couldn't get global connection");
}
- getLogger().log("Done connecting to database. globalConnection is "+
- globalConnection, LOG_CHANNEL, Logger.DEBUG);
+ getLogger().log("Done connecting to database. The global connection is "
+ + globalConnection, LOG_CHANNEL, Logger.DEBUG);
}
/**
- * Returns connection status
+ * Returns connection status.
*/
public boolean isConnected() {
+
try {
- return ds!=null && globalConnection != null &&
!globalConnection.isClosed();
+ return ((ds != null) && (globalConnection != null)
+ && !globalConnection.isClosed());
} catch(SQLException e) {
return false;
}
@@ -170,14 +256,14 @@
/**
- * Disconnects from data source.
+ * Closes the global connection to the data source.
*
- * @exception ServiceDisconnectionFailedException Disconnection
- * from database failed
+ * @exception ServiceDisconnectionFailedException if closing the connection
+ * failed
*/
public void disconnect()
throws ServiceDisconnectionFailedException {
- // This doesn't need to do anything any more.
+
try {
globalConnection.close();
} catch(SQLException e) {
@@ -193,49 +279,46 @@
* <li>Datasource is looked up from the pool</li>
* <li>Creation of the basic tables, if they didn't exist before</li>
*
- * @exception ServiceInitializationFailedException Throws an exception
- * if the data source has already been initialized before
+ * @exception ServiceInitializationFailedException thrown if the data source
+ * has already been initialized before
*/
-
public synchronized void initialize(NamespaceAccessToken token)
throws ServiceInitializationFailedException {
+
try {
-
// Loading and registering driver
- token.getLogger().log("Loading and registering datasource " +
datasource ,LOG_CHANNEL,Logger.INFO);
+ token.getLogger().log("Retrieving datasource '" + datasource + "'",
+ LOG_CHANNEL, Logger.INFO);
// Initialize database
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
- ds = (DataSource) envCtx.lookup(datasource);
- } catch (ClassCastException e) {
- token.getLogger().log("Loading and registering datasource " +
datasource + " failed",LOG_CHANNEL,Logger.ERROR);
- token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
- } catch (NamingException e) {
- token.getLogger().log("Loading and registering datasource " +
datasource + " failed",LOG_CHANNEL,Logger.ERROR);
- token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
+ ds = (DataSource)envCtx.lookup(datasource);
+
} catch (Exception e) {
- token.getLogger().log("Loading and registering datasource " +
datasource+ " failed",LOG_CHANNEL,Logger.ERROR);
+ token.getLogger().log("Retrieving data source instance '" +
+ datasource + "' failed: " + e.getMessage(),
+ LOG_CHANNEL, Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
+ throw new ServiceInitializationFailedException(
+ this, e.getMessage());
}
-
- if(ds == null) {
- token.getLogger().log("Datasource is null, can't initialise store");
- throw new ServiceInitializationFailedException(this, "Null datasource
from context");
+
+ if (ds == null) {
+ throw new ServiceInitializationFailedException(
+ this, "Data source not found");
}
}
/**
- * Deletes data source. Should remove stored data if possible.
+ * Does nothing.
*
* @exception ServiceResetFailedException Reset failed
*/
public synchronized void reset()
throws ServiceResetFailedException {
+
}
@@ -461,24 +544,23 @@
throw new XAException(XAException.XAER_INVAL);
id.status = TX_IDLE;
break;
- }
-
- }
-
+ }
+ }
+
+
// ------------------------------------------------------ Protected Methods
-
/**
* Get the Connection object associated with the current transaction.
*/
-
protected Connection getCurrentConnection() {
getLogger().log("Getting current connection for thread "+
- Thread.currentThread(), LOG_CHANNEL, Logger.DEBUG);
- TransactionId id = (TransactionId)connectionMap.get(Thread.currentThread());
- if(id == null) {
+ Thread.currentThread(), LOG_CHANNEL, Logger.DEBUG);
+ TransactionId id =
+ (TransactionId)connectionMap.get(Thread.currentThread());
+ if (id == null) {
getLogger().log("No id for current thread - called outside
transaction?", LOG_CHANNEL, Logger.DEBUG);
return globalConnection;
}
@@ -493,37 +575,108 @@
getLogger().log("Returning current valid connection from map", LOG_CHANNEL,
Logger.DEBUG);
return conn;
}
+
+
+ /**
+ * Returns the URI ID corresponding to an URI.
+ */
+ protected long getUriId(String uri)
+ throws SQLException {
- protected class TransactionId // made to static protected
- {
- public Xid xid;
- public int status;
- public boolean rollbackOnly;
- Connection connection;
+ Long uriIdLong = (Long)uriIdLookup.get(uri);
+ if (uriIdLong == null) {
+ Connection connection = getCurrentConnection();
+ Statement stmt = connection.createStatement();
+ StringBuffer buf =
+ new StringBuffer("SELECT URI_ID FROM URI ")
+ .append("WHERE URI_STRING = '").append(uri).append("'");
+ ResultSet rs = stmt.executeQuery(buf.toString());
+ if (rs.next()) {
+ long uriId = rs.getLong("URI_ID");
+ if (uriIdLookup.size() == CACHE_SIZE) {
+ uriIdLookup.clear();
+ uriLookup.clear();
+ }
+ rs.close();
+ uriIdLong = new Long(uriId);
+ uriIdLookup.put(uri, uriIdLong);
+ uriLookup.put(uriIdLong, uri);
+ }
+ }
+
+ return (uriIdLong != null) ? uriIdLong.longValue() : 0;
+ }
- public TransactionId(Xid xid, int status) {
- this.xid = xid;
- this.status = status;
- rollbackOnly = false;
- /* Now, fetch a connection from the DataSource */
- try {
- connection = ds.getConnection();
- if(connection == null) {
-// System.out.println("CONNDEBUG: Got null connection from
datasource");
- connection = globalConnection;
- return;
+ /**
+ * Retrieve the URI Name.
+ */
+ protected String getUri(long uriId)
+ throws SQLException {
+
+ Long uriIdLong = new Long(uriId);
+ String uri = (String)uriLookup.get(uriIdLong);
+ if (uri == null) {
+ Connection connection = getCurrentConnection();
+ Statement stmt = connection.createStatement();
+ StringBuffer buf =
+ new StringBuffer("SELECT URI_STRING FROM URI WHERE URI_ID = ")
+ .append(uriId);
+ ResultSet rslt = stmt.executeQuery(buf.toString());
+ if (rslt.next()) {
+ uri = rslt.getString("URI_STRING");
+ if (uriLookup.size() == CACHE_SIZE) {
+ uriLookup.clear();
+ uriIdLookup.clear();
}
- if (connection.getAutoCommit()) {
- connection.setAutoCommit(false);
- }
- } catch(SQLException e) {
- System.out.println("CONNDEBUG: Couldn't get connection:
"+e.getMessage());
- connection = globalConnection;
- e.printStackTrace();
+ rslt.close();
+ uriLookup.put(uriIdLong, uri);
+ uriIdLookup.put(uri, uriIdLong);
}
}
+
+ return uri;
+ }
+
+ /**
+ * Adds the URI into the URI ID table.
+ */
+ protected void setUriId(String uri)
+ throws SQLException {
+
+ if (getUriId(uri) == 0) {
+ Connection connection = getCurrentConnection();
+ Statement stmt = connection.createStatement();
+ StringBuffer buf =
+ new StringBuffer("INSERT INTO URI (URI_STRING) VALUES ('")
+ .append(uri).append("')");
+ stmt.execute(buf.toString());
+ stmt.close();
+ }
+ }
+
+
+ /**
+ *
+ */
+ protected void removeUri(String uri)
+ throws SQLException {
+
+ long uriId = getUriId(uri);
+ if (uriId != 0) {
+ Connection conn = getCurrentConnection();
+ Statement stmt = conn.createStatement();
+ StringBuffer buf =
+ new StringBuffer("DELETE FROM URI WHERE URI_ID = ").append(uri);
+ stmt.execute(buf.toString());
+ stmt.close();
+
+ uriIdLookup.remove(uri);
+ uriLookup.remove(new Long(uriId));
+ }
}
+
}
+
1.3 +8 -42
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEContentStore.java
Index: J2EEContentStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/J2EEContentStore.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- J2EEContentStore.java 8 Aug 2002 10:14:36 -0000 1.2
+++ J2EEContentStore.java 8 Aug 2002 21:12:12 -0000 1.3
@@ -143,7 +143,7 @@
try {
long versionid = this.getVersionID(
-
this.getURIID(revisionUri),
+
this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
selectStatement = connection.createStatement();
@@ -226,7 +226,7 @@
try {
long versionid = this.getVersionID(
-
this.getURIID(revisionUri),
+
this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
@@ -295,7 +295,7 @@
try {
long versionid = this.getVersionID(
- this.getURIID(revisionUri),
+ this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
@@ -360,7 +360,7 @@
try {
long versionid = this.getVersionID(
- this.getURIID(revisionUri),
+ this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
removeContent(versionid);
@@ -384,16 +384,16 @@
Connection connection = getCurrentConnection();
long versionid = this.getVersionID(
- this.getURIID(revisionUri),
+ this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
if (versionid == 0 ) {
this.setVersionID(
- this.getURIID(revisionUri),
+ this.getUriId(revisionUri),
this.getBranchID(revisionDescriptor.getBranchName()),
revisionNumber);
versionid = this.getVersionID(
- this.getURIID(revisionUri),
+ this.getUriId(revisionUri),
revisionDescriptor.getBranchName(),
revisionNumber);
}
@@ -503,41 +503,7 @@
}
- /**
- * Retrieve the URI ID For the URI.
- */
-
- protected long getURIID(String revisionUri)
- throws SQLException {
-
- Long urivalue = (Long)super.uriIdLookup.get(revisionUri);
- if (urivalue == null) {
- Connection connection = getCurrentConnection();
-
- Statement getStatement = connection.createStatement();
- StringBuffer theSQL = new StringBuffer
- ("select URI_ID from URI where URI_STRING = '");
- theSQL.append(revisionUri).append("'");
- ResultSet rslt = getStatement.executeQuery(theSQL.toString());
- if (rslt.next()) {
- long uriid = rslt.getLong("URI_ID");
- // A limit predecided wrt J2EEStore hashmap based cache
- if (super.uriIdLookup.size() == 2000) {
- super.uriIdLookup.clear();
- super.uriLookup.clear();
- }
- rslt.close();
- super.uriIdLookup.put(revisionUri,new Long(uriid));
- super.uriLookup.put(new Long(uriid),revisionUri);
- return uriid;
- } else {
- return 0;
- }
- } else {
- return urivalue.longValue();
- }
- }
-
+
/**
* Get the VersionID for the current URI
*/
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>