cmlenz 2002/08/21 02:51:27
Modified: src/stores/org/apache/slide/store/impl/rdbms JDBCStore.java
Log:
Here we go again for the LockStore implementation methods...
More cleanup: variable naming, StringBuffer reuse, etc
No functional changes
Revision Changes Path
1.9 +60 -69
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/JDBCStore.java
Index: JDBCStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/JDBCStore.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JDBCStore.java 21 Aug 2002 09:35:27 -0000 1.8
+++ JDBCStore.java 21 Aug 2002 09:51:27 -0000 1.9
@@ -918,7 +918,7 @@
public Enumeration enumeratePermissions(Uri uri)
throws ServiceAccessException {
- Vector permissions = new Vector();
+ Vector result = new Vector();
Statement stmt = null;
StringBuffer sql = new StringBuffer();
try {
@@ -939,9 +939,9 @@
NodePermission permission =
new NodePermission(uri.toString(), revision, subject,
action, inheritable, negative);
- permissions.addElement(permission);
+ result.addElement(permission);
}
-
+
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
@@ -956,7 +956,7 @@
}
}
- return permissions.elements();
+ return result.elements();
}
@@ -973,34 +973,36 @@
throws ServiceAccessException {
Statement stmt = null;
-
+ StringBuffer sql = new StringBuffer();
try {
stmt = connection.createStatement();
-
- StringBuffer sql =
- new StringBuffer("insert into LOCKS (LOCK_ID,OBJECT_ID,");
- sql.append("SUBJECT_ID,TYPE_ID,EXPIRATION_DATE,");
- sql.append("IS_INHERITABLE,IS_EXCLUSIVE) values( ");
- long in_lockid = getUriId(lock.getLockId());
- if (in_lockid == 0 ) {
+
+ long lockId = getUriId(lock.getLockId());
+ if (lockId == 0 ) {
setUriId(lock.getLockId());
- in_lockid = getUriId(lock.getLockId());
+ lockId = getUriId(lock.getLockId());
}
- sql.append(in_lockid).append(", ");
- sql.append(getUriId(lock.getObjectUri())).append(", ");
- sql.append(getUriId(lock.getSubjectUri())).append(", ");
- sql.append(getUriId(lock.getTypeUri())).append(", ");
- sql.append(lock.getExpirationDate().getTime()).append(", ");
- sql.append(lock.isInheritable()).append(", ");
- sql.append(lock.isExclusive()).append(" ) ");
- stmt.execute(sql.toString());
+
+ sql.setLength(0);
+ sql.append("INSERT INTO LOCKS (LOCK_ID, OBJECT_ID, SUBJECT_ID, ")
+ .append("TYPE_ID, EXPIRATION_DATE, IS_INHERITABLE, ")
+ .append("IS_EXCLUSIVE) VALUES (").append(lockId).append(", ")
+ .append(getUriId(lock.getObjectUri())).append(", ")
+ .append(getUriId(lock.getSubjectUri())).append(", ")
+ .append(getUriId(lock.getTypeUri())).append(", ")
+ .append(lock.getExpirationDate().getTime()).append(", ")
+ .append(lock.isInheritable()).append(", ")
+ .append(lock.isExclusive()).append(")");
+ stmt.executeUpdate(sql.toString());
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
try {
- stmt.close();
+ if (stmt != null) {
+ stmt.close();
+ }
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
@@ -1011,9 +1013,9 @@
/**
- * Renew a lock.
+ * Refresh a lock.
*
- * @param lock Token to renew
+ * @param lock the lock to renew
* @exception ServiceAccessException Service access error
* @exception LockTokenNotFoundException Lock token was not found
*/
@@ -1021,8 +1023,8 @@
throws ServiceAccessException, LockTokenNotFoundException {
try {
- if (!isLockExist(getUriId(lock.getLockId())) ) {
- putLock(uri,lock);
+ if (!isLockExist(getUriId(lock.getLockId()))) {
+ putLock(uri, lock);
}
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
@@ -1042,33 +1044,27 @@
throws ServiceAccessException, LockTokenNotFoundException {
Statement stmt = null;
-
+ StringBuffer sql = new StringBuffer();
try {
-
stmt = connection.createStatement();
+
+ long lockId = getUriId(lock.getLockId());
- int inheritable = 0;
- if (lock.isInheritable()) {
- inheritable = 1;
- }
-
- StringBuffer sql =
- new StringBuffer("delete from LOCKS where LOCK_ID= '");
- long in_lock = getUriId(lock.getLockId());
- sql.append(in_lock).append("'");
- stmt.execute(sql.toString());
- stmt.execute("delete from URI where URI_ID = " + 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));
+ sql.setLength(0);
+ sql.append("DELETE FROM LOCKS WHERE LOCK_ID = ")
+ .append(lockId);
+ stmt.executeUpdate(sql.toString());
+
+ removeUri(lock.getLockId());
+
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
try {
- stmt.close();
+ if (stmt != null) {
+ stmt.close();
+ }
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
@@ -1089,7 +1085,6 @@
throws ServiceAccessException, LockTokenNotFoundException {
removeLock(uri, lock);
-
}
@@ -1103,39 +1098,34 @@
public Enumeration enumerateLocks(Uri uri)
throws ServiceAccessException {
- Vector lockVector = new Vector();
+ Vector result = new Vector();
Statement stmt = null;
-
+ StringBuffer sql = new StringBuffer();
try {
-
stmt = connection.createStatement();
-
- StringBuffer sql =
- new StringBuffer("select * from LOCKS where OBJECT_ID= ");
- sql.append(getUriId(uri.toString()));
-
+
+ sql.setLength(0);
+ sql.append("SELECT * FROM LOCKS WHERE OBJECT_ID = ")
+ .append(getUriId(uri.toString()));
ResultSet rs = stmt.executeQuery(sql.toString());
-
while (rs.next()) {
Date expirationDate = null;
try {
- Long timeValue = new Long(rs.getLong
- ("EXPIRATION_DATE"));
- expirationDate = new Date(timeValue.longValue());
+ long timeValue = rs.getLong("EXPIRATION_DATE");
+ expirationDate = new Date(timeValue);
} catch (NumberFormatException e) {
expirationDate = new Date();
}
- NodeLock lock =
- new NodeLock(getUri(rs.getLong("LOCK_ID")),
- getUri(rs.getLong("OBJECT_ID")),
- getUri(rs.getLong("SUBJECT_ID")),
- getUri(rs.getLong("TYPE_ID")),
- expirationDate,
- rs.getBoolean("IS_INHERITABLE"),
- rs.getBoolean("IS_EXCLUSIVE"));
- lockVector.addElement(lock);
+ NodeLock lock = new NodeLock(getUri(rs.getLong("LOCK_ID")),
+ getUri(rs.getLong("OBJECT_ID")),
+ getUri(rs.getLong("SUBJECT_ID")),
+ getUri(rs.getLong("TYPE_ID")),
+ expirationDate,
+ rs.getBoolean("IS_INHERITABLE"),
+ rs.getBoolean("IS_EXCLUSIVE"));
+ result.addElement(lock);
}
-
+
} catch (SQLException e) {
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
@@ -1147,7 +1137,8 @@
throw new ServiceAccessException(this, e);
}
}
- return lockVector.elements();
+
+ return result.elements();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>