ozeigermann 2004/11/11 09:15:35
Modified: src/stores/org/apache/slide/store/impl/rdbms
MySqlRDBMSAdapter.java StandardRDBMSAdapter.java
MySql41RDBMSAdapter.java
Log:
Fixed delete problem with MySQL 4.1 described in issue 32175. Patch
contributed by Alex Cruikshank.
Revision Changes Path
1.10 +9 -9
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlRDBMSAdapter.java
Index: MySqlRDBMSAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySqlRDBMSAdapter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MySqlRDBMSAdapter.java 20 Sep 2004 22:41:32 -0000 1.9
+++ MySqlRDBMSAdapter.java 11 Nov 2004 17:15:35 -0000 1.10
@@ -158,7 +158,7 @@
try {
NodeProperty property = (NodeProperty)
properties.nextElement();
statement = connection
- .prepareStatement("delete PROPERTIES from
PROPERTIES p, VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and
vh.URI_ID = u.URI_ID AND u.URI_STRING = ? AND p.PROPERTY_NAME = ? AND
p.PROPERTY_NAMESPACE = ? and vh.REVISION_NO = ?");
+
.prepareStatement(deleteStatement("PROPERTIES","p",", VERSION_HISTORY vh, URI u
where p.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID AND u.URI_STRING =
? AND p.PROPERTY_NAME = ? AND p.PROPERTY_NAMESPACE = ? and vh.REVISION_NO =
?"));
statement.setString(1, uri.toString());
statement.setString(2, property.getName());
statement.setString(3, property.getNamespace());
@@ -174,7 +174,7 @@
int protectedProperty = property.isProtected() ? 1 : 0;
try {
statement = connection
- .prepareStatement("delete PROPERTIES from
PROPERTIES p, VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and
vh.URI_ID = u.URI_ID AND u.URI_STRING = ? AND p.PROPERTY_NAME = ? AND
p.PROPERTY_NAMESPACE = ? and vh.REVISION_NO = ?");
+
.prepareStatement(deleteStatement("PROPERTIES","p",", VERSION_HISTORY vh, URI u
where p.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID AND u.URI_STRING =
? AND p.PROPERTY_NAME = ? AND p.PROPERTY_NAMESPACE = ? and vh.REVISION_NO =
?"));
statement.setString(1, uri.toString());
statement.setString(2, property.getName());
statement.setString(3, property.getNamespace());
@@ -221,8 +221,8 @@
bindings = bindings + "?)";
statement =
connection.prepareStatement(
- "delete BINDING from BINDING c, URI u where u.URI_ID
= c.CHILD_UURI_ID and u.URI_STRING IN "
- + bindings);
+ deleteStatement("BINDING","c",", URI u where
u.URI_ID = c.CHILD_UURI_ID and u.URI_STRING IN "
+ + bindings) );
Iterator iter = updatedBindings.iterator();
for (int i = 1; iter.hasNext(); i++) {
@@ -237,7 +237,7 @@
try {
statement =
connection.prepareStatement(
- "delete PARENT_BINDING from PARENT_BINDING c, URI u
where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("PARENT_BINDING","c",", URI u where
c.URI_ID = u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
1.39 +29 -18
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/StandardRDBMSAdapter.java
Index: StandardRDBMSAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/StandardRDBMSAdapter.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- StandardRDBMSAdapter.java 10 Nov 2004 22:06:11 -0000 1.38
+++ StandardRDBMSAdapter.java 11 Nov 2004 17:15:35 -0000 1.39
@@ -209,7 +209,7 @@
try {
statement =
connection.prepareStatement(
- "delete LINKS from LINKS l, URI u where l.URI_ID =
u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("LINKS","l",", URI u where l.URI_ID
= u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -220,7 +220,7 @@
try {
statement =
connection.prepareStatement(
- "delete VERSION_HISTORY from VERSION_HISTORY vh, URI
u where vh.URI_ID = u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("VERSION_HISTORY","vh",", URI u
where vh.URI_ID = u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -230,7 +230,7 @@
try {
statement =
connection.prepareStatement(
- "delete VERSION from VERSION v, URI u where v.URI_ID
= u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("VERSION","v",", URI u where
v.URI_ID = u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -240,7 +240,7 @@
try {
statement =
connection.prepareStatement(
- "delete OBJECT from OBJECT o, URI u where o.URI_ID =
u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("OBJECT","o",", URI u where o.URI_ID
= u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -464,7 +464,7 @@
try {
statement =
connection.prepareStatement(
- "delete LOCKS from LOCKS, URI u where LOCK_ID =
u.URI_ID and u.URI_STRING=?");
+ deleteStatement("LOCKS","l",", URI u where l.LOCK_ID
= u.URI_ID and u.URI_STRING=?"));
statement.setString(1, lock.getLockId());
statement.executeUpdate();
} finally {
@@ -473,7 +473,7 @@
try {
statement =
connection.prepareStatement(
- "delete URI from URI, LOCKS l where URI_STRING=?");
+ deleteStatement("URI","u",", LOCKS l where
u.URI_STRING=?"));
statement.setString(1, lock.getLockId());
statement.executeUpdate();
} finally {
@@ -584,7 +584,7 @@
NodeRevisionNumber revisionNumber =
permission.getRevisionNumber();
statement =
connection.prepareStatement(
- "delete PERMISSIONS from PERMISSIONS, URI ou, URI
su, URI au where OBJECT_ID = ou.URI_ID and ou.URI_STRING = ? and SUBJECT_ID =
su.URI_ID and su.URI_STRING = ? and ACTION_ID = au.URI_ID and au.URI_STRING = ?
and VERSION_NO" + ((revisionNumber == null) ? " IS NULL " : " = '" +
revisionNumber.toString() + "'"));
+ deleteStatement("PERMISSIONS","p",", URI ou, URI su,
URI au where p.OBJECT_ID = ou.URI_ID and ou.URI_STRING = ? and p.SUBJECT_ID =
su.URI_ID and su.URI_STRING = ? and p.ACTION_ID = au.URI_ID and au.URI_STRING =
? and p.VERSION_NO") + ((revisionNumber == null) ? " IS NULL " : " = '" +
revisionNumber.toString() + "'"));
statement.setString(1, permission.getObjectUri());
statement.setString(2, permission.getSubjectUri());
statement.setString(3, permission.getActionUri());
@@ -601,7 +601,7 @@
try {
statement =
connection.prepareStatement(
- "delete PERMISSIONS from PERMISSIONS, URI u where
OBJECT_ID = u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("PERMISSIONS","p",", URI u where
p.OBJECT_ID = u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} catch (SQLException e) {
@@ -650,7 +650,7 @@
try {
statement =
connection.prepareStatement(
- "delete VERSION_CONTENT from VERSION_CONTENT vc,
VERSION_HISTORY vh, URI u where vc.VERSION_ID = vh.VERSION_ID and
vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?");
+ deleteStatement("VERSION_CONTENT","vc",",
VERSION_HISTORY vh, URI u where vc.VERSION_ID = vh.VERSION_ID and
vh.REVISION_NO = ? and vh.URI_ID=u.URI_ID AND u.URI_STRING=?"));
statement.setString(1,
revisionDescriptor.getRevisionNumber().toString());
statement.setString(2, uri.toString());
statement.executeUpdate();
@@ -670,7 +670,7 @@
try {
statement =
connection.prepareStatement(
- "delete PROPERTIES from PROPERTIES p,
VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO
= ? and vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
+ deleteStatement("PROPERTIES","p",", VERSION_HISTORY
vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and
vh.URI_ID = u.URI_ID AND u.URI_STRING = ?"));
statement.setString(1, revisionNumber.toString());
statement.setString(2, uri.toString());
statement.executeUpdate();
@@ -687,7 +687,7 @@
try {
statement =
connection.prepareStatement(
- "delete VERSION_PREDS from VERSION_PREDS vp,
VERSION_HISTORY vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID =
u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("VERSION_PREDS","vp",", VERSION_HISTORY
vh, URI u where vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and
u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} catch (SQLException e) {
@@ -1256,7 +1256,7 @@
PreparedStatement statement = null;
try {
statement = connection
- .prepareStatement("delete VERSION_LABELS from
VERSION_LABELS vl, VERSION_HISTORY vh, URI u where vl.VERSION_ID =
vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID AND u.URI_STRING
= ?");
+
.prepareStatement(deleteStatement("VERSION_LABELS","vl",", VERSION_HISTORY vh,
URI u where vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID
= u.URI_ID AND u.URI_STRING = ?"));
statement.setString(1, revisionNumber.toString());
statement.setString(2, uri.toString());
statement.executeUpdate();
@@ -1365,7 +1365,7 @@
try {
statement =
connection.prepareStatement(
- "delete BINDING from BINDING c, URI u where c.URI_ID =
u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("BINDING","c",", URI u where c.URI_ID =
u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -1375,7 +1375,7 @@
try {
statement =
connection.prepareStatement(
- "delete PARENT_BINDING from PARENT_BINDING c, URI u
where c.URI_ID = u.URI_ID and u.URI_STRING = ?");
+ deleteStatement("PARENT_BINDING","c",", URI u where
c.URI_ID = u.URI_ID and u.URI_STRING = ?"));
statement.setString(1, uri.toString());
statement.executeUpdate();
} finally {
@@ -1392,6 +1392,17 @@
// those bindings that have actually changed. Have a look at the
implementation for MySQL
// as a reference.
clearBinding(connection, uri);
+ }
+
+ /**
+ * Permits varying delete semantics between different db's or even db
versions.
+ * @param table name of table from which to delete
+ * @param alias alias of table from which to delete
+ * @param sql delete statement starting with " where" for single table
and ", tablename" for multiple table delete
+ * @return Delete statement in correct SQL dialect
+ */
+ protected String deleteStatement(String table, String alias, String sql)
{
+ return "delete " + table + " from " + table + " " + alias + sql;
}
// null means permission is valid for all revisions
1.4 +14 -255
jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySql41RDBMSAdapter.java
Index: MySql41RDBMSAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/MySql41RDBMSAdapter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MySql41RDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.3
+++ MySql41RDBMSAdapter.java 11 Nov 2004 17:15:35 -0000 1.4
@@ -28,6 +28,8 @@
import java.sql.SQLException;
import java.util.Enumeration;
+import java.util.Set;
+import java.util.Iterator;
import org.apache.slide.common.Service;
import org.apache.slide.common.ServiceAccessException;
@@ -55,259 +57,16 @@
public MySql41RDBMSAdapter(Service service, Logger logger) {
super(service, logger);
}
-
- /*
- * @see org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeObject(
- * java.sql.Connection, org.apache.slide.common.Uri,
- * org.apache.slide.structure.ObjectNode)
- */
- public void removeObject(Connection connection, Uri uri, ObjectNode object)
- throws ServiceAccessException, ObjectNotFoundException {
- PreparedStatement statement = null;
- try {
- clearBinding(connection, uri);
-
- // delete links
- try {
- statement =
- connection.prepareStatement(
- "delete l from LINKS l, URI u where l.URI_ID = u.URI_ID and
u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- // delete version history
- // FIXME: Is this true??? Should the version history be removed if the
object is removed???
- try {
- statement =
- connection.prepareStatement(
- "delete vh from VERSION_HISTORY vh, URI u where vh.URI_ID =
u.URI_ID and u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- // delete version
- try {
- statement =
- connection.prepareStatement(
- "delete v from VERSION v, URI u where v.URI_ID = u.URI_ID and
u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- // delete the object itself
- try {
- statement =
- connection.prepareStatement(
- "delete o from OBJECT o, URI u where o.URI_ID = u.URI_ID and
u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- // finally delete the uri
- try {
- statement = connection.prepareStatement("delete from URI where
URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- }
- catch (SQLException e) {
- throw createException(e, uri.toString());
- }
- }
-
- /*
- * @see
org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionContent(
- * java.sql.Connection, org.apache.slide.common.Uri,
- * org.apache.slide.content.NodeRevisionDescriptor)
- */
- public void removeRevisionContent(Connection connection, Uri uri,
- NodeRevisionDescriptor revisionDescriptor) throws
ServiceAccessException {
- try {
- PreparedStatement statement = null;
- try {
- statement =
- connection.prepareStatement(
- "delete vc from VERSION_CONTENT vc, VERSION_HISTORY vh, URI u
where vc.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and
vh.URI_ID=u.URI_ID AND u.URI_STRING=?");
- statement.setString(1,
revisionDescriptor.getRevisionNumber().toString());
- statement.setString(2, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- }
- catch (SQLException e) {
- throw createException(e, uri.toString());
- }
- }
-
- /*
- * @see
org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptor(
- * java.sql.Connection, org.apache.slide.common.Uri,
- * org.apache.slide.content.NodeRevisionNumber)
- */
- public void removeRevisionDescriptor(Connection connection, Uri uri,
- NodeRevisionNumber revisionNumber) throws ServiceAccessException {
- PreparedStatement statement = null;
- try {
- try {
- statement =
- connection.prepareStatement(
- "delete vl from VERSION_LABELS vl, VERSION_HISTORY vh, URI u where
vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID
AND u.URI_STRING = ?");
- statement.setString(1, revisionNumber.toString());
- statement.setString(2, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- try {
- statement =
- connection.prepareStatement(
- "delete p from PROPERTIES p, VERSION_HISTORY vh, URI u where
p.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and vh.URI_ID = u.URI_ID
AND u.URI_STRING = ?");
- statement.setString(1, revisionNumber.toString());
- statement.setString(2, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
- }
- catch (SQLException e) {
- throw createException(e, uri.toString());
- }
- }
-
- /*
- * @see
org.apache.slide.store.impl.rdbms.RDBMSAdapter#removeRevisionDescriptors(
- * java.sql.Connection, org.apache.slide.common.Uri)
- */
- public void removeRevisionDescriptors(Connection connection, Uri uri)
- throws ServiceAccessException {
- PreparedStatement statement = null;
- try {
- statement =
- connection.prepareStatement(
- "delete vp from VERSION_PREDS vp, VERSION_HISTORY vh, URI u where
vp.VERSION_ID = vh.VERSION_ID and vh.URI_ID = u.URI_ID and u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- } catch (SQLException e) {
- throw createException(e, uri.toString());
- } finally {
- close(statement);
- }
- }
-
- /*
- * @see
org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter#clearBinding(java.sql.Connection,
org.apache.slide.common.Uri)
+
+ /**
+ * Permits varying delete semantics between different db's or even db
versions.
+ * @param table name of table from which to delete
+ * @param alias alias of table from which to delete
+ * @param sql delete statement starting with " where" for single table and
", tablename" for multiple table delete
+ * @return Delete statement in correct SQL dialect
*/
- protected void clearBinding(Connection connection, Uri uri)
- throws ServiceAccessException, ObjectNotFoundException, SQLException {
- PreparedStatement statement = null;
-
- // clear this uri from having bindings and being bound
- try {
- statement =
- connection.prepareStatement(
- "delete c from BINDING c, URI u where c.URI_ID = u.URI_ID and
u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
-
- try {
- statement =
- connection.prepareStatement(
- "delete c from PARENT_BINDING c, URI u where c.URI_ID = u.URI_ID and
u.URI_STRING = ?");
- statement.setString(1, uri.toString());
- statement.executeUpdate();
- }
- finally {
- close(statement);
- }
+ protected String deleteStatement(String table, String alias, String sql) {
+ return "delete " + alias + " from " + table + " " + alias + sql;
}
- public void storeRevisionDescriptor(Connection connection, Uri uri,
NodeRevisionDescriptor revisionDescriptor)
- throws ServiceAccessException, RevisionDescriptorNotFoundException {
- PreparedStatement statement = null;
- try {
- removeVersionLabels(connection, uri,
revisionDescriptor.getRevisionNumber());
- createVersionLabels(connection, uri, revisionDescriptor);
- String revisionNumber =
revisionDescriptor.getRevisionNumber().toString();
- for (Enumeration properties =
revisionDescriptor.enumerateRemovedProperties(); properties.hasMoreElements();)
{
- try {
- NodeProperty property = (NodeProperty)
properties.nextElement();
- statement = connection
- .prepareStatement("delete p from PROPERTIES p,
VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.URI_ID =
u.URI_ID AND u.URI_STRING = ? AND p.PROPERTY_NAME = ? AND p.PROPERTY_NAMESPACE
= ? and vh.REVISION_NO = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, property.getName());
- statement.setString(3, property.getNamespace());
- statement.setString(4, revisionNumber);
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- }
- for (Enumeration properties =
revisionDescriptor.enumerateUpdatedProperties(); properties.hasMoreElements();)
{
- NodeProperty property = (NodeProperty)
properties.nextElement();
- int protectedProperty = property.isProtected() ? 1 : 0;
- try {
- statement = connection
- .prepareStatement("delete p from PROPERTIES p,
VERSION_HISTORY vh, URI u where p.VERSION_ID = vh.VERSION_ID and vh.URI_ID =
u.URI_ID AND u.URI_STRING = ? AND p.PROPERTY_NAME = ? AND p.PROPERTY_NAMESPACE
= ? and vh.REVISION_NO = ?");
- statement.setString(1, uri.toString());
- statement.setString(2, property.getName());
- statement.setString(3, property.getNamespace());
- statement.setString(4, revisionNumber);
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- try {
- statement = connection
-
.prepareStatement("insert into PROPERTIES
(VERSION_ID,PROPERTY_NAMESPACE,PROPERTY_NAME,PROPERTY_VALUE,PROPERTY_TYPE,IS_PROTECTED)
select vh.VERSION_ID, ?, ?, ?, ?, ? from VERSION_HISTORY vh, URI u where
vh.URI_ID = u.URI_ID and u.URI_STRING = ? and vh.REVISION_NO = ?");
- statement.setString(1,
property.getNamespace());
- statement.setString(2,
property.getName());
- statement.setString(3,
property.getValue().toString());
- statement.setString(4,
property.getType());
- statement.setInt(5, protectedProperty);
- statement.setString(6, uri.toString());
- statement.setString(7, revisionNumber);
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- }
- } catch (SQLException e) {
- throw createException(e, uri.toString());
- }
- revisionDescriptor.resetUpdatedProperties();
- revisionDescriptor.resetRemovedProperties();
- }
- protected void removeVersionLabels(Connection connection, Uri uri,
NodeRevisionNumber revisionNumber)
- throws SQLException {
- PreparedStatement statement = null;
- try {
- statement =
- connection.prepareStatement(
- "delete vl from VERSION_LABELS vl, VERSION_HISTORY
vh, URI u where vl.VERSION_ID = vh.VERSION_ID and vh.REVISION_NO = ? and
vh.URI_ID = u.URI_ID AND u.URI_STRING = ?");
- statement.setString(1, revisionNumber.toString());
- statement.setString(2, uri.toString());
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]