Author: rhauch
Date: 2009-11-16 18:23:02 -0500 (Mon, 16 Nov 2009)
New Revision: 1318
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/QueryEngine.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/Queryable.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/Schemata.java
trunk/dna-search/src/main/java/org/jboss/dna/search/IndexContext.java
trunk/dna-search/src/main/java/org/jboss/dna/search/IndexingStrategy.java
trunk/dna-search/src/main/java/org/jboss/dna/search/LuceneQueryEngine.java
trunk/dna-search/src/main/java/org/jboss/dna/search/SearchEngine.java
trunk/dna-search/src/main/java/org/jboss/dna/search/StoreLittleIndexingStrategy.java
trunk/dna-search/src/main/java/org/jboss/dna/search/WorkspaceSearchEngine.java
trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java
trunk/dna-search/src/test/java/org/jboss/dna/search/WorkspaceSearchEngineTest.java
Log:
DNA-467 Changed how the Queryable and QueryEngine use Schemata. Before, the schemata
instance was passed into the engine, and used for all queries. But this meant that the
schemata instance could change the Table objects it returns. This would be more difficult
to implement than if a different Schemata were passed with each query, since that Schemata
instance can be a reflection of the tables at the time the query is implemented. And,
Schemata can then be made to be immutable, not only simplifying the implementation but
also ensuring that the schema information doesn't change during the processing of a
query.
So, the Queryable and QueryEngine were changed to always pass a Schemata in with each
QueryCommand. This rippled down to the SearchEngine, but this also cleaned things up a
bit there, too.
It also allows different Schemata instances to be used for different languages (if that
would ever make sense).
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/QueryEngine.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/QueryEngine.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/QueryEngine.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -54,10 +54,20 @@
@ThreadSafe
public class QueryEngine implements Queryable {
+ /**
+ * A {@link Schemata} implementation that always returns null, meaning the table does
not exist.
+ */
+ private static final Schemata DEFAULT_SCHEMATA = new Schemata() {
+ public Table getTable( SelectorName name ) {
+ // This won't allow the query engine to do anything (or much of
anything),
+ // but it is legal and will result in meaningful problems
+ return null;
+ }
+ };
+
private final Planner planner;
private final Optimizer optimizer;
private final Processor processor;
- private final Schemata schemata;
/**
* Create a new query engine given the {@link Planner planner}, {@link Optimizer
optimizer}, {@link Processor processor}, and
@@ -68,49 +78,43 @@
* @param optimizer the optimizer that should be used to optimize the canonical query
plan; may be null if the
* {@link RuleBasedOptimizer} should be used
* @param processor the processor implementation that should be used to process the
planned query and return the results
- * @param schemata the schemata implementation, or null if an empty schema should be
used (resulting in errors when named
- * tables are queried)
* @throws IllegalArgumentException if the processor reference is null
*/
public QueryEngine( Planner planner,
Optimizer optimizer,
- Processor processor,
- Schemata schemata ) {
+ Processor processor ) {
CheckArg.isNotNull(processor, "processor");
this.planner = planner != null ? planner : new CanonicalPlanner();
this.optimizer = optimizer != null ? optimizer : new RuleBasedOptimizer();
this.processor = processor;
- this.schemata = schemata != null ? schemata : new Schemata() {
- public Table getTable( SelectorName name ) {
- // This won't allow the query engine to do anything (or much of
anything),
- // but it is legal and will result in meaningful problems
- return null;
- }
- };
}
/**
* {@inheritDoc}
*
* @see
org.jboss.dna.graph.query.Queryable#execute(org.jboss.dna.graph.ExecutionContext,
- * org.jboss.dna.graph.query.model.QueryCommand)
+ * org.jboss.dna.graph.query.model.QueryCommand,
org.jboss.dna.graph.query.validate.Schemata)
*/
public QueryResults execute( ExecutionContext context,
- QueryCommand query ) {
- return execute(context, query, new PlanHints());
+ QueryCommand query,
+ Schemata schemata ) {
+ return execute(context, query, schemata, new PlanHints());
}
/**
* {@inheritDoc}
*
* @see
org.jboss.dna.graph.query.Queryable#execute(org.jboss.dna.graph.ExecutionContext,
- * org.jboss.dna.graph.query.model.QueryCommand,
org.jboss.dna.graph.query.plan.PlanHints)
+ * org.jboss.dna.graph.query.model.QueryCommand,
org.jboss.dna.graph.query.validate.Schemata,
+ * org.jboss.dna.graph.query.plan.PlanHints)
*/
public QueryResults execute( ExecutionContext context,
QueryCommand query,
+ Schemata schemata,
PlanHints hints ) {
CheckArg.isNotNull(context, "context");
CheckArg.isNotNull(query, "query");
+ if (schemata == null) schemata = DEFAULT_SCHEMATA;
QueryContext queryContext = new QueryContext(context, hints, schemata);
// Create the canonical plan ...
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/Queryable.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/Queryable.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/Queryable.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -26,6 +26,7 @@
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.query.model.QueryCommand;
import org.jboss.dna.graph.query.plan.PlanHints;
+import org.jboss.dna.graph.query.validate.Schemata;
/**
* An interface defining the ability to submit a query and obtain results.
@@ -37,22 +38,26 @@
*
* @param context the context in which the query should be executed
* @param query the query that is to be executed
+ * @param schemata the schemata that should be used to validate the query
* @return the query results; never null
* @throws IllegalArgumentException if the context or query references are null
*/
QueryResults execute( ExecutionContext context,
- QueryCommand query );
+ QueryCommand query,
+ Schemata schemata );
/**
* Execute the supplied query by planning, optimizing, and then processing it.
*
* @param context the context in which the query should be executed
* @param query the query that is to be executed
+ * @param schemata the schemata that should be used to validate the query
* @param hints the hints for the execution; may be null if there are no hints
* @return the query results; never null
* @throws IllegalArgumentException if the context or query references are null
*/
QueryResults execute( ExecutionContext context,
QueryCommand query,
+ Schemata schemata,
PlanHints hints );
}
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/Schemata.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/Schemata.java 2009-11-09
19:29:50 UTC (rev 1317)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/validate/Schemata.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import net.jcip.annotations.Immutable;
import org.jboss.dna.graph.property.PropertyType;
import org.jboss.dna.graph.query.model.QueryCommand;
import org.jboss.dna.graph.query.model.SelectorName;
@@ -34,13 +35,13 @@
/**
* The interface used to access the structure being queried and validate a query.
*/
+@Immutable
public interface Schemata {
/**
* Get the information for the table or view with the supplied name within this
schema.
* <p>
- * The resulting definition is immutable, though subsequent calls to this method with
the same argument may result in a
- * different definition.
+ * The resulting definition is immutable.
* </p>
*
* @param name the table or view name; may not be null
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/IndexContext.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/IndexContext.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/IndexContext.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -40,7 +40,7 @@
* A set of index readers and writers.
*/
@NotThreadSafe
-final class IndexContext {
+public final class IndexContext {
private final ExecutionContext context;
private final Directory pathsIndexDirectory;
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/IndexingStrategy.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/IndexingStrategy.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/IndexingStrategy.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -34,12 +34,13 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.query.QueryResults;
import org.jboss.dna.graph.query.model.QueryCommand;
+import org.jboss.dna.graph.query.validate.Schemata;
import org.jboss.dna.graph.request.ChangeRequest;
/**
* Interface defining the behaviors associated with indexing graph content.
*/
-interface IndexingStrategy {
+public interface IndexingStrategy {
int getChangeCountForAutomaticOptimization();
@@ -108,14 +109,18 @@
List<Location> results ) throws IOException,
ParseException;
/**
- * Perform a query of the content.
+ * Perform a query of the content. The {@link QueryCommand query} is supplied in the
form of the Abstract Query Model, with
+ * the {@link Schemata} that defines the tables and views that are available to the
query, and the set of index readers (and
+ * writers) that should be used.
*
* @param query the query; never null
+ * @param schemata the definition of the tables used in the query; never null
* @param indexes the set of index readers and writers; never null
* @return the results of the query
* @throws IOException if there is a problem indexing or using the writers
* @throws ParseException if there is a problem parsing the query
*/
QueryResults performQuery( QueryCommand query,
+ Schemata schemata,
IndexContext indexes ) throws IOException,
ParseException;
}
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/LuceneQueryEngine.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/LuceneQueryEngine.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/LuceneQueryEngine.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -49,14 +49,15 @@
private QueryEngine engine;
- public LuceneQueryEngine( Schemata schemata ) {
- engine = new QueryEngine(new CanonicalPlanner(), new LuceneOptimizer(), new
LuceneProcessor(), schemata);
+ public LuceneQueryEngine() {
+ engine = new QueryEngine(new CanonicalPlanner(), new LuceneOptimizer(), new
LuceneProcessor());
}
/**
* Execute the supplied query by planning, optimizing, and then processing it.
*
* @param query the query that is to be executed
+ * @param schemata the schemata that defines the tables used in the query
* @param indexes the indexes that should be used to execute the query; never null
* @return the query results; never null
* @throws IllegalArgumentException if the context or query references are null
@@ -64,8 +65,9 @@
* @throws ParseException if there is a problem parsing the query
*/
public QueryResults execute( QueryCommand query,
+ Schemata schemata,
IndexContext indexes ) throws IOException,
ParseException {
- return engine.execute(indexes.context(), query, new PlanHints());
+ return engine.execute(indexes.context(), query, schemata, new PlanHints());
}
/**
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/SearchEngine.java
===================================================================
--- trunk/dna-search/src/main/java/org/jboss/dna/search/SearchEngine.java 2009-11-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-search/src/main/java/org/jboss/dna/search/SearchEngine.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -45,6 +45,7 @@
import org.jboss.dna.graph.property.PathFactory;
import org.jboss.dna.graph.query.QueryResults;
import org.jboss.dna.graph.query.model.QueryCommand;
+import org.jboss.dna.graph.query.validate.Schemata;
import org.jboss.dna.graph.request.ChangeRequest;
import org.jboss.dna.graph.request.InvalidWorkspaceException;
@@ -293,13 +294,17 @@
*
* @param workspaceName the name of the workspace
* @param query the query that is to be executed, in the form of the Abstract Query
Model
+ * @param schemata the definition of the tables and views that can be used in the
query; may not be null
* @return the query results; never null
- * @throws IllegalArgumentException if the context or query references are null
+ * @throws IllegalArgumentException if the context, query, or schemata references are
null
*/
public QueryResults execute( String workspaceName,
- QueryCommand query ) {
+ QueryCommand query,
+ Schemata schemata ) {
CheckArg.isNotNull(workspaceName, "workspaceName");
- return getWorkspaceEngine(workspaceName).execute(query);
+ CheckArg.isNotNull(query, "query");
+ CheckArg.isNotNull(schemata, "schemata");
+ return getWorkspaceEngine(workspaceName).execute(query, schemata);
}
}
Modified:
trunk/dna-search/src/main/java/org/jboss/dna/search/StoreLittleIndexingStrategy.java
===================================================================
---
trunk/dna-search/src/main/java/org/jboss/dna/search/StoreLittleIndexingStrategy.java 2009-11-09
19:29:50 UTC (rev 1317)
+++
trunk/dna-search/src/main/java/org/jboss/dna/search/StoreLittleIndexingStrategy.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -124,22 +124,19 @@
* Create a new indexing strategy instance that does not support queries.
*/
public StoreLittleIndexingStrategy() {
- this(null, null);
+ this(null);
}
/**
* Create a new indexing strategy instance.
*
- * @param schemata the schemata that defines the structure that can be queried; may
be null if queries are not going to be
- * used
* @param rules the indexing rules that govern how properties are to be index, or
null if the {@link #DEFAULT_RULES default
* rules} are to be used
*/
- public StoreLittleIndexingStrategy( Schemata schemata,
- IndexingRules rules ) {
+ public StoreLittleIndexingStrategy( IndexingRules rules ) {
this.rules = rules != null ? rules : DEFAULT_RULES;
this.logger = Logger.getLogger(getClass());
- this.queryEngine = new LuceneQueryEngine(schemata);
+ this.queryEngine = new LuceneQueryEngine();
}
/**
@@ -351,11 +348,13 @@
/**
* {@inheritDoc}
*
- * @see org.jboss.dna.search.IndexingStrategy#performQuery(QueryCommand,
IndexContext)
+ * @see
org.jboss.dna.search.IndexingStrategy#performQuery(org.jboss.dna.graph.query.model.QueryCommand,
+ * org.jboss.dna.graph.query.validate.Schemata,
org.jboss.dna.search.IndexContext)
*/
public QueryResults performQuery( QueryCommand query,
+ Schemata schemata,
IndexContext indexes ) throws IOException,
ParseException {
- return this.queryEngine.execute(query, indexes);
+ return this.queryEngine.execute(query, schemata, indexes);
}
/**
Modified: trunk/dna-search/src/main/java/org/jboss/dna/search/WorkspaceSearchEngine.java
===================================================================
---
trunk/dna-search/src/main/java/org/jboss/dna/search/WorkspaceSearchEngine.java 2009-11-09
19:29:50 UTC (rev 1317)
+++
trunk/dna-search/src/main/java/org/jboss/dna/search/WorkspaceSearchEngine.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -48,6 +48,7 @@
import org.jboss.dna.graph.property.Path;
import org.jboss.dna.graph.query.QueryResults;
import org.jboss.dna.graph.query.model.QueryCommand;
+import org.jboss.dna.graph.query.validate.Schemata;
import org.jboss.dna.graph.request.ChangeRequest;
/**
@@ -252,11 +253,13 @@
* representation of the query.
*
* @param query the query that is to be executed, in the form of the Abstract Query
Model
+ * @param schemata the definition of the tables available for the query; may not be
null
* @return the query results; never null
* @throws IllegalArgumentException if the context or query references are null
*/
- public QueryResults execute( QueryCommand query ) {
- return execute(false, queryContent(query)).getResults();
+ public QueryResults execute( QueryCommand query,
+ Schemata schemata ) {
+ return execute(false, queryContent(query, schemata)).getResults();
}
/**
@@ -540,14 +543,16 @@
* Create an activity that will perform a query against the index.
*
* @param query the query to be performed; may not be null
+ * @param schemata the definition of the tables being used in the query; may not be
null
* @return the activity that will perform the work
*/
- protected Query queryContent( final QueryCommand query ) {
+ protected Query queryContent( final QueryCommand query,
+ final Schemata schemata ) {
return new Query() {
private QueryResults results = null;
public void execute( IndexContext indexes ) throws IOException,
ParseException {
- results = strategy().performQuery(query, indexes);
+ results = strategy().performQuery(query, schemata, indexes);
}
public String messageFor( Throwable error ) {
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-09
19:29:50 UTC (rev 1317)
+++ trunk/dna-search/src/test/java/org/jboss/dna/search/SearchEngineTest.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -27,7 +27,6 @@
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.connector.RepositoryConnection;
@@ -35,7 +34,6 @@
import org.jboss.dna.graph.connector.RepositorySourceException;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.query.validate.Schemata;
import org.jboss.dna.graph.request.InvalidWorkspaceException;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +49,6 @@
private RepositoryConnectionFactory connectionFactory;
private DirectoryConfiguration directoryFactory;
private IndexingStrategy indexingStrategy;
- private Schemata schemata;
private Graph content;
@Before
@@ -84,14 +81,11 @@
}
};
- // Set up the schemata for the queries ...
- schemata = mock(Schemata.class);
-
// Set up the indexing strategy ...
IndexingRules rules =
IndexingRules.createBuilder(StoreLittleIndexingStrategy.DEFAULT_RULES)
.defaultTo(IndexingRules.INDEX |
IndexingRules.ANALYZE | IndexingRules.FULL_TEXT)
.build();
- indexingStrategy = new StoreLittleIndexingStrategy(schemata, rules);
+ indexingStrategy = new StoreLittleIndexingStrategy(rules);
// Now set up the search engine ...
directoryFactory = DirectoryConfigurations.inMemory();
Modified:
trunk/dna-search/src/test/java/org/jboss/dna/search/WorkspaceSearchEngineTest.java
===================================================================
---
trunk/dna-search/src/test/java/org/jboss/dna/search/WorkspaceSearchEngineTest.java 2009-11-09
19:29:50 UTC (rev 1317)
+++
trunk/dna-search/src/test/java/org/jboss/dna/search/WorkspaceSearchEngineTest.java 2009-11-16
23:23:02 UTC (rev 1318)
@@ -26,7 +26,6 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
import java.util.List;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
@@ -36,7 +35,6 @@
import org.jboss.dna.graph.connector.RepositorySourceException;
import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.query.validate.Schemata;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +49,6 @@
private DirectoryConfiguration directoryFactory;
private IndexingStrategy indexingStrategy;
private Graph content;
- private Schemata schemata;
@Before
public void beforeEach() throws Exception {
@@ -76,14 +73,11 @@
}
};
- // Set up the schemata for the queries ...
- schemata = mock(Schemata.class);
-
// Set up the indexing strategy ...
IndexingRules rules =
IndexingRules.createBuilder(StoreLittleIndexingStrategy.DEFAULT_RULES)
.defaultTo(IndexingRules.INDEX |
IndexingRules.ANALYZE | IndexingRules.FULL_TEXT)
.build();
- indexingStrategy = new StoreLittleIndexingStrategy(schemata, rules);
+ indexingStrategy = new StoreLittleIndexingStrategy(rules);
// Now set up the search engine ...
directoryFactory = DirectoryConfigurations.inMemory();