wam 2004/02/25 02:04:29
Modified: src/share/org/apache/slide/store AbstractStore.java
DefaultIndexer.java IndexStore.java
src/share/org/apache/slide/search/basic BasicQuery.java
BasicQueryImpl.java
Added: src/share/org/apache/slide/search Indexer.java
IndexException.java
Log:
change the indexer interface:
createIndex
updateIndex
dropIndex
Revision Changes Path
1.39 +10 -10
jakarta-slide/src/share/org/apache/slide/store/AbstractStore.java
Index: AbstractStore.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/store/AbstractStore.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- AbstractStore.java 11 Feb 2004 11:30:18 -0000 1.38
+++ AbstractStore.java 25 Feb 2004 10:04:29 -0000 1.39
@@ -1127,7 +1127,7 @@
enlist(propertiesIndexer);
enlist(revisionDescriptorStore);
try {
- propertiesIndexer.index (uri, revisionDescriptor, null);
+ propertiesIndexer.createIndex (uri, revisionDescriptor, null);
revisionDescriptorStore.createRevisionDescriptor
(uri, revisionDescriptor);
@@ -1164,7 +1164,7 @@
enlist (propertiesIndexer);
enlist(revisionDescriptorStore);
try {
- propertiesIndexer.index (uri, revisionDescriptor, null);
+ propertiesIndexer.createIndex (uri, revisionDescriptor, null);
revisionDescriptorStore.storeRevisionDescriptor
(uri, revisionDescriptor);
@@ -1204,7 +1204,7 @@
enlist(revisionDescriptorStore);
try {
- propertiesIndexer.drop (uri, number);
+ propertiesIndexer.dropIndex (uri, number);
revisionDescriptorStore.removeRevisionDescriptor(uri, number);
} catch (ServiceAccessException e) {
delist(propertiesIndexer, false);
@@ -1292,7 +1292,7 @@
enlist(contentIndexer);
enlist(contentStore);
try {
- contentIndexer.index (uri, revisionDescriptor, null);
+ contentIndexer.createIndex (uri, revisionDescriptor, revisionContent);
contentStore.createRevisionContent(uri, revisionDescriptor,
revisionContent);
@@ -1332,7 +1332,7 @@
enlist (contentIndexer);
enlist(contentStore);
try {
- contentIndexer.index (uri, revisionDescriptor, null);
+ contentIndexer.updateIndex (uri, revisionDescriptor, revisionContent);
contentStore.storeRevisionContent(uri, revisionDescriptor,
revisionContent);
} catch (ServiceAccessException e) {
@@ -1371,7 +1371,7 @@
enlist(contentStore);
try {
- contentIndexer.drop (uri, revisionDescriptor.getRevisionNumber());
+ contentIndexer.dropIndex (uri, revisionDescriptor.getRevisionNumber());
contentStore.removeRevisionContent(uri, revisionDescriptor);
} catch (ServiceAccessException e) {
1.3 +33 -20
jakarta-slide/src/share/org/apache/slide/store/DefaultIndexer.java
Index: DefaultIndexer.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/store/DefaultIndexer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultIndexer.java 11 Feb 2004 15:03:39 -0000 1.2
+++ DefaultIndexer.java 25 Feb 2004 10:04:29 -0000 1.3
@@ -5,7 +5,7 @@
*
* ====================================================================
*
- * Copyright 1999 The Apache Software Foundation
+ * Copyright 1999 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.search.IndexException;
import org.apache.slide.search.basic.IBasicExpressionFactory;
import org.apache.slide.search.basic.IBasicExpressionFactoryProvider;
import org.apache.slide.store.IndexStore;
@@ -45,12 +46,11 @@
* which means, no search possible on store (unless generic search).
* Fakes two phase commit.
*
- * @author [EMAIL PROTECTED]
- *
* @version $Revision$
*/
public class DefaultIndexer extends AbstractService implements IndexStore
{
+
private IBasicExpressionFactory factory = null;
/**
@@ -84,34 +84,50 @@
* Index an object content. Do nothing.
*
* @param uri Uri
- * @exception ServiceAccessException Error accessing the Data Source
+ * @exception IndexException Error accessing the Data Source
*/
- public void index(Uri uri, NodeRevisionDescriptor revisionDescriptor,
- NodeRevisionContent revisionContent)
- throws ServiceAccessException
+ public void createIndex(Uri uri, NodeRevisionDescriptor revisionDescriptor,
+ NodeRevisionContent revisionContent)
+ throws IndexException
{
- // System.out.println("index " + uri);
+ // do nothing
}
/**
+ * updates an index for a resource
+ *
+ * @param uri uri of the resource
+ * @param number nodeRevisionNumber of the resource
+ * @param revisionContent the content of the resource
+ *
+ * @throws IndexException
+ *
+ */
+ public void updateIndex(Uri uri, NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent) throws IndexException
+ {
+ // do nothing
+ }
+
+
+ /**
* Drop an object revision from the index. Do nothing
*
* @param uri Uri
- * @exception ServiceAccessException Error accessing the Data Source
+ * @exception IndexException Error accessing the Data Source
*/
- public void drop(Uri uri, NodeRevisionNumber number) throws
ServiceAccessException
+ public void dropIndex(Uri uri, NodeRevisionNumber number)
+ throws IndexException
{
- //System.out.println("drop");
+ // do nothing
}
/**
* Connects to the underlying data source (if any is needed).
*
- * @exception ServiceConnectionFailedException Connection failed
+ * @exception ServiceConnectionFailedException Connection failed
*/
public void connect() throws ServiceConnectionFailedException
{
- // System.out.println("connect");
started = true;
}
@@ -123,8 +139,6 @@
*/
public boolean isConnected() throws ServiceAccessException
{
- // System.out.println("isConnected");
- // TODO
return started;
}
@@ -143,7 +157,7 @@
*/
public void setParameters(Hashtable parameters) throws
ServiceParameterErrorException, ServiceParameterMissingException
{
- // System.out.println("setParameters");
+ // do nothing
}
/**
@@ -153,7 +167,6 @@
*/
public void disconnect() throws ServiceDisconnectionFailedException
{
- // System.out.println("disconnect");
started = false;
}
@@ -164,7 +177,7 @@
*/
public void reset() throws ServiceResetFailedException
{
- //System.out.println("reset");
+ // do nothing
}
}
1.8 +13 -34 jakarta-slide/src/share/org/apache/slide/store/IndexStore.java
Index: IndexStore.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/store/IndexStore.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- IndexStore.java 11 Feb 2004 11:30:18 -0000 1.7
+++ IndexStore.java 25 Feb 2004 10:04:29 -0000 1.8
@@ -5,7 +5,7 @@
*
* ====================================================================
*
- * Copyright 1999-2004 The Apache Software Foundation
+ * Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,40 +28,19 @@
import org.apache.slide.common.Uri;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
-import org.apache.slide.search.basic.IBasicExpressionFactoryProvider;
import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.search.Indexer;
+import org.apache.slide.search.basic.IBasicExpressionFactoryProvider;
/**
- * Store for Index.
+ * Store for Index. Implement this interface, if you want to run the indexer
+ * in the store context with two phase commit.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @version $Revision$
*/
-public interface IndexStore extends Service, IBasicExpressionFactoryProvider {
-
-
-
- // ------------------------------------------------------ Interface Methods
- /**
- * Method drop
- *
- * @param uri an Uri
- * @param number a NodeRevisionNumber
- *
- */
- public void drop(Uri uri, NodeRevisionNumber number)
- throws ServiceAccessException;
-
-
-
- /**
- * Index an object content.
- *
- * @param uri Uri
- * @exception ServiceAccessException Error accessing the Data Source
- */
- void index(Uri uri, NodeRevisionDescriptor revisionDescriptor,
- NodeRevisionContent revisionContent)
- throws ServiceAccessException;
-
+public interface IndexStore extends Indexer,
+ IBasicExpressionFactoryProvider,
+ Service
+{
}
1.20 +83 -77
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java
Index: BasicQuery.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- BasicQuery.java 11 Feb 2004 11:30:16 -0000 1.19
+++ BasicQuery.java 25 Feb 2004 10:04:29 -0000 1.20
@@ -5,7 +5,7 @@
*
* ====================================================================
*
- * Copyright 1999-2002 The Apache Software Foundation
+ * Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,81 +51,83 @@
* @version $Revision$
*/
public abstract class BasicQuery extends SearchQuery implements IBasicQuery {
-
+
/**
* Message of a BadQueryException that is thrown if the query element
* is <code>null</code>.
*/
public static final String NO_QUERY_ELEMENT = "No query element";
-
+
/**
* The provider which delivers the expression compiler to use.
*/
protected IBasicExpressionCompilerProvider expressionCompilerProvider = null;
-
+
/**
* Message of a BadQueryException that is thrown if the query element
* does not contain a <select> element.
*/
public static final String SELECT_ELEMENT_MISSING = "Required element <select>
not supplied";
-
+
/**
* Message of a BadQueryException that is thrown if the query element
* does not contain a <from> element.
*/
public static final String FROM_ELEMENT_MISSING = "Required element <from> not
supplied";
-
+
/**
* Message of a BadQueryException that is thrown if the query element
* neither contains a <prop> nor a <allprop> element.
*/
public static final String PROP_OR_ALLPROP_ELEMENT_MISSING = "Required element
<prop> or <allprop> not supplied";
-
-
-
+
+ private IBasicExpressionFactory contentExpressionFactory;
+ private IBasicExpressionFactory propertiesExpressionFactory;
+
+
/** the element describing this query */
protected Element queryElement;
-
+
/** the namespace for this query */
protected Namespace namespace;
-
+
/** the scope of this query, <FROM> */
protected QueryScope queryScope;
-
+
/** the element describing the WHERE clauise */
protected Element whereElement;
-
+
/** List of requested properties, <SELECT> */
protected RequestedProperties requestedProperties;
-
+
/** <LIMIT> */
protected int limit;
-
+
/** ORDER BY */
protected OrderBy orderBy;
-
+
/** indicates, if a limit is defined */
protected boolean limitDefined = false;
-
+
/** The store for this query, may be used to access store parameters */
protected AbstractStore store;
-
+
/** the top level expression in the <WHERE> clause */
protected IBasicExpression rootExpression;
-
+
/** used to get the slidePath */
protected SlideUri slideUri;
-
+
/** The provider for the properties */
protected PropertyProvider propertyProvider;
-
-
+
+
protected BasicQuery () {}
-
+
protected BasicQuery (SearchToken searchToken) {
init(searchToken);
}
-
+
public void init (SearchToken token) {
this.searchToken = token;
slideUri = searchToken.getSlideContext();
@@ -142,7 +144,11 @@
*/
public IBasicExpressionFactory getContentExpressionFactory ()
{
- return store.getContentIndexer().getBasicExpressionFactory();
+ if (contentExpressionFactory == null)
+ contentExpressionFactory =
+ store.getContentIndexer().getBasicExpressionFactory();
+
+ return contentExpressionFactory;
}
@@ -155,13 +161,13 @@
*/
public IBasicExpressionFactory getPropertiesExpressionFactory ()
{
- IBasicExpressionFactory factory =
+ propertiesExpressionFactory =
store.getPropertiesIndexer().getBasicExpressionFactory();
- return store.getPropertiesIndexer().getBasicExpressionFactory();
+ return propertiesExpressionFactory;
}
-
+
/**
* Method getStore
*
@@ -171,7 +177,7 @@
public AbstractStore getStore () {
return store;
}
-
+
/**
* Method getSlidePath
*
@@ -183,7 +189,7 @@
public String getSlidePath () throws InvalidScopeException {
return slideUri.getSlidePath (queryScope.getHref());
}
-
+
/**
* Method getSearchToken
*
@@ -193,7 +199,7 @@
public SearchToken getSearchToken (){
return searchToken;
}
-
+
/**
* Method getPropertyProvider
*
@@ -203,7 +209,7 @@
public PropertyProvider getPropertyProvider () {
return propertyProvider;
}
-
+
/**
* Builds the internal structure from the JDOM tree. Concrete implementations
* may use parseQueryElementWithoutExpression to create most of the
@@ -216,20 +222,20 @@
* @throws BadQueryException
*/
public void parseQueryElement (Element basicSearchElement, PropertyProvider
propertyProvider) throws BadQueryException {
-
+
queryScope = getScope(basicSearchElement);
this.propertyProvider = propertyProvider;
-
+
// might be null in testsuite
if (searchToken.getNamespace() != null) {
-// Uri uri = new Uri (searchToken.getNamespace(),
slideUri.getSlidePath(queryScope.getHref()));
+ // Uri uri = new Uri (searchToken.getNamespace(),
slideUri.getSlidePath(queryScope.getHref()));
Uri uri =
searchToken.getNamespace().getUri(this.getSearchToken().getSlideToken(),
slideUri.getSlidePath(queryScope.getHref()));
store = (AbstractStore)uri.getStore();
}
-
+
parseQuery(basicSearchElement, propertyProvider);
}
-
+
/**
* builds the internal structure from the JDOM tree. Concrete implementations
* may use [EMAIL PROTECTED] #parseQueryWithoutExpression
parseQueryWithoutExpression}
@@ -243,7 +249,7 @@
*/
public abstract void parseQuery (Element basicSearchElement, PropertyProvider
propertyProvider)
throws BadQueryException;
-
+
/**
* Executes a request. A store specific implementation should overwrite
* this to optimize the execution.
@@ -254,7 +260,7 @@
*
*/
public abstract SearchQueryResult execute () throws ServiceAccessException;
-
+
/**
* builds the internal structure from the JDOM tree. It may be used by the
* concrete implementation of BasicQuery. It does NOT create the tree of
@@ -265,65 +271,65 @@
* @throws BadQueryException
*/
protected void parseQueryWithoutExpression (Element basicSearchElement) throws
BadQueryException {
-
+
if (basicSearchElement == null)
throw new BadQueryException (NO_QUERY_ELEMENT);
-
+
namespace = basicSearchElement.getNamespace();
-
+
Element selectElement = basicSearchElement.getChild
(Literals.SELECT, namespace);
-
+
// SELECT is mandatory
if (selectElement == null)
throw new BadQueryException (SELECT_ELEMENT_MISSING);
-
+
Element fromElement = basicSearchElement.getChild
(Literals.FROM, namespace);
-
+
// FROM is mandatory
if (fromElement == null) {
throw new BadQueryException (FROM_ELEMENT_MISSING);
}
-
+
whereElement = basicSearchElement.getChild
(Literals.WHERE, namespace);
-
+
Element orderByElement = basicSearchElement.getChild
(Literals.ORDERBY, namespace);
-
+
Element limitElement = basicSearchElement.getChild
(Literals.LIMIT, namespace);
-
+
Element propElement = selectElement.getChild (Literals.PROP, namespace);
if (propElement == null) {
propElement = selectElement.getChild (Literals.ALLPROP, namespace);
}
-
+
if (propElement == null) {
throw new BadQueryException(PROP_OR_ALLPROP_ELEMENT_MISSING);
}
-
+
try {
requestedProperties = new RequestedPropertiesImpl (propElement);
}
catch (PropertyParseException e) {
throw new BadQueryException(e.getMessage(), e);
}
-
+
queryScope = new BasicQueryScope (fromElement);
-
+
if (orderByElement != null) {
orderBy = new OrderBy ();
orderBy.init (orderByElement);
}
-
+
if (limitElement != null) {
limit = new Integer (limitElement.getTextTrim()).intValue();
limitDefined = true;
}
}
-
+
/**
* QueryScope accessor
*
@@ -333,7 +339,7 @@
public QueryScope getScope () {
return queryScope;
}
-
+
/**
* Method getSelectedProperties
*
@@ -342,7 +348,7 @@
public RequestedProperties requestedProperties () {
return requestedProperties;
}
-
+
/**
* Method getExpression
*
@@ -352,8 +358,8 @@
public IBasicExpression getExpression () {
return rootExpression;
}
-
-
+
+
/**
* Method isLimitDefined
*
@@ -362,7 +368,7 @@
public boolean isLimitDefined () {
return limitDefined;
}
-
+
/**
* Method getLimit
*
@@ -371,7 +377,7 @@
public int getLimit () {
return limit;
}
-
+
/**
* Method setScope
*
@@ -381,7 +387,7 @@
public void setScope (QueryScope queryScope) {
this.queryScope = queryScope;
}
-
+
/**
* Method getOrderBy
*
@@ -391,8 +397,8 @@
public OrderBy getOrderBy () {
return orderBy;
}
-
-
+
+
/**
* For debugging purpose.
*
@@ -400,14 +406,14 @@
*
*/
public String toString () {
-
+
String result =
"SELECT [" + requestedProperties + "] FROM [" + queryScope + "] "
+ "WHERE [" + rootExpression + "]";
-
+
return result;
}
-
+
/**
* Needed to decide, which implementation of BasicQuery to load
*
@@ -423,18 +429,18 @@
{
if (basicSearchElementJDOM == null)
throw new BadQueryException (NO_QUERY_ELEMENT);
-
+
Namespace namespace = basicSearchElementJDOM.getNamespace();
Element fromElement = basicSearchElementJDOM.getChild
(Literals.FROM, namespace);
-
+
// FROM is mandatory
if (fromElement == null)
throw new BadQueryException (FROM_ELEMENT_MISSING);
-
+
return new BasicQueryScope (fromElement);
}
-
+
/**
* This IBasicExpressionCompilerProvider implementation returns a
* BasicQueryCompiler instance in method getCompiler().
@@ -444,7 +450,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Ralf Stuckert</a>
**/
public static class ExpressionCompilerProvider implements
IBasicExpressionCompilerProvider {
-
+
/**
* Returns an IBasicExpressionCompiler for the given parameters.
*
1.13 +5 -5
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryImpl.java
Index: BasicQueryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- BasicQueryImpl.java 11 Feb 2004 11:30:16 -0000 1.12
+++ BasicQueryImpl.java 25 Feb 2004 10:04:29 -0000 1.13
@@ -86,7 +86,7 @@
/** the NotNormalizer, may be overridden in extending classes */
protected NotNormalizer notNormalizer;
- IBasicExpressionFactory defaultExpressionFactory = new BasicExpressionFactory
();
+// IBasicExpressionFactory defaultExpressionFactory = new BasicExpressionFactory
();
/**
* Creates a BasicQueryImpl.
1.1 jakarta-slide/src/share/org/apache/slide/search/Indexer.java
Index: Indexer.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/Indexer.java,v
1.1 2004/02/25 10:04:29 wam Exp $
* $Revision: 1.1 $
* $Date: 2004/02/25 10:04:29 $
*
* ====================================================================
*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.search;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.Uri;
import org.apache.slide.content.NodeRevisionContent;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionNumber;
/**
* An Indexer may create an index on a resource, update it or delete it.
*
* @version $Revision: 1.1 $
*/
public interface Indexer
{
/**
* Drops the index of the specified resource
*
* @param uri uri of the resource
* @param number nodeRevisionNumber of the resource
*
* @throws IndexException
*
*/
public void dropIndex (Uri uri, NodeRevisionNumber number)
throws IndexException;
/**
* creates an index for a resource
*
* @param uri uri of the resource
* @param number nodeRevisionNumber of the resource
* @param revisionContent the content of the resource
*
* @throws IndexException
*
*/
void createIndex (Uri uri, NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws IndexException;
/**
* updates an index for a resource
*
* @param uri uri of the resource
* @param number nodeRevisionNumber of the resource
* @param revisionContent the content of the resource
*
* @throws IndexException
*
*/
void updateIndex (Uri uri, NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws IndexException;
}
1.1
jakarta-slide/src/share/org/apache/slide/search/IndexException.java
Index: IndexException.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/IndexException.java,v 1.1
2004/02/25 10:04:29 wam Exp $
* $Revision: 1.1 $
* $Date: 2004/02/25 10:04:29 $
*
* ====================================================================
*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.search;
import org.apache.slide.common.SlideException;
/**
* Generic search exception.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
* @version $Revision: 1.1 $
*/
public class IndexException extends SlideException {
Throwable rootCause;
// ----------------------------------------------------------- Constructors
/**
* Constructor.
*
* @param message Exception message
*/
public IndexException(String message) {
super(message);
}
/**
* Constructor.
*
* @param message Exception message
*/
public IndexException (String message, Throwable t) {
super (message);
rootCause = t;
}
/**
* Constructor.
*
* @param t Exception message
*/
public IndexException (Throwable t) {
super (t.getMessage());
rootCause = t;
}
/**
* Accesses the rootCause
*
* @return the rootCause (a Throwable)
*/
public Throwable getRootCause () {
return rootCause;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]