You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by oz...@apache.org on 2004/09/21 00:41:33 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/structure ObjectNode.java
ozeigermann 2004/09/20 15:41:33
Modified: src/stores/org/apache/slide/store/impl/rdbms
MySqlRDBMSAdapter.java StandardRDBMSAdapter.java
src/share/org/apache/slide/structure ObjectNode.java
Log:
Added second part of patch #30442 contributed by Tara Talbott.
Revision Changes Path
1.9 +54 -4 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MySqlRDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.8
+++ MySqlRDBMSAdapter.java 20 Sep 2004 22:41:32 -0000 1.9
@@ -29,10 +29,13 @@
import java.sql.SQLException;
import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
import org.apache.slide.content.*;
import org.apache.slide.common.*;
import org.apache.slide.macro.ConflictException;
+import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.util.logger.Logger;
/**
@@ -201,4 +204,51 @@
revisionDescriptor.resetUpdatedProperties();
revisionDescriptor.resetRemovedProperties();
}
+
+ protected void clearBinding(Connection connection, Uri uri, Set updatedBindings)
+ throws ServiceAccessException, ObjectNotFoundException, SQLException {
+ PreparedStatement statement = null;
+
+ // clear this uri from having bindings and being bound
+ int bsize = updatedBindings.size();
+ //If there are bindings to update, only remove those from the database
+ if (bsize > 0) {
+
+ try {
+ String bindings = "(";
+ for (int i = 1; i < bsize; i++)
+ bindings = bindings + "?,";
+ 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);
+
+ Iterator iter = updatedBindings.iterator();
+ for (int i = 1; iter.hasNext(); i++) {
+ String next = iter.next().toString();
+ statement.setString(i, next);
+ }
+ statement.executeUpdate();
+ } finally {
+ close(statement);
+ }
+
+ try {
+ statement =
+ connection.prepareStatement(
+ "delete PARENT_BINDING 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);
+ }
+ } else {
+ //otherwise remove all related to the uri
+ clearBinding(connection, uri);
+ }
+
+ }
+
+
}
1.34 +22 -5 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.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- StandardRDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.33
+++ StandardRDBMSAdapter.java 20 Sep 2004 22:41:32 -0000 1.34
@@ -94,6 +94,7 @@
throws ServiceAccessException {
String className = object.getClass().getName();
long uriid;
+ Set updatedBindings = object.getUpdatedBindings();
try {
PreparedStatement statement = null;
ResultSet res = null;
@@ -130,7 +131,7 @@
// update binding...
try {
- clearBinding(connection, uri);
+ clearBinding(connection, uri, updatedBindings);
} catch (ObjectNotFoundException e1) {
// clear only if it existed
}
@@ -138,6 +139,8 @@
Enumeration bindings = object.enumerateBindings();
while (bindings.hasMoreElements()) {
ObjectNode.Binding binding = (ObjectNode.Binding) bindings.nextElement();
+ //Only insert the binding if it has been updated
+ if(updatedBindings.contains(binding.getUuri())){
try {
statement =
connection.prepareStatement(
@@ -150,6 +153,7 @@
close(statement);
}
}
+ }
Enumeration parentBindings = object.enumerateParentBindings();
while (parentBindings.hasMoreElements()) {
@@ -190,6 +194,7 @@
} catch (SQLException e) {
throw createException(e, uri.toString());
}
+ object.resetUpdatedBindings();
return true;
}
@@ -253,6 +258,7 @@
throw createException(e, uri.toString());
}
+ object.resetUpdatedBindings();
}
public ObjectNode retrieveObject(Connection connection, Uri uri)
@@ -1366,6 +1372,17 @@
} finally {
close(statement);
}
+ }
+
+ protected void clearBinding(Connection connection, Uri uri, Set updatedBindings)
+ throws ServiceAccessException, ObjectNotFoundException, SQLException {
+ PreparedStatement statement = null;
+
+ // XXX This default implementation does not do anything meaningfull with the additional
+ // information in updatedBindings. Implement this in the specific adapters to remove only
+ // those bindings that have actually changed. Have a look at the implementation for MySQL
+ // as a reference.
+ clearBinding(connection, uri);
}
// null means permission is valid for all revisions
1.28 +28 -4 jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java
Index: ObjectNode.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- ObjectNode.java 5 Aug 2004 15:44:58 -0000 1.27
+++ ObjectNode.java 20 Sep 2004 22:41:33 -0000 1.28
@@ -26,6 +26,8 @@
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;
+import java.util.Set;
+import java.util.HashSet;
import org.apache.slide.common.ObjectValidationFailedException;
import org.apache.slide.common.UriPath;
import org.apache.slide.util.Messages;
@@ -40,6 +42,12 @@
public abstract class ObjectNode
implements Serializable, Cloneable {
+
+ /**
+ * For tracking which bindings need to be updated.
+ */
+ private Set updatedBindings = null;
+
/**
* Uniform ressource identifier (URI) of the object.
*/
@@ -95,6 +103,7 @@
this.links = new Vector();
this.bindings = new BindingList();
this.parentBindings = new ParentBindingList();
+ this.updatedBindings = new HashSet();
}
/**
@@ -125,6 +134,10 @@
this.bindings = new BindingList(bindings);
this.parentBindings = new ParentBindingList(parentBindings);
this.links = links;
+ Enumeration e = bindings.elements();
+ while(e.hasMoreElements()) {
+ updatedBindings.add(((ObjectNode.Binding)e.nextElement()).getUuri());
+ }
}
/**
@@ -173,6 +186,15 @@
this.uuri = uuri;
}
+
+ public Set getUpdatedBindings() {
+ return updatedBindings;
+ }
+
+ public void resetUpdatedBindings() {
+ updatedBindings.clear();
+ }
+
/**
* Return this object's children
*
@@ -459,6 +481,7 @@
* @param source the child ObjectNode
*/
public void addBinding( String bindingName, ObjectNode source ) {
+ updatedBindings.add(source.getUri());
if (!hasBinding(bindingName)) {
if(bindingsShared) {
// Lazy cloning on first write access
@@ -482,6 +505,7 @@
* @param child The child to remove
*/
public void removeChild(ObjectNode child) {
+ updatedBindings.add(child.getUri());
if (child == null) {
return;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org