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/08/10 12:14:16 UTC
cvs commit: jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms MySqlRDBMSAdapter.java MySql41RDBMSAdapter.java SQLServerRDBMSAdapter.java StandardRDBMSAdapter.java
ozeigermann 2004/08/10 03:14:16
Modified: src/stores/org/apache/slide/store/impl/rdbms
MySqlRDBMSAdapter.java MySql41RDBMSAdapter.java
SQLServerRDBMSAdapter.java
StandardRDBMSAdapter.java
Log:
Committed performance enhancement
http://issues.apache.org/bugzilla/show_bug.cgi?id=30442
based on the work of Tara Talbott
Revision Changes Path
1.8 +63 -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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MySqlRDBMSAdapter.java 28 Jul 2004 09:34:17 -0000 1.7
+++ MySqlRDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.8
@@ -28,6 +28,9 @@
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Enumeration;
+
+import org.apache.slide.content.*;
import org.apache.slide.common.*;
import org.apache.slide.macro.ConflictException;
import org.apache.slide.util.logger.Logger;
@@ -141,5 +144,61 @@
close(selectStatement, res);
}
}
+ 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 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 = ?");
+ 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 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 = ?");
+ 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();
+ }
}
1.3 +78 -3 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MySql41RDBMSAdapter.java 28 Jul 2004 09:34:17 -0000 1.2
+++ MySql41RDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.3
@@ -27,9 +27,13 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.util.Enumeration;
+
import org.apache.slide.common.Service;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.Uri;
+import org.apache.slide.content.NodeProperty;
+import org.apache.slide.content.RevisionDescriptorNotFoundException;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.store.impl.rdbms.MySqlRDBMSAdapter;
@@ -235,4 +239,75 @@
close(statement);
}
}
+ 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);
+ }
+ }
}
1.7 +78 -4 jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java
Index: SQLServerRDBMSAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/SQLServerRDBMSAdapter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SQLServerRDBMSAdapter.java 28 Jul 2004 09:34:16 -0000 1.6
+++ SQLServerRDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.7
@@ -27,9 +27,14 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Enumeration;
import org.apache.slide.common.Service;
import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.Uri;
+import org.apache.slide.content.NodeProperty;
+import org.apache.slide.content.NodeRevisionDescriptor;
+import org.apache.slide.content.RevisionDescriptorNotFoundException;
import org.apache.slide.macro.ConflictException;
import org.apache.slide.util.logger.Logger;
@@ -126,6 +131,75 @@
close(statement);
close(selectStatement, res);
}
+ }
+
+ 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 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 = ?");
+ 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 updated = 0;
+ int protectedProperty = property.isProtected() ? 1 : 0;
+ try {
+ statement = connection
+ .prepareStatement("update PROPERTIES set PROPERTY_VALUE = ?, PROPERTY_TYPE = ?, IS_PROTECTED = ? 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, property.getValue().toString());
+ statement.setString(2, property.getType());
+ statement.setInt(3, protectedProperty);
+
+ statement.setString(4, uri.toString());
+ statement.setString(5, property.getName());
+ statement.setString(6, property.getNamespace());
+ statement.setString(7, revisionNumber);
+ updated = statement.executeUpdate();
+
+ } finally {
+ close(statement);
+ }
+
+ // if it has not already been there we need to add it now
+ if (updated == 0) {
+ 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();
}
public boolean sequenceExists(Connection conn, String sequenceName) throws ServiceAccessException {
1.33 +39 -29 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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- StandardRDBMSAdapter.java 4 Aug 2004 11:45:59 -0000 1.32
+++ StandardRDBMSAdapter.java 10 Aug 2004 10:14:16 -0000 1.33
@@ -612,21 +612,7 @@
try {
assureVersionInfo(connection, uri, revisionDescriptor);
-
- for (Enumeration labels = revisionDescriptor.enumerateLabels(); labels.hasMoreElements();) {
- long labelId = assureLabelId(connection, (String) labels.nextElement());
- try {
- statement =
- connection.prepareStatement(
- "insert into VERSION_LABELS (VERSION_ID, LABEL_ID) select VERSION_ID, ? from VERSION_HISTORY vh, URI u where vh.URI_ID = u.URI_ID and u.URI_STRING = ? and vh.REVISION_NO = ?");
- statement.setLong(1, labelId);
- statement.setString(2, uri.toString());
- statement.setString(3, revisionDescriptor.getRevisionNumber().toString());
- statement.executeUpdate();
- } finally {
- close(statement);
- }
- }
+ createVersionLabels(connection, uri, revisionDescriptor);
for (Enumeration properties = revisionDescriptor.enumerateProperties(); properties.hasMoreElements();) {
try {
NodeProperty property = (NodeProperty) properties.nextElement();
@@ -674,16 +660,7 @@
throws ServiceAccessException {
PreparedStatement statement = null;
try {
- 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 = ?");
- statement.setString(1, revisionNumber.toString());
- statement.setString(2, uri.toString());
- statement.executeUpdate();
- } finally {
- close(statement);
- }
+ removeVersionLabels(connection, uri, revisionNumber);
try {
statement =
connection.prepareStatement(
@@ -1257,6 +1234,39 @@
throws ServiceAccessException, RevisionDescriptorNotFoundException {
removeRevisionDescriptors(connection, uri);
createRevisionDescriptors(connection, uri, revisionDescriptors);
+ }
+
+ protected void removeVersionLabels(Connection connection, Uri uri, NodeRevisionNumber revisionNumber)
+ throws SQLException {
+ 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 = ?");
+ statement.setString(1, revisionNumber.toString());
+ statement.setString(2, uri.toString());
+ statement.executeUpdate();
+ } finally {
+ close(statement);
+ }
+ }
+
+ protected void createVersionLabels(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor)
+ throws SQLException {
+
+ PreparedStatement statement = null;
+ for (Enumeration labels = revisionDescriptor.enumerateLabels(); labels.hasMoreElements();) {
+ long labelId = assureLabelId(connection, (String) labels.nextElement());
+ try {
+ statement = connection
+ .prepareStatement("insert into VERSION_LABELS (VERSION_ID, LABEL_ID) select VERSION_ID, ? from VERSION_HISTORY vh, URI u where vh.URI_ID = u.URI_ID and u.URI_STRING = ? and vh.REVISION_NO = ?");
+ statement.setLong(1, labelId);
+ statement.setString(2, uri.toString());
+ statement.setString(3, revisionDescriptor.getRevisionNumber().toString());
+ statement.executeUpdate();
+ } finally {
+ close(statement);
+ }
+ }
}
protected long assureUriId(Connection connection, String uri) throws SQLException {
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org