You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by wa...@apache.org on 2003/08/22 16:21:41 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/search CompareHint.java InvalidQueryException.java SearchQueryResult.java

wam         2003/08/22 07:21:41

  Modified:    src/share/org/apache/slide/search/basic BasicQuery.java
                        BasicQueryImpl.java ComparableResourceImpl.java
                        OrderBy.java
               src/share/org/apache/slide/search CompareHint.java
                        InvalidQueryException.java SearchQueryResult.java
  Log:
  some minor changes concerning OrderBy
  
  Revision  Changes    Path
  1.16      +88 -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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BasicQuery.java	22 Aug 2002 11:53:32 -0000	1.15
  +++ BasicQuery.java	22 Aug 2003 14:21:41 -0000	1.16
  @@ -101,87 +101,87 @@
    * @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 &lt;select&gt; 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 &lt;from&gt; 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 &lt;prop&gt; nor a &lt;allprop&gt; element.
        */
       public static final String PROP_OR_ALLPROP_ELEMENT_MISSING = "Required element <prop> or <allprop> not supplied";
  -    
  -    
  -    
  +
  +
  +
       /** 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();
           this.expressionCompilerProvider = new ExpressionCompilerProvider();
       }
  -    
  +
       /**
        * Method getStore
        *
  @@ -191,7 +191,7 @@
       public AbstractStore getStore () {
           return store;
       }
  -    
  +
       /**
        * Method getSlidePath
        *
  @@ -203,7 +203,7 @@
       public String getSlidePath () throws InvalidScopeException {
           return slideUri.getSlidePath (queryScope.getHref());
       }
  -    
  +
       /**
        * Method getSearchToken
        *
  @@ -213,7 +213,7 @@
       public SearchToken getSearchToken (){
           return searchToken;
       }
  -    
  +
       /**
        * Method getPropertyProvider
        *
  @@ -223,7 +223,7 @@
       public PropertyProvider getPropertyProvider () {
           return propertyProvider;
       }
  -    
  +
       /**
        * Builds the internal structure from the JDOM tree. Concrete implementations
        * may use parseQueryElementWithoutExpression to create most of the
  @@ -236,20 +236,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 = 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 {@link #parseQueryWithoutExpression parseQueryWithoutExpression}
  @@ -263,7 +263,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.
  @@ -274,7 +274,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
  @@ -285,64 +285,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 (orderByElement);
  +            orderBy = new OrderBy ();
  +            orderBy.init (orderByElement);
           }
  -        
  +
           if (limitElement != null) {
               limit = new Integer (limitElement.getTextTrim()).intValue();
               limitDefined = true;
           }
       }
  -    
  +
       /**
        * QueryScope accessor
        *
  @@ -352,7 +353,7 @@
       public QueryScope getScope () {
           return queryScope;
       }
  -    
  +
       /**
        * Method getSelectedProperties
        *
  @@ -361,7 +362,7 @@
       public RequestedProperties requestedProperties () {
           return requestedProperties;
       }
  -    
  +
       /**
        * Method getExpression
        *
  @@ -371,8 +372,8 @@
       public IBasicExpression getExpression () {
           return rootExpression;
       }
  -    
  -    
  +
  +
       /**
        * Method isLimitDefined
        *
  @@ -381,7 +382,7 @@
       public boolean isLimitDefined () {
           return limitDefined;
       }
  -    
  +
       /**
        * Method getLimit
        *
  @@ -390,7 +391,7 @@
       public int getLimit () {
           return limit;
       }
  -    
  +
       /**
        * Method setScope
        *
  @@ -400,8 +401,18 @@
       public void setScope (QueryScope queryScope) {
           this.queryScope = queryScope;
       }
  -    
  -    
  +
  +    /**
  +     * Method getOrderBy
  +     *
  +     * @return   an OrderBy
  +     *
  +     */
  +    public OrderBy getOrderBy () {
  +        return orderBy;
  +    }
  +
  +
       /**
        * For debugging purpose.
        *
  @@ -409,14 +420,14 @@
        *
        */
       public String toString () {
  -        
  +
           String result =
               "SELECT [" + requestedProperties + "] FROM [" + queryScope + "] "
               + "WHERE [" + rootExpression + "]";
  -        
  +
           return result;
       }
  -    
  +
       /**
        * Needed to decide, which implementation of BasicQuery to load
        *
  @@ -432,23 +443,23 @@
       {
           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);
       }
  -    
  -    
  +
  +
       public abstract IBasicExpressionFactory getExpressionFactory ();
  -    
  -    
  -    
  +
  +
  +
       /**
        * This IBasicExpressionCompilerProvider implementation returns a
        * BasicQueryCompiler instance in method getCompiler().
  @@ -458,7 +469,7 @@
        * @author <a href="mailto:ralf.stuckert@softwareag.com">Ralf Stuckert</a>
        **/
       public static class ExpressionCompilerProvider implements IBasicExpressionCompilerProvider {
  -        
  +
           /**
            * Returns an IBasicExpressionCompiler for the given parameters.
            *
  @@ -472,6 +483,6 @@
               return new BasicExpressionCompiler(query, propertyProvider);
           }
       }
  -    
  +
   }
   
  
  
  
  1.9       +91 -79    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BasicQueryImpl.java	7 Aug 2003 12:41:25 -0000	1.8
  +++ BasicQueryImpl.java	22 Aug 2003 14:21:41 -0000	1.9
  @@ -96,43 +96,43 @@
    * @version $Revision$
    */
   public class BasicQueryImpl extends BasicQuery 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";
  -    
  +
       /**
        * Message of a BadQueryException that is thrown if the query element
        * does not contain a &lt;from&gt; element.
        */
       public static final String FROM_ELEMENT_MISSING = "Required element <from> not supplied";
  -    
  +
       /**
        * Message of a BadQueryException that is thrown if the query element
        * does not contain a &lt;select&gt; element.
        */
       public static final String SELECT_ELEMENT_MISSING = "Required element <select> not supplied";
  -    
  +
       /**
        * Message of a BadQueryException that is thrown if the query element
        * neither contains a &lt;from&gt; nor a &lt;from&gt; element.
        */
       public static final String PROP_OR_ALLPROP_ELEMENT_MISSING = "Required element <prop> or <allprop> not supplied";
  -    
  +
       /**
        * Message of a BadQueryException that is thrown if the query element
        * neither contains a &lt;from&gt; nor a &lt;from&gt; element.
        */
       public static final String NRESULTS_MISSING = "Required element <nresults> (when limit is supplied) not supplied";
   
  -    
  +
       /** the NotNormalizer, may be overridden in extending classes */
       protected NotNormalizer notNormalizer;
  -    
  +
       IBasicExpressionFactory expressionFactory = new BasicExpressionFactory ();
  -    
  +
       /**
        * Creates a BasicQueryImpl.
        */
  @@ -140,21 +140,21 @@
           super.init (searchToken);
           notNormalizer = new NotNormalizer ();
       }
  -    
  +
       /**
        * Default constructor, to enable creation by reflection
        */
       public BasicQueryImpl() {
           notNormalizer = new NotNormalizer ();
       }
  -    
  +
       /**
        * Initailize
        *
        * @param    token               a  SearchToken
        *
        */
  -    
  +
       /**
        * Creates a BasicQueryImpl. Used for testing
        *
  @@ -165,7 +165,7 @@
           init (searchToken);
           this.expressionCompilerProvider = expressionCompilerProvider;
       }
  -    
  +
       /**
        * Executes a request.
        *
  @@ -176,14 +176,22 @@
        */
       public SearchQueryResult execute () throws ServiceAccessException {
           SearchQueryResult result = null;
  -        
  +
           try {
  -            
  +
               IBasicResultSet resultSet = getExpression().execute();
  -            
  +
               if (orderBy != null) {
  -                result = new SearchQueryResult (resultSet,
  -                                                orderBy.getComparator());
  +                if (isLimitDefined()) {
  +                    result = new SearchQueryResult (resultSet,
  +                                                    orderBy.getComparator(),
  +                                                    limit);
  +                }
  +                else {
  +                    result = new SearchQueryResult (resultSet,
  +                                                    orderBy.getComparator());
  +                }
  +
               }
               else {
                   result = new SearchQueryResult (resultSet);
  @@ -193,30 +201,30 @@
                   result.setDescription ("The server truncated the result set");
               }
           }
  -        
  +
           catch (InvalidScopeException e) {
               result = new SearchQueryResult ();
               result.setStatus (SearchQueryResult.STATUS_INVALID_SCOPE);
               result.setHref (queryScope.getHref());
           }
  -        
  +
           catch (BadQueryException e) { // is this only INVALID_SCOPE?
               result = new SearchQueryResult ();
               result.setStatus (SearchQueryResult.STATUS_BAD_QUERY);
               result.setDescription (e.getMessage());
               result.setHref (queryScope.getHref());
           }
  -        
  +
           catch (SearchException e) { // is this only INVALID_SCOPE?
               result = new SearchQueryResult ();
               result.setStatus (SearchQueryResult.STATUS_BAD_QUERY);
               result.setDescription (e.getMessage());
               result.setHref (queryScope.getHref());
           }
  -        
  +
           return result;
       }
  -    
  +
       /**
        * builds the internal structure from the JDOM tree
        *
  @@ -228,17 +236,17 @@
        */
       public void parseQuery(Element expressionElement, PropertyProvider propertyProvider)
           throws BadQueryException {
  -        
  +
           parseQueryWithoutExpression (expressionElement);
           IBasicExpressionCompiler expressionCompiler = expressionCompilerProvider.getCompiler(this, propertyProvider);
  -        
  +
           // <where> is not mandatory
           if (whereElement != null) {
               List expressionList = whereElement.getChildren();
               if (expressionList.size() != 1) {
                   throw new BadQueryException ("where must have exactly one nested element");
               }
  -            
  +
               Element whereWithoutNot =
                   notNormalizer.getQueryWithoutNotExpression((Element)expressionList.get (0));
               rootExpression = expressionCompiler.compile(whereWithoutNot);
  @@ -247,9 +255,9 @@
               rootExpression = expressionCompiler.compile(null);
           }
       }
  -    
  -    
  -    
  +
  +
  +
       /**
        * Method getSelectedProperties
        *
  @@ -258,7 +266,7 @@
       public RequestedProperties requestedProperties () {
           return requestedProperties;
       }
  -    
  +
       /**
        * Method getExpression
        *
  @@ -268,7 +276,7 @@
       //    public IBasicExpression getExpression () {
       //        return rootExpression;
       //    }
  -    
  +
       /**
        * Method getLimit
        *
  @@ -277,7 +285,7 @@
       //    public int getLimit () {
       //        return limit;
       //    }
  -    
  +
       /**
        * Method getPropertyProvider
        *
  @@ -297,7 +305,7 @@
       //    public QueryScope getScope () {
       //        return queryScope;
       //    }
  -    
  +
       /**
        * Method setScope
        *
  @@ -307,7 +315,7 @@
       //    public void setScope (QueryScope queryScope) {
       //        this.queryScope = queryScope;
       //    }
  -    
  +
       /**
        * Method getSlidePath
        *
  @@ -319,7 +327,7 @@
       //    public String getSlidePath () throws InvalidScopeException {
       //        return slideUri.getSlidePath (queryScope.getHref());
       //    }
  -    
  +
       /**
        * Method getSearchToken
        *
  @@ -329,7 +337,7 @@
       //    public SearchToken getSearchToken (){
       //        return searchToken;
       //    }
  -    
  +
       /**
        * Method getStore
        *
  @@ -353,14 +361,13 @@
        */
       public void parseQueryElement (Element basicSearchElement,
                                      PropertyProvider propertyProvider)
  -        
  -        throws BadQueryException
  -    {
  +
  +        throws BadQueryException {
           this.parseQueryElement (basicSearchElement,
                                   propertyProvider,
                                   getScope(basicSearchElement));
       }
  -    
  +
       /**
        * Builds the internal structure from the JDOM tree. Concrete implementations
        * may use parseQueryElementWithoutExpression to create most of the
  @@ -375,23 +382,22 @@
       public void parseQueryElement (Element basicSearchElement,
                                      PropertyProvider propertyProvider,
                                      QueryScope queryScope)
  -        
  -        throws BadQueryException
  -    {
  +
  +        throws BadQueryException {
           this.queryScope = queryScope;
           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);
       }
  -    
  -    
  +
  +
       /**
        * Method isLimitDefined
        *
  @@ -400,8 +406,8 @@
       //    public boolean isLimitDefined () {
       //        return limitDefined;
       //    }
  -    
  -    
  +
  +
       /**
        * Needed to decide, which implementation of BasicQuery to load
        * (hier rausschmeissen, nach BasicSearchLanguage)
  @@ -413,22 +419,21 @@
        *
        */
       public static QueryScope getScope(Element basicSearchElementJDOM)
  -        throws BadQueryException
  -    {
  +        throws BadQueryException {
           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);
       }
  -    
  +
       /**
        * 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
  @@ -440,53 +445,53 @@
        */
       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);
           }
  -        
  +
           requestedProperties = createRequestedProperties (propElement);
  -        
  +
           //queryScope = new BasicQueryScope (fromElement);
  -        
  +
           if (orderByElement != null) {
  -            orderBy = new OrderBy (orderByElement);
  +            orderBy = createNewOrderBy (orderByElement);
           }
  -        
  +
           if (limitElement != null) {
               Element nResElem = limitElement.getChild (Literals.NRESULTS, namespace);
               if (nResElem == null)
  @@ -496,13 +501,20 @@
               limitDefined = true;
           }
       }
  -    
  +
       public IBasicExpressionFactory getExpressionFactory() {
           return expressionFactory;
       }
  -    
  -    
  -    
  +
  +    protected OrderBy createNewOrderBy (Element orderByElement) throws InvalidQueryException {
  +        OrderBy result = new OrderBy ();
  +        result.init(orderByElement);
  +        return result;
  +    }
  +
  +
  +
  +
       /**
        * This method may be overridden, if a store specific implementation adds
        * new property semantic.
  
  
  
  1.5       +6 -6      jakarta-slide/src/share/org/apache/slide/search/basic/ComparableResourceImpl.java
  
  Index: ComparableResourceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/ComparableResourceImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ComparableResourceImpl.java	20 Aug 2002 11:56:11 -0000	1.4
  +++ ComparableResourceImpl.java	22 Aug 2003 14:21:41 -0000	1.5
  @@ -490,8 +490,8 @@
       public int compareTo (ComparableResource otherResource, CompareHint hint) {
           int result = 0;
           
  -        Comparable otherValue = (Comparable) otherResource.getThisValue (hint.getProperty(), hint.getPropNamespace());
  -        Comparable thisValue = (Comparable) getThisValue (hint.getProperty(), hint.getPropNamespace());
  +        Comparable otherValue = (Comparable) otherResource.getThisValue (hint.getPropName(), hint.getPropNamespace());
  +        Comparable thisValue = (Comparable) getThisValue (hint.getPropName(), hint.getPropNamespace());
           
           if (getInternalHref().equals (otherResource.getInternalHref()))
               result = 0;
  
  
  
  1.8       +73 -68    jakarta-slide/src/share/org/apache/slide/search/basic/OrderBy.java
  
  Index: OrderBy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/OrderBy.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- OrderBy.java	29 Jul 2002 12:17:26 -0000	1.7
  +++ OrderBy.java	22 Aug 2003 14:21:41 -0000	1.8
  @@ -63,18 +63,16 @@
   
   package org.apache.slide.search.basic;
   
  -import org.jdom.Element;
  -import org.jdom.Attribute;
  -import org.jdom.Namespace;
  -
  -import org.apache.slide.search.InvalidQueryException;
  -import org.apache.slide.search.RequestedResource;
  -import org.apache.slide.search.CompareHint;
  -
  -import java.util.Comparator;
  -import java.util.List;
   import java.util.ArrayList;
  +import java.util.Comparator;
   import java.util.Iterator;
  +import java.util.List;
  +import org.apache.slide.common.PropertyName;
  +import org.apache.slide.search.CompareHint;
  +import org.apache.slide.search.InvalidQueryException;
  +import org.jdom.Attribute;
  +import org.jdom.Element;
  +import org.jdom.Namespace;
   
   
   /**
  @@ -85,37 +83,41 @@
    * @version $Revision$
    */
   public class OrderBy {
  -    
  +
       /** the comparator according to this expression */
  -    Comparator theComparator = new _Comparator ();
  -    
  +    private Comparator theComparator = new _Comparator ();
  +
       /** all orderby elements of this expression */
  -    List orderByElements = new ArrayList ();
  -    
  +    protected List orderByElements = new ArrayList ();
  +
       /**
  -     * Constructs an OrderBy.
  +     * initializes an OrderBy.
        *
        * @param orderByElements  the JDOM element containing the
        *        orderBy expression
        */
  -    OrderBy (Element orderByElement) throws InvalidQueryException {
  +    public void init (Element orderByElement) throws InvalidQueryException {
           Namespace nameSpace = orderByElement.getNamespace ();
           Iterator it =
               orderByElement.getChildren (Literals.ORDER, nameSpace).iterator();
  -        
  +
           while (it.hasNext()) {
               Element order = (Element) it.next();
  -            _Property p = getProperty(order);
  -            String propName = p.name;
  -            String propNamespace = p.namespace;
  +            PropertyName p = getProperty (order);
               boolean isAscending = isAscending (order);
               boolean isCaseSensitive = isCaseSensitive (order);
  -            
  +
               orderByElements.add
  -                (new CompareHint (propName, propNamespace, isAscending, isCaseSensitive));
  +                (createCompareHint (p, isAscending, isCaseSensitive));
           }
       }
  -    
  +
  +    protected CompareHint createCompareHint (PropertyName prop,
  +                                             boolean isAscending,
  +                                             boolean isCaseSensitive) {
  +        return new CompareHint (prop, isAscending, isCaseSensitive) ;
  +    }
  +
       /**
        * Method getComparator
        *
  @@ -125,8 +127,8 @@
       public Comparator getComparator () {
           return theComparator;
       }
  -    
  -    
  +
  +
       /**
        * Method isCaseSensitive
        *
  @@ -139,7 +141,7 @@
           boolean result = true;
           Attribute caseSens =
               order.getAttribute (Literals.CASESENSITIVE, order.getNamespace());
  -        
  +
           if (caseSens != null) {
               try {
                   result = caseSens.getBooleanValue();
  @@ -150,9 +152,9 @@
           }
           return result;
       }
  -    
  -    
  -    
  +
  +
  +
       /**
        * Method isAscending
        *
  @@ -167,16 +169,16 @@
           Element asc = order.getChild (Literals.ASCENDING, order.getNamespace());
           Element desc = order.getChild (Literals.DESCENDING, order.getNamespace());
           boolean result = true;
  -        
  +
           if (asc != null && desc != null)
               throw new InvalidQueryException ("either ascending or descending may be supplied");
  -        
  +
           if (desc != null)
               result = false;
  -        
  +
           return result;
       }
  -    
  +
       /**
        * Method getPropName
        *
  @@ -187,29 +189,40 @@
        * @throws   InvalidQueryException
        *
        */
  -    private _Property getProperty (Element order) throws InvalidQueryException {
  -        
  -        Element prop = order.getChild (Literals.PROP, order.getNamespace ());
  -        
  +    private PropertyName getProperty (Element orderElem) throws InvalidQueryException {
  +
           List propList =
  -            order.getChild (Literals.PROP, order.getNamespace()).getChildren();
  -        
  +            orderElem.getChild (Literals.PROP, orderElem.getNamespace()).getChildren();
  +
           if (propList.size() != 1)
               throw new InvalidQueryException
                   ("Expected exactly 1 prop element, found " + propList.size());
  -        
  +
           Element propElem = (Element)propList.get(0);
  +
  +        return createProperty (propElem);
  +    }
  +
  +    /**
  +     * Method createProperty
  +     *
  +     * @param    propElem            an Element
  +     *
  +     * @return   a _Property
  +     *
  +     */
  +    protected PropertyName createProperty (Element propElem) throws InvalidQueryException {
           String name = propElem.getName();
           String nameSpace = propElem.getNamespace().getURI();
  -        return new _Property (name, nameSpace);
  +        return new PropertyName (name, nameSpace);
       }
  -    
  -    
  +
  +
       /**
        * a comparator that sorts according to the OrderBy element
        */
  -    class _Comparator implements Comparator  {
  -        
  +    private class _Comparator implements Comparator  {
  +
           /**
            * Compares two ComparableResources. Two resources are equal, if they
            * have the same URI. Each <order> element within <orderby> generates
  @@ -229,34 +242,26 @@
           public int compare(Object o1, Object o2) {
               ComparableResource r1 = (ComparableResource)o1;
               ComparableResource r2 = (ComparableResource)o2;
  -        
  +
               int result = 0;
               if (r1.getInternalHref().equals (r2.getInternalHref())) {
                   result = 0;
               }
               else {
  -            
  -            Iterator it = orderByElements.iterator();
  -            while (it.hasNext() && result == 0) {
  -                CompareHint obe = (CompareHint)it.next();
  -                result = r1.compareTo (r2, obe);
  -            }
  -                
  +
  +                Iterator it = orderByElements.iterator();
  +                while (it.hasNext() && result == 0) {
  +                    CompareHint obe = (CompareHint)it.next();
  +                    result = r1.compareTo (r2, obe);
  +                }
  +
                   if (result == 0)
                       result = 1;
               }
  -            
  +
               return result;
           }
       }
  -    
  -    class _Property {
  -        String name;
  -        String namespace;
  -        _Property (String name, String namespace) {
  -            this.name=name;
  -            this.namespace = namespace;
  -        }
  -    }
  +
   }
   
  
  
  
  1.6       +47 -24    jakarta-slide/src/share/org/apache/slide/search/CompareHint.java
  
  Index: CompareHint.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/CompareHint.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CompareHint.java	26 Apr 2002 15:19:12 -0000	1.5
  +++ CompareHint.java	22 Aug 2003 14:21:41 -0000	1.6
  @@ -71,31 +71,36 @@
    * @author <a href="mailto:martin.wallmer@softwareag.com">Martin Wallmer</a>
    * @version $Revision$
    */
  +import org.apache.slide.common.PropertyName;
  +//import org.apache.slide.search.basic.ComparedProperty;
  +
   public class CompareHint {
  -    
  +
       /** the name of the property, which shall be compared */
  -    private String property;
  -    
  +    protected String propName;
  +
       /** the property's namespace */
  -    private String propNamespace;
  -    
  +    protected String propNamespace;
  +
       /** if the associated comparator is used for sort, ascending or descending? */
       private boolean ascending;
  -    
  +
       /** is compare case sensitive or not */
       private boolean caseSensitive;
  -    
  -    
  +
  +    private PropertyName comparedProperty;
  +
  +
       /**
  -     * Method getProperty
  +     * Method getPropName
        *
  -     * @return   a String
  +     * @return   the property's name
        *
        */
  -    public String getProperty () {
  -        return property;
  +    public String getPropName () {
  +        return propName;
       }
  -    
  +
       /**
        * Method getPropNamespace
        *
  @@ -105,7 +110,7 @@
       public String getPropNamespace () {
           return propNamespace;
       }
  -    
  +
       /**
        * Method isAscending
        *
  @@ -115,7 +120,7 @@
       public boolean isAscending () {
           return ascending;
       }
  -    
  +
       /**
        * Method isCaseSensitive
        *
  @@ -125,15 +130,33 @@
       public boolean isCaseSensitive () {
           return caseSensitive;
       }
  -    
  +
  +
       /**
  -     * constructs a CompareHint
  +     * Constructor
  +     *
  +     * @param    prop                a  ComparedProperty
  +     * @param    ascending           a  boolean
  +     * @param    caseSensitive       a  boolean
  +     *
        */
  -    public CompareHint (String property, String propNamespace, boolean ascending, boolean caseSensitive) {
  -        this.property = property;
  -        this.propNamespace = propNamespace;
  +    public CompareHint (PropertyName prop, boolean ascending, boolean caseSensitive) {
  +        this.propName = prop.getName();
  +        this.propNamespace = prop.getNamespace();
           this.ascending = ascending;
           this.caseSensitive = caseSensitive;
  +        this.comparedProperty = prop;
  +    }
  +
  +
  +    /**
  +     * Method getComparedProperty
  +     *
  +     * @return   a ComparedProperty
  +     *
  +     */
  +    public PropertyName getComparedProperty () {
  +        return comparedProperty;
       }
   }
   
  
  
  
  1.6       +18 -9     jakarta-slide/src/share/org/apache/slide/search/InvalidQueryException.java
  
  Index: InvalidQueryException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/InvalidQueryException.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InvalidQueryException.java	25 Apr 2002 21:12:31 -0000	1.5
  +++ InvalidQueryException.java	22 Aug 2003 14:21:41 -0000	1.6
  @@ -72,11 +72,11 @@
    * @version $Revision$
    */
   public class InvalidQueryException extends BadQueryException {
  -    
  -    
  +
  +
       // ----------------------------------------------------------- Constructors
  -    
  -    
  +
  +
       /**
        * Constructor.
        *
  @@ -85,5 +85,14 @@
       public InvalidQueryException(String message) {
           super(message);
       }
  -    
  +
  +        /**
  +     * Constructor.
  +     *
  +     * @param message Exception message
  +     * @param t root cause
  +     */
  +    public InvalidQueryException (String message, Throwable t) {
  +        super (message, t);
  +    }
   }
  
  
  
  1.13      +48 -38    jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java
  
  Index: SearchQueryResult.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchQueryResult.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SearchQueryResult.java	9 Oct 2002 14:14:42 -0000	1.12
  +++ SearchQueryResult.java	22 Aug 2003 14:21:41 -0000	1.13
  @@ -63,15 +63,12 @@
   
   package org.apache.slide.search;
   
  -import java.util.Set;
  +import java.util.Comparator;
   import java.util.HashSet;
  -import java.util.TreeSet;
   import java.util.Iterator;
  -import java.util.Comparator;
  -import org.apache.slide.common.*;
  -import org.apache.slide.structure.*;
  -import org.apache.slide.authenticate.CredentialsToken;
  -import org.apache.slide.util.Configuration;
  +import java.util.Set;
  +import java.util.SortedSet;
  +import java.util.TreeSet;
   
   /**
    * Aggregates a set containing the result items of a query. This set is either
  @@ -85,7 +82,7 @@
    * @version $Revision$
    */
   public class SearchQueryResult {
  -    
  +
       public final static int STATUS_OK             = 0;
       public final static int STATUS_BAD_QUERY      = 1;
       public final static int STATUS_INVALID_SCOPE  = 2;
  @@ -93,11 +90,11 @@
       public final static int STATUS_UNPROCESSABLE_ENTITY = 4;
       public final static int STATUS_BAD_GATEWAY    = 5;
       public final static int STATUS_FORBIDDEN      = 6;
  -    
  +
       private int status;
       private String description;
       private String href;
  -    
  +
       private Set result;
       /**
        * Method setStatus
  @@ -108,7 +105,7 @@
       public void setStatus(int status) {
           this.status = status;
       }
  -    
  +
       /**
        * Method getStatus
        *
  @@ -118,7 +115,7 @@
       public int getStatus() {
           return status;
       }
  -    
  +
       /**
        * Method setDescription
        *
  @@ -128,7 +125,7 @@
       public void setDescription(String description) {
           this.description = description;
       }
  -    
  +
       /**
        * Method getDescription
        *
  @@ -138,7 +135,7 @@
       public String getDescription() {
           return description;
       }
  -    
  +
       /**
        * Method setHref
        *
  @@ -157,7 +154,7 @@
       public String getHref () {
           return href;
       }
  -    
  +
       /**
        * Method add
        *
  @@ -167,15 +164,15 @@
       public void add (SearchQueryResult subResultSet) {
           result.addAll (subResultSet.getResultSet());
       }
  -    
  +
       /**
        * Constructs an empty unorderred SearchQueryResult
        *
        */
       public SearchQueryResult () {
  -		this (null, null);
  +        this (null, null);
       }
  -    
  +
       /**
        * Constructs an unordered SearchQueryResult
        *
  @@ -184,15 +181,15 @@
       public SearchQueryResult (Set result) {
           this (result, null);
       }
  -    
  +
       /**
  -	 * Constructs an empty orderred SearchQueryResult
  -	 *
  -	 */
  -	public SearchQueryResult (Comparator comparator) {
  -		this (null, comparator);
  -	}
  -    
  +     * Constructs an empty orderred SearchQueryResult
  +     *
  +     */
  +    public SearchQueryResult (Comparator comparator) {
  +        this (null, comparator);
  +    }
  +
       /**
        * Constructs an ordered SearchQueryResult
        *
  @@ -200,21 +197,34 @@
        * @param comparator for ordering
        */
       public SearchQueryResult (Set result, Comparator comparator) {
  -		if (comparator == null) {
  -			if (result == null)
  -				this.result =  new HashSet ();
  -			else
  +        if (comparator == null) {
  +            if (result == null)
  +                this.result =  new HashSet ();
  +            else
               this.result = result;
  -		}
  +        }
           else {
               this.result = new TreeSet (comparator);
  -			if (result != null)
  +            if (result != null)
               this.result.addAll (result);
           }
           status = STATUS_OK;
           description = "";
       }
  -    
  +
  +
  +    public SearchQueryResult (Set result, Comparator comparator, int limit) {
  +        this (result, comparator);
  +        if (this.result.size() > limit) {
  +            SortedSet tmp = new TreeSet (comparator);
  +            Iterator it = this.result.iterator();
  +            for (int i = 0; i < limit; i++) {
  +                tmp.add (it.next());
  +            }
  +            this.result = tmp;
  +        }
  +    }
  +
       /**
        * Method iterator
        *
  @@ -224,7 +234,7 @@
       public Iterator iterator () {
           return result.iterator();
       }
  -    
  +
       /**
        * Method getResultSet. needed to add result subsets.
        *