cmlenz 2002/08/19 04:10:24
Modified: src/stores/org/apache/slide/store/impl/rdbms JDBCStore.java
Log:
More cleanup
Database initialization removed for now
(Preparing to migrate to the new schema)
Revision Changes Path
1.4 +311 -433
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDBCStore.java 19 Aug 2002 08:32:54 -0000 1.3
+++ JDBCStore.java 19 Aug 2002 11:10:23 -0000 1.4
@@ -258,10 +258,12 @@
/**
* Initializes the data source with a set of parameters.
*
- * @param parameters Hashtable containing the parameters' name
- * and associated value
- * @exception ServiceParameterErrorException Incorrect service parameter
- * @exception ServiceParameterMissingException Service parameter missing
+ * @param parameters a Hashtable containing the parameters' name and
+ * associated value
+ * @exception ServiceParameterErrorException a service parameter holds an
+ * invalid value
+ * @exception ServiceParameterMissingException a required parameter is
+ * missing
*/
public void setParameters(Hashtable parameters)
throws ServiceParameterErrorException,
@@ -307,39 +309,26 @@
*/
public synchronized void connect()
throws ServiceConnectionFailedException {
- getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\"",
LOG_CHANNEL, Logger.INFO);
+
+ getLogger().log("Connecting to '" + url + "' as user '" + user + "'",
+ LOG_CHANNEL, Logger.INFO);
try {
- connection = DriverManager.getConnection
- (url, user, password);
+ connection = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
- getLogger().log("Connecting to \"" + url + "\" as user \"" + user + "\"
failed", LOG_CHANNEL, Logger.ERROR);
- getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
+ getLogger().log("Connecting to '" + url + "' as user '" + user +
+ "' failed (" + e.getMessage() + ")", LOG_CHANNEL,
+ Logger.ERROR);
throw new ServiceConnectionFailedException(this, e);
}
-
+
// all updates must be done inside a transaction, no auto commits
try {
connection.setAutoCommit(false);
} catch (SQLException e) {
}
- Statement statement = null;
- try {
- statement = connection.createStatement();
- String[] statements = getDatabaseCreateStatements();
- for (int i=0; i<statements.length ; i++ ) {
- statement.execute(statements[i]);
- }
- // Cloudscape needs a commit on DDL statements (create,...)
- connection.commit();
- } catch (SQLException e) {
- try { connection.rollback(); } catch (SQLException ex) { }
- } finally {
- closeStatement(statement);
- }
-
// we are just connected and are not enlisted
- alreadyEnlisted=false;
+ alreadyEnlisted = false;
}
@@ -351,30 +340,36 @@
*/
public void disconnect()
throws ServiceDisconnectionFailedException {
- getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user +
"\"", LOG_CHANNEL, Logger.INFO);
+
+ getLogger().log("Disconnecting from '" + url + "' as user '" + user +
+ "'", LOG_CHANNEL, Logger.INFO);
try {
- if (connection != null)
+ if (connection != null) {
connection.close();
- connection = null;
+ connection = null;
+ }
} catch (SQLException e) {
- getLogger().log("Disconnecting from \"" + url + "\" as user \"" + user
+ "\" failed", LOG_CHANNEL, Logger.ERROR);
- getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
+ getLogger().log("Disconnecting from '" + url + "' as user '" +
+ user + "' failed (" + e.getMessage() + ")",
+ LOG_CHANNEL, Logger.ERROR);
throw new ServiceDisconnectionFailedException(this, e);
}
}
+
/**
* Tries to reconnect if needed but doesn't report failure.
*/
private synchronized void connectIfNeededAndPossible() {
+
try {
connectIfNeeded();
- }
- catch (Throwable ex) {
+ } catch (Throwable ex) {
// ignore
}
}
-
+
+
/**
* Initializes data source.
* <p/>
@@ -392,34 +387,16 @@
try {
// Loading and registering driver
- token.getLogger().log("Loading and registering driver: " + driver,
LOG_CHANNEL, Logger.INFO);
+ token.getLogger().log("Loading and registering driver '" + driver +
+ "'", LOG_CHANNEL, Logger.INFO);
Class driverClass = Class.forName(driver);
- Driver databaseDriver = (Driver)driverClass.newInstance();
- DriverManager.registerDriver(databaseDriver);
- } catch (ClassNotFoundException e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
- } catch (InstantiationException e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
- } catch (IllegalAccessException e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
- } catch (SQLException e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
- } catch (ClassCastException e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
+ Driver driverInstance = (Driver)driverClass.newInstance();
+ DriverManager.registerDriver(driverInstance);
} catch (Exception e) {
- token.getLogger().log("Loading and registering driver " + driver + "
failed", LOG_CHANNEL, Logger.ERROR);
- token.getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR);
- throw new ServiceInitializationFailedException(this, e.getMessage());
+ token.getLogger().log("Loading and registering driver '" + driver +
+ "' failed (" + e.getMessage() + ")",
+ LOG_CHANNEL, Logger.ERROR);
+ throw new ServiceInitializationFailedException(this, e);
}
}
@@ -431,65 +408,7 @@
*/
public synchronized void reset()
throws ServiceResetFailedException {
- Statement statement = null;
- try {
- connectIfNeeded();
-
- statement = connection.createStatement();
- String s = null;
-
- s = "drop table objects";
- statement.execute(s);
-
- s = "drop table children";
- statement.execute(s);
-
- s = "drop table links";
- statement.execute(s);
-
- s = "drop table permissions";
- statement.execute(s);
-
- s = "drop table locks";
- statement.execute(s);
-
- s = "drop table revisions";
- statement.execute(s);
-
- s = "drop table workingrevision";
- statement.execute(s);
-
- s = "drop table latestrevisions";
- statement.execute(s);
-
- s = "drop table branches";
- statement.execute(s);
-
- s = "drop table revision";
- statement.execute(s);
-
- s = "drop table label";
- statement.execute(s);
-
- s = "drop table property";
- statement.execute(s);
-
- s = "drop table revisioncontent";
- statement.execute(s);
-
- statement.close();
- disconnect();
- } catch (SQLException e) {
- throw new ServiceResetFailedException(this, e.getMessage());
- } catch (ServiceAccessException e) {
- throw new ServiceResetFailedException(this, e.getMessage());
- } catch (ServiceConnectionFailedException e) {
- throw new ServiceResetFailedException(this, e.getMessage());
- } catch (ServiceDisconnectionFailedException e) {
- throw new ServiceResetFailedException(this, e.getMessage());
- } finally {
- closeStatement(statement);
- }
+
}
@@ -508,7 +427,8 @@
}
Statement stmt = connection.createStatement();
stmt.executeQuery("select 1 from objects where uri is null");
- return true; // test executed without throwing an exception
+ // test executed without throwing an exception
+ return true;
} catch (SQLException e) {
throw new ServiceAccessException(this, e);
}
@@ -584,15 +504,15 @@
throws ServiceAccessException, ObjectNotFoundException {
ObjectNode result = null;
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from objects where uri= ?");
- statement.setString(1, uri.toString());
+ stmt.setString(1, uri.toString());
- ResultSet res = statement.executeQuery();
+ ResultSet res = stmt.executeQuery();
// Parsing result set
@@ -606,13 +526,13 @@
throw new ObjectNotFoundException(uri);
}
- closeStatement(statement);
+ closeStatement(stmt);
// Then, retrieve the children
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from children where uri= ?");
- statement.setString(1,uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1,uri.toString());
+ res = stmt.executeQuery();
Vector childrenVector = new Vector();
@@ -621,12 +541,12 @@
// Load each permission
childrenVector.addElement(res.getString(CHILDREN_CHILDURI));
}
- closeStatement(statement);
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from links where linkto= ?");
- statement.setString(1,uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1,uri.toString());
+ res = stmt.executeQuery();
Vector linksVector = new Vector();
@@ -636,20 +556,20 @@
linksVector.addElement(res.getString(LINKS_LINKTO));
}
- closeStatement(statement);
+ closeStatement(stmt);
if (className.equals("org.apache.slide.structure.LinkNode")) {
String linkTo = new String();
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from links where link= ?");
- statement.setString(1,uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1,uri.toString());
+ res = stmt.executeQuery();
if(res.next())
linkTo = res.getString(LINKS_LINKTO);
- closeStatement(statement);
+ closeStatement(stmt);
result = new LinkNode(uri.toString(), childrenVector,
linksVector, linkTo);
@@ -681,7 +601,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
return result;
}
@@ -697,14 +617,14 @@
public void storeObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectNotFoundException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from objects where uri= ?");
- statement.setString(1, uri.toString());
+ stmt.setString(1, uri.toString());
- ResultSet res = statement.executeQuery();
+ ResultSet res = stmt.executeQuery();
// Parsing result set
@@ -712,55 +632,55 @@
throw new ObjectNotFoundException(uri);
}
- closeStatement(statement);
+ closeStatement(stmt);
// Updating children
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from children where uri= ?");
- statement.setString(1, object.getUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, object.getUri());
+ stmt.execute();
+ closeStatement(stmt);
- statement = null;
+ stmt = null;
Enumeration children = object.enumerateChildren();
while (children.hasMoreElements()) {
- if (statement == null){
- statement = connection.prepareStatement
+ if (stmt == null){
+ stmt = connection.prepareStatement
("insert into children values(?, ?)");
}
- statement.setString(1, object.getUri());
- statement.setString(2, (String)children.nextElement());
- statement.execute();
+ stmt.setString(1, object.getUri());
+ stmt.setString(2, (String)children.nextElement());
+ stmt.execute();
}
- closeStatement(statement);
+ closeStatement(stmt);
// Updating inbound links
/*
s = "delete from links where linkto='" + object.getUri() + "'";
- statement.execute(s);
+ stmt.execute(s);
Enumeration links = object.enumerateLinks();
while (children.hasMoreElements()) {
s = "insert into links values('"
+ (String) links.nextElement() + "', '"
+ object.getUri() + "')";
- statement.execute(s);
+ stmt.execute(s);
}
*/
// Updating links
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from links where link= ?");
- statement.setString(1, object.getUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, object.getUri());
+ stmt.execute();
+ closeStatement(stmt);
if (object instanceof LinkNode) {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into links values(?,?)");
- statement.setString(1, object.getUri());
- statement.setString(2, ((LinkNode) object).getLinkedUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, object.getUri());
+ stmt.setString(2, ((LinkNode) object).getLinkedUri());
+ stmt.execute();
+ closeStatement(stmt);
}
} catch (SQLException e) {
@@ -768,7 +688,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -786,17 +706,17 @@
public void createObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectAlreadyExistsException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
String className = object.getClass().getName();
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from objects where uri= ?");
- statement.setString(1, uri.toString());
+ stmt.setString(1, uri.toString());
- ResultSet res = statement.executeQuery();
+ ResultSet res = stmt.executeQuery();
// Parsing result set
@@ -804,29 +724,29 @@
throw new ObjectAlreadyExistsException(uri.toString());
}
- closeStatement(statement);
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into objects values(?,?)");
- statement.setString(1, uri.toString());
- statement.setString(2, className );
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, className );
- statement.execute();
- closeStatement(statement);
+ stmt.execute();
+ closeStatement(stmt);
- statement = null;
+ stmt = null;
// Inserting children
Enumeration children = object.enumerateChildren();
while (children.hasMoreElements()) {
- if (statement == null){
- statement = connection.prepareStatement
+ if (stmt == null){
+ stmt = connection.prepareStatement
("insert into children values(?,?)");
}
- statement.setString(1, uri.toString());
- statement.setString(2, (String) children.nextElement());
- statement.execute();
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, (String) children.nextElement());
+ stmt.execute();
}
- closeStatement(statement);
+ closeStatement(stmt);
// Updating inbound links
/*
@@ -835,18 +755,18 @@
s = "insert into links values('"
+ (String) links.nextElement() + "', '"
+ object.getUri() + "')";
- statement.execute(s);
+ stmt.execute(s);
}
*/
// If the object is a link, also store the link information
if (object instanceof LinkNode) {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into links values(?,?)");
- statement.setString(1, uri.toString());
- statement.setString(2, ((LinkNode) object).getLinkedUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, ((LinkNode) object).getLinkedUri());
+ stmt.execute();
+ closeStatement(stmt);
}
} catch (SQLException e) {
@@ -854,7 +774,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -870,36 +790,36 @@
public void removeObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectNotFoundException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
// Removing object
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from objects where uri= ?");
- statement.setString(1,object.getUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1,object.getUri());
+ stmt.execute();
+ closeStatement(stmt);
// Removing children
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from children where uri=?");
- statement.setString(1, object.getUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, object.getUri());
+ stmt.execute();
+ closeStatement(stmt);
// Removing inbound links
/*
s = "delete from links where linkto='" + object.getUri() + "'";
- statement.execute(s);
+ stmt.execute(s);
*/
// Removing links
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from links where link= ?");
- statement.setString(1, object.getUri());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, object.getUri());
+ stmt.execute();
+ closeStatement(stmt);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
@@ -918,7 +838,7 @@
public void grantPermission(Uri uri, NodePermission permission)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
int inheritable = 0;
@@ -935,21 +855,21 @@
String revisionNumberStr =
(revisionNumber == null) ? null : revisionNumber.toString();
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into permissions values(?,?,?,?,?,?)");
- statement.setString(1, permission.getObjectUri());
- statement.setString(2, revisionNumberStr);
- statement.setString(3, permission.getSubjectUri());
- statement.setString(4, permission.getActionUri());
- statement.setInt(5, inheritable);
- statement.setInt(6, negative);
- statement.execute();
+ stmt.setString(1, permission.getObjectUri());
+ stmt.setString(2, revisionNumberStr);
+ stmt.setString(3, permission.getSubjectUri());
+ stmt.setString(4, permission.getActionUri());
+ stmt.setInt(5, inheritable);
+ stmt.setInt(6, negative);
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -966,31 +886,31 @@
/* Warning changes to this method should also be done to
CloudscapeDescriptorsStore */
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
if(revisionNumber != null) {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from permissions where object= ? and subject = ? and
action = ? and revisionnumber = ? ");
- statement.setString(4, revisionNumber.toString());
+ stmt.setString(4, revisionNumber.toString());
}
else {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from permissions where object = ? and subject = ? and
action = ? and revisionnumber is NULL");
}
- statement.setString(1, permission.getObjectUri());
- statement.setString(2, permission.getSubjectUri());
- statement.setString(3, permission.getActionUri());
+ stmt.setString(1, permission.getObjectUri());
+ stmt.setString(2, permission.getSubjectUri());
+ stmt.setString(3, permission.getActionUri());
- statement.execute();
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1005,20 +925,20 @@
public void revokePermissions(Uri uri)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from permissions where object= ?");
- statement.setString(1, uri.toString());
- statement.execute();
+ stmt.setString(1, uri.toString());
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1034,13 +954,13 @@
throws ServiceAccessException {
Vector permissionVector = new Vector();
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from permissions where object= ?");
- statement.setString(1, uri.toString());
- ResultSet res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ ResultSet res = stmt.executeQuery();
while (res.next()) {
String object = res.getString(PERMISSIONS_OBJECT);
@@ -1067,7 +987,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
return permissionVector.elements();
@@ -1083,7 +1003,7 @@
public void putLock(Uri uri, NodeLock lock)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
int inheritable = 0;
@@ -1096,23 +1016,23 @@
exclusive = 1;
}
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into locks values(?,?,?,?,?,?,?)");
- statement.setString(1, lock.getLockId());
- statement.setString(2, lock.getObjectUri());
- statement.setString(3, lock.getSubjectUri());
- statement.setString(4, lock.getTypeUri());
- statement.setString
+ stmt.setString(1, lock.getLockId());
+ stmt.setString(2, lock.getObjectUri());
+ stmt.setString(3, lock.getSubjectUri());
+ stmt.setString(4, lock.getTypeUri());
+ stmt.setString
(5, String.valueOf(lock.getExpirationDate().getTime()));
- statement.setInt(6,inheritable);
- statement.setInt(7, exclusive);
- statement.execute();
+ stmt.setInt(6,inheritable);
+ stmt.setInt(7, exclusive);
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1128,7 +1048,7 @@
public void renewLock(Uri uri, NodeLock lock)
throws ServiceAccessException, LockTokenNotFoundException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
@@ -1142,30 +1062,30 @@
exclusive = 1;
}
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from locks where id=?");
- statement.setString(1, lock.getLockId());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, lock.getLockId());
+ stmt.execute();
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into locks values(?,?,?,?,?,?,?)");
- statement.setString(1, lock.getLockId());
- statement.setString(2, lock.getObjectUri());
- statement.setString(3, lock.getSubjectUri());
- statement.setString(4, lock.getTypeUri());
- statement.setString
+ stmt.setString(1, lock.getLockId());
+ stmt.setString(2, lock.getObjectUri());
+ stmt.setString(3, lock.getSubjectUri());
+ stmt.setString(4, lock.getTypeUri());
+ stmt.setString
(5, String.valueOf(lock.getExpirationDate().getTime()));
- statement.setInt(6, inheritable);
- statement.setInt(7, exclusive);
- statement.execute();
+ stmt.setInt(6, inheritable);
+ stmt.setInt(7, exclusive);
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1181,11 +1101,11 @@
public void removeLock(Uri uri, NodeLock lock)
throws ServiceAccessException, LockTokenNotFoundException {
- Statement statement = null;
+ Statement stmt = null;
try {
- statement = connection.createStatement();
+ stmt = connection.createStatement();
int inheritable = 0;
if (lock.isInheritable()) {
@@ -1195,14 +1115,14 @@
String s = null;
s = "delete from locks where id='" + lock.getLockId() + "'";
- statement.execute(s);
+ stmt.execute(s);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1234,15 +1154,15 @@
throws ServiceAccessException {
Vector lockVector = new Vector();
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from locks where object= ?");
- statement.setString(1, uri.toString());
- statement.execute();
- ResultSet res = statement.getResultSet();
+ stmt.setString(1, uri.toString());
+ stmt.execute();
+ ResultSet res = stmt.getResultSet();
while (res.next()) {
Date expirationDate = null;
@@ -1269,7 +1189,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
return lockVector.elements();
}
@@ -1287,8 +1207,8 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
NodeRevisionDescriptors revisionDescriptors = null;
- PreparedStatement statement = null;
- PreparedStatement statement2 = null;
+ PreparedStatement stmt = null;
+ PreparedStatement stmt2 = null;
try {
ResultSet res = null;
@@ -1299,10 +1219,10 @@
Hashtable branches = new Hashtable();
boolean isVersioned = false;
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from revisions where uri= ?");
- statement.setString(1, uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ res = stmt.executeQuery();
if (res.next()) {
int isVersionedInt = res.getInt(REVISIONS_ISVERSIONED);
@@ -1313,23 +1233,23 @@
throw new RevisionDescriptorNotFoundException(uri.toString());
}
- closeStatement(statement);
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from workingrevision where uri= ?");
- statement.setString(1, uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ res = stmt.executeQuery();
while(res.next()) {
// TODO : Parse each working revision definition
}
- closeStatement(statement);
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from latestrevisions where uri=?");
- statement.setString(1, uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ res = stmt.executeQuery();
while(res.next()) {
latestRevisionNumbers
@@ -1337,24 +1257,24 @@
new NodeRevisionNumber
(res.getString(LATESTREVISIONS_NUMBER)));
}
- closeStatement(statement);
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from revision where uri= ?");
- statement.setString(1, uri.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ res = stmt.executeQuery();
while(res.next()) {
String currentRevisionNumber = res.getString(REVISION_NUMBER);
// We parse the revision list of the object
- if (statement2 == null){
- statement2 = connection.prepareStatement
+ if (stmt2 == null){
+ stmt2 = connection.prepareStatement
("select * from branches where uri = ? and xnumber = ?");
}
- statement2.setString(1, uri.toString());
- statement2.setString(2, currentRevisionNumber);
- ResultSet res2 = statement2.executeQuery();
+ stmt2.setString(1, uri.toString());
+ stmt2.setString(2, currentRevisionNumber);
+ ResultSet res2 = stmt2.executeQuery();
Vector childList = new Vector();
while (res2.next()) {
@@ -1367,7 +1287,7 @@
res2.close();
}
- closeStatement(statement2);
+ closeStatement(stmt2);
revisionDescriptors = new NodeRevisionDescriptors
(uri.toString(), initialRevision, workingRevisions,
@@ -1378,8 +1298,8 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
- closeStatement(statement2);
+ closeStatement(stmt);
+ closeStatement(stmt2);
}
return revisionDescriptors;
}
@@ -1399,7 +1319,7 @@
// TODO : Here, we have the option of "cleaning up" before
// creating the new records in the database.
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
ResultSet res = null;
@@ -1411,14 +1331,14 @@
isVersioned = 1;
}
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into revisions values(?,?,?)");
- statement.setString(1,uri.toString());
- statement.setInt(2, isVersioned);
- statement.setString
+ stmt.setString(1,uri.toString());
+ stmt.setInt(2, isVersioned);
+ stmt.setString
(3, revisionDescriptors.getInitialRevision().toString());
- statement.execute();
- closeStatement(statement);
+ stmt.execute();
+ closeStatement(stmt);
// Creating records in working revisions table
// ... TODO (working revisions are not used for now)
@@ -1427,15 +1347,15 @@
// For now, only the latest revision from the main branch is stored
if (revisionDescriptors.getLatestRevision() != null) {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into latestrevisions values(?,?,?)");
- statement.setString(1, uri.toString());
- statement.setString
+ stmt.setString(1, uri.toString());
+ stmt.setString
(2, NodeRevisionDescriptors.MAIN_BRANCH.toString());
- statement.setString
+ stmt.setString
(3, revisionDescriptors.getLatestRevision().toString());
- statement.execute();
- closeStatement(statement);
+ stmt.execute();
+ closeStatement(stmt);
}
// Creating records in the branches table
@@ -1446,7 +1366,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1480,40 +1400,40 @@
public void removeRevisionDescriptors(Uri uri)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from revisions where uri= ?");
- statement.setString(1, uri.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.execute();
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from workingrevision where uri= ?");
- statement.setString(1, uri.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.execute();
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from latestrevisions where uri= ?");
- statement.setString(1, uri.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.execute();
+ closeStatement(stmt);
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from branches where uri= ?");
- statement.setString(1, uri.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.execute();
+ closeStatement(stmt);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1530,7 +1450,7 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
NodeRevisionDescriptor revisionDescriptor = null;
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
if(revisionNumber == null)
throw new RevisionDescriptorNotFoundException(uri.toString());
@@ -1546,11 +1466,11 @@
// Retrieving branch name (and also check that revision
// does indeed exist)
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from revision where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, revisionNumber.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, revisionNumber.toString());
+ res = stmt.executeQuery();
if (res.next()) {
branchName = res.getString(REVISION_BRANCHNAME);
@@ -1558,29 +1478,29 @@
throw new RevisionDescriptorNotFoundException(uri.toString());
}
- closeStatement(statement);
+ closeStatement(stmt);
// Retrieve labels
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from label where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, revisionNumber.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, revisionNumber.toString());
+ res = stmt.executeQuery();
while (res.next()) {
labels.addElement(res.getString(LABEL_LABEL));
}
- closeStatement(statement);
+ closeStatement(stmt);
// Retrieve properties
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("select * from property where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, revisionNumber.toString());
- res = statement.executeQuery();
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, revisionNumber.toString());
+ res = stmt.executeQuery();
while (res.next()) {
String propertyName = res.getString(PROPERTY_NAME);
@@ -1603,7 +1523,7 @@
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
return revisionDescriptor;
@@ -1621,39 +1541,39 @@
(Uri uri, NodeRevisionDescriptor revisionDescriptor)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
ResultSet res = null;
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("insert into revision values(?, ?, ?)");
- statement.setString(1, uri.toString());
- statement.setString
+ stmt.setString(1, uri.toString());
+ stmt.setString
(2, revisionDescriptor.getRevisionNumber().toString());
- statement.setString(3, revisionDescriptor.getBranchName());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(3, revisionDescriptor.getBranchName());
+ stmt.execute();
+ closeStatement(stmt);
// Creating revision labels
- statement = null;
+ stmt = null;
Enumeration labels = revisionDescriptor.enumerateLabels();
while (labels.hasMoreElements()) {
- if (statement == null){
- statement = connection.prepareStatement
+ if (stmt == null){
+ stmt = connection.prepareStatement
("insert into label values(?,?,?)");
}
- statement.setString(1, uri.toString());
- statement.setString
+ stmt.setString(1, uri.toString());
+ stmt.setString
(2, revisionDescriptor.getRevisionNumber().toString());
- statement.setString(3, (String)labels.nextElement());
- statement.execute();
+ stmt.setString(3, (String)labels.nextElement());
+ stmt.execute();
}
- closeStatement(statement);
+ closeStatement(stmt);
// Creating associated properties
- statement = null;
+ stmt = null;
Enumeration properties = revisionDescriptor.enumerateProperties();
while (properties.hasMoreElements()) {
NodeProperty property =
@@ -1662,28 +1582,28 @@
if (property.isProtected()) {
protectedProperty = 1;
}
- if (statement == null){
- statement = connection.prepareStatement
+ if (stmt == null){
+ stmt = connection.prepareStatement
("insert into property values(?,?,?,?,?,?,?)");
}
- statement.setString(1, uri.toString());
- statement.setString
+ stmt.setString(1, uri.toString());
+ stmt.setString
(2, revisionDescriptor.getRevisionNumber().toString());
- statement.setString(3, property.getName());
- statement.setString(4, property.getValue().toString());
- statement.setString(5, property.getNamespace());
- statement.setString(6, property.getType());
- statement.setInt(7, protectedProperty);
- statement.execute();
+ stmt.setString(3, property.getName());
+ stmt.setString(4, property.getValue().toString());
+ stmt.setString(5, property.getNamespace());
+ stmt.setString(6, property.getType());
+ stmt.setInt(7, protectedProperty);
+ stmt.execute();
}
- closeStatement(statement);
+ closeStatement(stmt);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1717,40 +1637,40 @@
public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number)
throws ServiceAccessException {
- PreparedStatement statement = null;
+ PreparedStatement stmt = null;
try {
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from revision where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, number.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, number.toString());
+ stmt.execute();
+ closeStatement(stmt);
// Removing revision labels
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from label where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, number.toString());
- statement.execute();
- closeStatement(statement);
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, number.toString());
+ stmt.execute();
+ closeStatement(stmt);
// Removing associated properties
- statement = connection.prepareStatement
+ stmt = connection.prepareStatement
("delete from property where uri= ? and xnumber = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, number.toString());
- statement.execute();
+ stmt.setString(1, uri.toString());
+ stmt.setString(2, number.toString());
+ stmt.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
connectIfNeededAndPossible();
throw new ServiceAccessException(this, e);
} finally {
- closeStatement(statement);
+ closeStatement(stmt);
}
}
@@ -1801,7 +1721,7 @@
result.setContent(is);
// this input stream passes on the closure of itself onto the
- // jdbc statement and resultSet
+ // jdbc stmt and resultSet
result.setContent( new JDBCAwareInputStream(is,selectStatement) );
} catch (SQLException e) {
@@ -1980,12 +1900,12 @@
/**
- * Close specified statement.
+ * Close specified stmt.
*/
- private void closeStatement(Statement statement) {
- if (statement != null) {
+ private void closeStatement(Statement stmt) {
+ if (stmt != null) {
try {
- statement.close();
+ stmt.close();
} catch (SQLException e) {
connectIfNeededAndPossible();
}
@@ -2084,48 +2004,6 @@
deleteStatement.executeUpdate();
deleteStatement.close();
- }
-
-
- /**
- * Returns the sql statements to create the database objects.
- */
- private String[] getDatabaseCreateStatements() {
-
- String[] statements = {
- "create table objects(uri varchar(65536) primary key," +
- " classname varchar(4096))",
- "create table children(uri varchar(65536), " +
- " childuri varchar(65536))",
- "create table links(link varchar(65536), " +
- " linkto varchar(65536))",
- "create table permissions(object varchar(65536)," +
- " revisionnumber varchar(20), " +
- " subject varchar(65536), action varchar(65536), " +
- " inheritable int, negative int)",
- "create table locks(id varchar(65536), object varchar(4096)," +
- " subject varchar(4096), type varchar(4096), " +
- " expirationdate varchar(15), inheritable int, " +
- " xexclusive int)",
- "create table revisions(uri varchar(65536) primary key, " +
- " isversioned int, initialrevision varchar(10))",
- "create table workingrevision(uri varchar(65536), " +
- " baserevision varchar(20), xnumber varchar(20))",
- "create table latestrevisions(uri varchar(65536), " +
- " branchname varchar(4096), xnumber varchar(20))",
- "create table branches(uri varchar(65536), xnumber varchar(20)," +
- " childnumber varchar(20))",
- "create table revision(uri varchar(65536), xnumber varchar(20)," +
- " branchname varchar(4096))",
- "create table label(uri varchar(65536), xnumber varchar(20)," +
- " label varchar(4096))",
- "create table property(uri varchar(65536), xnumber varchar(20)," +
- " name varchar(4096), value varchar(65536), " +
- " namespace varchar(4096), type varchar(100), private int)",
- "create table revisioncontent(uri varchar(65536), " +
- " xnumber varchar(20), content LONGVARBINARY)"};
-
- return statements;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>