Author: rhauch
Date: 2009-12-17 20:53:48 -0500 (Thu, 17 Dec 2009)
New Revision: 1454
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueTypeSystem.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/model/TypeSystem.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/ProcessingComponent.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/ImmutableSchemata.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/search/AbstractSearchEngine.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/NodeTypeSchemata.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java
Log:
DNA-468 Further integrated the query system by fixing several issues, including how the
NodeTypeSchemata creates the IndexRules for the search engine.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueTypeSystem.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueTypeSystem.java 2009-12-18
01:53:09 UTC (rev 1453)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/property/ValueTypeSystem.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -51,6 +51,7 @@
private final TypeFactory<Double> doubleFactory;
private final TypeFactory<?> dateFactory;
private final TypeFactory<?> pathFactory;
+ private final TypeFactory<?> binaryFactory;
/**
* Create a type system using the supplied value factories.
@@ -102,19 +103,7 @@
}
};
this.pathFactory = new Factory<Path>(valueFactories.getPathFactory());
- factories.put(PropertyType.STRING, this.stringFactory);
- factories.put(PropertyType.BOOLEAN, this.booleanFactory);
- factories.put(PropertyType.DATE, this.dateFactory);
- factories.put(PropertyType.DECIMAL, new
Factory<BigDecimal>(valueFactories.getDecimalFactory()));
- factories.put(PropertyType.DOUBLE, this.doubleFactory);
- factories.put(PropertyType.LONG, this.longFactory);
- factories.put(PropertyType.NAME, new
Factory<Name>(valueFactories.getNameFactory()));
- factories.put(PropertyType.OBJECT, new
Factory<Object>(valueFactories.getObjectFactory()));
- factories.put(PropertyType.PATH, this.pathFactory);
- factories.put(PropertyType.REFERENCE, new
Factory<Reference>(valueFactories.getReferenceFactory()));
- factories.put(PropertyType.URI, new
Factory<URI>(valueFactories.getUriFactory()));
- factories.put(PropertyType.UUID, new
Factory<UUID>(valueFactories.getUuidFactory()));
- factories.put(PropertyType.BINARY, new
Factory<Binary>(valueFactories.getBinaryFactory()) {
+ this.binaryFactory = new Factory<Binary>(valueFactories.getBinaryFactory())
{
/**
* {@inheritDoc}
*
@@ -137,7 +126,20 @@
Binary binary = this.valueFactory.create(value);
return binary != null ? binary.getSize() : 0;
}
- });
+ };
+ factories.put(PropertyType.STRING, this.stringFactory);
+ factories.put(PropertyType.BOOLEAN, this.booleanFactory);
+ factories.put(PropertyType.DATE, this.dateFactory);
+ factories.put(PropertyType.DECIMAL, new
Factory<BigDecimal>(valueFactories.getDecimalFactory()));
+ factories.put(PropertyType.DOUBLE, this.doubleFactory);
+ factories.put(PropertyType.LONG, this.longFactory);
+ factories.put(PropertyType.NAME, new
Factory<Name>(valueFactories.getNameFactory()));
+ factories.put(PropertyType.OBJECT, new
Factory<Object>(valueFactories.getObjectFactory()));
+ factories.put(PropertyType.PATH, this.pathFactory);
+ factories.put(PropertyType.REFERENCE, new
Factory<Reference>(valueFactories.getReferenceFactory()));
+ factories.put(PropertyType.URI, new
Factory<URI>(valueFactories.getUriFactory()));
+ factories.put(PropertyType.UUID, new
Factory<UUID>(valueFactories.getUuidFactory()));
+ factories.put(PropertyType.BINARY, this.binaryFactory);
this.typeFactoriesByPropertyType = Collections.unmodifiableMap(factories);
Map<String, PropertyType> propertyTypeByName = new HashMap<String,
PropertyType>();
for (Map.Entry<PropertyType, TypeFactory<?>> entry :
this.typeFactoriesByPropertyType.entrySet()) {
@@ -236,6 +238,15 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.graph.query.model.TypeSystem#getBinaryFactory()
+ */
+ public TypeFactory<?> getBinaryFactory() {
+ return binaryFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.graph.query.model.TypeSystem#getTypeFactory(java.lang.String)
*/
public TypeFactory<?> getTypeFactory( String typeName ) {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/model/TypeSystem.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/model/TypeSystem.java 2009-12-18
01:53:09 UTC (rev 1453)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/model/TypeSystem.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -93,6 +93,13 @@
TypeFactory<?> getPathFactory();
/**
+ * Get the type factory for binary objects.
+ *
+ * @return the binary factory, or null if this type system doesn't support binary
objects
+ */
+ TypeFactory<?> getBinaryFactory();
+
+ /**
* Get the name of the type that is used by default.
*
* @return the default type name; never null
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/ProcessingComponent.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/ProcessingComponent.java 2009-12-18
01:53:09 UTC (rev 1453)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/process/ProcessingComponent.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -161,13 +161,14 @@
Table table = schemata.getTable(propValue.getSelectorName());
Column schemaColumn = table.getColumn(propertyName);
final String expectedType = schemaColumn.getPropertyType();
+ final TypeFactory<?> typeFactory =
typeSystem.getTypeFactory(expectedType);
return new DynamicOperation() {
public String getExpectedType() {
return expectedType;
}
public Object evaluate( Object[] tuple ) {
- return tuple[index];
+ return typeFactory.create(tuple[index]);
}
};
}
@@ -183,9 +184,10 @@
Column schemaColumn = table.getColumn(propertyName);
final String expectedType = schemaColumn.getPropertyType();
final TypeFactory<?> typeFactory =
typeSystem.getTypeFactory(expectedType);
+ final TypeFactory<Long> longFactory = typeSystem.getLongFactory();
return new DynamicOperation() {
public String getExpectedType() {
- return typeSystem.getLongFactory().getTypeName(); // length is always
LONG
+ return longFactory.getTypeName(); // length is always LONG
}
public Object evaluate( Object[] tuple ) {
@@ -293,11 +295,12 @@
FullTextSearchScore score = (FullTextSearchScore)operand;
String selectorName = score.getSelectorName().getName();
final int index = columns.getFullTextSearchScoreIndexFor(selectorName);
+ final TypeFactory<Double> doubleFactory =
typeSystem.getDoubleFactory();
if (index < 0) {
// No full-text search score for this selector, so return 0.0d;
return new DynamicOperation() {
public String getExpectedType() {
- return typeSystem.getDoubleFactory().getTypeName();
+ return doubleFactory.getTypeName();
}
public Object evaluate( Object[] tuple ) {
@@ -307,7 +310,7 @@
}
return new DynamicOperation() {
public String getExpectedType() {
- return typeSystem.getDoubleFactory().getTypeName();
+ return doubleFactory.getTypeName();
}
public Object evaluate( Object[] tuple ) {
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/ImmutableSchemata.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/ImmutableSchemata.java 2009-12-18
01:53:09 UTC (rev 1453)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/ImmutableSchemata.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -308,7 +308,9 @@
QueryContext queryContext = new QueryContext(schemata, typeSystem);
CanonicalPlanner planner = new CanonicalPlanner();
PlanNode plan = planner.createPlan(queryContext, command);
- if (queryContext.getProblems().hasErrors()) continue;
+ if (queryContext.getProblems().hasErrors()) {
+ continue;
+ }
// Get the columns from the top-level PROJECT ...
PlanNode project = plan.findAtOrBelow(Type.PROJECT);
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/search/AbstractSearchEngine.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/search/AbstractSearchEngine.java 2009-12-18
01:53:09 UTC (rev 1453)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/search/AbstractSearchEngine.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -53,7 +53,7 @@
public abstract class AbstractSearchEngine<WorkspaceType extends
SearchEngineWorkspace, ProcessorType extends SearchEngineProcessor>
implements SearchEngine {
- public static final boolean DEFAULT_VERIFY_WORKSPACE_IN_SOURCE = true;
+ public static final boolean DEFAULT_VERIFY_WORKSPACE_IN_SOURCE = false;
private final boolean verifyWorkspaceInSource;
private final RepositoryConnectionFactory connectionFactory;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-12-18
01:53:09 UTC (rev 1453)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrPropertyDefinition.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -241,6 +241,48 @@
}
/**
+ * Return the minimum value allowed by the constraints, or null if no such minimum
value is defined by the definition given
+ * it's required type and constraints. A minimum value can only be found for
numeric types, such as {@link PropertyType#DATE
+ * DATE}, {@link PropertyType#LONG LONG}, and {@link PropertyType#DOUBLE DOUBLE}; all
other types will return null.
+ *
+ * @return the minimum value, or null if no minimum value could be identified
+ */
+ Object getMinimumValue() {
+ if (requiredType == PropertyType.DATE || requiredType == PropertyType.DOUBLE ||
requiredType == PropertyType.LONG) {
+ ConstraintChecker checker = this.checker;
+ if (checker == null || checker.getType() != requiredType) {
+ checker = createChecker(context, requiredType, valueConstraints);
+ this.checker = checker;
+ }
+ assert checker instanceof RangeConstraintChecker;
+ RangeConstraintChecker<?> rangeChecker =
(RangeConstraintChecker<?>)checker;
+ return rangeChecker.getMinimum(); // may still be null
+ }
+ return null;
+ }
+
+ /**
+ * Return the maximum value allowed by the constraints, or null if no such maximum
value is defined by the definition given
+ * it's required type and constraints. A maximum value can only be found for
numeric types, such as {@link PropertyType#DATE
+ * DATE}, {@link PropertyType#LONG LONG}, and {@link PropertyType#DOUBLE DOUBLE}; all
other types will return null.
+ *
+ * @return the maximum value, or null if no maximum value could be identified
+ */
+ Object getMaximumValue() {
+ if (requiredType == PropertyType.DATE || requiredType == PropertyType.DOUBLE ||
requiredType == PropertyType.LONG) {
+ ConstraintChecker checker = this.checker;
+ if (checker == null || checker.getType() != requiredType) {
+ checker = createChecker(context, requiredType, valueConstraints);
+ this.checker = checker;
+ }
+ assert checker instanceof RangeConstraintChecker;
+ RangeConstraintChecker<?> rangeChecker =
(RangeConstraintChecker<?>)checker;
+ return rangeChecker.getMaximum(); // may still be null
+ }
+ return null;
+ }
+
+ /**
* Returns <code>true</code> if <code>value</code> can be
cast to <code>property.getRequiredType()</code> per the type
* conversion rules in section 6.2.6 of the JCR 1.0 specification AND
<code>value</code> satisfies the constraints (if any)
* for the property definition. If the property definition has a required type of
{@link PropertyType#UNDEFINED}, the cast
@@ -367,6 +409,10 @@
private interface Range<T> {
boolean accepts( T value );
+
+ Comparable<T> getMinimum();
+
+ Comparable<T> getMaximum();
}
/**
@@ -378,6 +424,8 @@
private static abstract class RangeConstraintChecker<T extends
Comparable<T>> implements ConstraintChecker {
private final Range<T>[] constraints;
private final ValueFactory<T> valueFactory;
+ private T minimumValue;
+ private T maximumValue;
@SuppressWarnings( "unchecked" )
protected RangeConstraintChecker( String[] valueConstraints,
@@ -394,6 +442,46 @@
protected abstract Comparable<T> parseValue( String s );
+ @SuppressWarnings( "unchecked" )
+ protected T getMinimum() {
+ if (minimumValue == null) {
+ // This is idempotent, so okay to recreate ...
+ Comparable<T> minimum = null;
+ // Go through the value constraints and see which one is the minimum
value ...
+ for (Range<T> range : constraints) {
+ T rangeMin = (T)range.getMinimum();
+ if (rangeMin == null) continue;
+ if (minimum == null) {
+ minimum = rangeMin;
+ } else {
+ minimum = minimum.compareTo(rangeMin) > 0 ? rangeMin :
minimum;
+ }
+ }
+ minimumValue = (T)minimum;
+ }
+ return minimumValue;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ protected T getMaximum() {
+ if (maximumValue == null) {
+ // This is idempotent, so okay to recreate ...
+ Comparable<T> maximum = null;
+ // Go through the value constraints and see which one is the minimum
value ...
+ for (Range<T> range : constraints) {
+ T rangeMax = (T)range.getMaximum();
+ if (rangeMax == null) continue;
+ if (maximum == null) {
+ maximum = rangeMax;
+ } else {
+ maximum = maximum.compareTo(rangeMax) > 0 ? rangeMax :
maximum;
+ }
+ }
+ maximumValue = (T)maximum;
+ }
+ return maximumValue;
+ }
+
/**
* Parses one constraint value into a {@link Range} that will accept only values
which match the range described by the
* value constraint.
@@ -425,6 +513,24 @@
}
return true;
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrPropertyDefinition.Range#getMaximum()
+ */
+ public Comparable<T> getMaximum() {
+ return lower;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.jcr.JcrPropertyDefinition.Range#getMinimum()
+ */
+ public Comparable<T> getMinimum() {
+ return upper;
+ }
};
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-12-18 01:53:09
UTC (rev 1453)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-12-18 01:53:48
UTC (rev 1454)
@@ -307,7 +307,7 @@
/**
* The default value for the {@link Option#QUERY_INDEXES_UPDATED_SYNCHRONOUSLY}
option is {@value} .
*/
- public static final String QUERY_INDEXES_UPDATED_SYNCHRONOUSLY =
Boolean.FALSE.toString();
+ public static final String QUERY_INDEXES_UPDATED_SYNCHRONOUSLY =
Boolean.TRUE.toString();
/**
* The default value for the {@link Option#QUERY_INDEX_DIRECTORY} option is
{@value} .
@@ -575,13 +575,8 @@
// Otherwise create a repository query manager that maintains its own
search engine ...
String indexDirectory = this.options.get(Option.QUERY_INDEX_DIRECTORY);
boolean updateIndexesSynchronously =
Boolean.valueOf(this.options.get(Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY));
- // At this point in time, we cannot query the federated connector ...
- String sourceToQuery = this.sourceName;
- // But we need to observe the federated source (if there is one) ...
- final String sourceToObserve = federatedSource != null ?
federatedSource.getName() : this.sourceName;
- // We actually want to use the federated source to crawl and watch for
changes ...
- this.queryManager = new
RepositoryQueryManager.SelfContained(executionContext, sourceToQuery, sourceToObserve,
-
connectionFactoryWithSystem, repositoryObservable,
+ this.queryManager = new
RepositoryQueryManager.SelfContained(executionContext, this.sourceName,
+
connectionFactory, repositoryObservable,
indexDirectory, updateIndexesSynchronously);
}
} else {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/NodeTypeSchemata.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/NodeTypeSchemata.java 2009-12-18
01:53:09 UTC (rev 1453)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/NodeTypeSchemata.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -33,6 +33,8 @@
import javax.jcr.nodetype.PropertyDefinition;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.NotThreadSafe;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.NameFactory;
@@ -44,6 +46,8 @@
import org.jboss.dna.graph.query.model.TypeSystem;
import org.jboss.dna.graph.query.validate.ImmutableSchemata;
import org.jboss.dna.graph.query.validate.Schemata;
+import org.jboss.dna.search.lucene.IndexRules;
+import org.jboss.dna.search.lucene.LuceneSearchEngine;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
@@ -62,6 +66,7 @@
private final Iterable<JcrPropertyDefinition> propertyDefinitions;
private final Map<Name, JcrNodeType> nodeTypesByName;
private final Multimap<JcrNodeType, JcrNodeType> subtypesByName =
LinkedHashMultimap.create();
+ private final IndexRules indexRules;
NodeTypeSchemata( ExecutionContext context,
Map<Name, JcrNodeType> nodeTypes,
@@ -71,6 +76,11 @@
this.propertyDefinitions = propertyDefinitions;
this.nodeTypesByName = nodeTypes;
+ // Register all the namespace prefixes by URIs ...
+ for (Namespace namespace : context.getNamespaceRegistry().getNamespaces()) {
+ this.prefixesByUris.put(namespace.getNamespaceUri(), namespace.getPrefix());
+ }
+
// Identify the subtypes for each node type, and do this before we build any
views ...
for (JcrNodeType nodeType : nodeTypesByName.values()) {
// For each of the supertypes ...
@@ -92,7 +102,8 @@
}
// Create the "ALLNODES" table, which will contain all possible
properties ...
- addAllNodesTable(builder, context);
+ IndexRules.Builder indexRulesBuilder =
IndexRules.createBuilder(LuceneSearchEngine.DEFAULT_RULES);
+ addAllNodesTable(builder, indexRulesBuilder, context);
// Define a view for each node type ...
for (JcrNodeType nodeType : nodeTypesByName.values()) {
@@ -100,19 +111,24 @@
}
schemata = builder.build();
+ indexRules = indexRulesBuilder.build();
}
+ /**
+ * Get the index rules ...
+ *
+ * @return indexRules
+ */
+ public IndexRules getIndexRules() {
+ return indexRules;
+ }
+
protected JcrNodeType getNodeType( Name nodeTypeName ) {
return nodeTypesByName.get(nodeTypeName);
}
- private void recordName( NamespaceRegistry registry,
- Name name ) {
- String uri = name.getNamespaceUri();
- prefixesByUris.put(uri, registry.getPrefixForNamespaceUri(uri, false));
- }
-
protected final void addAllNodesTable( ImmutableSchemata.Builder builder,
+ IndexRules.Builder indexRuleBuilder,
ExecutionContext context ) {
NamespaceRegistry registry = context.getNamespaceRegistry();
TypeSystem typeSystem = context.getValueFactories().getTypeSystem();
@@ -123,9 +139,8 @@
Set<String> fullTextSearchableNames = new HashSet<String>();
for (JcrPropertyDefinition defn : propertyDefinitions) {
if (defn.isResidual()) continue;
- if (defn.isMultiple()) continue;
+ // if (defn.isMultiple()) continue;
Name name = defn.getInternalName();
- recordName(registry, name);
String columnName = name.getString(registry);
if (first) {
builder.addTable(tableName, columnName);
@@ -145,9 +160,53 @@
if (fullTextSearchable) fullTextSearchableNames.add(columnName);
// Add (or overwrite) the column ...
builder.addColumn(tableName, columnName, type, fullTextSearchable);
+
+ // And build an indexing rule for this type ...
+ if (indexRuleBuilder != null) addIndexRule(indexRuleBuilder, defn, type,
typeSystem);
}
}
+ /**
+ * Add an index rule for the given property definition and the type in the {@link
TypeSystem}.
+ *
+ * @param builder the index rule builder; never null
+ * @param defn the property definition; never null
+ * @param type the TypeSystem type, which may be a more general type than dictated by
the definition, since multiple
+ * definitions with the same name require the index rule to use the common
base type; never null
+ * @param typeSystem the type system; never null
+ */
+ protected final void addIndexRule( IndexRules.Builder builder,
+ JcrPropertyDefinition defn,
+ String type,
+ TypeSystem typeSystem ) {
+ Store store = Store.YES;
+ Index index = defn.isFullTextSearchable() ? Index.ANALYZED : Index.NO;
+ if (typeSystem.getStringFactory().getTypeName().equals(type)) {
+ builder.stringField(defn.getInternalName(), store, index);
+ } else if (typeSystem.getDateTimeFactory().getTypeName().equals(type)) {
+ Long minimum = typeSystem.getLongFactory().create(defn.getMinimumValue());
+ Long maximum = typeSystem.getLongFactory().create(defn.getMaximumValue());
+ builder.dateField(defn.getInternalName(), store, index, minimum, maximum);
+ } else if (typeSystem.getLongFactory().getTypeName().equals(type)) {
+ Long minimum = typeSystem.getLongFactory().create(defn.getMinimumValue());
+ Long maximum = typeSystem.getLongFactory().create(defn.getMaximumValue());
+ builder.longField(defn.getInternalName(), store, index, minimum, maximum);
+ } else if (typeSystem.getDoubleFactory().getTypeName().equals(type)) {
+ Double minimum =
typeSystem.getDoubleFactory().create(defn.getMinimumValue());
+ Double maximum =
typeSystem.getDoubleFactory().create(defn.getMaximumValue());
+ builder.doubleField(defn.getInternalName(), store, index, minimum, maximum);
+ } else if (typeSystem.getBooleanFactory().getTypeName().equals(type)) {
+ builder.booleanField(defn.getInternalName(), store, index);
+ } else if (typeSystem.getBinaryFactory().getTypeName().equals(type)) {
+ store = Store.NO;
+ builder.binaryField(defn.getInternalName(), store, index);
+ } else {
+ // Everything else gets stored as a string ...
+ builder.stringField(defn.getInternalName(), store, index);
+ }
+
+ }
+
protected final void addView( ImmutableSchemata.Builder builder,
ExecutionContext context,
JcrNodeType nodeType ) {
@@ -171,49 +230,68 @@
if (defn.isResidual()) continue;
if (defn.isMultiple()) continue;
Name name = defn.getInternalName();
- recordName(registry, name);
String columnName = name.getString(registry);
if (first) first = false;
else viewDefinition.append(',');
viewDefinition.append('[').append(columnName).append(']');
}
- viewDefinition.append(" FROM
").append(AllNodes.ALL_NODES_NAME).append(" WHERE ");
+ viewDefinition.append(" FROM ").append(AllNodes.ALL_NODES_NAME);
- Collection<JcrNodeType> typeAndSubtypes = subtypesByName.get(nodeType);
- if (nodeType.isMixin()) {
- // Build the list of mixin types ...
- StringBuilder mixinTypes = null;
- for (JcrNodeType thisOrSupertype : typeAndSubtypes) {
- if (!thisOrSupertype.isMixin()) continue;
- if (mixinTypes == null) {
- mixinTypes = new StringBuilder();
-
mixinTypes.append('[').append(JcrLexicon.MIXIN_TYPES.getString(registry)).append("]
IN (");
+ // The 'nt:base' node type will have every single object in it, so we
don't need to add the type criteria ...
+ if (!JcrNtLexicon.BASE.equals(nodeType.getInternalName())) {
+ // The node type is not 'nt:base', which
+ viewDefinition.append(" WHERE ");
+
+ Collection<JcrNodeType> typeAndSubtypes =
subtypesByName.get(nodeType);
+ if (nodeType.isMixin()) {
+ // Build the list of mixin types ...
+ StringBuilder mixinTypes = null;
+ int count = 0;
+ for (JcrNodeType thisOrSupertype : typeAndSubtypes) {
+ if (!thisOrSupertype.isMixin()) continue;
+ if (mixinTypes == null) {
+ mixinTypes = new StringBuilder();
+ } else {
+ mixinTypes.append(',');
+ }
+ assert
prefixesByUris.containsKey(thisOrSupertype.getInternalName().getNamespaceUri());
+ String name = thisOrSupertype.getInternalName().getString(registry);
+ mixinTypes.append('[').append(name).append(']');
+ ++count;
+ }
+ assert mixinTypes != null; // should at least include itself
+ assert count > 0;
+
viewDefinition.append('[').append(JcrLexicon.MIXIN_TYPES.getString(registry)).append(']');
+ if (count == 1) {
+ viewDefinition.append('=').append(mixinTypes);
} else {
- mixinTypes.append(',');
+ viewDefinition.append(" IN
(").append(mixinTypes).append(')');
}
- assert
prefixesByUris.containsKey(thisOrSupertype.getInternalName().getNamespaceUri());
- String name = thisOrSupertype.getInternalName().getString(registry);
- mixinTypes.append(name);
- }
- assert mixinTypes != null; // should at least include itself
- viewDefinition.append(mixinTypes);
- } else {
- // Build the list of node type names ...
- StringBuilder primaryTypes = null;
- for (JcrNodeType thisOrSupertype : typeAndSubtypes) {
- if (thisOrSupertype.isMixin()) continue;
- if (primaryTypes == null) {
- primaryTypes = new StringBuilder();
-
primaryTypes.append('[').append(JcrLexicon.PRIMARY_TYPE.getString(registry)).append("]
IN (");
+ } else {
+ // Build the list of node type names ...
+ StringBuilder primaryTypes = null;
+ int count = 0;
+ for (JcrNodeType thisOrSupertype : typeAndSubtypes) {
+ if (thisOrSupertype.isMixin()) continue;
+ if (primaryTypes == null) {
+ primaryTypes = new StringBuilder();
+ } else {
+ primaryTypes.append(',');
+ }
+ assert
prefixesByUris.containsKey(thisOrSupertype.getInternalName().getNamespaceUri());
+ String name = thisOrSupertype.getInternalName().getString(registry);
+ primaryTypes.append('[').append(name).append(']');
+ ++count;
+ }
+ assert primaryTypes != null; // should at least include itself
+ assert count > 0;
+
viewDefinition.append('[').append(JcrLexicon.PRIMARY_TYPE.getString(registry)).append(']');
+ if (count == 1) {
+ viewDefinition.append('=').append(primaryTypes);
} else {
- primaryTypes.append(',');
+ viewDefinition.append(" IN
(").append(primaryTypes).append(')');
}
- assert
prefixesByUris.containsKey(thisOrSupertype.getInternalName().getNamespaceUri());
- String name = thisOrSupertype.getInternalName().getString(registry);
- primaryTypes.append(name);
}
- assert primaryTypes != null; // should at least include itself
- viewDefinition.append(primaryTypes);
}
// Define the view ...
@@ -298,7 +376,7 @@
this.nameFactory = context.getValueFactories().getNameFactory();
this.builder =
ImmutableSchemata.createBuilder(context.getValueFactories().getTypeSystem());
// Add the "AllNodes" table ...
- addAllNodesTable(builder, context);
+ addAllNodesTable(builder, null, context);
this.schemata = builder.build();
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java 2009-12-18
01:53:09 UTC (rev 1453)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java 2009-12-18
01:53:48 UTC (rev 1454)
@@ -141,7 +141,6 @@
SelfContained( ExecutionContext context,
String nameOfSourceToBeSearchable,
- final String observableSource,
RepositoryConnectionFactory connectionFactory,
Observable observable,
String indexDirectory,
@@ -190,15 +189,17 @@
// Set up the search engine ...
org.apache.lucene.analysis.Analyzer analyzer = null;
- searchEngine = new LuceneSearchEngine(nameOfSourceToBeSearchable,
connectionFactory, true, configuration, indexRules,
- analyzer);
+ boolean verifyWorkspaces = false;
+ searchEngine = new LuceneSearchEngine(nameOfSourceToBeSearchable,
connectionFactory, verifyWorkspaces, configuration,
+ indexRules, analyzer);
// Set up an original source observer to keep the index up to date ...
if (updateIndexesSynchronously) {
this.service = null;
this.searchObserver = new Observer() {
+ @SuppressWarnings( "synthetic-access" )
public void notify( Changes changes ) {
- if (changes.getSourceName().equals(observableSource)) {
+ if (changes.getSourceName().equals(sourceName)) {
process(changes);
}
}
@@ -209,7 +210,7 @@
this.searchObserver = new Observer() {
@SuppressWarnings( "synthetic-access" )
public void notify( final Changes changes ) {
- if (changes.getSourceName().equals(observableSource)) {
+ if (changes.getSourceName().equals(sourceName)) {
service.submit(new Runnable() {
public void run() {
process(changes);
@@ -249,7 +250,6 @@
protected void process( Changes changes ) {
try {
- Logger.getLogger(getClass()).warn(JcrI18n.errorUpdatingQueryIndexes,
"JUST KIDDING");
searchEngine.index(context, changes.getChangeRequests());
} catch (RuntimeException e) {
Logger.getLogger(getClass()).error(e, JcrI18n.errorUpdatingQueryIndexes,
e.getLocalizedMessage());