[jboss-svn-commits] JBL Code SVN: r6052 - in labs/jbossrules/trunk/drools-repository/src: java/org/drools/repository java/org/drools/repository/test node_type_definitions
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 31 17:21:36 EDT 2006
Author: michael.neale at jboss.com
Date: 2006-08-31 17:21:29 -0400 (Thu, 31 Aug 2006)
New Revision: 6052
Added:
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/ScalabilityTest.java
Modified:
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/VersionableItem.java
labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
labs/jbossrules/trunk/drools-repository/src/node_type_definitions/versionable_node_type.cnd
Log:
refactoring
Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java 2006-08-31 21:21:29 UTC (rev 6052)
@@ -169,38 +169,15 @@
Calendar lastModified = Calendar.getInstance();
this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
- this.node.getSession().save();
-
- this.node.checkin();
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
- }
- private void checkout() {
- try {
- this.node.checkout();
}
- catch(UnsupportedRepositoryOperationException e) {
- String message = "";
- try {
- message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
- log.error(message, e);
- }
- catch (RepositoryException e1) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e1);
- }
- throw new RulesRepositoryException(message, e);
- }
catch(Exception e) {
log.error("Caught Exception", e);
throw new RulesRepositoryException(e);
}
}
+
+
/**
* @return the date the rule becomes expired
@@ -223,17 +200,7 @@
}
}
- private Node getVersionContentNode() throws RepositoryException,
- PathNotFoundException {
- Node ruleNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- ruleNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- ruleNode = this.node;
- }
- return ruleNode;
- }
+
/**
* Creates a new version of this object's rule node, updating the expired date for the
@@ -250,10 +217,7 @@
Calendar lastModified = Calendar.getInstance();
this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
- this.node.getSession().save();
-
- this.node.checkin();
+;
}
catch(Exception e) {
log.error("Caught Exception", e);
@@ -285,7 +249,7 @@
* @param lhs the new lhs content for the rule
* @throws RulesRepositoryException
*/
- public void updateLhs(String newLhsContent) throws RulesRepositoryException {
+ public RuleItem updateLhs(String newLhsContent) throws RulesRepositoryException {
checkout();
try {
@@ -293,10 +257,7 @@
Calendar lastModified = Calendar.getInstance();
this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
- this.node.getSession().save();
-
- this.node.checkin();
+ return this;
}
catch(Exception e) {
log.error("Caught Exception", e);
@@ -319,10 +280,7 @@
Calendar lastModified = Calendar.getInstance();
this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
- this.node.getSession().save();
-
- this.node.checkin();
+
}
catch(Exception e) {
log.error("Caught Exception", e);
@@ -376,8 +334,7 @@
newTagValues[i] = this.node.getSession().getValueFactory().createValue(tagItem.getNode());
this.node.checkout();
this.node.setProperty(TAG_PROPERTY_NAME, newTagValues);
- this.node.getSession().save();
- this.node.checkin();
+ //this.node.getSession().save();
}
else {
log.error("reached expected path of execution when adding tag '" + tag + "' to ruleNode: " + this.node.getName());
@@ -446,10 +403,8 @@
}
finally {
if(newTagValues != null) {
- this.node.checkout();
+ checkout();
this.node.setProperty(TAG_PROPERTY_NAME, newTagValues);
- this.node.getSession().save();
- this.node.checkin();
}
else {
log.error("reached expected path of execution when removing tag '" + tag + "' from ruleNode: " + this.node.getName());
@@ -533,10 +488,8 @@
}
//now set the state property of the rule
- this.node.checkout();
+ checkout();
this.node.setProperty(STATE_PROPERTY_NAME, stateItem.getNode());
- this.node.getSession().save();
- this.node.checkin();
}
catch(Exception e) {
log.error("Caught exception", e);
Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java 2006-08-31 21:21:29 UTC (rev 6052)
@@ -5,8 +5,10 @@
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import javax.jcr.NamespaceException;
@@ -417,35 +419,42 @@
}
}
+ private Map areaNodeCache = new HashMap();
+
private Node getAreaNode(String areaName) throws RulesRepositoryException {
- Node folderNode = null;
- int tries = 0;
- while(folderNode == null && tries < 2) {
- try {
- tries++;
- folderNode = this.session.getRootNode().getNode(RULES_REPOSITORY_NAME + "/" + areaName);
- }
- catch(PathNotFoundException e) {
- if(tries == 1) {
- //hmm..repository must have gotten screwed up. set it up again
- log.warn("The repository appears to have become corrupted. It will be re-setup now.");
- this.setupRepository();
+ if (areaNodeCache.containsKey( areaName )) {
+ return (Node) areaNodeCache.get( areaName );
+ } else {
+ Node folderNode = null;
+ int tries = 0;
+ while(folderNode == null && tries < 2) {
+ try {
+ tries++;
+ folderNode = this.session.getRootNode().getNode(RULES_REPOSITORY_NAME + "/" + areaName);
}
- else {
- log.error("Unable to correct repository corruption");
+ catch(PathNotFoundException e) {
+ if(tries == 1) {
+ //hmm..repository must have gotten screwed up. set it up again
+ log.warn("The repository appears to have become corrupted. It will be re-setup now.");
+ this.setupRepository();
+ }
+ else {
+ log.error("Unable to correct repository corruption");
+ }
}
+ catch(Exception e) {
+ log.error("Caught Exception", e);
+ throw new RulesRepositoryException("Caught exception " + e.getClass().getName(), e);
+ }
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException("Caught exception " + e.getClass().getName(), e);
+ if(folderNode == null) {
+ String message = "Could not get a reference to a node for " + RULES_REPOSITORY_NAME + "/" + areaName;
+ log.error(message);
+ throw new RulesRepositoryException(message);
}
+ areaNodeCache.put( areaName, folderNode );
+ return folderNode;
}
- if(folderNode == null) {
- String message = "Could not get a reference to a node for " + RULES_REPOSITORY_NAME + "/" + areaName;
- log.error(message);
- throw new RulesRepositoryException(message);
- }
- return folderNode;
}
/**
@@ -724,7 +733,9 @@
ruleNode.setProperty(RuleItem.FORMAT_PROPERTY_NAME, RuleItem.RULE_FORMAT);
ruleNode.setProperty(RuleItem.LHS_PROPERTY_NAME, lhsContent);
ruleNode.setProperty(RuleItem.RHS_PROPERTY_NAME, rhsContent);
+ ruleNode.setProperty( VersionableItem.CHECKIN_COMMENT, "Initial" );
+
Calendar lastModified = Calendar.getInstance();
ruleNode.setProperty(RuleItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/VersionableItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/VersionableItem.java 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/VersionableItem.java 2006-08-31 21:21:29 UTC (rev 6052)
@@ -12,51 +12,58 @@
import org.drools.repository.Item;
public abstract class VersionableItem extends Item {
-
+
/**
* The name of the title property on the node type
*/
- public static final String TITLE_PROPERTY_NAME = "drools:title";
-
+ public static final String TITLE_PROPERTY_NAME = "drools:title";
+
/**
* The name of the contributor property on the node type
*/
- public static final String CONTRIBUTOR_PROPERTY_NAME = "drools:contributor";
-
+ public static final String CONTRIBUTOR_PROPERTY_NAME = "drools:contributor";
+
/**
* The name of the description property on the rule node type
*/
- public static final String DESCRIPTION_PROPERTY_NAME = "drools:description";
-
+ public static final String DESCRIPTION_PROPERTY_NAME = "drools:description";
+
/**
* The name of the last modified property on the rule node type
*/
public static final String LAST_MODIFIED_PROPERTY_NAME = "drools:last_modified";
-
+
/**
* The name of the last modified property on the rule node type
*/
- public static final String FORMAT_PROPERTY_NAME = "drools:format";
+ public static final String FORMAT_PROPERTY_NAME = "drools:format";
+ /** The name of the checkin/change comment for change tracking */
+ public static final String CHECKIN_COMMENT = "drools:checkin_comment";
+
/**
* The possible formats for the format property of the node
*/
- public static final String RULE_FORMAT = "Rule";
- public static final String DSL_FORMAT = "DSL";
- public static final String RULE_PACKAGE_FORMAT = "Rule Package";
- public static final String FUNCTION_FORMAT = "Function";
-
+ public static final String RULE_FORMAT = "Rule";
+ public static final String DSL_FORMAT = "DSL";
+ public static final String RULE_PACKAGE_FORMAT = "Rule Package";
+ public static final String FUNCTION_FORMAT = "Function";
+
+ private Node contentNode = null;
+
/**
* Sets this object's node attribute to the specified node
*
* @param rulesRepository the RulesRepository object that this object is being created from
* @param node the node in the repository that this item corresponds to
*/
- public VersionableItem(RulesRepository rulesRepository, Node node) {
- super(rulesRepository, node);
+ public VersionableItem(RulesRepository rulesRepository,
+ Node node) {
+ super( rulesRepository,
+ node );
}
-
+
/**
* @return the predessor node of this node in the version history, or null if no predecessor version exists
* @throws RulesRepositoryException
@@ -64,35 +71,33 @@
protected Node getPrecedingVersionNode() throws RulesRepositoryException {
try {
Node versionNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
+ if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
versionNode = this.node;
+ } else {
+ versionNode = this.node.getBaseVersion();
}
- else {
- versionNode = this.node.getBaseVersion();
- }
-
- Property predecessorsProperty = versionNode.getProperty("jcr:predecessors");
- Value [] predecessorValues = predecessorsProperty.getValues();
-
- if(predecessorValues.length > 0) {
- Node predecessorNode = this.node.getSession().getNodeByUUID(predecessorValues[0].getString());
-
+
+ Property predecessorsProperty = versionNode.getProperty( "jcr:predecessors" );
+ Value[] predecessorValues = predecessorsProperty.getValues();
+
+ if ( predecessorValues.length > 0 ) {
+ Node predecessorNode = this.node.getSession().getNodeByUUID( predecessorValues[0].getString() );
+
//we don't want to return the root node - it isn't a true predecessor
- if(predecessorNode.getName().equals("jcr:rootVersion")) {
- return null;
+ if ( predecessorNode.getName().equals( "jcr:rootVersion" ) ) {
+ return null;
}
-
+
return predecessorNode;
- }
- }
- catch(PathNotFoundException e) {
+ }
+ } catch ( PathNotFoundException e ) {
//do nothing - this will happen if no predecessors exits
+ } catch ( Exception e ) {
+ log.error( "Caught exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught exception", e);
- throw new RulesRepositoryException(e);
- }
- return null;
+ return null;
}
/**
@@ -101,21 +106,20 @@
*/
protected Node getSucceedingVersionNode() throws RulesRepositoryException {
try {
- Property successorsProperty = this.node.getProperty("jcr:successors");
- Value [] successorValues = successorsProperty.getValues();
-
- if(successorValues.length > 0) {
- Node successorNode = this.node.getSession().getNodeByUUID(successorValues[0].getString());
+ Property successorsProperty = this.node.getProperty( "jcr:successors" );
+ Value[] successorValues = successorsProperty.getValues();
+
+ if ( successorValues.length > 0 ) {
+ Node successorNode = this.node.getSession().getNodeByUUID( successorValues[0].getString() );
return successorNode;
- }
- }
- catch(PathNotFoundException e) {
+ }
+ } catch ( PathNotFoundException e ) {
//do nothing - this will happen if no successors exist
+ } catch ( Exception e ) {
+ log.error( "Caught exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught exception", e);
- throw new RulesRepositoryException(e);
- }
return null;
}
@@ -125,17 +129,18 @@
* @throws RulesRepositoryException
*/
public ItemVersionIterator getSuccessorVersionsIterator() throws RulesRepositoryException {
- return new ItemVersionIterator(this, ItemVersionIterator.ITERATION_TYPE_SUCCESSOR);
+ return new ItemVersionIterator( this,
+ ItemVersionIterator.ITERATION_TYPE_SUCCESSOR );
}
-
/**
* @return an Iterator over VersionableItem objects encapsulating each predecessor node of this
* Item's node
* @throws RulesRepositoryException
*/
public ItemVersionIterator getPredecessorVersionsIterator() throws RulesRepositoryException {
- return new ItemVersionIterator(this, ItemVersionIterator.ITERATION_TYPE_PREDECESSOR);
+ return new ItemVersionIterator( this,
+ ItemVersionIterator.ITERATION_TYPE_PREDECESSOR );
}
/**
@@ -151,7 +156,7 @@
* @throws RulesRepositoryException
*/
public abstract VersionableItem getPrecedingVersion() throws RulesRepositoryException;
-
+
/**
* Clients of this method can cast the resulting object to the type of object they are
* calling the method on (e.g.
@@ -165,8 +170,8 @@
* version history.
* @throws RulesRepositoryException
*/
- public abstract VersionableItem getSucceedingVersion() throws RulesRepositoryException;
-
+ public abstract VersionableItem getSucceedingVersion() throws RulesRepositoryException;
+
/**
* Gets the Title of the versionable node. See the Dublin Core documentation for more
* explanation: http://dublincore.org/documents/dces/
@@ -175,22 +180,21 @@
* @throws RulesRepositoryException
*/
public String getTitle() throws RulesRepositoryException {
- try {
+ try {
Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
+ if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
+ theNode = this.node.getNode( "jcr:frozenNode" );
+ } else {
theNode = this.node;
}
-
- Property data = theNode.getProperty(TITLE_PROPERTY_NAME);
+
+ Property data = theNode.getProperty( TITLE_PROPERTY_NAME );
return data.getValue().getString();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
/**
@@ -204,30 +208,31 @@
* @throws RulesRepositoryException
*/
public void updateTitle(String title) throws RulesRepositoryException {
- try {
+ try {
Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
+ if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
+ theNode = this.node.getNode( "jcr:frozenNode" );
+ } else {
theNode = this.node;
}
-
+
theNode.checkout();
- theNode.setProperty(TITLE_PROPERTY_NAME, title);
-
+ theNode.setProperty( TITLE_PROPERTY_NAME,
+ title );
+
Calendar lastModified = Calendar.getInstance();
- this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
+ this.node.setProperty( LAST_MODIFIED_PROPERTY_NAME,
+ lastModified );
theNode.save();
- theNode.checkin();
+ theNode.checkin();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
-
+
/**
* Gets the Contributor of the versionable node. See the Dublin Core documentation for more
* explanation: http://dublincore.org/documents/dces/
@@ -236,24 +241,16 @@
* @throws RulesRepositoryException
*/
public String getContributor() {
- try {
- Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- theNode = this.node;
- }
-
- Property data = theNode.getProperty(CONTRIBUTOR_PROPERTY_NAME);
+ try {
+ Property data = getVersionContentNode().getProperty( CONTRIBUTOR_PROPERTY_NAME );
return data.getValue().getString();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
-
+
/**
* See the Dublin Core documentation for more
* explanation: http://dublincore.org/documents/dces/
@@ -262,47 +259,47 @@
* @throws RulesRepositoryException
*/
public String getDescription() throws RulesRepositoryException {
- try {
- Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- theNode = this.node;
- }
-
- Property data = theNode.getProperty(DESCRIPTION_PROPERTY_NAME);
+ try {
+
+ Property data = getVersionContentNode().getProperty( DESCRIPTION_PROPERTY_NAME );
return data.getValue().getString();
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- }
+ }
/**
+ * This will return the checkin comment for the latest revision.
+ */
+ public String getCheckinComment() throws RulesRepositoryException {
+ try {
+ Property data = getVersionContentNode().getProperty( CHECKIN_COMMENT );
+ return data.getValue().getString();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
+ }
+ }
+
+ /**
* @return the date the function node (this version) was last modified
* @throws RulesRepositoryException
*/
public Calendar getLastModified() throws RulesRepositoryException {
- try {
- Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
- theNode = this.node;
- }
-
- Property lastModifiedProperty = theNode.getProperty("drools:last_modified");
+ try {
+
+ Property lastModifiedProperty = getVersionContentNode().getProperty( "drools:last_modified" );
return lastModifiedProperty.getDate();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
-
+
/**
* Creates a new version of this object's node, updating the description content
* for the node.
@@ -316,40 +313,43 @@
public void updateDescription(String newDescriptionContent) throws RulesRepositoryException {
try {
this.node.checkout();
- }
- catch(UnsupportedRepositoryOperationException e) {
+ } catch ( UnsupportedRepositoryOperationException e ) {
String message = "";
try {
message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout node: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
- log.error(message, e);
+ log.error( message,
+ e );
+ } catch ( RepositoryException e1 ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e1 );
}
- catch (RepositoryException e1) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e1);
- }
- throw new RulesRepositoryException(message, e);
+ throw new RulesRepositoryException( message,
+ e );
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
-
- try {
- this.node.setProperty(DESCRIPTION_PROPERTY_NAME, newDescriptionContent);
-
+
+ try {
+ this.node.setProperty( DESCRIPTION_PROPERTY_NAME,
+ newDescriptionContent );
+
Calendar lastModified = Calendar.getInstance();
- this.node.setProperty(LAST_MODIFIED_PROPERTY_NAME, lastModified);
-
+ this.node.setProperty( LAST_MODIFIED_PROPERTY_NAME,
+ lastModified );
+
this.node.getSession().save();
-
+
this.node.checkin();
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
- }
}
-
+
/**
* See the Dublin Core documentation for more
* explanation: http://dublincore.org/documents/dces/
@@ -358,21 +358,81 @@
* @throws RulesRepositoryException
*/
public String getFormat() throws RulesRepositoryException {
- try {
+ try {
Node theNode;
- if(this.node.getPrimaryNodeType().getName().equals("nt:version")) {
- theNode = this.node.getNode("jcr:frozenNode");
- }
- else {
+ if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
+ theNode = this.node.getNode( "jcr:frozenNode" );
+ } else {
theNode = this.node;
}
-
- Property data = theNode.getProperty(FORMAT_PROPERTY_NAME);
+
+ Property data = theNode.getProperty( FORMAT_PROPERTY_NAME );
return data.getValue().getString();
- }
- catch(Exception e) {
- log.error("Caught Exception", e);
- throw new RulesRepositoryException(e);
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
}
- }
+ }
+
+ /**
+ * When retrieving content, if we are dealing with a version in the history,
+ * we need to get the actual content node to retrieve values.
+ *
+ */
+ public Node getVersionContentNode() throws RepositoryException,
+ PathNotFoundException {
+ if ( this.contentNode == null ) {
+
+ if ( this.node.getPrimaryNodeType().getName().equals( "nt:version" ) ) {
+ contentNode = this.node.getNode( "jcr:frozenNode" );
+ } else {
+ contentNode = this.node;
+ }
+
+ }
+
+ return contentNode;
+ }
+
+ /**
+ * This will check out the node prior to editing.
+ */
+ public void checkout() {
+
+ try {
+ this.node.checkout();
+ } catch ( UnsupportedRepositoryOperationException e ) {
+ String message = "";
+ try {
+ message = "Error: Caught UnsupportedRepositoryOperationException when attempting to checkout rule: " + this.node.getName() + ". Are you sure your JCR repository supports versioning? ";
+ log.error( message,
+ e );
+ } catch ( RepositoryException e1 ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e1 );
+ }
+ throw new RulesRepositoryException( message,
+ e );
+ } catch ( Exception e ) {
+ log.error( "Caught Exception",
+ e );
+ throw new RulesRepositoryException( e );
+ }
+ }
+
+ /**
+ * This will save the content (if it hasn't been already) and
+ * then check it in to create a new version.
+ */
+ public void checkin(String comment) {
+ try {
+ this.node.setProperty( VersionableItem.CHECKIN_COMMENT, comment);
+ this.node.getSession().save();
+ this.node.checkin();
+ } catch (Exception e) {
+ throw new RulesRepositoryException("Unable to checkin.", e);
+ }
+ }
}
Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java 2006-08-31 21:21:29 UTC (rev 6052)
@@ -69,9 +69,15 @@
assertEquals("new lhs content", ruleItem1.getLhs());
+ ruleItem1.checkin( "yeah !" );
+
+ assertEquals("yeah !", ruleItem1.getCheckinComment());
+
RuleItem prev = (RuleItem) ruleItem1.getPredecessorVersionsIterator().next();
assertEquals("test lhs content", prev.getLhs());
+ assertFalse("yeah !".equals(prev.getCheckinComment()));
+
assertEquals(prev, ruleItem1.getPrecedingVersion());
}
@@ -80,6 +86,7 @@
RuleItem ruleItem1 = getRepo().addRule("testUpdateRhs", "test lhs content", "test rhs content");
ruleItem1.updateRhs("new rhs content");
assertEquals("new rhs content", ruleItem1.getRhs());
+ ruleItem1.checkin( "la" );
RuleItem prev = (RuleItem) ruleItem1.getPrecedingVersion();
assertEquals("test rhs content", prev.getRhs());
@@ -97,6 +104,7 @@
tags = ruleItem1.getCategories();
assertEquals(2, tags.size());
+ ruleItem1.checkin( "woot" );
//now test retrieve by tags
List result = getRepo().findRulesByTag("testAddTagTestTag");
@@ -191,6 +199,7 @@
long before = cal.getTimeInMillis();
ruleItem1.updateLhs("new lhs");
+ ruleItem1.checkin( "woot" );
Calendar cal2 = ruleItem1.getLastModified();
long lastMod = cal2.getTimeInMillis();
@@ -265,12 +274,19 @@
assertTrue(predecessorRuleItem == null);
ruleItem1.updateLhs("new lhs");
+ ruleItem1.updateRhs( "hola" );
+ ruleItem1.checkin( "two changes" );
+
predecessorRuleItem = (RuleItem) ruleItem1.getPrecedingVersion();
assertNotNull(predecessorRuleItem);
assertEquals("test lhs content", predecessorRuleItem.getLhs());
+ assertEquals("test rhs content", predecessorRuleItem.getRhs());
+
+
ruleItem1.updateLhs("newer lhs");
+ ruleItem1.checkin( "another" );
predecessorRuleItem = (RuleItem) ruleItem1.getPrecedingVersion();
assertNotNull(predecessorRuleItem);
@@ -289,7 +305,9 @@
assertTrue(succeedingRuleItem == null);
ruleItem1.updateLhs("new lhs");
+ ruleItem1.checkin( "la" );
+
RuleItem predecessorRuleItem = (RuleItem) ruleItem1.getPrecedingVersion();
assertEquals("test lhs content", predecessorRuleItem.getLhs());
succeedingRuleItem = (RuleItem) predecessorRuleItem.getSucceedingVersion();
@@ -309,8 +327,9 @@
assertNotNull(iterator);
assertFalse(iterator.hasNext());
- ruleItem1.updateLhs("new lhs");
+ ruleItem1.updateLhs("new lhs").checkin( "ya" );
+
iterator = ruleItem1.getSuccessorVersionsIterator();
assertNotNull(iterator);
assertFalse(iterator.hasNext());
@@ -324,6 +343,7 @@
assertFalse(iterator.hasNext());
ruleItem1.updateLhs("newer lhs");
+ ruleItem1.checkin( "boo" );
iterator = predecessorRuleItem.getSuccessorVersionsIterator();
assertNotNull(iterator);
@@ -349,6 +369,7 @@
assertFalse(iterator.hasNext());
ruleItem1.updateLhs("new lhs");
+ ruleItem1.checkin( "boo" );
iterator = ruleItem1.getPredecessorVersionsIterator();
assertNotNull(iterator);
@@ -358,7 +379,9 @@
assertEquals("test lhs content", nextRuleItem.getLhs());
ruleItem1.updateLhs("newer lhs");
+ ruleItem1.checkin( "wee" );
+
iterator = ruleItem1.getPredecessorVersionsIterator();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
Added: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/ScalabilityTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/ScalabilityTest.java 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/ScalabilityTest.java 2006-08-31 21:21:29 UTC (rev 6052)
@@ -0,0 +1,94 @@
+package org.drools.repository.test;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+import org.apache.jackrabbit.core.TransientRepository;
+import org.drools.repository.RuleItem;
+import org.drools.repository.RulesRepository;
+import org.drools.repository.RulesRepositoryException;
+
+import junit.framework.TestCase;
+
+public class ScalabilityTest extends TestCase {
+
+ private static final int NUM = 5000;
+
+
+ public void xxtestRun() throws Exception {
+
+ RulesRepository repo = new RulesRepository(false);
+
+
+ long start = System.currentTimeMillis();
+ setupData( repo );
+ System.out.println("time to add, version and tag 5000: " + (System.currentTimeMillis() - start));
+ List list = listACat(repo);
+ System.out.println("list size is: " + list.size());
+
+ start = System.currentTimeMillis();
+ RuleItem item = (RuleItem) list.get( 0 );
+ item.updateDescription( "this is a description" );
+ System.out.println("time to update and version: " + (System.currentTimeMillis() - start));
+ }
+
+ private List listACat(RulesRepository repo) {
+ long start = System.currentTimeMillis();
+ List results = repo.findRulesByTag( "HR/CAT_1" );
+ System.out.println("Time for listing a cat: " + (System.currentTimeMillis() - start));
+ return results;
+ }
+
+ private void setupData(RulesRepository repo) throws Exception {
+
+
+ int count = 1;
+
+ String prefix = "HR/";
+ String cat = prefix + "CAT_1";
+ for (int i=1; i <= NUM; i++ ) {
+
+ if (i > 2500) {
+ prefix = "FINANCE/";
+ }
+
+ if (count == 100) {
+ count = 1;
+ cat = prefix + "CAT_" + i;
+ System.err.println("changing CAT");
+ System.gc();
+
+ } else {
+ count++;
+ }
+
+ String ruleName = "rule_" + i + "_" + System.currentTimeMillis();
+ System.out.println("ADDING rule: " + ruleName);
+
+
+ RuleItem item = repo.addRule( ruleName, "Foo(bar == " + i + ")", "panic(" + i + ");" );
+ //item.addCategory( cat );
+
+ }
+
+
+ }
+
+ static void hacked() throws Exception {
+ Repository repository = new TransientRepository();
+ Session session = repository.login(
+ new SimpleCredentials("username", "password".toCharArray()));
+
+ }
+
+
+
+}
Modified: labs/jbossrules/trunk/drools-repository/src/node_type_definitions/versionable_node_type.cnd
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/node_type_definitions/versionable_node_type.cnd 2006-08-31 20:55:25 UTC (rev 6051)
+++ labs/jbossrules/trunk/drools-repository/src/node_type_definitions/versionable_node_type.cnd 2006-08-31 21:21:29 UTC (rev 6052)
@@ -29,4 +29,6 @@
mandatory
- drools:format (string)
- mandatory
\ No newline at end of file
+ mandatory
+
+ - drools:checkin_comment (string)
\ No newline at end of file
More information about the jboss-svn-commits
mailing list