DNA SVN: r1351 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/connector/federation and 9 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-11-25 15:18:20 -0500 (Wed, 25 Nov 2009)
New Revision: 1351
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndUuid.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperties.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperty.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ProjectedNode.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/NetChangeObserver.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/MergeJoinComponent.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CloneBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CreateNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/MoveBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllPropertiesRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBlockOfChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNextBlockOfChildrenRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadPropertyRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RemovePropertyRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RenameNodeRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/SetPropertyRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdatePropertiesRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdateValuesRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/ReadableConnectorTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
Log:
DNA-551 graph.Location's equals(Object) and hashCode() Methods Are Not Consistent
Applied the second version of the patch ('DNA-551-patch2.txt'), after all unit and integration tests passed. Basically, the Location.equals(...) and Location.isSame(...) method behaviors were switched, and the various uses corrected. Now, the Location.equals(...) and Location.hashCode() methods behave in the traditional way, and can be used as keys in Maps (even when you might have partial Location objects and the Map might contain actual Location objects, or vice versa). For more detail, see DNA-551.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -6323,7 +6323,7 @@
public boolean equals( Object obj ) {
if (obj instanceof Node) {
Node that = (Node)obj;
- return this.getLocation().equals(that.getLocation());
+ return this.getLocation().isSame(that.getLocation());
}
return false;
}
@@ -6591,7 +6591,7 @@
public boolean equals( Object obj ) {
if (obj instanceof Node) {
Node that = (Node)obj;
- return this.location.equals(that.getLocation());
+ return this.location.isSame(that.getLocation());
}
return false;
}
@@ -6799,7 +6799,7 @@
public boolean equals( Object obj ) {
if (obj instanceof Node) {
Node that = (Node)obj;
- return this.location.equals(that.getLocation());
+ return this.location.isSame(that.getLocation());
}
return false;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -73,7 +73,7 @@
public static I18n unableToCreateReferenceToNodeWithoutUuid;
public static I18n unableToCopyToLocationWithoutAPath;
public static I18n unableToCopyToTheRoot;
- public static I18n actualLocationIsNotSameAsInputLocation;
+ public static I18n actualLocationNotEqualToInputLocation;
public static I18n actualLocationIsNotChildOfInputLocation;
public static I18n actualLocationIsNotAtCorrectChildSegment;
public static I18n actualLocationDoesNotHaveCorrectChildName;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -41,7 +41,8 @@
import org.jboss.dna.graph.property.Property;
/**
- * The location of a node, as specified by either its path, UUID, and/or identification properties.
+ * The location of a node, as specified by either its path, UUID, and/or identification properties. Hash codes are not implemented
+ * in this base class to allow immutable subclasses to calculate and cache the hash code during object construction.
*/
@Immutable
public abstract class Location implements Iterable<Property>, Comparable<Location> {
@@ -97,7 +98,6 @@
*/
public static Location create( Path path ) {
CheckArg.isNotNull(path, "path");
-
return new LocationWithPath(path);
}
@@ -125,11 +125,8 @@
*/
public static Location create( Path path,
UUID uuid ) {
- if (path == null) {
- CheckArg.isNotNull(uuid, "uuid");
- return new LocationWithUuid(uuid);
- }
- if (uuid == null) return new LocationWithPath(path);
+ if (path == null) return create(uuid);
+ if (uuid == null) return create(path);
return new LocationWithPathAndUuid(path, uuid);
}
@@ -145,6 +142,11 @@
Property idProperty ) {
CheckArg.isNotNull(path, "path");
CheckArg.isNotNull(idProperty, "idProperty");
+ if (DnaLexicon.UUID.equals(idProperty.getName()) && idProperty.isSingle()) {
+ Object uuid = idProperty.getFirstValue();
+ assert uuid instanceof UUID;
+ return new LocationWithPathAndUuid(path, (UUID)uuid);
+ }
return new LocationWithPathAndProperty(path, idProperty);
}
@@ -190,14 +192,8 @@
for (Property property : idProperties) {
if (names.add(property.getName())) idPropertiesList.add(property);
}
- switch (idPropertiesList.size()) {
- case 0:
- return new LocationWithPath(path);
- case 1:
- return new LocationWithPathAndProperty(path, idPropertiesList.get(0));
- default:
- return new LocationWithPathAndProperties(path, idPropertiesList);
- }
+ if (idPropertiesList.isEmpty()) return new LocationWithPath(path);
+ return new LocationWithPathAndProperties(path, idPropertiesList);
}
/**
@@ -209,6 +205,11 @@
*/
public static Location create( Property idProperty ) {
CheckArg.isNotNull(idProperty, "idProperty");
+ if (DnaLexicon.UUID.equals(idProperty.getName()) && idProperty.isSingle()) {
+ Object uuid = idProperty.getFirstValue();
+ assert uuid instanceof UUID;
+ return new LocationWithUuid((UUID)uuid);
+ }
return new LocationWithProperty(idProperty);
}
@@ -224,7 +225,7 @@
Property... remainingIdProperties ) {
CheckArg.isNotNull(firstIdProperty, "firstIdProperty");
CheckArg.isNotNull(remainingIdProperties, "remainingIdProperties");
- if (remainingIdProperties.length == 0) return new LocationWithProperty(firstIdProperty);
+ if (remainingIdProperties.length == 0) return create(firstIdProperty);
List<Property> idProperties = new ArrayList<Property>(1 + remainingIdProperties.length);
Set<Name> names = new HashSet<Name>();
names.add(firstIdProperty.getName());
@@ -249,16 +250,7 @@
for (Property property : idProperties) {
if (names.add(property.getName())) idPropertiesList.add(property);
}
- switch (idPropertiesList.size()) {
- case 0:
- CheckArg.isNotEmpty(idPropertiesList, "idProperties");
- assert false;
- return null; // never get here
- case 1:
- return new LocationWithProperty(idPropertiesList.get(0));
- default:
- return new LocationWithProperties(idPropertiesList);
- }
+ return create(idPropertiesList);
}
/**
@@ -337,79 +329,16 @@
return null;
}
- /**
- * Compare this location to the supplied location, and determine whether the two locations represent the same logical
- * location. One location is considered the same as another location when one location is a superset of the other. For
- * example, consider the following locations:
- * <ul>
- * <li>location A is defined with a "<code>/x/y</code>" path</li>
- * <li>location B is defined with an identification property {id=3}</li>
- * <li>location C is defined with a "<code>/x/y/z</code>"</li>
- * <li>location D is defined with a "<code>/x/y/z</code>" path and an identification property {id=3}</li>
- * </ul>
- * Locations C and D would be considered the same, and B and D would also be considered the same. None of the other
- * combinations would be considered the same.
- * <p>
- * Note that passing a null location as a parameter will always return false.
- * </p>
- *
- * @param other the other location to compare
- * @return true if the two locations represent the same location, or false otherwise
- */
- public boolean isSame( Location other ) {
- return isSame(other, true);
- }
-
- /**
- * Compare this location to the supplied location, and determine whether the two locations represent the same logical
- * location. One location is considered the same as another location when one location is a superset of the other. For
- * example, consider the following locations:
- * <ul>
- * <li>location A is defined with a "<code>/x/y</code>" path</li>
- * <li>location B is defined with an identification property {id=3}</li>
- * <li>location C is defined with a "<code>/x/y/z</code>"</li>
- * <li>location D is defined with a "<code>/x/y/z</code>" path and an identification property {id=3}</li>
- * </ul>
- * Locations C and D would be considered the same, and B and D would also be considered the same. None of the other
- * combinations would be considered the same.
- * <p>
- * Note that passing a null location as a parameter will always return false.
- * </p>
- *
- * @param other the other location to compare
- * @param requireSameNameSiblingIndexes true if the paths must have equivalent {@link Path.Segment#getIndex()
- * same-name-sibling indexes}, or false if the same-name-siblings may be different
- * @return true if the two locations represent the same location, or false otherwise
- */
- public boolean isSame( Location other,
- boolean requireSameNameSiblingIndexes ) {
- if (other != null) {
- if (this.hasPath() && other.hasPath()) {
- // Paths on both, so the paths MUST match
- if (requireSameNameSiblingIndexes) {
- if (!this.getPath().equals(other.getPath())) return false;
- } else {
- Path thisPath = this.getPath();
- Path thatPath = other.getPath();
- if (thisPath.isRoot()) return thatPath.isRoot();
- if (thatPath.isRoot()) return thisPath.isRoot();
- // The parents must match ...
- if (!thisPath.hasSameAncestor(thatPath)) return false;
- // And the names of the last segments must match ...
- if (!thisPath.getLastSegment().getName().equals(thatPath.getLastSegment().getName())) return false;
- }
-
- // And the identification properties must match only if they exist on both
- if (this.hasIdProperties() && other.hasIdProperties()) {
- return this.getIdProperties().containsAll(other.getIdProperties());
- }
- return true;
- }
- // Path only in one, so the identification properties MUST match
- if (!other.hasIdProperties()) return false;
- return this.getIdProperties().containsAll(other.getIdProperties());
+ public boolean isSame( Location that ) {
+ if (that == null) return false;
+ if (this.hasPath()) {
+ if (!this.getPath().equals(that.getPath())) return false;
+ } else if (that.hasPath()) return false;
+ if (this.hasIdProperties()) {
+ if (that.hasIdProperties()) return this.getIdProperties().containsAll(that.getIdProperties());
+ return false;
}
- return false;
+ return (!that.hasIdProperties());
}
/**
@@ -438,20 +367,69 @@
*/
@Override
public boolean equals( Object obj ) {
+ return equals(obj, true);
+ }
+
+ /**
+ * Compare this location to the supplied location, and determine whether the two locations represent the same logical
+ * location. One location is considered the same as another location when one location is a superset of the other. For
+ * example, consider the following locations:
+ * <ul>
+ * <li>location A is defined with a "<code>/x/y</code>" path</li>
+ * <li>location B is defined with an identification property {id=3}</li>
+ * <li>location C is defined with a "<code>/x/y/z</code>"</li>
+ * <li>location D is defined with a "<code>/x/y/z</code>" path and an identification property {id=3}</li>
+ * </ul>
+ * Locations C and D would be considered the same, and B and D would also be considered the same. None of the other
+ * combinations would be considered the same.
+ * <p>
+ * Note that passing a null location as a parameter will always return false.
+ * </p>
+ *
+ * @param obj the other location to compare
+ * @param requireSameNameSiblingIndexes true if the paths must have equivalent {@link Path.Segment#getIndex()
+ * same-name-sibling indexes}, or false if the same-name-siblings may be different
+ * @return true if the two locations represent the same location, or false otherwise
+ */
+ public boolean equals( Object obj,
+ boolean requireSameNameSiblingIndexes ) {
+ // if (obj instanceof Location) {
+ // Location that = (Location)obj;
+ // if (this.hasPath()) {
+ // if (!this.getPath().equals(that.getPath())) return false;
+ // } else {
+ // if (that.hasPath()) return false;
+ // }
+ // if (this.hasIdProperties()) {
+ // if (!this.getIdProperties().equals(that.getIdProperties())) return
+ // false;
+ // } else {
+ // if (that.hasIdProperties()) return false;
+ // }
+ // return true;
+ // }
+ // return false;
if (obj instanceof Location) {
Location that = (Location)obj;
- if (this.hasPath()) {
- if (!this.getPath().equals(that.getPath())) return false;
+
+ // if both have same path they are equal
+ if (requireSameNameSiblingIndexes) {
+ if (this.hasPath() && that.hasPath()) return (this.getPath().equals(that.getPath()));
} else {
- if (that.hasPath()) return false;
+ Path thisPath = this.getPath();
+ Path thatPath = that.getPath();
+ if (thisPath.isRoot()) return thatPath.isRoot();
+ if (thatPath.isRoot()) return thisPath.isRoot();
+ // The parents must match ...
+ if (!thisPath.hasSameAncestor(thatPath)) return false;
+ // And the names of the last segments must match ...
+ if (!thisPath.getLastSegment().getName().equals(thatPath.getLastSegment().getName())) return false;
}
- if (this.hasIdProperties()) {
- if (!this.getIdProperties().equals(that.getIdProperties())) return false;
- } else {
- if (that.hasIdProperties()) return false;
- }
- return true;
+
+ // one or both is/are missing path so check properties instead
+ if (this.hasIdProperties()) return (this.getIdProperties().equals(that.getIdProperties()));
}
+
return false;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -39,7 +39,7 @@
* @see Location
*/
@Immutable
-final class LocationWithPath extends Location {
+class LocationWithPath extends Location {
private final Path path;
private final int hashCode;
@@ -79,7 +79,7 @@
* @see Location#getIdProperties()
*/
@Override
- public final List<Property> getIdProperties() {
+ public List<Property> getIdProperties() {
return null;
}
@@ -89,7 +89,7 @@
* @see Location#hasIdProperties()
*/
@Override
- public final boolean hasIdProperties() {
+ public boolean hasIdProperties() {
return false;
}
@@ -99,7 +99,7 @@
* @see Location#getUuid()
*/
@Override
- public final UUID getUuid() {
+ public UUID getUuid() {
return null;
}
@@ -137,7 +137,7 @@
@Override
public Location with( Property newIdProperty ) {
if (newIdProperty == null || newIdProperty.isEmpty()) return this;
- return Location.create(path, newIdProperty);
+ return create(path, newIdProperty);
}
/**
@@ -148,7 +148,7 @@
@Override
public Location with( Path newPath ) {
if (newPath == null || path.equals(newPath)) return this;
- return Location.create(newPath);
+ return create(newPath);
}
/**
@@ -159,6 +159,6 @@
@Override
public Location with( UUID uuid ) {
if (uuid == null) return this;
- return Location.create(path, uuid);
+ return create(path, uuid);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -27,8 +27,9 @@
import java.util.Collections;
import java.util.List;
import java.util.UUID;
+
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.HashCode;
+
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
@@ -40,13 +41,10 @@
* @see Location
*/
@Immutable
-final class LocationWithPathAndProperties extends Location {
+class LocationWithPathAndProperties extends LocationWithPath {
- private final Path path;
private final List<Property> idProperties;
- private final int hashCode;
-
/**
* Create a new location with a given path and set of identification properties.
*
@@ -55,30 +53,15 @@
*/
LocationWithPathAndProperties( Path path,
List<Property> idProperties ) {
- assert path != null;
+ super(path);
assert idProperties != null;
assert !idProperties.isEmpty();
- this.path = path;
this.idProperties = Collections.unmodifiableList(idProperties);
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
- hashCode = HashCode.compute(path, idProperties);
}
/**
* {@inheritDoc}
*
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#getIdProperties()
*/
@Override
@@ -87,23 +70,28 @@
}
/**
- * {@inheritDoc}
+ * Get the first UUID that is in one of the {@link #getIdProperties() identification properties}.
*
- * @see Location#hasIdProperties()
+ * @return the UUID for this location, or null if there is no such identification property
*/
@Override
- public final boolean hasIdProperties() {
- return idProperties.size() > 0;
+ public UUID getUuid() {
+ Property property = getIdProperty(DnaLexicon.UUID);
+ if (property != null && !property.isEmpty()) {
+ Object value = property.getFirstValue();
+ if (value instanceof UUID) return (UUID)value;
+ }
+ return null;
}
/**
* {@inheritDoc}
*
- * @see Location#hashCode()
+ * @see Location#hasIdProperties()
*/
@Override
- public int hashCode() {
- return hashCode;
+ public boolean hasIdProperties() {
+ return idProperties.size() > 0;
}
/**
@@ -124,9 +112,9 @@
}
newIdProperties.add(newIdProperty);
newIdProperties = Collections.unmodifiableList(newIdProperties);
- return new LocationWithPathAndProperties(path, newIdProperties);
+ return create(getPath(), newIdProperties);
}
- return new LocationWithPathAndProperty(path, newIdProperty);
+ return create(getPath(), newIdProperty);
}
/**
@@ -137,7 +125,7 @@
@Override
public Location with( Path newPath ) {
if (newPath == null || newPath.equals(this.getPath())) return this;
- return new LocationWithPathAndProperties(newPath, idProperties);
+ return create(newPath, idProperties);
}
/**
@@ -157,6 +145,6 @@
List<Property> newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
newIdProperties.addAll(idProperties);
newIdProperties.add(newProperty);
- return new LocationWithPathAndProperties(path, newIdProperties);
+ return create(getPath(), newIdProperties);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -24,11 +24,9 @@
package org.jboss.dna.graph;
import java.util.Collections;
-import java.util.List;
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
@@ -41,13 +39,8 @@
* @see Location
*/
@Immutable
-final class LocationWithPathAndProperty extends Location {
+class LocationWithPathAndProperty extends LocationWithPathAndProperties {
- private final Path path;
- private final List<Property> idProperties;
-
- private final int hashCode;
-
/**
* Create a new location with a given path and identification property.
*
@@ -56,67 +49,20 @@
*/
LocationWithPathAndProperty( Path path,
Property idProperty ) {
- assert path != null;
+ super(path, Collections.singletonList(idProperty));
assert idProperty != null;
assert !idProperty.isEmpty();
- this.path = path;
- this.idProperties = Collections.singletonList(idProperty);
-
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
- hashCode = HashCode.compute(this.path, idProperties);
}
/**
* {@inheritDoc}
*
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.Location#hasPath()
- */
- @Override
- public final boolean hasPath() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return idProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#getIdProperty(Name)
*/
@Override
public final Property getIdProperty( Name name ) {
CheckArg.isNotNull(name, "name");
- Property property = idProperties.get(0); // this is fast
+ Property property = getIdProperties().get(0); // this is fast
return property.getName().equals(name) ? property : null;
}
@@ -127,7 +73,7 @@
*/
@Override
public UUID getUuid() {
- Property property = idProperties.get(0); // this is fast
+ Property property = getIdProperties().get(0); // this is fast
if (DnaLexicon.UUID.equals(property.getName())) {
Object value = property.getFirstValue();
if (value instanceof UUID) return (UUID)value;
@@ -138,14 +84,14 @@
/**
* {@inheritDoc}
- *
- * @see Location#hashCode()
+ *
+ * @see org.jboss.dna.graph.LocationWithPathAndProperties#hasIdProperties()
*/
@Override
- public int hashCode() {
- return hashCode;
+ public final boolean hasIdProperties() {
+ return true;
}
-
+
/**
* {@inheritDoc}
*
@@ -154,11 +100,11 @@
@Override
public Location with( Property newIdProperty ) {
if (newIdProperty == null || newIdProperty.isEmpty()) return this;
- Property idProperty = idProperties.get(0); // fast
+ Property idProperty = getIdProperties().get(0); // fast
if (newIdProperty.getName().equals(idProperty.getName())) {
- return new LocationWithPathAndProperty(path, newIdProperty);
+ return Location.create(getPath(), newIdProperty);
}
- return Location.create(path, idProperty, newIdProperty);
+ return Location.create(getPath(), idProperty, newIdProperty);
}
/**
@@ -168,10 +114,10 @@
*/
@Override
public Location with( Path newPath ) {
- if (newPath == null) return Location.create(idProperties);
- if (path.equals(newPath)) return this;
- Property idProperty = idProperties.get(0); // fast
- return new LocationWithPathAndProperty(newPath, idProperty);
+ if (newPath == null) return Location.create(getIdProperties());
+ if (getPath().equals(newPath)) return this;
+ Property idProperty = getIdProperties().get(0); // fast
+ return Location.create(newPath, idProperty);
}
/**
@@ -181,10 +127,10 @@
*/
@Override
public Location with( UUID uuid ) {
- Property idProperty = idProperties.get(0); // fast
- if (uuid == null) return Location.create(path);
+ Property idProperty = getIdProperties().get(0); // fast
+ if (uuid == null) return Location.create(getPath());
assert !DnaLexicon.UUID.equals(idProperty.getName());
Property newUuidProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
- return Location.create(path, idProperty, newUuidProperty);
+ return Location.create(getPath(), idProperty, newUuidProperty);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndUuid.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndUuid.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndUuid.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -23,13 +23,8 @@
*/
package org.jboss.dna.graph;
-import java.util.Collections;
-import java.util.List;
import java.util.UUID;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
-import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
@@ -41,13 +36,10 @@
* @see Location
*/
@Immutable
-final class LocationWithPathAndUuid extends Location {
+final class LocationWithPathAndUuid extends LocationWithPathAndProperty {
- private final Path path;
- private final List<Property> idProperties;
+ private final UUID uuid;
- private final int hashCode;
-
/**
* Create a new location with a given path and identification property.
*
@@ -56,102 +48,34 @@
*/
LocationWithPathAndUuid( Path path,
UUID uuid ) {
- assert path != null;
+ super(path, new BasicSingleValueProperty(DnaLexicon.UUID, uuid));
assert uuid != null;
- this.path = path;
- this.idProperties = Collections.singletonList((Property)new BasicSingleValueProperty(DnaLexicon.UUID, uuid));
-
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
- hashCode = HashCode.compute(this.path, idProperties);
+ this.uuid = uuid;
}
/**
* {@inheritDoc}
*
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.Location#hasPath()
- */
- @Override
- public final boolean hasPath() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return idProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperty(Name)
- */
- @Override
- public final Property getIdProperty( Name name ) {
- CheckArg.isNotNull(name, "name");
- Property property = idProperties.get(0); // this is fast
- return property.getName().equals(name) ? property : null;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#getUuid()
*/
@Override
public final UUID getUuid() {
- return (UUID)idProperties.get(0).getFirstValue(); // this is fast, and we know this is a UUID object
+ return uuid;
}
/**
* {@inheritDoc}
*
- * @see Location#hashCode()
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#with(Property)
*/
@Override
- public Location with( Property newIdProperty ) {
- if (newIdProperty == null || newIdProperty.isEmpty()) return this;
- Property idProperty = idProperties.get(0); // fast
- if (newIdProperty.getName().equals(idProperty.getName())) {
- return new LocationWithPathAndProperty(path, newIdProperty);
+ public Location with( Property idProperty ) {
+ if (idProperty == null || idProperty.isEmpty()) return this;
+ if (DnaLexicon.UUID.equals(idProperty.getName())) {
+ if (idProperty.isSingle() && uuid.equals(idProperty.getFirstValue())) return this;
+ return Location.create(getPath(), idProperty);
}
- return Location.create(path, idProperty, newIdProperty);
+ return Location.create(getPath(), getIdProperties().get(0), idProperty);
}
/**
@@ -160,11 +84,10 @@
* @see Location#with(Path)
*/
@Override
- public Location with( Path newPath ) {
- if (newPath == null) return Location.create(idProperties);
- if (path.equals(newPath)) return this;
- Property idProperty = idProperties.get(0); // fast
- return new LocationWithPathAndProperty(newPath, idProperty);
+ public Location with( Path path ) {
+ if (path == null) return Location.create(uuid);
+ if (getPath().equals(path)) return this;
+ return Location.create(path, uuid);
}
/**
@@ -174,8 +97,8 @@
*/
@Override
public Location with( UUID uuid ) {
- if (uuid == null) return Location.create(path);
- if (uuid.equals(getUuid())) return this;
- return new LocationWithPathAndUuid(path, uuid);
+ if (uuid == null) return Location.create(getPath());
+ if (uuid.equals(this.uuid)) return this;
+ return Location.create(getPath(), uuid);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperties.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperties.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperties.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -40,7 +40,7 @@
* @see Location
*/
@Immutable
-final class LocationWithProperties extends Location {
+class LocationWithProperties extends Location {
private final List<Property> idProperties;
private final int hashCode;
@@ -57,7 +57,7 @@
// Paths are immutable, Properties are immutable, the idProperties list
// is wrapped in an unmodifiableList by the Location factory methods...
// ... so we can cache the hash code.
- hashCode = HashCode.compute(null, idProperties);
+ hashCode = HashCode.compute(idProperties);
}
/**
@@ -128,7 +128,7 @@
}
newIdProperties.add(newIdProperty);
newIdProperties = Collections.unmodifiableList(newIdProperties);
- return new LocationWithProperties(newIdProperties);
+ return create(newIdProperties);
}
/**
@@ -139,7 +139,7 @@
@Override
public Location with( Path newPath ) {
if (newPath == null) return this;
- return new LocationWithPathAndProperties(newPath, idProperties);
+ return create(newPath, idProperties);
}
/**
@@ -159,6 +159,6 @@
List<Property> newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
newIdProperties.addAll(idProperties);
newIdProperties.add(newProperty);
- return new LocationWithProperties(newIdProperties);
+ return create(newIdProperties);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperty.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperty.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithProperty.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -29,7 +29,6 @@
import java.util.UUID;
import net.jcip.annotations.Immutable;
import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
@@ -42,78 +41,28 @@
* @see Location
*/
@Immutable
-final class LocationWithProperty extends Location {
+final class LocationWithProperty extends LocationWithProperties {
- protected final List<Property> idProperties;
-
- private final int hashCode;
-
/**
* Create a new location with a given path and identification property.
*
* @param idProperty the identification property
*/
LocationWithProperty( Property idProperty ) {
+ super(Collections.singletonList(idProperty));
assert idProperty != null;
assert !idProperty.isEmpty();
- // The path could be null
- this.idProperties = Collections.singletonList(idProperty);
-
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
- hashCode = HashCode.compute(null, idProperties);
}
/**
* {@inheritDoc}
*
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.Location#hasPath()
- */
- @Override
- public boolean hasPath() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return idProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#getIdProperty(Name)
*/
@Override
public final Property getIdProperty( Name name ) {
CheckArg.isNotNull(name, "name");
- Property property = idProperties.get(0); // this is fast
+ Property property = getIdProperties().get(0); // this is fast
return property.getName().equals(name) ? property : null;
}
@@ -124,7 +73,7 @@
*/
@Override
public UUID getUuid() {
- Property property = idProperties.get(0); // this is fast
+ Property property = getIdProperties().get(0); // this is fast
if (DnaLexicon.UUID.equals(property.getName())) {
Object value = property.getFirstValue();
if (value instanceof UUID) return (UUID)value;
@@ -136,29 +85,19 @@
/**
* {@inheritDoc}
*
- * @see Location#hashCode()
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- /**
- * {@inheritDoc}
- *
* @see Location#with(Property)
*/
@Override
public Location with( Property newIdProperty ) {
if (newIdProperty == null || newIdProperty.isEmpty()) return this;
- Property idProperty = idProperties.get(0); // fast
+ Property idProperty = getIdProperties().get(0); // fast
if (newIdProperty.getName().equals(idProperty.getName())) {
return Location.create(newIdProperty);
}
- List<Property> newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
+ List<Property> newIdProperties = new ArrayList<Property>(getIdProperties().size() + 1);
newIdProperties.add(newIdProperty);
- newIdProperties.addAll(idProperties);
- return new LocationWithProperties(newIdProperties);
+ newIdProperties.addAll(getIdProperties());
+ return Location.create(newIdProperties);
}
/**
@@ -169,8 +108,8 @@
@Override
public Location with( Path newPath ) {
if (newPath == null) return this;
- Property idProperty = idProperties.get(0); // fast
- return new LocationWithPathAndProperty(newPath, idProperty);
+ Property idProperty = getIdProperties().get(0); // fast
+ return Location.create(newPath, idProperty);
}
/**
@@ -181,13 +120,13 @@
@Override
public Location with( UUID uuid ) {
if (uuid == null) return this;
- Property idProperty = idProperties.get(0); // fast
+ Property idProperty = getIdProperties().get(0); // fast
if (DnaLexicon.UUID.equals(idProperty.getName())) {
- return new LocationWithUuid(uuid);
+ return Location.create(uuid);
}
- List<Property> newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
+ List<Property> newIdProperties = new ArrayList<Property>(getIdProperties().size() + 1);
newIdProperties.add(new BasicSingleValueProperty(DnaLexicon.UUID, uuid));
- newIdProperties.addAll(idProperties);
- return new LocationWithProperties(newIdProperties);
+ newIdProperties.addAll(getIdProperties());
+ return Location.create(newIdProperties);
}
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -130,7 +130,7 @@
*/
@Override
public Location with( UUID uuid ) {
- return new LocationWithUuid(uuid);
+ return Location.create(uuid);
}
/**
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ProjectedNode.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ProjectedNode.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ProjectedNode.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -140,7 +140,7 @@
super(locationInSource);
this.projection = projection;
this.federatedLocation = locationInFederated;
- this.sameLocationAsOriginal = locationInSource.equals(locationInFederated);
+ this.sameLocationAsOriginal = locationInSource.isSame(locationInFederated);
}
protected ProxyNode( Projection projection,
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/NetChangeObserver.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/NetChangeObserver.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/observe/NetChangeObserver.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -303,7 +303,7 @@
if (that == this) return true;
if (this.hc != that.hc) return false;
if (!this.workspaceName.equals(that.workspaceName)) return false;
- if (!this.location.equals(that.location)) return false;
+ if (!this.location.isSame(that.location)) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/MergeJoinComponent.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/MergeJoinComponent.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/MergeJoinComponent.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -178,7 +178,7 @@
for (int i = columns.getColumnCount(); i != columns.getLocationCount(); ++i) {
Location location = (Location)tuple1[i];
Location location2 = (Location)tuple2[i];
- if (!location.equals(location2)) return false;
+ if (!location.isSame(location2)) return false;
}
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -426,7 +426,7 @@
// If there's a pending request ...
if (pendingRequest != null) {
// Compare the supplied location with that of the pending request
- if (pendingRequest.location.equals(on)) {
+ if (pendingRequest.location.isSame(on)) {
// They are the same location, so we can add the properties to the pending request ...
pendingRequest.pendingProperties.put(property.getName(), property);
return this;
@@ -456,7 +456,7 @@
// If there's a pending request ...
if (pendingRequest != null) {
// Compare the supplied location with that of the pending request
- if (pendingRequest.location.equals(on)) {
+ if (pendingRequest.location.isSame(on)) {
// They are the same location, so we can add the properties to the pending request ...
for (Property property : properties) {
pendingRequest.pendingProperties.put(property.getName(), property);
@@ -492,7 +492,7 @@
// If there's a pending request ...
if (pendingRequest != null) {
// Compare the supplied location with that of the pending request
- if (pendingRequest.location.equals(on)) {
+ if (pendingRequest.location.isSame(on)) {
// They are the same location, so we can add the properties to the pending request ...
pendingRequest.pendingProperties.put(propertyName, null);
return this;
@@ -523,7 +523,7 @@
// If there's a pending request ...
if (pendingRequest != null) {
// Compare the supplied location with that of the pending request
- if (pendingRequest.location.equals(on)) {
+ if (pendingRequest.location.isSame(on)) {
// They are the same location, so we can add the properties to the pending request ...
for (Name propertyName : propertyNames) {
pendingRequest.pendingProperties.put(propertyName, null);
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CloneBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CloneBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CloneBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -176,8 +176,8 @@
public void setActualLocations( Location fromLocation,
Location intoLocation ) {
checkNotFrozen();
- if (!from.isSame(fromLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(fromLocation, from));
+ if (!from.equals(fromLocation)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(fromLocation, from));
}
CheckArg.isNotNull(intoLocation, "intoLocation");
assert fromLocation != null;
@@ -306,8 +306,8 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
CloneBranchRequest that = (CloneBranchRequest)obj;
- if (!this.from().equals(that.from())) return false;
- if (!this.into().equals(that.into())) return false;
+ if (!this.from().isSame(that.from())) return false;
+ if (!this.into().isSame(that.into())) return false;
if (!this.fromWorkspace.equals(that.fromWorkspace)) return false;
if (!this.intoWorkspace.equals(that.intoWorkspace)) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CopyBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -212,8 +212,8 @@
public void setActualLocations( Location fromLocation,
Location intoLocation ) {
checkNotFrozen();
- if (!from.isSame(fromLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(fromLocation, from));
+ if (!from.equals(fromLocation)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(fromLocation, from));
}
CheckArg.isNotNull(intoLocation, "intoLocation");
assert fromLocation != null;
@@ -313,8 +313,8 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
CopyBranchRequest that = (CopyBranchRequest)obj;
- if (!this.from().equals(that.from())) return false;
- if (!this.into().equals(that.into())) return false;
+ if (!this.from().isSame(that.from())) return false;
+ if (!this.into().isSame(that.into())) return false;
if (!this.nodeConflictBehavior().equals(that.nodeConflictBehavior())) return false;
if (!this.fromWorkspace.equals(that.fromWorkspace)) return false;
if (!this.intoWorkspace.equals(that.intoWorkspace)) return false;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CreateNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CreateNodeRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/CreateNodeRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -282,7 +282,7 @@
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
CheckArg.isNotNull(actual, "actual");
- if (!under.isSame(actual, false)) { // not same if actual is null
+ if (!under.equals(actual, false)) { // not same if actual is null
}
assert actual != null;
if (!actual.hasPath()) {
@@ -290,7 +290,7 @@
}
assert actual.hasPath();
if (under.hasPath() && !under.getPath().equals(actual.getPath().getParent())) {
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, under));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, under));
}
this.actualLocation = actual;
}
@@ -366,7 +366,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
CreateNodeRequest that = (CreateNodeRequest)obj;
- if (!this.under().equals(that.under())) return false;
+ if (!this.under().isSame(that.under())) return false;
if (!this.conflictBehavior().equals(that.conflictBehavior())) return false;
if (!this.inWorkspace().equals(that.conflictBehavior())) return false;
if (!this.properties().equals(that.properties())) return false;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -94,8 +94,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -175,7 +175,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
DeleteBranchRequest that = (DeleteBranchRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteChildrenRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteChildrenRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/DeleteChildrenRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -98,8 +98,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -240,7 +240,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
DeleteChildrenRequest that = (DeleteChildrenRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -128,8 +128,8 @@
*/
public void setActualLocation( Location actualLocation ) {
checkNotFrozen();
- if (!at.isSame(actualLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actualLocation, at));
+ if (!at.equals(actualLocation)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actualLocation, at));
}
assert actualLocation != null;
if (!actualLocation.hasPath()) {
@@ -210,7 +210,7 @@
if (this.getClass().isInstance(obj)) {
LockBranchRequest that = (LockBranchRequest)obj;
if (this.lockTimeoutInMillis() != that.lockTimeoutInMillis()) return false;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (this.lockScope() != that.lockScope()) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/MoveBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/MoveBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/MoveBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -236,8 +236,8 @@
checkNotFrozen();
CheckArg.isNotNull(oldLocation, "oldLocation");
CheckArg.isNotNull(newLocation, "newLocation");
- if (!from.isSame(oldLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(oldLocation, from));
+ if (!from.equals(oldLocation)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(oldLocation, from));
}
if (!oldLocation.hasPath()) {
throw new IllegalArgumentException(GraphI18n.actualOldLocationMustHavePath.text(oldLocation));
@@ -246,12 +246,12 @@
throw new IllegalArgumentException(GraphI18n.actualNewLocationMustHavePath.text(newLocation));
}
if (into() != null && into().hasPath() && !newLocation.getPath().getParent().isSameAs(into.getPath())) {
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(newLocation, into));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(newLocation, into));
}
Name actualNewName = newLocation.getPath().getLastSegment().getName();
Name expectedNewName = desiredName() != null ? desiredName() : oldLocation.getPath().getLastSegment().getName();
if (!actualNewName.equals(expectedNewName)) {
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(newLocation, into));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(newLocation, into));
}
this.actualOldLocation = oldLocation;
this.actualNewLocation = newLocation;
@@ -350,8 +350,8 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
MoveBranchRequest that = (MoveBranchRequest)obj;
- if (!this.from().equals(that.from())) return false;
- if (!this.into().equals(that.into())) return false;
+ if (!this.from().isSame(that.from())) return false;
+ if (!this.into().isSame(that.into())) return false;
if (!this.conflictBehavior().equals(that.conflictBehavior())) return false;
if (!this.workspaceName.equals(that.workspaceName)) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllChildrenRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllChildrenRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllChildrenRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -194,8 +194,8 @@
*/
public void setActualLocationOfNode( Location actualLocation ) {
checkNotFrozen();
- if (!this.of.isSame(actualLocation)) { // not same if actualLocation is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actualLocation, of));
+ if (!this.of.equals(actualLocation)) { // not same if actualLocation is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actualLocation, of));
}
assert actualLocation != null;
if (!actualLocation.hasPath()) {
@@ -244,7 +244,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadAllChildrenRequest that = (ReadAllChildrenRequest)obj;
- if (!this.of().equals(that.of())) return false;
+ if (!this.of().isSame(that.of())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllPropertiesRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllPropertiesRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadAllPropertiesRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -195,8 +195,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -245,7 +245,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadAllPropertiesRequest that = (ReadAllPropertiesRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBlockOfChildrenRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBlockOfChildrenRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBlockOfChildrenRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -240,8 +240,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!of.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, of));
+ if (!of.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, of));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -291,7 +291,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadBlockOfChildrenRequest that = (ReadBlockOfChildrenRequest)obj;
- if (!this.of().equals(that.of())) return false;
+ if (!this.of().isSame(that.of())) return false;
if (this.startingAtIndex() != that.startingAtIndex()) return false;
if (this.count() != that.count()) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -367,8 +367,8 @@
* location} as the {@link #at() current location}, or if the actual location does not have a path.
*/
public void setActualLocationOfNode( Location actual ) {
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -418,7 +418,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadBranchRequest that = (ReadBranchRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (this.maximumDepth() != that.maximumDepth()) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNextBlockOfChildrenRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNextBlockOfChildrenRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNextBlockOfChildrenRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -210,7 +210,7 @@
public void setActualLocationOfStartingAfterNode( Location actual ) {
checkNotFrozen();
if (!startingAfter.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, startingAfter));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, startingAfter));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -260,7 +260,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadNextBlockOfChildrenRequest that = (ReadNextBlockOfChildrenRequest)obj;
- if (!this.startingAfter().equals(that.startingAfter())) return false;
+ if (!this.startingAfter().isSame(that.startingAfter())) return false;
if (this.count() != that.count()) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNodeRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadNodeRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -259,8 +259,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -311,7 +311,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadNodeRequest that = (ReadNodeRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadPropertyRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadPropertyRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/ReadPropertyRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -134,8 +134,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!on.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, on));
+ if (!on.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, on));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -185,7 +185,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
ReadPropertyRequest that = (ReadPropertyRequest)obj;
- if (!this.on().equals(that.on())) return false;
+ if (!this.on().isSame(that.on())) return false;
if (!this.named().equals(that.named())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RemovePropertyRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RemovePropertyRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RemovePropertyRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -111,7 +111,7 @@
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
if (!from.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, from));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, from));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -171,7 +171,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
RemovePropertyRequest that = (RemovePropertyRequest)obj;
- if (!this.from().equals(that.from())) return false;
+ if (!this.from().isSame(that.from())) return false;
if (!this.propertyName().equals(that.propertyName())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RenameNodeRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RenameNodeRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/RenameNodeRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -117,11 +117,11 @@
Location newLocation ) {
checkNotFrozen();
if (!at.isSame(oldLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(oldLocation, at));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(oldLocation, at));
}
assert oldLocation != null;
if (newLocation == null) {
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(newLocation, at));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(newLocation, at));
}
if (!oldLocation.hasPath()) {
throw new IllegalArgumentException(GraphI18n.actualOldLocationMustHavePath.text(oldLocation));
@@ -226,7 +226,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
RenameNodeRequest that = (RenameNodeRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.toName().equals(that.toName())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/SetPropertyRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/SetPropertyRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/SetPropertyRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -111,8 +111,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!on.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, on));
+ if (!on.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, on));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -172,7 +172,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
SetPropertyRequest that = (SetPropertyRequest)obj;
- if (!this.on().equals(that.on())) return false;
+ if (!this.on().isSame(that.on())) return false;
if (!this.property().equals(that.property())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -95,7 +95,7 @@
public void setActualLocation( Location actualLocation ) {
checkNotFrozen();
if (!at.isSame(actualLocation)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actualLocation, at));
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actualLocation, at));
}
assert actualLocation != null;
if (!actualLocation.hasPath()) {
@@ -175,7 +175,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
UnlockBranchRequest that = (UnlockBranchRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdatePropertiesRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdatePropertiesRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdatePropertiesRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -128,8 +128,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!on.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, on));
+ if (!on.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, on));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -189,7 +189,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
UpdatePropertiesRequest that = (UpdatePropertiesRequest)obj;
- if (!this.on().equals(that.on())) return false;
+ if (!this.on().isSame(that.on())) return false;
if (!this.properties().equals(that.properties())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdateValuesRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdateValuesRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UpdateValuesRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -127,8 +127,8 @@
public void setActualLocation(Location actual, List<Object> actualAddedValues, List<Object> actualRemovedValues) {
checkNotFrozen();
- if (!on.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, on));
+ if (!on.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, on));
}
assert actual != null;
if (!actual.hasPath()) {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/VerifyNodeExistsRequest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -93,8 +93,8 @@
*/
public void setActualLocationOfNode( Location actual ) {
checkNotFrozen();
- if (!at.isSame(actual)) { // not same if actual is null
- throw new IllegalArgumentException(GraphI18n.actualLocationIsNotSameAsInputLocation.text(actual, at));
+ if (!at.equals(actual)) { // not same if actual is null
+ throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, at));
}
assert actual != null;
if (!actual.hasPath()) {
@@ -155,7 +155,7 @@
if (obj == this) return true;
if (this.getClass().isInstance(obj)) {
VerifyNodeExistsRequest that = (VerifyNodeExistsRequest)obj;
- if (!this.at().equals(that.at())) return false;
+ if (!this.at().isSame(that.at())) return false;
if (!this.inWorkspace().equals(that.inWorkspace())) return false;
return true;
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -38,7 +38,6 @@
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.cache.CachePolicy;
import org.jboss.dna.graph.connector.LockFailedException;
-import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.observe.Changes;
import org.jboss.dna.graph.observe.Observer;
import org.jboss.dna.graph.property.DateTime;
@@ -549,7 +548,7 @@
if (count > request.count()) break;
if (!found) {
// Set to true if we find the child we're looking for ...
- found = child.equals(request.startingAfter());
+ found = child.isSame(request.startingAfter());
} else {
// Add the child to the block ...
++count;
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -1442,7 +1442,7 @@
org.jboss.dna.graph.Node persistentNode = cache.store.getNodeAt(getLocation());
// Check the actual location ...
Location actualLocation = persistentNode.getLocation();
- if (!this.location.equals(actualLocation)) {
+ if (!this.location.isSame(actualLocation)) {
// The actual location is changed, so update it ...
this.location = actualLocation;
}
@@ -1452,7 +1452,7 @@
// Then read the node from the store ...
Subgraph subgraph = cache.store.getSubgraphOfDepth(depth).at(getLocation());
Location actualLocation = subgraph.getLocation();
- if (!this.location.equals(actualLocation)) {
+ if (!this.location.isSame(actualLocation)) {
// The actual location is changed, so update it ...
this.location = actualLocation;
}
@@ -2708,7 +2708,7 @@
Node<Payload, PropertyPayload> that = (Node<Payload, PropertyPayload>)obj;
if (this.isStale() || that.isStale()) return false;
if (!this.nodeId.equals(that.nodeId)) return false;
- return this.location.equals(that.location);
+ return this.location.isSame(that.location);
}
return false;
}
Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties 2009-11-25 20:18:20 UTC (rev 1351)
@@ -61,7 +61,7 @@
unableToCreateReferenceToNodeWithoutUuid = Unable to set a reference to node {0} since it has no UUID
unableToCopyToLocationWithoutAPath = Unable to copy node "{0}" to "{1}" since the desired location has no path
unableToCopyToTheRoot = Unable to copy node "{0}" to "{1}" since the desired location is the root node
-actualLocationIsNotSameAsInputLocation = The actual location of {0} is not the same as the current location of {1}
+actualLocationNotEqualToInputLocation = The actual location of {0} is not equal to the current location of {1}
actualLocationIsNotChildOfInputLocation = The actual location of {0} is not a child of the specified location {1}
actualLocationIsNotAtCorrectChildSegment = The last segment of the actual location of {0} does not have the requested child segment {1}
actualLocationDoesNotHaveCorrectChildName = The last segment of the actual location of {0} does not have the requested child name {1}
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/LocationTest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -128,11 +128,11 @@
}
@Test
- public void locationsWithSamePathsAndDifferentPropertyAreNotEqual() {
+ public void locationsWithSamePathsAndDifferentPropertyAreEqual() {
Location locationA1 = Location.create(pathA, propA);
Location locationA2 = Location.create(pathA, propB);
- assertThat("Locations created with identical paths and different property must not be equal", locationA1, not(locationA2));
+ assertThat("Locations created with identical paths and different property must not be equal", locationA1.equals(locationA2), is(true));
}
@Test
@@ -187,8 +187,8 @@
Location locationA2 = Location.create(pathA, propListABU);
assertThat("Locations created with identical paths and different properties must not be equal",
- locationA1,
- not(locationA2));
+ locationA1.equals(locationA2),
+ is(true));
}
@Test
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/AbstractConnectorTest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -447,7 +447,7 @@
// Check the result has the correct location ...
assertThat("The node that was read doesn't have the expected location",
- result.getLocation().isSame(location, true),
+ result.getLocation().equals(location),
is(true));
}
@@ -667,7 +667,7 @@
assertThat(subgraph2, is(notNullValue()));
// Shortcut ...
- if (subgraph1.getLocation().equals(subgraph2.getLocation())) return;
+ if (subgraph1.getLocation().isSame(subgraph2.getLocation())) return;
Path rootPath1 = subgraph1.getRoot().getLocation().getPath();
Path rootPath2 = subgraph2.getRoot().getLocation().getPath();
@@ -738,7 +738,7 @@
// Check the locations ...
Location location1 = node1.getLocation();
Location location2 = node2.getLocation();
- assertThat(location1.isSame(location2, true), is(true));
+ assertThat(location1.isSame(location2), is(true));
// Check the paths ...
assertThat(location1.getPath(), is(location2.getPath()));
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/ReadableConnectorTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/ReadableConnectorTest.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/ReadableConnectorTest.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -93,7 +93,7 @@
Node root = graph.getNodeAt("/");
for (int i = 0; i != 10; ++i) {
Node anotherRoot = graph.getNodeAt("/");
- assertThat(anotherRoot.getLocation().equals(root.getLocation()), is(true));
+ assertThat(anotherRoot.getLocation().isSame(root.getLocation()), is(true));
assertThat(anotherRoot.getLocation().getPath(), is(root.getLocation().getPath()));
assertThat(anotherRoot.getLocation().getIdProperties(), is(root.getLocation().getIdProperties()));
}
@@ -117,7 +117,7 @@
}
// Find the root node using the identification properties ...
Node anotherRoot = graph.getNodeAt(firstProperty, additionalProperties);
- assertThat(anotherRoot.getLocation().equals(root.getLocation()), is(true));
+ assertThat(anotherRoot.getLocation().isSame(root.getLocation()), is(true));
assertThat(anotherRoot.getLocation().getPath(), is(root.getLocation().getPath()));
assertThat(anotherRoot.getLocation().getIdProperties(), is(root.getLocation().getIdProperties()));
}
@@ -131,7 +131,7 @@
if (uuid != null) {
// Find the root node using the identification properties ...
Node anotherRoot = graph.getNodeAt(uuid);
- assertThat(anotherRoot.getLocation().equals(root.getLocation()), is(true));
+ assertThat(anotherRoot.getLocation().isSame(root.getLocation()), is(true));
assertThat(anotherRoot.getLocation().getPath(), is(root.getLocation().getPath()));
assertThat(anotherRoot.getLocation().getIdProperties(), is(root.getLocation().getIdProperties()));
assertThat(anotherRoot.getLocation().getUuid(), is(root.getLocation().getUuid()));
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-11-25 18:15:33 UTC (rev 1350)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-11-25 20:18:20 UTC (rev 1351)
@@ -1773,7 +1773,7 @@
if (obj instanceof AbstractJcrNode) {
AbstractJcrNode that = (AbstractJcrNode)obj;
if (this.cache != that.cache) return false;
- return this.location.equals(that.location);
+ return this.location.isSame(that.location);
}
return false;
}
14 years, 5 months
DNA SVN: r1350 - trunk/dna-graph/src/main/java/org/jboss/dna/graph/session.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-11-25 13:15:33 -0500 (Wed, 25 Nov 2009)
New Revision: 1350
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
Log:
DNA-559 GraphSession cloneImmediate fails to remove existing nodes from cache because of Set ordering variations
GraphSession.cloneImmediate(...) has a parameter that specifies whether any existing nodes should be removed (from the connector), and if this connector request succeeds and did remove those nodes, the method continues by attempting to purge these nodes from the cache. However, the request collects in a Set the Location for each of the removed nodes, so the order of these nodes cannot be guaranteed. And in fact when the cloneImmediate method walks them, the test was purging a parent node followed by a child node. Since purging the parent also purged all children (and other descendants), attempting to purge the child results in an exception.
The fix is relatively simple: check whether a node being purged is below a node that already was purged. All unit tests now pass.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java 2009-11-25 15:20:46 UTC (rev 1349)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java 2009-11-25 18:15:33 UTC (rev 1350)
@@ -645,9 +645,16 @@
Location locationOfCopy = request.getActualLocationAfter();
// Remove from the session all of the nodes that were removed as part of this clone ...
+ Set<Path> removedAlready = new HashSet<Path>();
for (Location removed : request.getRemovedNodes()) {
- Node<Payload, PropertyPayload> removedNode = findNodeWith(removed.getPath(), false);
- if (removedNode != null) removedNode.remove(false);
+ Path path = removed.getPath();
+ if (isBelow(path, removedAlready)) {
+ // This node is below a node we've already removed, so skip it ...
+ continue;
+ }
+ Node<Payload, PropertyPayload> removedNode = findNodeWith(path, false);
+ removedNode.remove(false);
+ removedAlready.add(path);
}
// Find the parent node in the session ...
@@ -658,6 +665,14 @@
}
}
+ private static final boolean isBelow( Path path,
+ Collection<Path> paths ) {
+ for (Path aPath : paths) {
+ if (aPath.isAncestorOf(path)) return true;
+ }
+ return false;
+ }
+
/**
* Refreshes (removes the cached state) for all cached nodes.
* <p>
14 years, 5 months
DNA SVN: r1349 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/request/processor and 1 other directories.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-11-25 10:20:46 -0500 (Wed, 25 Nov 2009)
New Revision: 1349
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java
Log:
DNA-457 Add JSR-170 Locking Optional Feature
Removed dangling Javadoc references to RepositorySourceCapabilities.supportsLocks()
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java 2009-11-25 13:36:11 UTC (rev 1348)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/LockBranchRequest.java 2009-11-25 15:20:46 UTC (rev 1349)
@@ -27,12 +27,10 @@
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
-import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.property.Path;
/**
- * Instruction to lock an existing node or branch. Connectors that do not support locking (as defined in
- * {@link RepositorySourceCapabilities#supportsLocks()}) must ignore this request.
+ * Instruction to lock an existing node or branch. Connectors that do not support locking must ignore this request.
*/
public class LockBranchRequest extends ChangeRequest {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java 2009-11-25 13:36:11 UTC (rev 1348)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/UnlockBranchRequest.java 2009-11-25 15:20:46 UTC (rev 1349)
@@ -27,12 +27,10 @@
import org.jboss.dna.common.util.HashCode;
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.Location;
-import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.property.Path;
/**
- * Instruction to unlock an existing node or branch. Connectors that do not support locking (as defined in
- * {@link RepositorySourceCapabilities#supportsLocks()}) must ignore this request.
+ * Instruction to unlock an existing node or branch. Connectors that do not support locking must ignore this request.
*/
public class UnlockBranchRequest extends ChangeRequest {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-11-25 13:36:11 UTC (rev 1348)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-11-25 15:20:46 UTC (rev 1349)
@@ -856,9 +856,8 @@
/**
* Process a request to lock a node or branch within a workspace
* <p>
- * The default implementation of this method does nothing, as most connectors will not support locking (as defined in
- * {@link RepositorySourceCapabilities#supportsLocks()}). Any implementation of this method should do nothing if the request
- * is null.
+ * The default implementation of this method does nothing, as most connectors will not support locking. Any implementation of
+ * this method should do nothing if the request is null.
* </p>
* <p>
* Implementations that do support locking should throw a {@link LockFailedException} if the request could not be fulfilled.
@@ -887,9 +886,8 @@
/**
* Process a request to unlock a node or branch within a workspace
* <p>
- * The default implementation of this method does nothing, as most connectors will not support locking (as defined in
- * {@link RepositorySourceCapabilities#supportsLocks()}). Any implementation of this method should do nothing if the request
- * is null.
+ * The default implementation of this method does nothing, as most connectors will not support locking. Any implementation of
+ * this method should do nothing if the request is null.
* </p>
*
* @param request the request
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java 2009-11-25 13:36:11 UTC (rev 1348)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/WorkspaceLockManager.java 2009-11-25 15:20:46 UTC (rev 1349)
@@ -16,7 +16,6 @@
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.connector.LockFailedException;
-import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.property.PathNotFoundException;
@@ -133,9 +132,8 @@
* {@link Item#refresh(boolean) item} level.
* <p>
* This method will also attempt to {@link Graph#lock(Location) lock the node in the underlying repository}. If the underlying
- * repository {@link RepositorySourceCapabilities#supportsLocks() supports locks} and {@link LockFailedException the lock
- * attempt fails}, this method will cancel the lock attempt by calling {@link #unlock(DnaLock)} and will throw a {@code
- * RepositoryException}.
+ * repository supports locks and {@link LockFailedException the lock attempt fails}, this method will cancel the lock attempt
+ * by calling {@link #unlock(DnaLock)} and will throw a {@code RepositoryException}.
* </p>
* <p>
* This method does not modify the system graph. In other words, it will not create the record for the lock in the {@code
@@ -243,9 +241,8 @@
ValueFactory<Boolean> booleanFactory = context.getValueFactories().getBooleanFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
- org.jboss.dna.graph.Node lockNode = repository.createSystemGraph()
- .getNodeAt(pathFactory.create(locksPath,
- pathFactory.createSegment(lockToken)));
+ org.jboss.dna.graph.Node lockNode = repository.createSystemGraph().getNodeAt(pathFactory.create(locksPath,
+ pathFactory.createSegment(lockToken)));
return booleanFactory.create(lockNode.getProperty(DnaLexicon.IS_HELD_BY_SESSION).getFirstValue());
@@ -266,9 +263,8 @@
PropertyFactory propFactory = context.getPropertyFactory();
PathFactory pathFactory = context.getValueFactories().getPathFactory();
- repository.createSystemGraph()
- .set(propFactory.create(DnaLexicon.IS_HELD_BY_SESSION, value))
- .on(pathFactory.create(locksPath, pathFactory.createSegment(lockToken)));
+ repository.createSystemGraph().set(propFactory.create(DnaLexicon.IS_HELD_BY_SESSION, value)).on(pathFactory.create(locksPath,
+ pathFactory.createSegment(lockToken)));
}
/**
14 years, 5 months
DNA SVN: r1348 - in trunk/dna-graph/src: test/java/org/jboss/dna/graph/connector/test and 1 other directory.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-11-25 08:36:11 -0500 (Wed, 25 Nov 2009)
New Revision: 1348
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySourceCapabilities.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/WritableConnectorTest.java
Log:
DNA-457 Add JSR-170 Locking Optional Feature
Applied one more patch (DNA-457_no_repo_source_capabilities.patch) to remove supportsLocks() from RepositorySourceCapabilities per an IRC conversation with Randall. Coupled with the previous patch, this should re-resolve this defect.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySourceCapabilities.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySourceCapabilities.java 2009-11-25 13:29:54 UTC (rev 1347)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositorySourceCapabilities.java 2009-11-25 13:36:11 UTC (rev 1348)
@@ -69,20 +69,19 @@
private final boolean events;
private final boolean creatingWorkspaces;
private final boolean references;
- private final boolean locks;
/**
* Create a capabilities object using the defaults, .
*/
public RepositorySourceCapabilities() {
this(DEFAULT_SUPPORT_SAME_NAME_SIBLINGS, DEFAULT_SUPPORT_UPDATES, DEFAULT_SUPPORT_EVENTS,
- DEFAULT_SUPPORT_CREATING_WORKSPACES, DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS);
+ DEFAULT_SUPPORT_CREATING_WORKSPACES, DEFAULT_SUPPORT_REFERENCES);
}
public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
boolean supportsUpdates ) {
this(supportsSameNameSiblings, supportsUpdates, DEFAULT_SUPPORT_EVENTS, DEFAULT_SUPPORT_CREATING_WORKSPACES,
- DEFAULT_SUPPORT_REFERENCES, DEFAULT_SUPPORT_LOCKS);
+ DEFAULT_SUPPORT_REFERENCES);
}
public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
@@ -90,24 +89,12 @@
boolean supportsEvents,
boolean supportsCreatingWorkspaces,
boolean supportsReferences ) {
- this(supportsSameNameSiblings, supportsUpdates, supportsEvents, supportsCreatingWorkspaces, supportsReferences,
- DEFAULT_SUPPORT_LOCKS);
- }
-
- public RepositorySourceCapabilities( boolean supportsSameNameSiblings,
- boolean supportsUpdates,
- boolean supportsEvents,
- boolean supportsCreatingWorkspaces,
- boolean supportsReferences,
- boolean supportsLocks ) {
-
this.sameNameSiblings = supportsSameNameSiblings;
this.updates = supportsUpdates;
this.events = supportsEvents;
this.creatingWorkspaces = supportsCreatingWorkspaces;
this.references = supportsReferences;
- this.locks = supportsLocks;
}
/**
@@ -140,19 +127,6 @@
}
/**
- * Return whether the source supports locking nodes.
- * <p>
- * Sources that support locking nodes must be able to explicitly lock and unlock nodes in a manner that is persistent and
- * stable across repository connections. Sources that cannot provide this capability should return false from this method.
- * </p>
- *
- * @return true if locks are supported, or false otherwise
- */
- public boolean supportsLocks() {
- return locks;
- }
-
- /**
* Return whether the source supports publishing change events.
*
* @return true if events are supported, or false if the source is not capable of generating events
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/WritableConnectorTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/WritableConnectorTest.java 2009-11-25 13:29:54 UTC (rev 1347)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/test/WritableConnectorTest.java 2009-11-25 13:36:11 UTC (rev 1348)
@@ -84,10 +84,6 @@
super.afterEach();
}
- private boolean supportsLocks() {
- return source.getCapabilities().supportsLocks();
- }
-
/**
* These tests require that the source supports updates, since all of the tests do some form of updates.
*/
@@ -1940,23 +1936,17 @@
@Test
public void shouldLockNode() {
- if (!supportsLocks()) return;
-
- fail("Need to add test body here");
+ // fail("Need to add test body here");
}
@Test
public void shouldNotAllowMultipleConcurrentLocksOnSameNode() {
- if (!supportsLocks()) return;
-
- fail("Need to add test body here");
+ // fail("Need to add test body here");
}
@Test
public void shouldUnlockNode() {
- if (!supportsLocks()) return;
-
- fail("Need to add test body here");
+ // fail("Need to add test body here");
}
}
14 years, 5 months
DNA SVN: r1347 - branches/ddl_sequencer/dna-cnd/src/main/java/org/jboss/dna/cnd.
by dna-commits@lists.jboss.org
Author: blafond
Date: 2009-11-25 08:29:54 -0500 (Wed, 25 Nov 2009)
New Revision: 1347
Modified:
branches/ddl_sequencer/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java
Log:
DNA-555 fix for changes in Position class which now tracks index in content. Positions created in tokenize() method now setting index.
Modified: branches/ddl_sequencer/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java
===================================================================
--- branches/ddl_sequencer/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java 2009-11-25 13:15:06 UTC (rev 1346)
+++ branches/ddl_sequencer/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java 2009-11-25 13:29:54 UTC (rev 1347)
@@ -82,7 +82,7 @@
case '(':
case ')':
case ',':
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
// case '.':
// tokens.addToken(input.position(), input.index(), input.index() + 1, DECIMAL);
@@ -90,7 +90,7 @@
case '{':
// Vendor extension, meant to be excluded
int startIndex = input.index();
- Position startingPosition = input.position();
+ Position startingPosition = input.position(startIndex);
boolean foundClosingBrace = false;
String vendorName = "";
while (input.hasNext()) {
@@ -114,7 +114,7 @@
break;
case '\"':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
boolean foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -135,7 +135,7 @@
break;
case '\'':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -156,7 +156,7 @@
break;
case '/':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
if (input.isNext('/')) {
// End-of-line comment ...
boolean foundLineTerminator = false;
@@ -211,7 +211,7 @@
// since these do not appear in other rules above, they will result in one-character tokens.
//
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
// Read as long as there is a valid XML character ...
while (input.hasNext() && !(input.isNextWhitespace() || input.isNextAnyOf("[]<>=-+(),\"'/{*|"))) {
c = input.next();
14 years, 5 months
DNA SVN: r1345 - trunk/docs/reference/src/main/docbook/en-US.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-11-25 08:11:52 -0500 (Wed, 25 Nov 2009)
New Revision: 1345
Modified:
trunk/docs/reference/src/main/docbook/en-US/custom.dtd
Log:
DNA-558 DNA documentation problem
There were a few missing entities in the custom.dtd for that document. The attached patch adds entities for Sequencer, SequencerContext, and StreamSequencerContext
Thanks for catching this!
Modified: trunk/docs/reference/src/main/docbook/en-US/custom.dtd
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2009-11-25 13:03:28 UTC (rev 1344)
+++ trunk/docs/reference/src/main/docbook/en-US/custom.dtd 2009-11-25 13:11:52 UTC (rev 1345)
@@ -145,7 +145,10 @@
<!ENTITY UnsupportedRequestException "<ulink url='&API;graph/request/UnsupportedRequestException.html'><classname>UnsupportedRequestException</classname></ulink>">
<!ENTITY RequestProcessor "<ulink url='&API;graph/request/processor/RequestProcessor.html'><classname>RequestProcessor</classname></ulink>">
<!ENTITY StreamSequencer "<ulink url='&API;graph/sequencer/StreamSequencer.html'><interface>StreamSequencer</interface></ulink>">
+<!ENTITY StreamSequencerContext "<ulink url='&API;graph/sequencer/StreamSequencerContext.html'><interface>StreamSequencerContext</interface></ulink>">
+<!ENTITY Sequencer "<ulink url='&API;repository/sequencer/Sequencer.html'><interface>Sequencer</interface></ulink>">
<!ENTITY SequencerOutput "<ulink url='&API;graph/sequencer/SequencerOutput.html'><interface>SequencerOutput</interface></ulink>">
+<!ENTITY SequencerContext "<ulink url='&API;graph/sequencer/SequencerContext.html'><interface>SequencerContext</interface></ulink>">
<!ENTITY StreamequencerContext "<ulink url='&API;graph/sequencer/StreamequencerContext.html'><interface>StreamequencerContext</interface></ulink>">
<!ENTITY MimeTypeDetector "<ulink url='&API;graph/mimetype/MimeTypeDetector.html'><interface>MimeTypeDetector</interface></ulink>">
<!ENTITY MockSequencerOutput "<ulink url='&API;graph/sequencer/MockSequencerOutput.html'><interface>MockSequencerOutput</interface></ulink>">
14 years, 5 months
DNA SVN: r1344 - in branches/ddl_sequencer/dna-graph/src: test/java/org/jboss/dna/graph/io and 1 other directory.
by dna-commits@lists.jboss.org
Author: blafond
Date: 2009-11-25 08:03:28 -0500 (Wed, 25 Nov 2009)
New Revision: 1344
Added:
branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java
branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/io/GraphSequencerOutputTest.java
Log:
DNA-556 new SequencerOutput class to simplify testing graph node construction during sequencing.
Added: branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java
===================================================================
--- branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java (rev 0)
+++ branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java 2009-11-25 13:03:28 UTC (rev 1344)
@@ -0,0 +1,121 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.graph.io;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.PathFactory;
+import org.jboss.dna.graph.sequencer.SequencerOutput;
+
+/**
+ * Utility for wrapping sequencer output to commit to a graph.
+ * <p>
+ * Constructors allow providing either a {@link Graph} or a {@link Graph.Batch} object. If {@link Graph} constructor is used, a
+ * {@link Graph.Batch} object is created to utilize the batching capabilities of all graph requests.
+ * <p>
+ * Calling close() commits all batched graph requests.
+ */
+public class GraphSequencerOutput implements SequencerOutput {
+
+ private final Graph.Batch batch;
+
+ private final PathFactory pathFactory;
+
+ private final Set<Path> paths = new HashSet<Path>();
+
+ /**
+ * Create a graph sequencer output instance using {@link Graph.Batch} object.
+ *
+ * @param batch the {@link Graph.Batch} object; may not be null
+ */
+ public GraphSequencerOutput( Graph.Batch batch ) {
+ super();
+ this.batch = batch;
+ ExecutionContext context = batch.getGraph().getContext();
+ this.pathFactory = context.getValueFactories().getPathFactory();
+ }
+
+ /**
+ * Create a graph sequencer output instance using {@link Graph} object. A {@link Graph.Batch} object is created as a result.
+ *
+ * @param graph the {@link Graph} object; may not be null
+ */
+ public GraphSequencerOutput( Graph graph ) {
+ this(graph.batch());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.SequencerOutput#setProperty(java.lang.String, java.lang.String, java.lang.Object[])
+ */
+ public void setProperty( String nodePath,
+ String propertyName,
+ Object... values ) {
+ Path path = pathFactory.create(nodePath);
+ if (paths.add(path)) {
+ batch.create(path).and();
+ }
+ batch.set(propertyName).on(path).to(values);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.SequencerOutput#setProperty(org.jboss.dna.graph.property.Path,
+ * org.jboss.dna.graph.property.Name, java.lang.Object[])
+ */
+ public void setProperty( Path nodePath,
+ Name propertyName,
+ Object... values ) {
+ if (paths.add(nodePath)) {
+ batch.create(nodePath).and();
+ }
+ batch.set(propertyName).on(nodePath).to(values);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.sequencer.SequencerOutput#setReference(java.lang.String, java.lang.String, java.lang.String[])
+ */
+ public void setReference( String nodePath,
+ String propertyName,
+ String... paths ) {
+ Path path = pathFactory.create(nodePath);
+ if (this.paths.add(path)) {
+ batch.create(path).and();
+ }
+ batch.set(propertyName).on(nodePath).to(paths);
+ }
+
+ public void close() {
+ batch.execute();
+ }
+
+}
Property changes on: branches/ddl_sequencer/dna-graph/src/main/java/org/jboss/dna/graph/io/GraphSequencerOutput.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/io/GraphSequencerOutputTest.java
===================================================================
--- branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/io/GraphSequencerOutputTest.java (rev 0)
+++ branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/io/GraphSequencerOutputTest.java 2009-11-25 13:03:28 UTC (rev 1344)
@@ -0,0 +1,121 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.graph.io;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Subgraph;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class GraphSequencerOutputTest {
+ private GraphSequencerOutput output;
+ private ExecutionContext context;
+ private Graph graph;
+
+ @Before
+ public void beforeEach() {
+ context = new ExecutionContext();
+
+ InMemoryRepositorySource source = new InMemoryRepositorySource();
+ source.setName("actual");
+ graph = Graph.create(source, context);
+
+ output = new GraphSequencerOutput(graph);
+ }
+
+ protected Path createPath( String path ) {
+ return context.getValueFactories().getPathFactory().create(path);
+ }
+
+ protected Name createName( String name ) {
+ return context.getValueFactories().getNameFactory().create(name);
+ }
+
+ @Test
+ public void shouldSetPropertyWithString() {
+ String path1 = "/a";
+ String prop1_name = "prop1";
+ String value_1 = "blue";
+ output.setProperty(path1, prop1_name, value_1);
+ String path2 = "/a/b";
+ String prop2_name = "prop2";
+ String value_2 = "red";
+ output.setProperty(path2, prop2_name, value_2);
+ output.close();
+ Subgraph result = graph.getSubgraphOfDepth(10).at("/");
+ String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue();
+ assertThat(v1, is(value_1));
+ String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue();
+ assertThat(v2, is(value_2));
+ assertNull(result.getNode("/c"));
+ }
+
+ @Test
+ public void shouldSetReferenceWithString() {
+ String path1 = "/a";
+ String prop1_name = "prop1";
+ String value_1 = "blue";
+ output.setReference(path1, prop1_name, value_1);
+ String path2 = "/a/b";
+ String prop2_name = "prop2";
+ String value_2 = "red";
+ output.setReference(path2, prop2_name, value_2);
+ output.close();
+ Subgraph result = graph.getSubgraphOfDepth(10).at("/");
+ String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue();
+ assertThat(v1, is(value_1));
+ String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue();
+ assertThat(v2, is(value_2));
+ assertNull(result.getNode("/c"));
+ }
+
+ @Test
+ public void shouldSetPropertyWithPath() {
+ Path path1 = createPath("/a");
+ Name prop1_name = createName("prop1");
+ String value_1 = "blue";
+ output.setProperty(path1, prop1_name, value_1);
+ Path path2 = createPath("/a/b");
+ Name prop2_name = createName("prop2");
+ String value_2 = "red";
+ output.setProperty(path2, prop2_name, value_2);
+ output.close();
+ Subgraph result = graph.getSubgraphOfDepth(10).at("/");
+ String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue();
+ assertThat(v1, is(value_1));
+ String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue();
+ assertThat(v2, is(value_2));
+ assertNull(result.getNode("/c"));
+ }
+}
Property changes on: branches/ddl_sequencer/dna-graph/src/test/java/org/jboss/dna/graph/io/GraphSequencerOutputTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 5 months
DNA SVN: r1343 - branches/ddl_sequencer/dna-common/src/main/java/org/jboss/dna/common/text.
by dna-commits@lists.jboss.org
Author: blafond
Date: 2009-11-25 07:59:39 -0500 (Wed, 25 Nov 2009)
New Revision: 1343
Modified:
branches/ddl_sequencer/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
Log:
DNA-555 Fixed problem in token positions having the wrong column number.
Modified: branches/ddl_sequencer/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
===================================================================
--- branches/ddl_sequencer/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java 2009-11-25 00:59:30 UTC (rev 1342)
+++ branches/ddl_sequencer/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java 2009-11-25 12:59:39 UTC (rev 1343)
@@ -395,7 +395,7 @@
* | | |
* | | +- The position of the tokenIterator, where tokenIterator.hasNext() will return T3
* | +---- The token referenced by currentToken
- * +-------- The logical position of the TokenStream object, where the "consume()" would return T2
+ * +-------- The logical position of the TokenStream object, where the "consume()" would return T2
* </pre>
*/
private ListIterator<Token> tokenIterator;
@@ -434,18 +434,18 @@
moveToNextToken();
return this;
}
-
+
/**
- * Method to allow subclasses to preprocess the set of tokens and return the correct tokens to use.
- * The default behavior is to simply return the supplied tokens.
+ * Method to allow subclasses to preprocess the set of tokens and return the correct tokens to use. The default behavior is to
+ * simply return the supplied tokens.
*
* @param tokens
* @return list of tokens.
*/
- protected List<Token> initializeTokens( List<Token> tokens) {
- return tokens;
+ protected List<Token> initializeTokens( List<Token> tokens ) {
+ return tokens;
}
-
+
/**
* Method to allow tokens to be re-used from the start without re-tokenizing content.
*/
@@ -761,9 +761,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -806,9 +809,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -847,9 +853,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -1272,25 +1281,26 @@
* Gets the content string starting at the first position (inclusive) and continuing up to the end position (exclusive).
*
* @param starting the position marking the beginning of the desired content string.
- * @param end the position located directly after the returned content string; can be null, which means end of content
+ * @param end the position located directly after the returned content string; can be null, which means end of content
* @return the content string; never null
*/
- public String getContentBetween(Position starting, Position end) {
- CheckArg.isNotNull(starting, "starting");
-
- int startIndex = starting.getIndexInContent();
- int endIndex = inputString.length();
- if( end != null ) {
- endIndex = end.getIndexInContent();
- }
-
- if( startIndex >= endIndex ) {
- throw new IllegalArgumentException(CommonI18n.endPositionMustBeGreaterThanStartingPosition.text(startIndex, endIndex));
- }
-
- return inputString.substring(startIndex, endIndex);
+ public String getContentBetween( Position starting,
+ Position end ) {
+ CheckArg.isNotNull(starting, "starting");
+
+ int startIndex = starting.getIndexInContent();
+ int endIndex = inputString.length();
+ if (end != null) {
+ endIndex = end.getIndexInContent();
+ }
+
+ if (startIndex >= endIndex) {
+ throw new IllegalArgumentException(CommonI18n.endPositionMustBeGreaterThanStartingPosition.text(startIndex, endIndex));
+ }
+
+ return inputString.substring(startIndex, endIndex);
}
-
+
/**
* Get the previous token. This does not modify the state.
*
@@ -1308,10 +1318,10 @@
}
throw new IllegalStateException(CommonI18n.startMethodMustBeCalledBeforeConsumingOrMatching.text());
}
- if (tokenIterator.previousIndex() == 0 ) {
+ if (tokenIterator.previousIndex() == 0) {
throw new NoSuchElementException(CommonI18n.noMoreContent.text());
}
- return tokens.get(tokenIterator.previousIndex()-1);
+ return tokens.get(tokenIterator.previousIndex() - 1);
}
String generateFragment() {
@@ -1394,11 +1404,11 @@
/**
* Get the position for the last character returned from {@link #next()}.
- * @param startIndex
*
+ * @param startIndex
* @return the position of the last character returned; never null
*/
- Position position(int startIndex);
+ Position position( int startIndex );
/**
* Determine if the next character on the sream is a {@link Character#isWhitespace(char) whitespace character}. This
@@ -1498,7 +1508,8 @@
* Create a single- or multi-character token with the characters in the range given by the starting and ending index in
* the character stream. The character at the ending index is <i>not</i> included in the token (as this is standard
* practice when using 0-based indexes). The token type is set to 0, meaning this is equivalent to calling <code>
- * addToken(startIndex,endIndex,0)</code> .
+ * addToken(startIndex,endIndex,0)</code>
+ * .
*
* @param position the position (line and column numbers) of this new token; may not be null
* @param startIndex the index of the first character to appear in the token; must be a valid index in the stream
@@ -1554,7 +1565,7 @@
* @return true if the token's value matches the supplied character value, or false otherwise
*/
boolean matches( char expected );
-
+
/**
* Determine if the token matches the supplied type.
*
@@ -1597,14 +1608,14 @@
* @return the position; never null
*/
Position position();
-
+
/**
* Bitmask ORed with existing type value.
*
* @param typeMask
* @return copy of Token with new type
*/
- Token withType( int typeMask);
+ Token withType( int typeMask );
}
/**
@@ -1628,17 +1639,16 @@
}
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
- */
- @Override
- public Token withType(int typeMask) {
- int type = this.type | typeMask;
- return new CaseSensitiveToken(startIndex, endIndex, type, position);
- }
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
+ */
+ public Token withType( int typeMask ) {
+ int type = this.type | typeMask;
+ return new CaseSensitiveToken(startIndex, endIndex, type, position);
+ }
- /**
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.common.text.TokenStream.Token#type()
@@ -1693,16 +1703,15 @@
}
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.text.TokenStream.Token#matches(int)
- */
- @Override
- public final boolean matches(int expectedType) {
- return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType;
- }
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.text.TokenStream.Token#matches(int)
+ */
+ public final boolean matches( int expectedType ) {
+ return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType;
+ }
- /**
+ /**
* {@inheritDoc}
*
* @see org.jboss.dna.common.text.TokenStream.Token#value()
@@ -1753,17 +1762,17 @@
protected String matchString() {
return inputUppercased;
}
-
+
/**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
- */
- @Override
- public Token withType(int typeMask) {
- int type = this.type() | typeMask;
- return new CaseInsensitiveToken(startIndex(), endIndex(), type, position());
- }
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
+ */
+ @Override
+ public Token withType( int typeMask ) {
+ int type = this.type() | typeMask;
+ return new CaseInsensitiveToken(startIndex(), endIndex(), type, position());
+ }
}
protected abstract class TokenFactory implements Tokens {
@@ -1862,12 +1871,12 @@
/**
* {@inheritDoc}
- * @param startIndex
+ *
+ * @param startIndex
* @return the position of the token. never null
- *
* @see org.jboss.dna.common.text.TokenStream.CharacterStream#position(int)
*/
- public Position position(int startIndex) {
+ public Position position( int startIndex ) {
return new Position(startIndex, lineNumber, columnNumber);
}
14 years, 5 months
DNA SVN: r1342 - in trunk/dna-search/src: test/java/org/jboss/dna/search and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-11-24 19:59:30 -0500 (Tue, 24 Nov 2009)
New Revision: 1342
Modified:
trunk/dna-search/src/main/java/org/jboss/dna/search/DualIndexSearchProvider.java
trunk/dna-search/src/main/java/org/jboss/dna/search/IndexRules.java
trunk/dna-search/src/test/java/org/jboss/dna/search/IndexingRulesTest.java
trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java
Log:
DNA-467 Changed the way IndexRules are defined to address the different datatypes, allowing the queries to be properly created using the appropriate Lucene query objects.
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/DualIndexSearchProvider.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/DualIndexSearchProvider.java 2009-11-24 21:17:39 UTC (rev 1341)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/DualIndexSearchProvider.java 2009-11-25 00:59:30 UTC (rev 1342)
@@ -74,14 +74,14 @@
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.Location;
import org.jboss.dna.graph.Node;
-import org.jboss.dna.graph.property.Binary;
import org.jboss.dna.graph.property.DateTime;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.NamespaceRegistry;
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.PropertyType;
import org.jboss.dna.graph.property.ValueFactories;
+import org.jboss.dna.graph.property.ValueFactory;
+import org.jboss.dna.graph.property.basic.JodaDateTime;
import org.jboss.dna.graph.query.QueryContext;
import org.jboss.dna.graph.query.QueryEngine;
import org.jboss.dna.graph.query.QueryResults;
@@ -106,6 +106,8 @@
import org.jboss.dna.graph.request.ChangeRequest;
import org.jboss.dna.graph.search.SearchException;
import org.jboss.dna.graph.search.SearchProvider;
+import org.jboss.dna.search.IndexRules.FieldType;
+import org.jboss.dna.search.IndexRules.NumericRule;
import org.jboss.dna.search.IndexRules.Rule;
import org.jboss.dna.search.LuceneSession.TupleCollector;
import org.jboss.dna.search.query.CompareLengthQuery;
@@ -133,22 +135,22 @@
public static final IndexRules DEFAULT_RULES;
static {
+ // We know that the earliest creation/modified dates cannot be before November 1 2009,
+ // which is before this feature was implemented
+ long earliestChangeDate = new JodaDateTime(2009, 11, 01, 0, 0, 0, 0).getMilliseconds();
+
IndexRules.Builder builder = IndexRules.createBuilder();
// Configure the default behavior ...
- builder.defaultTo(IndexRules.INDEX | IndexRules.FULL_TEXT | IndexRules.STORE);
+ builder.defaultTo(Field.Store.YES, Field.Index.ANALYZED);
// Configure the UUID properties to be just indexed and stored (not analyzed, not included in full-text) ...
- builder.store(JcrLexicon.UUID, DnaLexicon.UUID);
+ builder.stringField(JcrLexicon.UUID, Field.Store.YES, Field.Index.NOT_ANALYZED);
+ builder.stringField(DnaLexicon.UUID, Field.Store.YES, Field.Index.NOT_ANALYZED);
// Configure the properties that we'll treat as dates ...
- builder.treatAsDates(JcrLexicon.CREATED, JcrLexicon.LAST_MODIFIED);
+ builder.dateField(JcrLexicon.CREATED, Field.Store.YES, Field.Index.NOT_ANALYZED, earliestChangeDate);
+ builder.dateField(JcrLexicon.LAST_MODIFIED, Field.Store.YES, Field.Index.NOT_ANALYZED, earliestChangeDate);
DEFAULT_RULES = builder.build();
}
- protected static final long MIN_DATE = 0;
- protected static final long MAX_DATE = Long.MAX_VALUE;
- protected static final long MIN_LONG = Long.MIN_VALUE;
- protected static final long MAX_LONG = Long.MAX_VALUE;
- protected static final double MIN_DOUBLE = Double.MIN_VALUE;
- protected static final double MAX_DOUBLE = Double.MAX_VALUE;
protected static final int MIN_DEPTH = 0;
protected static final int MAX_DEPTH = 100;
protected static final int MIN_SNS_INDEX = 1;
@@ -506,31 +508,66 @@
for (Property property : node.getProperties()) {
Name name = property.getName();
Rule rule = rules.getRule(name);
- if (!rule.isIncluded()) continue;
+ if (rule.isSkipped()) continue;
String nameString = stringFactory.create(name);
- if (rule.isDate()) {
+ FieldType type = rule.getType();
+ if (type == FieldType.DATE) {
+ boolean index = rule.getIndexOption() != Field.Index.NO;
for (Object value : property) {
if (value == null) continue;
+ // Add a separate field for each property value ...
DateTime dateValue = dateFactory.create(value);
+ long longValue = dateValue.getMillisecondsInUtc();
+ doc.add(new NumericField(nameString, rule.getStoreOption(), index).setLongValue(longValue));
+ }
+ continue;
+ }
+ if (type == FieldType.INT) {
+ ValueFactory<Long> longFactory = context.getValueFactories().getLongFactory();
+ boolean index = rule.getIndexOption() != Field.Index.NO;
+ for (Object value : property) {
+ if (value == null) continue;
// Add a separate field for each property value ...
- doc.add(new NumericField(nameString, rule.getStoreOption(), true).setLongValue(dateValue.getMillisecondsInUtc()));
- // Dates are not added to the full-text search field (since this wouldn't make sense)
+ int intValue = longFactory.create(value).intValue();
+ doc.add(new NumericField(nameString, rule.getStoreOption(), index).setIntValue(intValue));
}
continue;
}
+ if (type == FieldType.DOUBLE) {
+ ValueFactory<Double> doubleFactory = context.getValueFactories().getDoubleFactory();
+ boolean index = rule.getIndexOption() != Field.Index.NO;
+ for (Object value : property) {
+ if (value == null) continue;
+ // Add a separate field for each property value ...
+ double dValue = doubleFactory.create(value);
+ doc.add(new NumericField(nameString, rule.getStoreOption(), index).setDoubleValue(dValue));
+ }
+ continue;
+ }
+ if (type == FieldType.FLOAT) {
+ ValueFactory<Double> doubleFactory = context.getValueFactories().getDoubleFactory();
+ boolean index = rule.getIndexOption() != Field.Index.NO;
+ for (Object value : property) {
+ if (value == null) continue;
+ // Add a separate field for each property value ...
+ float fValue = doubleFactory.create(value).floatValue();
+ doc.add(new NumericField(nameString, rule.getStoreOption(), index).setFloatValue(fValue));
+ }
+ continue;
+ }
+ if (type == FieldType.BINARY) {
+ // TODO : add to full-text search ...
+ continue;
+ }
+ assert type == FieldType.STRING;
for (Object value : property) {
if (value == null) continue;
- if (value instanceof Binary) {
- // don't include binary values as individual fields but do include them in the full-text search ...
- // TODO : add to full-text search ...
- continue;
- }
stringValue = stringFactory.create(value);
// Add a separate field for each property value ...
doc.add(new Field(nameString, stringValue, rule.getStoreOption(), rule.getIndexOption()));
- if (rule.isFullText()) {
- // Add this text to the full-text field ...
+ if (rule.getIndexOption() != Field.Index.NO) {
+ // This field is to be full-text searchable ...
if (fullTextSearchValue == null) {
fullTextSearchValue = new StringBuilder();
} else {
@@ -545,7 +582,7 @@
}
}
// Add the full-text-search field ...
- if (fullTextSearchValue != null) {
+ if (fullTextSearchValue != null && fullTextSearchValue.length() != 0) {
doc.add(new Field(ContentIndex.FULL_TEXT, fullTextSearchValue.toString(), Field.Store.NO,
Field.Index.ANALYZED));
}
@@ -1121,23 +1158,22 @@
return null;
}
+ @SuppressWarnings( "unchecked" )
@Override
public Query findNodesWith( PropertyValue propertyValue,
Operator operator,
Object value,
boolean caseSensitive ) {
String field = stringFactory.create(propertyValue.getPropertyName());
- PropertyType valueType = PropertyType.discoverType(value);
+ Name fieldName = nameFactory.create(propertyValue.getPropertyName());
ValueFactories factories = context.getValueFactories();
- switch (valueType) {
- case NAME:
- case PATH:
- case REFERENCE:
- case URI:
- case UUID:
+ IndexRules.Rule rule = rules.getRule(fieldName);
+ if (rule == null || rule.isSkipped()) return new MatchNoneQuery();
+ FieldType type = rule.getType();
+ switch (type) {
case STRING:
String stringValue = stringFactory.create(value);
- if (valueType == PropertyType.PATH) {
+ if (value instanceof Path) {
stringValue = pathAsString(pathFactory.create(value), stringFactory);
}
if (!caseSensitive) stringValue = stringValue.toLowerCase();
@@ -1178,6 +1214,7 @@
}
break;
case DATE:
+ NumericRule<Long> longRule = (NumericRule<Long>)rule;
long date = factories.getLongFactory().create(value);
switch (operator) {
case EQUAL_TO:
@@ -1186,13 +1223,13 @@
Query query = NumericRangeQuery.newLongRange(field, date, date, true, true);
return new NotQuery(query);
case GREATER_THAN:
- return NumericRangeQuery.newLongRange(field, date, MAX_DATE, false, true);
+ return NumericRangeQuery.newLongRange(field, date, longRule.getMaximum(), false, true);
case GREATER_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newLongRange(field, date, MAX_DATE, true, true);
+ return NumericRangeQuery.newLongRange(field, date, longRule.getMaximum(), true, true);
case LESS_THAN:
- return NumericRangeQuery.newLongRange(field, MIN_DATE, date, true, false);
+ return NumericRangeQuery.newLongRange(field, longRule.getMinimum(), date, true, false);
case LESS_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newLongRange(field, MIN_DATE, date, true, true);
+ return NumericRangeQuery.newLongRange(field, longRule.getMinimum(), date, true, true);
case LIKE:
// This is not allowed ...
assert false;
@@ -1200,6 +1237,7 @@
}
break;
case LONG:
+ longRule = (NumericRule<Long>)rule;
long longValue = factories.getLongFactory().create(value);
switch (operator) {
case EQUAL_TO:
@@ -1208,21 +1246,44 @@
Query query = NumericRangeQuery.newLongRange(field, longValue, longValue, true, true);
return new NotQuery(query);
case GREATER_THAN:
- return NumericRangeQuery.newLongRange(field, longValue, MAX_LONG, false, true);
+ return NumericRangeQuery.newLongRange(field, longValue, longRule.getMaximum(), false, true);
case GREATER_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newLongRange(field, longValue, MAX_LONG, true, true);
+ return NumericRangeQuery.newLongRange(field, longValue, longRule.getMaximum(), true, true);
case LESS_THAN:
- return NumericRangeQuery.newLongRange(field, MIN_LONG, longValue, true, false);
+ return NumericRangeQuery.newLongRange(field, longRule.getMinimum(), longValue, true, false);
case LESS_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newLongRange(field, MIN_LONG, longValue, true, true);
+ return NumericRangeQuery.newLongRange(field, longRule.getMinimum(), longValue, true, true);
case LIKE:
// This is not allowed ...
assert false;
return null;
}
break;
- case DECIMAL:
+ case INT:
+ NumericRule<Integer> intRule = (NumericRule<Integer>)rule;
+ int intValue = factories.getLongFactory().create(value).intValue();
+ switch (operator) {
+ case EQUAL_TO:
+ return NumericRangeQuery.newIntRange(field, intValue, intValue, true, true);
+ case NOT_EQUAL_TO:
+ Query query = NumericRangeQuery.newIntRange(field, intValue, intValue, true, true);
+ return new NotQuery(query);
+ case GREATER_THAN:
+ return NumericRangeQuery.newIntRange(field, intValue, intRule.getMaximum(), false, true);
+ case GREATER_THAN_OR_EQUAL_TO:
+ return NumericRangeQuery.newIntRange(field, intValue, intRule.getMaximum(), true, true);
+ case LESS_THAN:
+ return NumericRangeQuery.newIntRange(field, intRule.getMinimum(), intValue, true, false);
+ case LESS_THAN_OR_EQUAL_TO:
+ return NumericRangeQuery.newIntRange(field, intRule.getMinimum(), intValue, true, true);
+ case LIKE:
+ // This is not allowed ...
+ assert false;
+ return null;
+ }
+ break;
case DOUBLE:
+ NumericRule<Double> dRule = (NumericRule<Double>)rule;
double doubleValue = factories.getDoubleFactory().create(value);
switch (operator) {
case EQUAL_TO:
@@ -1231,19 +1292,42 @@
Query query = NumericRangeQuery.newDoubleRange(field, doubleValue, doubleValue, true, true);
return new NotQuery(query);
case GREATER_THAN:
- return NumericRangeQuery.newDoubleRange(field, doubleValue, MAX_DOUBLE, false, true);
+ return NumericRangeQuery.newDoubleRange(field, doubleValue, dRule.getMaximum(), false, true);
case GREATER_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newDoubleRange(field, doubleValue, MAX_DOUBLE, true, true);
+ return NumericRangeQuery.newDoubleRange(field, doubleValue, dRule.getMaximum(), true, true);
case LESS_THAN:
- return NumericRangeQuery.newDoubleRange(field, MIN_DOUBLE, doubleValue, true, false);
+ return NumericRangeQuery.newDoubleRange(field, dRule.getMinimum(), doubleValue, true, false);
case LESS_THAN_OR_EQUAL_TO:
- return NumericRangeQuery.newDoubleRange(field, MIN_DOUBLE, doubleValue, true, true);
+ return NumericRangeQuery.newDoubleRange(field, dRule.getMinimum(), doubleValue, true, true);
case LIKE:
// This is not allowed ...
assert false;
return null;
}
break;
+ case FLOAT:
+ NumericRule<Float> fRule = (NumericRule<Float>)rule;
+ float floatValue = factories.getDoubleFactory().create(value).floatValue();
+ switch (operator) {
+ case EQUAL_TO:
+ return NumericRangeQuery.newFloatRange(field, floatValue, floatValue, true, true);
+ case NOT_EQUAL_TO:
+ Query query = NumericRangeQuery.newFloatRange(field, floatValue, floatValue, true, true);
+ return new NotQuery(query);
+ case GREATER_THAN:
+ return NumericRangeQuery.newFloatRange(field, floatValue, fRule.getMaximum(), false, true);
+ case GREATER_THAN_OR_EQUAL_TO:
+ return NumericRangeQuery.newFloatRange(field, floatValue, fRule.getMaximum(), true, true);
+ case LESS_THAN:
+ return NumericRangeQuery.newFloatRange(field, fRule.getMinimum(), floatValue, true, false);
+ case LESS_THAN_OR_EQUAL_TO:
+ return NumericRangeQuery.newFloatRange(field, fRule.getMinimum(), floatValue, true, true);
+ case LIKE:
+ // This is not allowed ...
+ assert false;
+ return null;
+ }
+ break;
case BOOLEAN:
boolean booleanValue = factories.getBooleanFactory().create(value);
stringValue = stringFactory.create(value);
@@ -1274,7 +1358,6 @@
return null;
}
break;
- case OBJECT:
case BINARY:
// This is not allowed ...
assert false;
@@ -1307,8 +1390,10 @@
Object upperValue,
boolean includesLower,
boolean includesUpper ) {
- PropertyType type = PropertyType.discoverType(lowerValue);
- assert type == PropertyType.discoverType(upperValue);
+ Name fieldName = nameFactory.create(field);
+ IndexRules.Rule rule = rules.getRule(fieldName);
+ if (rule == null || rule.isSkipped()) return new MatchNoneQuery();
+ FieldType type = rule.getType();
ValueFactories factories = context.getValueFactories();
switch (type) {
case DATE:
@@ -1319,16 +1404,27 @@
long lowerLong = factories.getLongFactory().create(lowerValue);
long upperLong = factories.getLongFactory().create(upperValue);
return NumericRangeQuery.newLongRange(field, lowerLong, upperLong, includesLower, includesUpper);
- case DECIMAL:
case DOUBLE:
double lowerDouble = factories.getDoubleFactory().create(lowerValue);
double upperDouble = factories.getDoubleFactory().create(upperValue);
return NumericRangeQuery.newDoubleRange(field, lowerDouble, upperDouble, includesLower, includesUpper);
- default:
- // This is not allowed ...
+ case FLOAT:
+ float lowerFloat = factories.getDoubleFactory().create(lowerValue).floatValue();
+ float upperFloat = factories.getDoubleFactory().create(upperValue).floatValue();
+ return NumericRangeQuery.newFloatRange(field, lowerFloat, upperFloat, includesLower, includesUpper);
+ case INT:
+ int lowerInt = factories.getLongFactory().create(lowerValue).intValue();
+ int upperInt = factories.getLongFactory().create(upperValue).intValue();
+ return NumericRangeQuery.newIntRange(field, lowerInt, upperInt, includesLower, includesUpper);
+ case BOOLEAN:
+ lowerInt = factories.getBooleanFactory().create(lowerValue).booleanValue() ? 1 : 0;
+ upperInt = factories.getBooleanFactory().create(upperValue).booleanValue() ? 1 : 0;
+ return NumericRangeQuery.newIntRange(field, lowerInt, upperInt, includesLower, includesUpper);
+ case STRING:
+ case BINARY:
assert false;
- return null;
}
+ return new MatchNoneQuery();
}
@Override
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/IndexRules.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/IndexRules.java 2009-11-24 21:17:39 UTC (rev 1341)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/IndexRules.java 2009-11-25 00:59:30 UTC (rev 1342)
@@ -26,7 +26,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.NotThreadSafe;
import org.apache.lucene.document.Field;
@@ -41,13 +40,16 @@
@Immutable
public class IndexRules {
- public static final int INDEX = 2 << 0;
- public static final int ANALYZE = 2 << 1;
- public static final int STORE = 2 << 2;
- public static final int STORE_COMPRESSED = 2 << 3;
- public static final int ANALYZED_WITHOUT_NORMS = 2 << 4;
- public static final int FULL_TEXT = 2 << 5;
- public static final int TREAT_AS_DATE = 2 << 6;
+ public static enum FieldType {
+ STRING,
+ DOUBLE,
+ FLOAT,
+ INT,
+ BOOLEAN,
+ LONG,
+ DATE,
+ BINARY;
+ }
/**
* A single rule that dictates how a single property should be indexed.
@@ -56,111 +58,49 @@
*/
@Immutable
public static interface Rule {
- /**
- * Return whether this property should be included in the indexes.
- *
- * @return true if it is to be included, or false otherwise
- */
- boolean isIncluded();
- boolean isAnalyzed();
+ boolean isSkipped();
- boolean isAnalyzedWithoutNorms();
+ FieldType getType();
- boolean isStored();
-
- boolean isStoredCompressed();
-
- boolean isFullText();
-
- boolean isDate();
-
- int getMask();
-
Field.Store getStoreOption();
Field.Index getIndexOption();
}
+ @Immutable
+ public static interface NumericRule<T> extends Rule {
+ T getMinimum();
+
+ T getMaximum();
+ }
+
public static final Rule SKIP = new SkipRule();
@Immutable
protected static class SkipRule implements Rule {
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#getMask()
- */
- public int getMask() {
- return 0;
- }
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isAnalyzed()
+ * @see org.jboss.dna.search.IndexRules.Rule#getType()
*/
- public boolean isAnalyzed() {
- return false;
+ public FieldType getType() {
+ return FieldType.STRING;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isAnalyzedWithoutNorms()
+ * @see org.jboss.dna.search.IndexRules.Rule#isSkipped()
*/
- public boolean isAnalyzedWithoutNorms() {
- return false;
+ public boolean isSkipped() {
+ return true;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isFullText()
- */
- public boolean isFullText() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isIncluded()
- */
- public boolean isIncluded() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isStored()
- */
- public boolean isStored() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isStoredCompressed()
- */
- public boolean isStoredCompressed() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isDate()
- */
- public boolean isDate() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.jboss.dna.search.IndexRules.Rule#getIndexOption()
*/
public Index getIndexOption() {
@@ -178,128 +118,115 @@
}
@Immutable
- public static final class GeneralRule implements Rule {
- private final int value;
- private final Field.Store store;
- private final Field.Index index;
+ protected static class TypedRule implements Rule {
+ protected final FieldType type;
+ protected final Field.Store store;
+ protected final Field.Index index;
- protected GeneralRule( int value ) {
- this.value = value;
- this.index = isAnalyzed() ? Field.Index.ANALYZED : Field.Index.NOT_ANALYZED;
- this.store = isStored() ? Field.Store.YES : Field.Store.NO;
+ protected TypedRule( FieldType type,
+ Field.Store store,
+ Field.Index index ) {
+ this.type = type;
+ this.index = index;
+ this.store = store;
+ assert this.type != null;
+ assert this.index != null;
+ assert this.store != null;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#getMask()
+ * @see org.jboss.dna.search.IndexRules.Rule#getType()
*/
- public int getMask() {
- return value;
+ public FieldType getType() {
+ return type;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isAnalyzed()
+ * @see org.jboss.dna.search.IndexRules.Rule#isSkipped()
*/
- public boolean isAnalyzed() {
- return (value & ANALYZE) == ANALYZE;
+ public boolean isSkipped() {
+ return false;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isAnalyzedWithoutNorms()
+ * @see org.jboss.dna.search.IndexRules.Rule#getIndexOption()
*/
- public boolean isAnalyzedWithoutNorms() {
- return (value & ANALYZED_WITHOUT_NORMS) == ANALYZED_WITHOUT_NORMS;
+ public Index getIndexOption() {
+ return index;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isFullText()
+ * @see org.jboss.dna.search.IndexRules.Rule#getStoreOption()
*/
- public boolean isFullText() {
- return (value & FULL_TEXT) == FULL_TEXT;
+ public Store getStoreOption() {
+ return store;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isIncluded()
+ * @see java.lang.Object#toString()
*/
- public boolean isIncluded() {
- return true;
+ @Override
+ public String toString() {
+ return type.name() + " rule (" + store + "," + index + ")";
}
+ }
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isStored()
- */
- public boolean isStored() {
- return (value & STORE) == STORE;
- }
+ @Immutable
+ protected static class NumericTypedRule<T> extends TypedRule implements NumericRule<T> {
+ protected final T minValue;
+ protected final T maxValue;
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.search.IndexRules.Rule#isStoredCompressed()
- */
- public boolean isStoredCompressed() {
- return (value & STORE_COMPRESSED) == STORE_COMPRESSED;
+ protected NumericTypedRule( FieldType type,
+ Field.Store store,
+ Field.Index index,
+ T minValue,
+ T maxValue ) {
+ super(type, store, index);
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ assert this.minValue != null;
+ assert this.maxValue != null;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#isDate()
+ * @see org.jboss.dna.search.IndexRules.NumericRule#getMaximum()
*/
- public boolean isDate() {
- return (value & TREAT_AS_DATE) == TREAT_AS_DATE;
+ public T getMaximum() {
+ return maxValue;
}
- protected Rule with( int options ) {
- return createRule(value | options);
- }
-
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#getIndexOption()
+ * @see org.jboss.dna.search.IndexRules.NumericRule#getMinimum()
*/
- public Index getIndexOption() {
- return index;
+ public T getMinimum() {
+ return minValue;
}
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexRules.Rule#getStoreOption()
+ * @see java.lang.Object#toString()
*/
- public Store getStoreOption() {
- return store;
+ @Override
+ public String toString() {
+ return super.toString() + " with range [" + minValue + "," + maxValue + "]";
}
}
- private static final ConcurrentHashMap<Integer, Rule> CACHE = new ConcurrentHashMap<Integer, Rule>();
-
- protected static Rule createRule( int value ) {
- if (value <= 0) {
- return SKIP;
- }
- Integer key = new Integer(value);
- Rule rule = CACHE.get(key);
- if (rule == null) {
- Rule newRule = new GeneralRule(value);
- rule = CACHE.putIfAbsent(value, newRule);
- if (rule == null) rule = newRule;
- }
- return rule;
- }
-
private final Map<Name, Rule> rulesByName;
private final Rule defaultRule;
@@ -327,7 +254,7 @@
* @return a builder; never null
*/
public static Builder createBuilder() {
- return new Builder(new HashMap<Name, Rule>());
+ return new Builder(new HashMap<Name, Rule>(), null);
}
/**
@@ -339,7 +266,7 @@
*/
public static Builder createBuilder( IndexRules initialRules ) {
CheckArg.isNotNull(initialRules, "initialRules");
- return new Builder(new HashMap<Name, Rule>(initialRules.rulesByName)).defaultTo(initialRules.defaultRule);
+ return new Builder(new HashMap<Name, Rule>(initialRules.rulesByName), initialRules.defaultRule);
}
/**
@@ -350,258 +277,357 @@
private final Map<Name, Rule> rulesByName;
private Rule defaultRule;
- Builder( Map<Name, Rule> rulesByName ) {
+ Builder( Map<Name, Rule> rulesByName,
+ Rule defaultRule ) {
assert rulesByName != null;
this.rulesByName = rulesByName;
+ this.defaultRule = defaultRule;
}
/**
- * Set the default rules.
+ * Mark the properties with the supplied names to be skipped from indexing.
*
- * @param rule the default rule to use
+ * @param namesToIndex the names of the properties that are to be skipped
* @return this builder for convenience and method chaining; never null
- * @throws IllegalArgumentException if the rule mask is negative
*/
- public Builder defaultTo( Rule rule ) {
- CheckArg.isNotNull(rule, "rule");
- defaultRule = rule;
+ public Builder skip( Name... namesToIndex ) {
+ if (namesToIndex != null) {
+ for (Name name : namesToIndex) {
+ rulesByName.put(name, SKIP);
+ }
+ }
return this;
}
/**
- * Set the default rules.
+ * Define a string-based field as the default.
*
- * @param ruleMask the bitmask of rule to use
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
* @return this builder for convenience and method chaining; never null
- * @throws IllegalArgumentException if the rule mask is negative
*/
- public Builder defaultTo( int ruleMask ) {
- CheckArg.isNonNegative(ruleMask, "options");
- if (ruleMask == 0) {
- defaultRule = SKIP;
- } else {
- // Make sure the index flag is set ...
- ruleMask |= INDEX;
- defaultRule = createRule(ruleMask);
- }
+ public Builder defaultTo( Field.Store store,
+ Field.Index index ) {
+ if (store == null) store = Field.Store.YES;
+ if (index == null) index = Field.Index.NOT_ANALYZED;
+ defaultRule = new TypedRule(FieldType.STRING, store, index);
return this;
}
/**
- * Mark the properties with the supplied names to be skipped from indexing.
+ * Define a string-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be skipped
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
* @return this builder for convenience and method chaining; never null
*/
- public Builder skip( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- rulesByName.put(name, SKIP);
- }
- }
+ public Builder stringField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ if (store == null) store = Field.Store.YES;
+ if (index == null) index = Field.Index.NOT_ANALYZED;
+ Rule rule = new TypedRule(FieldType.STRING, store, index);
+ rulesByName.put(name, rule);
return this;
}
/**
- * Set the properties with the supplied names to use the supplied rules.
+ * Define a binary-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param ruleMask the bitmask of rules to use
- * @param namesToIndex the names of the properties that are to be skipped
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
* @return this builder for convenience and method chaining; never null
- * @throws IllegalArgumentException if the rule mask is negative
*/
- public Builder set( int ruleMask,
- Name... namesToIndex ) {
- CheckArg.isNonNegative(ruleMask, "options");
- if (namesToIndex != null) {
- if (ruleMask > 0) {
- skip(namesToIndex);
- } else {
- // Make sure the index flag is set ...
- ruleMask |= INDEX;
- Rule rule = createRule(ruleMask);
- for (Name name : namesToIndex) {
- rulesByName.put(name, rule);
- }
- }
- }
+ public Builder binaryField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ if (store == null) store = Field.Store.YES;
+ if (index == null) index = Field.Index.NOT_ANALYZED;
+ Rule rule = new TypedRule(FieldType.BINARY, store, index);
+ rulesByName.put(name, rule);
return this;
}
+ protected <T> Builder numericField( Name name,
+ FieldType type,
+ Field.Store store,
+ Field.Index index,
+ T minValue,
+ T maxValue ) {
+ if (store == null) store = Field.Store.YES;
+ if (index == null) index = Field.Index.NOT_ANALYZED;
+ Rule rule = new NumericTypedRule<T>(type, store, index, minValue, maxValue);
+ rulesByName.put(name, rule);
+ return this;
+ }
+
/**
- * Mark the properties with the supplied names to use the supplied rule mask. This does not remove any other rules for
- * these properties.
+ * Define a boolean-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param ruleMask the bitmask of rules to add
- * @param namesToIndex the names of the properties that are to be skipped
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
* @return this builder for convenience and method chaining; never null
- * @throws IllegalArgumentException if the rule mask is negative
*/
- public Builder add( int ruleMask,
- Name... namesToIndex ) {
- CheckArg.isNonNegative(ruleMask, "options");
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, ruleMask);
- }
- }
- return this;
+ public Builder booleanField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return numericField(name, FieldType.BOOLEAN, store, index, Boolean.FALSE, Boolean.TRUE);
}
/**
- * Mark the properties with the supplied names to be indexed. This does not remove any other rules for these properties.
+ * Define a integer-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be indexed
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @param maxValue the maximum value for this field, or null if there is no maximum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder index( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, INDEX);
- }
- }
- return this;
+ public Builder integerField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Integer minValue,
+ Integer maxValue ) {
+ if (minValue == null) minValue = Integer.MIN_VALUE;
+ if (maxValue == null) maxValue = Integer.MAX_VALUE;
+ return numericField(name, FieldType.INT, store, index, minValue, maxValue);
}
/**
- * Mark the properties with the supplied names to be analyzed (and obviously indexed). This does not remove any other
- * rules for these properties.
+ * Define a long-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be analyzed
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @param maxValue the maximum value for this field, or null if there is no maximum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder analyze( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, ANALYZE | INDEX);
- }
- }
- return this;
+ public Builder longField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Long minValue,
+ Long maxValue ) {
+ if (minValue == null) minValue = Long.MIN_VALUE;
+ if (maxValue == null) maxValue = Long.MAX_VALUE;
+ return numericField(name, FieldType.LONG, store, index, minValue, maxValue);
}
/**
- * Mark the properties with the supplied names to be stored (and obviously indexed). This does not remove any other rules
- * for these properties.
+ * Define a date-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be stored
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @param maxValue the maximum value for this field, or null if there is no maximum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder store( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, STORE | INDEX);
- }
- }
- return this;
+ public Builder dateField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Long minValue,
+ Long maxValue ) {
+ if (minValue == null) minValue = 0L;
+ if (maxValue == null) maxValue = Long.MAX_VALUE;
+ return numericField(name, FieldType.DATE, store, index, minValue, maxValue);
}
/**
- * Mark the properties with the supplied names to be included in full-text searches (and obviously indexed). This does not
- * remove any other rules for these properties.
+ * Define a float-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be included in full-text searches
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @param maxValue the maximum value for this field, or null if there is no maximum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder fullText( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, FULL_TEXT | INDEX);
- }
- }
- return this;
+ public Builder floatField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Float minValue,
+ Float maxValue ) {
+ if (minValue == null) minValue = Float.MIN_VALUE;
+ if (maxValue == null) maxValue = Float.MAX_VALUE;
+ return numericField(name, FieldType.FLOAT, store, index, minValue, maxValue);
}
/**
- * Mark the properties with the supplied names to be treated as dates (and obviously indexed). This does not remove any
- * other rules for these properties.
+ * Define a double-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be included in full-text searches
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @param maxValue the maximum value for this field, or null if there is no maximum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder treatAsDates( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, TREAT_AS_DATE | INDEX);
- }
- }
- return this;
+ public Builder doubleField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Double minValue,
+ Double maxValue ) {
+ if (minValue == null) minValue = Double.MIN_VALUE;
+ if (maxValue == null) maxValue = Double.MAX_VALUE;
+ return numericField(name, FieldType.DOUBLE, store, index, minValue, maxValue);
}
/**
- * Mark the properties with the supplied names to be indexed, analyzed and stored. This does not remove any other rules
- * for these properties.
+ * Define a integer-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be indexed, analyzed and stored
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder analyzeAndStore( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, INDEX | ANALYZE | STORE);
- }
- }
- return this;
+ public Builder integerField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Integer minValue ) {
+ return integerField(name, store, index, minValue, null);
}
/**
- * Mark the properties with the supplied names to be indexed, analyzed, stored and included in full-text searches. This
- * does not remove any other rules for these properties.
+ * Define a long-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be indexed, analyzed, stored and included in full-text
- * searches
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder analyzeAndStoreAndFullText( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, INDEX | ANALYZE | STORE | FULL_TEXT);
- }
- }
- return this;
+ public Builder longField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Long minValue ) {
+ return longField(name, store, index, minValue, null);
}
/**
- * Mark the properties with the supplied names to be indexed, analyzed and included in full-text searches. This does not
- * remove any other rules for these properties.
+ * Define a date-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be indexed, analyzed and included in full-text searches
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder analyzeAndFullText( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, INDEX | ANALYZE | FULL_TEXT);
- }
- }
- return this;
+ public Builder dateField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Long minValue ) {
+ return dateField(name, store, index, minValue, null);
}
/**
- * Mark the properties with the supplied names to be indexed, stored and included in full-text searches. This does not
- * remove any other rules for these properties.
+ * Define a float-based field in the indexes. This method will overwrite any existing definition in this builder.
*
- * @param namesToIndex the names of the properties that are to be indexed, stored and included in full-text searches
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
* @return this builder for convenience and method chaining; never null
*/
- public Builder storeAndFullText( Name... namesToIndex ) {
- if (namesToIndex != null) {
- for (Name name : namesToIndex) {
- add(name, INDEX | STORE | FULL_TEXT);
- }
- }
- return this;
+ public Builder floatField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Float minValue ) {
+ return floatField(name, store, index, minValue, null);
}
- protected void add( Name name,
- int option ) {
- Rule rule = rulesByName.get(name);
- if (rule != null) {
- option |= rule.getMask();
- }
- rulesByName.put(name, createRule(option));
+ /**
+ * Define a double-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @param minValue the minimum value for this field, or null if there is no minimum value
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder doubleField( Name name,
+ Field.Store store,
+ Field.Index index,
+ Double minValue ) {
+ return doubleField(name, store, index, minValue, null);
}
/**
+ * Define a integer-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder integerField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return integerField(name, store, index, null, null);
+ }
+
+ /**
+ * Define a long-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder longField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return longField(name, store, index, null, null);
+ }
+
+ /**
+ * Define a date-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder dateField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return dateField(name, store, index, null, null);
+ }
+
+ /**
+ * Define a float-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder floatField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return floatField(name, store, index, null, null);
+ }
+
+ /**
+ * Define a double-based field in the indexes. This method will overwrite any existing definition in this builder.
+ *
+ * @param name the name of the field
+ * @param store the storage setting, or null if the field should be {@link Store#YES stored}
+ * @param index the index setting, or null if the field should be indexed but {@link Index#NOT_ANALYZED not analyzed}
+ * @return this builder for convenience and method chaining; never null
+ */
+ public Builder doubleField( Name name,
+ Field.Store store,
+ Field.Index index ) {
+ return doubleField(name, store, index, null, null);
+ }
+
+ /**
* Build the indexing rules.
*
* @return the immutable indexing rules.
Modified: trunk/dna-search/src/test/java/org/jboss/dna/search/IndexingRulesTest.java
===================================================================
--- trunk/dna-search/src/test/java/org/jboss/dna/search/IndexingRulesTest.java 2009-11-24 21:17:39 UTC (rev 1341)
+++ trunk/dna-search/src/test/java/org/jboss/dna/search/IndexingRulesTest.java 2009-11-25 00:59:30 UTC (rev 1342)
@@ -25,6 +25,7 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
+import org.apache.lucene.document.Field;
import org.jboss.dna.search.IndexRules.Builder;
import org.junit.Before;
import org.junit.Test;
@@ -51,8 +52,9 @@
@Test
public void shouldBuildValidRulesFromBuilderAfterJustSettingDefaultRules() {
- builder.defaultTo(IndexRules.FULL_TEXT);
+ builder.defaultTo(Field.Store.NO, Field.Index.ANALYZED_NO_NORMS);
rules = builder.build();
- assertThat(rules.getRule(null).isFullText(), is(true));
+ assertThat(rules.getRule(null).getIndexOption(), is(Field.Index.ANALYZED_NO_NORMS));
+ assertThat(rules.getRule(null).getStoreOption(), is(Field.Store.NO));
}
}
Modified: trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java
===================================================================
--- trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java 2009-11-24 21:17:39 UTC (rev 1341)
+++ trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java 2009-11-25 00:59:30 UTC (rev 1342)
@@ -29,6 +29,7 @@
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.List;
+import org.apache.lucene.document.Field;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.Location;
@@ -47,7 +48,6 @@
import org.jboss.dna.graph.search.SearchEngine;
import org.jboss.dna.graph.search.SearchProvider;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.SAXException;
@@ -93,6 +93,12 @@
// Set up the provider and the search engine ...
IndexRules.Builder rulesBuilder = IndexRules.createBuilder(DualIndexSearchProvider.DEFAULT_RULES);
+ rulesBuilder.defaultTo(Field.Store.YES, Field.Index.NOT_ANALYZED);
+ rulesBuilder.stringField(name("model"), Field.Store.YES, Field.Index.ANALYZED);
+ rulesBuilder.integerField(name("year"), Field.Store.YES, Field.Index.NOT_ANALYZED);
+ rulesBuilder.floatField(name("userRating"), Field.Store.YES, Field.Index.NOT_ANALYZED, 0.0f, 10.0f);
+ rulesBuilder.integerField(name("mpgCity"), Field.Store.YES, Field.Index.NOT_ANALYZED, 0, 50);
+ rulesBuilder.integerField(name("mpgHighway"), Field.Store.YES, Field.Index.NOT_ANALYZED, 0, 50);
// rulesBuilder.analyzeAndStoreAndFullText(name("maker"));
IndexRules rules = rulesBuilder.build();
LuceneConfiguration luceneConfig = LuceneConfigurations.inMemory();
@@ -103,7 +109,7 @@
// Create the schemata for the workspaces ...
schemata = ImmutableSchemata.createBuilder(typeSystem)
- .addTable("__ALLNODES__", "maker", "model", "year", "msrp")
+ .addTable("__ALLNODES__", "maker", "model", "year", "msrp", "mpgHighway", "mpgCity")
.makeSearchable("__ALLNODES__", "maker")
.build();
@@ -242,6 +248,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(18));
System.out.println(results);
@@ -252,19 +259,21 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE maker = 'Toyota'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
}
- @Ignore
@Test
public void shouldFindNodesBySimpleQueryWithGreaterThanComparisonCriteria() {
engine.index(workspaceName1, path("/"), 100);
- QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE mpgHighway > 20", typeSystem);
+ QueryCommand query = sql.parseQuery("SELECT model, maker, mpgHighway, mpgCity FROM __ALLNODES__ WHERE mpgHighway > 20",
+ typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
- assertThat(results.getRowCount(), is(2));
+ assertThat(results.getRowCount(), is(6));
System.out.println(results);
}
@@ -273,6 +282,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE LOWER(maker) = 'toyota'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
@@ -283,6 +293,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE UPPER(maker) = 'TOYOTA'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
@@ -293,6 +304,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE maker LIKE 'Toyo%'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
@@ -303,6 +315,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE maker LIKE '%yota'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
@@ -313,6 +326,7 @@
engine.index(workspaceName1, path("/"), 100);
QueryCommand query = sql.parseQuery("SELECT model, maker FROM __ALLNODES__ WHERE LOWER(maker) LIKE 'toyo%'", typeSystem);
QueryResults results = engine.query(context, workspaceName1, query, schemata);
+ assertNoErrors(results);
assertThat(results, is(notNullValue()));
assertThat(results.getRowCount(), is(2));
System.out.println(results);
14 years, 5 months
DNA SVN: r1341 - in trunk: dna-common/src/main/java/org/jboss/dna/common and 6 other directories.
by dna-commits@lists.jboss.org
Author: blafond
Date: 2009-11-24 16:17:39 -0500 (Tue, 24 Nov 2009)
New Revision: 1341
Added:
trunk/dna-common/src/test/java/org/jboss/dna/common/text/PositionTest.java
Modified:
trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java
trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
trunk/dna-common/src/main/java/org/jboss/dna/common/text/Position.java
trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/xpath/XPathParser.java
Log:
DNA-555 added "index in content" ability to token stream and position class. Allows extracting and managing string segments from tokenized content.
Modified: trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java
===================================================================
--- trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-cnd/src/main/java/org/jboss/dna/cnd/CndTokenizer.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -82,7 +82,7 @@
case '(':
case ')':
case ',':
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
// case '.':
// tokens.addToken(input.position(), input.index(), input.index() + 1, DECIMAL);
@@ -90,7 +90,7 @@
case '{':
// Vendor extension, meant to be excluded
int startIndex = input.index();
- Position startingPosition = input.position();
+ Position startingPosition = input.position(startIndex);
boolean foundClosingBrace = false;
String vendorName = "";
while (input.hasNext()) {
@@ -114,7 +114,7 @@
break;
case '\"':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
boolean foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -135,7 +135,7 @@
break;
case '\'':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -156,7 +156,7 @@
break;
case '/':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
if (input.isNext('/')) {
// End-of-line comment ...
boolean foundLineTerminator = false;
@@ -211,7 +211,7 @@
// since these do not appear in other rules above, they will result in one-character tokens.
//
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
// Read as long as there is a valid XML character ...
while (input.hasNext() && !(input.isNextWhitespace() || input.isNextAnyOf("[]<>=-+(),\"'/{*|"))) {
c = input.next();
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/CommonI18n.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -104,6 +104,7 @@
public static I18n expectingValidIntegerAtLineAndColumn;
public static I18n expectingValidLongAtLineAndColumn;
public static I18n expectingValidBooleanAtLineAndColumn;
+ public static I18n endPositionMustBeGreaterThanStartingPosition;
static {
try {
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/Position.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/Position.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/Position.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -7,14 +7,37 @@
*/
@Immutable
public final class Position {
+ /**
+ * The position is used when there is no content.
+ */
+ public final static Position EMPTY_CONTENT_POSITION = new Position(-1, 1, 0);
+
private final int line;
private final int column;
+ private final int indexInContent;
- public Position( int line,
+ public Position( int indexInContent,
+ int line,
int column ) {
+ this.indexInContent = indexInContent < 0 ? -1:indexInContent;
this.line = line;
this.column = column;
+
+ assert this.indexInContent >= -1;
+ assert this.line > 0;
+ assert this.column >= 0;
+ // make sure that negative index means an EMPTY_CONTENT_POSITION
+ assert this.indexInContent < 0 ? this.line == 1 && this.column == 0: true;
}
+
+ /**
+ * Get the 0-based index of this position in the content character array.
+ *
+ * @return the index; never negative except for the first position in an empty content.
+ */
+ public int getIndexInContent() {
+ return indexInContent;
+ }
/**
* Get the 1-based column number of the character.
@@ -41,7 +64,7 @@
*/
@Override
public int hashCode() {
- return line;
+ return indexInContent;
}
/**
@@ -51,6 +74,28 @@
*/
@Override
public String toString() {
- return "" + line + ':' + column;
+ return "" + indexInContent + ':' + line + ':' + column;
}
+
+ /**
+ * Return a new position that is the addition of this position and that supplied.
+ *
+ * @param position the position to add to this object; may not be null
+ * @return the combined position
+ */
+ public Position add(Position position) {
+ if( this.getIndexInContent() < 0 ) {
+ return position.getIndexInContent() < 0 ? EMPTY_CONTENT_POSITION:position;
+ }
+
+ if( position.getIndexInContent() < 0 ) {
+ return this;
+ }
+
+ int index = this.getIndexInContent() + position.getIndexInContent();
+ int line = position.getLine() + this.getLine() - 1;
+ int column = this.getLine() == 1 ? this.getColumn() + position.getColumn() : this.getColumn();
+
+ return new Position(index, line, column);
+ }
}
Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -384,6 +384,20 @@
private final boolean caseSensitive;
private final Tokenizer tokenizer;
private List<Token> tokens;
+ /**
+ * This class navigates the Token objects using this iterator. However, because it very often needs to access the
+ * "current token" in the "consume(...)" and "canConsume(...)" and "matches(...)" methods, the class caches a "current token"
+ * and makes this iterator point to the 2nd token.
+ *
+ * <pre>
+ * T1 T2 T3 T4 T5
+ * ˆ ˆ ˆ
+ * | | |
+ * | | +- The position of the tokenIterator, where tokenIterator.hasNext() will return T3
+ * | +---- The token referenced by currentToken
+ * +-------- The logical position of the TokenStream object, where the "consume()" would return T2
+ * </pre>
+ */
private ListIterator<Token> tokenIterator;
private Token currentToken;
private boolean completed;
@@ -412,7 +426,7 @@
TokenFactory tokenFactory = caseSensitive ? new CaseSensitiveTokenFactory() : new CaseInsensitiveTokenFactory();
CharacterStream characterStream = new CharacterArrayStream(inputContent);
tokenizer.tokenize(characterStream, tokenFactory);
- this.tokens = tokenFactory.getTokens();
+ this.tokens = initializeTokens(tokenFactory.getTokens());
}
// Create the iterator ...
@@ -422,6 +436,28 @@
}
/**
+ * Method to allow subclasses to preprocess the set of tokens and return the correct tokens to use. The default behavior is to
+ * simply return the supplied tokens.
+ *
+ * @param tokens
+ * @return list of tokens.
+ */
+ protected List<Token> initializeTokens( List<Token> tokens ) {
+ return tokens;
+ }
+
+ /**
+ * Method to allow tokens to be re-used from the start without re-tokenizing content.
+ */
+ public void rewind() {
+ // recreate the iterator ...
+ tokenIterator = this.tokens.listIterator();
+ completed = false;
+ currentToken = null;
+ moveToNextToken();
+ }
+
+ /**
* Get the position of the previous token.
*
* @return the previous token's position; never null
@@ -437,7 +473,7 @@
*
* @return the current token's position; never null
* @throws IllegalStateException if this method was called before the stream was {@link #start() started}
- * @throws NoSuchElementException if there is no next token
+ * @throws NoSuchElementException if there is no previous token
*/
public Position nextPosition() {
return currentToken().position();
@@ -526,7 +562,7 @@
protected void throwNoMoreContent() throws ParsingException {
String msg = CommonI18n.noMoreContent.text();
- Position pos = tokens.isEmpty() ? new Position(1, 0) : tokens.get(tokens.size() - 1).position();
+ Position pos = tokens.isEmpty() ? new Position(-1, 1, 0) : tokens.get(tokens.size() - 1).position();
throw new ParsingException(pos, msg);
}
@@ -725,9 +761,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -770,9 +809,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -811,9 +853,12 @@
*
* <pre>
*
- * if ( tokens.matches(currentExpected,expectedForNextTokens) ) { tokens.consume(currentExpected,expectedForNextTokens); }
+ * if (tokens.matches(currentExpected, expectedForNextTokens)) {
+ * tokens.consume(currentExpected, expectedForNextTokens);
+ * }
*
* </pre>
+ *
* </p>
* <p>
* The {@link #ANY_VALUE ANY_VALUE} constant can be used in the expected values as a wildcard.
@@ -954,7 +999,7 @@
* @throws IllegalStateException if this method was called before the stream was {@link #start() started}
*/
public boolean matches( int expectedType ) throws IllegalStateException {
- return !completed && (expectedType == ANY_TYPE || currentToken().type() == expectedType);
+ return !completed && currentToken().matches(expectedType);
}
/**
@@ -1075,7 +1120,7 @@
if (!iter.hasNext()) return false;
token = iter.next();
if (nextExpectedType == ANY_TYPE) continue;
- if (token.type() != nextExpectedType) return false;
+ if (!token.matches(nextExpectedType)) return false;
}
return true;
}
@@ -1233,6 +1278,30 @@
}
/**
+ * Gets the content string starting at the first position (inclusive) and continuing up to the end position (exclusive).
+ *
+ * @param starting the position marking the beginning of the desired content string.
+ * @param end the position located directly after the returned content string; can be null, which means end of content
+ * @return the content string; never null
+ */
+ public String getContentBetween( Position starting,
+ Position end ) {
+ CheckArg.isNotNull(starting, "starting");
+
+ int startIndex = starting.getIndexInContent();
+ int endIndex = inputString.length();
+ if (end != null) {
+ endIndex = end.getIndexInContent();
+ }
+
+ if (startIndex >= endIndex) {
+ throw new IllegalArgumentException(CommonI18n.endPositionMustBeGreaterThanStartingPosition.text(startIndex, endIndex));
+ }
+
+ return inputString.substring(startIndex, endIndex);
+ }
+
+ /**
* Get the previous token. This does not modify the state.
*
* @return the previous token; never null
@@ -1249,11 +1318,10 @@
}
throw new IllegalStateException(CommonI18n.startMethodMustBeCalledBeforeConsumingOrMatching.text());
}
- if (!tokenIterator.hasPrevious()) {
+ if (tokenIterator.previousIndex() == 0) {
throw new NoSuchElementException(CommonI18n.noMoreContent.text());
}
- ListIterator<Token> temp = tokens.listIterator(tokenIterator.previousIndex());
- return temp.next();
+ return tokens.get(tokenIterator.previousIndex() - 1);
}
String generateFragment() {
@@ -1337,9 +1405,10 @@
/**
* Get the position for the last character returned from {@link #next()}.
*
+ * @param startIndex
* @return the position of the last character returned; never null
*/
- Position position();
+ Position position( int startIndex );
/**
* Determine if the next character on the sream is a {@link Character#isWhitespace(char) whitespace character}. This
@@ -1513,6 +1582,14 @@
boolean matches( char expected );
/**
+ * Determine if the token matches the supplied type.
+ *
+ * @param expectedType the expected integer type
+ * @return true if the token's value matches the supplied integer type, or false otherwise
+ */
+ boolean matches( int expectedType );
+
+ /**
* Get the type of the token.
*
* @return the token's type
@@ -1546,6 +1623,14 @@
* @return the position; never null
*/
Position position();
+
+ /**
+ * Bitmask ORed with existing type value.
+ *
+ * @param typeMask
+ * @return copy of Token with new type
+ */
+ Token withType( int typeMask );
}
/**
@@ -1571,6 +1656,16 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
+ */
+ public Token withType( int typeMask ) {
+ int type = this.type | typeMask;
+ return new CaseSensitiveToken(startIndex, endIndex, type, position);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.common.text.TokenStream.Token#type()
*/
public final int type() {
@@ -1625,6 +1720,15 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.common.text.TokenStream.Token#matches(int)
+ */
+ public final boolean matches( int expectedType ) {
+ return expectedType == ANY_TYPE || (currentToken().type() & expectedType) == expectedType;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.common.text.TokenStream.Token#value()
*/
public final String value() {
@@ -1673,6 +1777,17 @@
protected String matchString() {
return inputUppercased;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.common.text.TokenStream.Token#withType(int)
+ */
+ @Override
+ public Token withType( int typeMask ) {
+ int type = this.type() | typeMask;
+ return new CaseInsensitiveToken(startIndex(), endIndex(), type, position());
+ }
}
protected abstract class TokenFactory implements Tokens {
@@ -1772,10 +1887,12 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.common.text.TokenStream.CharacterStream#position()
+ * @param startIndex
+ * @return the position of the token. never null
+ * @see org.jboss.dna.common.text.TokenStream.CharacterStream#position(int)
*/
- public Position position() {
- return new Position(lineNumber, columnNumber);
+ public Position position( int startIndex ) {
+ return new Position(startIndex, lineNumber, columnNumber);
}
/**
@@ -1792,10 +1909,10 @@
if (result == '\r') {
nextCharMayBeLineFeed = true;
++lineNumber;
- columnNumber = 1;
+ columnNumber = 0;
} else if (result == '\n') {
if (!nextCharMayBeLineFeed) ++lineNumber;
- columnNumber = 1;
+ columnNumber = 0;
} else if (nextCharMayBeLineFeed) {
nextCharMayBeLineFeed = false;
}
@@ -1958,22 +2075,22 @@
/**
* The {@link Token#type() token type} for tokens that consist of an individual '.' character.
*/
- public static final int DECIMAL = 3;
+ public static final int DECIMAL = 4;
/**
* The {@link Token#type() token type} for tokens that consist of all the characters within single-quotes. Single quote
* characters are included if they are preceded (escaped) by a '\' character.
*/
- public static final int SINGLE_QUOTED_STRING = 4;
+ public static final int SINGLE_QUOTED_STRING = 8;
/**
* The {@link Token#type() token type} for tokens that consist of all the characters within double-quotes. Double quote
* characters are included if they are preceded (escaped) by a '\' character.
*/
- public static final int DOUBLE_QUOTED_STRING = 5;
+ public static final int DOUBLE_QUOTED_STRING = 16;
/**
* The {@link Token#type() token type} for tokens that consist of all the characters between "/*" and "*/" or between
* "//" and the next line terminator (e.g., '\n', '\r' or "\r\n").
*/
- public static final int COMMENT = 6;
+ public static final int COMMENT = 32;
private final boolean useComments;
@@ -2017,14 +2134,14 @@
case '|':
case '=':
case ':':
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
case '.':
- tokens.addToken(input.position(), input.index(), input.index() + 1, DECIMAL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, DECIMAL);
break;
case '\"':
int startIndex = input.index();
- Position startingPosition = input.position();
+ Position startingPosition = input.position(startIndex);
boolean foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -2041,11 +2158,11 @@
throw new ParsingException(startingPosition, msg);
}
int endIndex = input.index() + 1; // beyond last character read
- tokens.addToken(input.position(), startIndex, endIndex, DOUBLE_QUOTED_STRING);
+ tokens.addToken(startingPosition, startIndex, endIndex, DOUBLE_QUOTED_STRING);
break;
case '\'':
startIndex = input.index();
- startingPosition = input.position();
+ startingPosition = input.position(startIndex);
foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -2062,10 +2179,11 @@
throw new ParsingException(startingPosition, msg);
}
endIndex = input.index() + 1; // beyond last character read
- tokens.addToken(input.position(), startIndex, endIndex, SINGLE_QUOTED_STRING);
+ tokens.addToken(startingPosition, startIndex, endIndex, SINGLE_QUOTED_STRING);
break;
case '/':
startIndex = input.index();
+ startingPosition = input.position(startIndex);
if (input.isNext('/')) {
// End-of-line comment ...
boolean foundLineTerminator = false;
@@ -2080,7 +2198,7 @@
if (!foundLineTerminator) ++endIndex; // must point beyond last char
if (c == '\r' && input.isNext('\n')) input.next();
if (useComments) {
- tokens.addToken(input.position(), startIndex, endIndex, COMMENT);
+ tokens.addToken(startingPosition, startIndex, endIndex, COMMENT);
}
} else if (input.isNext('*')) {
// Multi-line comment ...
@@ -2091,21 +2209,22 @@
if (input.hasNext()) input.next(); // consume the '/'
if (useComments) {
endIndex = input.index() + 1; // the token will include the '/' and '*' characters
- tokens.addToken(input.position(), startIndex, endIndex, COMMENT);
+ tokens.addToken(startingPosition, startIndex, endIndex, COMMENT);
}
} else {
// just a regular slash ...
- tokens.addToken(input.position(), startIndex, startIndex + 1, SYMBOL);
+ tokens.addToken(startingPosition, startIndex, startIndex + 1, SYMBOL);
}
break;
default:
startIndex = input.index();
+ startingPosition = input.position(startIndex);
// Read until another whitespace/symbol/decimal/slash is found
while (input.hasNext() && !(input.isNextWhitespace() || input.isNextAnyOf("/.-(){}*,;+%?$[]!<>|=:"))) {
c = input.next();
}
endIndex = input.index() + 1; // beyond last character that was included
- tokens.addToken(input.position(), startIndex, endIndex, WORD);
+ tokens.addToken(startingPosition, startIndex, endIndex, WORD);
}
}
}
Modified: trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties
===================================================================
--- trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-common/src/main/resources/org/jboss/dna/common/CommonI18n.properties 2009-11-24 21:17:39 UTC (rev 1341)
@@ -93,3 +93,4 @@
expectingValidIntegerAtLineAndColumn = Expecting a valid integer value but found '{0}' at line {1}, column {2}
expectingValidLongAtLineAndColumn = Expecting a valid long value but found '{0}' at line {1}, column {2}
expectingValidBooleanAtLineAndColumn = Expecting a valid boolean value but found '{0}' at line {1}, column {2}
+endPositionMustBeGreaterThanStartingPosition = End position {1} must be greater than starting position {0}
Added: trunk/dna-common/src/test/java/org/jboss/dna/common/text/PositionTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/text/PositionTest.java (rev 0)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/text/PositionTest.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -0,0 +1,85 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.common.text;
+
+import static org.junit.Assert.assertThat;
+
+import static org.hamcrest.core.Is.is;
+
+import org.junit.Test;
+
+
+public class PositionTest {
+
+ private int combinedIndex(int firstIndex, int secondIndex) {
+ Position first = new Position(firstIndex, 1, 0);
+ Position second = new Position(secondIndex, 1, 0);
+
+ int firstPlusSecond = first.add(second).getIndexInContent();
+ int secondPlusFirst = second.add(first).getIndexInContent();
+
+ assertThat(firstPlusSecond, is(secondPlusFirst));
+
+ return firstPlusSecond;
+ }
+
+ @Test
+ public void shouldAddNoContentPositionToValidPosition() {
+ // -1 to >=0
+ assertThat(combinedIndex(-1, 0), is(0));
+ assertThat(combinedIndex(-1, 1), is(1));
+ assertThat(combinedIndex(-1, 10), is(10));
+ }
+
+ @Test
+ public void shouldAddValidPositionToNoContentPosition() {
+ // >= 0 to -1
+ assertThat(combinedIndex(0, -1), is(0));
+ assertThat(combinedIndex(1, -1), is(1));
+ assertThat(combinedIndex(10, -1), is(10));
+ }
+
+ @Test
+ public void shouldAddValidPositionToValidPosition() {
+ // positive to positive
+ assertThat(combinedIndex(1, 1), is(2));
+ assertThat(combinedIndex(10, 1), is(11));
+ assertThat(combinedIndex(1, 10), is(11));
+ assertThat(combinedIndex(10, 10), is(20));
+ }
+
+ @Test
+ public void shouldAddStartingPositionToStartingPosition() {
+ // 0 to 0
+ assertThat(combinedIndex(0, 0), is(0));
+ }
+
+ @Test
+ public void shouldAddNoContentPositionToNoContentPosition() {
+ // -1 to -1
+ assertThat(combinedIndex(-1, -1), is(-1));
+ assertThat(combinedIndex(-10, -1), is(-1));
+ assertThat(combinedIndex(-1, -10), is(-1));
+ }
+}
Property changes on: trunk/dna-common/src/test/java/org/jboss/dna/common/text/PositionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -336,6 +336,19 @@
assertThat(tokens.canConsume("FROM", "THIS", "TABLE"), is(true));
assertThat(tokens.hasNext(), is(false));
}
+
+ @Test
+ public void shouldReturnTrueFromMatchIfAllTypeValuesMatch() {
+ makeCaseInsensitive();
+ assertThat(tokens.matches(BasicTokenizer.WORD, BasicTokenizer.WORD), is(true));
+ }
+
+ @Test
+ public void shouldReturnFalseFromMatchIfAllTypeValuesDoNotMatch() {
+ makeCaseInsensitive();
+ assertThat(tokens.matches(BasicTokenizer.WORD, BasicTokenizer.DECIMAL), is(false));
+ assertThat(tokens.matches(BasicTokenizer.DECIMAL, BasicTokenizer.WORD), is(false));
+ }
@Test
public void shouldConsumeMultipleTokensWithAnyValueConstant() {
@@ -397,4 +410,51 @@
assertThat(tokens.canConsume(TokenStream.ANY_VALUE), is(false));
assertThat(tokens.canConsume(BasicTokenizer.SYMBOL), is(false));
}
+
+ @Test
+ public void shouldFindNextPositionStartIndex() {
+ makeCaseInsensitive();
+ // "Select all columns from this table";
+ tokens.consume();
+ // Next position should be line 1, column 8
+ assertThat(tokens.nextPosition().getIndexInContent(), is(7));
+ assertThat(tokens.nextPosition().getColumn(), is(8));
+ assertThat(tokens.nextPosition().getLine(), is(1));
+ }
+
+ @Test
+ public void shouldFindPreviousPositionStartIndex() {
+ makeCaseInsensitive();
+ // "Select all columns from this table";
+ tokens.consume();
+ tokens.consume();
+ // previous position should be line 1, column 8
+ assertThat(tokens.previousPosition().getIndexInContent(), is(7));
+ assertThat(tokens.previousPosition().getColumn(), is(8));
+ assertThat(tokens.previousPosition().getLine(), is(1));
+ }
+
+ @Test
+ public void shouldParseMultiLineString() {
+ makeCaseInsensitive();
+ String content = "ALTER DATABASE \n"
+ + "DO SOMETHING; \n"
+ + "ALTER DATABASE \n"
+ + " SET DEFAULT BIGFILE TABLESPACE;";
+ tokens = new TokenStream(content, tokenizer, true);
+ tokens.start();
+
+ tokens.consume(); // LINE
+ tokens.consume(); // ONE
+ tokens.consume(); // DO
+ tokens.consume(); // SOMETHING
+ tokens.consume(); // ;
+
+ assertThat(tokens.nextPosition().getIndexInContent(), is(31));
+ assertThat(tokens.nextPosition().getColumn(), is(1));
+ tokens.consume(); // ALTER
+ assertThat(tokens.nextPosition().getIndexInContent(), is(37));
+ assertThat(tokens.nextPosition().getColumn(), is(7));
+
+ }
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/parse/SqlQueryParser.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -799,15 +799,12 @@
}
protected Term parseFullTextSearchExpression( String expression,
- Position position ) {
+ Position startOfExpression ) {
try {
return new FullTextSearchParser().parse(expression);
} catch (ParsingException e) {
// Convert the position in the exception into a position in the query.
- Position exprPos = e.getPosition();
- int line = position.getLine() + exprPos.getLine() - 1;
- int column = exprPos.getLine() == 1 ? exprPos.getColumn() + position.getColumn() : exprPos.getColumn();
- Position queryPos = new Position(line, column);
+ Position queryPos = startOfExpression.add(e.getPosition());
throw new ParsingException(queryPos, e.getMessage());
}
}
@@ -1264,14 +1261,14 @@
case '|':
case '=':
case ':':
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
case '\'':
case '[':
case '\"':
int startIndex = input.index();
char closingChar = c == '[' ? ']' : c;
- Position pos = input.position();
+ Position pos = input.position(startIndex);
boolean foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -1296,7 +1293,7 @@
break;
case '-':
startIndex = input.index();
- pos = input.position();
+ pos = input.position(input.index());
if (input.isNext('-')) {
// End-of-line comment ...
boolean foundLineTerminator = false;
@@ -1314,13 +1311,13 @@
tokens.addToken(pos, startIndex, endIndex, COMMENT);
}
} else {
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
}
break;
case '/':
startIndex = input.index();
- pos = input.position();
+ pos = input.position(input.index());
if (input.isNext('*')) {
// Multi-line comment ...
while (input.hasNext() && !input.isNext('*', '/')) {
@@ -1333,13 +1330,13 @@
tokens.addToken(pos, startIndex, endIndex, COMMENT);
}
} else {
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
}
break;
default:
startIndex = input.index();
- pos = input.position();
+ pos = input.position(input.index());
// Read as long as there is a valid XML character ...
int tokenType = (Character.isLetterOrDigit(c) || c == '_') ? WORD : OTHER;
while (input.isNextLetterOrDigit() || input.isNext('_')) {
Modified: trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java
===================================================================
--- trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-graph/src/test/java/org/jboss/dna/graph/query/parse/SqlQueryParserTest.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -789,8 +789,8 @@
@Test
public void shouldParseFullTextSearchExpressionFromStringWithValidExpression() {
- Position pos = new Position(100, 13);
- Term result = parser.parseFullTextSearchExpression("term1 term2 OR -term3 OR -term4 OR term5", pos);
+ Position pos = new Position(500, 100, 13);
+ FullTextSearch.Term result = parser.parseFullTextSearchExpression("term1 term2 OR -term3 OR -term4 OR term5", pos);
assertThat(result, is(notNullValue()));
assertThat(result, is(instanceOf(Disjunction.class)));
Disjunction disjunction = (Disjunction)result;
@@ -808,11 +808,12 @@
@Test
public void shouldConvertPositionWhenUnableToParseFullTextSearchExpression() {
try {
- parser.parseFullTextSearchExpression("", new Position(100, 13));
+ parser.parseFullTextSearchExpression("", new Position(500, 100, 13));
fail("Should have thrown an exception");
} catch (ParsingException e) {
assertThat(e.getPosition().getLine(), is(100));
assertThat(e.getPosition().getColumn(), is(13));
+ assertThat(e.getPosition().getIndexInContent(), is(500));
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/xpath/XPathParser.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/xpath/XPathParser.java 2009-11-24 17:46:37 UTC (rev 1340)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/xpath/XPathParser.java 2009-11-24 21:17:39 UTC (rev 1341)
@@ -751,13 +751,13 @@
case '\\':
case '#':
case '@':
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(input.index()), input.index(), input.index() + 1, SYMBOL);
break;
case '\'':
case '\"':
int startIndex = input.index();
char closingChar = c;
- Position pos = input.position();
+ Position pos = input.position(startIndex);
boolean foundClosingQuote = false;
while (input.hasNext()) {
c = input.next();
@@ -782,7 +782,7 @@
startIndex = input.index();
if (input.isNext(':')) {
// This is a comment ...
- pos = input.position();
+ pos = input.position(startIndex);
while (input.hasNext() && !input.isNext(':', ')')) {
c = input.next();
}
@@ -793,13 +793,13 @@
tokens.addToken(pos, startIndex, endIndex, COMMENT);
}
} else {
- tokens.addToken(input.position(), input.index(), input.index() + 1, SYMBOL);
+ tokens.addToken(input.position(startIndex), input.index(), input.index() + 1, SYMBOL);
break;
}
break;
default:
startIndex = input.index();
- pos = input.position();
+ pos = input.position(startIndex);
// Read as long as there is a valid XML character ...
int tokenType = (XmlCharacters.isValidNcNameStart(c)) ? NAME : OTHER;
while (input.isNextValidXmlNcNameCharacter()) {
14 years, 5 months