vgritsenko    2004/01/06 20:03:50

  Modified:    java/src/org/apache/xindice/core/indexer IndexManager.java
                        IndexPattern.java IndexQuery.java Indexer.java
                        MemValueIndexer.java ValueIndexer.java
               java/src/org/apache/xindice/core/indexer/helpers
                        IndexQueryANY.java
  Log:
  Optimizing Value.getData(); other minor changes.
  
  Revision  Changes    Path
  1.23      +5 -4      
xml-xindice/java/src/org/apache/xindice/core/indexer/IndexManager.java
  
  Index: IndexManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/IndexManager.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- IndexManager.java 23 Dec 2003 12:18:11 -0000      1.22
  +++ IndexManager.java 7 Jan 2004 04:03:50 -0000       1.23
  @@ -270,10 +270,11 @@
   
               Map tbl = (Map) bestIndexers.get(style);
               if (tbl == null) {
  -                tbl = new WeakHashMap();
  +                tbl = new WeakHashMap(); // FIXME: Review usage of 
WeakHashMap
                   bestIndexers.put(style, tbl);
  +            } else {
  +                tbl.clear();
               }
  -            tbl.clear();
               idxList = (IndexerInfo[]) 
indexes.values().toArray(EmptyIndexerInfo);
   
               return idx;
  
  
  
  1.10      +4 -4      
xml-xindice/java/src/org/apache/xindice/core/indexer/IndexPattern.java
  
  Index: IndexPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/IndexPattern.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- IndexPattern.java 6 Dec 2003 22:44:36 -0000       1.9
  +++ IndexPattern.java 7 Jan 2004 04:03:50 -0000       1.10
  @@ -101,7 +101,7 @@
           } else {
               elemID = SymbolTable.getNormalizedSymbol(symbols, elemName, 
nsMap, true);
           }
  -        
  +
           if (st.hasMoreTokens()) {
               attrName = st.nextToken();
               if (attrName.equals("*")) {
  @@ -255,7 +255,7 @@
       }
   
       public int hashCode() {
  -        return new Integer((elemID << 16) + attrID).hashCode();
  +        return new Integer((elemID << 16) + attrID).hashCode(); // FIXME: 
VG: Remove "new Integer"
       }
   
       public boolean equals(Object obj) {
  
  
  
  1.7       +69 -30    
xml-xindice/java/src/org/apache/xindice/core/indexer/IndexQuery.java
  
  Index: IndexQuery.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/IndexQuery.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- IndexQuery.java   9 Aug 2003 21:19:52 -0000       1.6
  +++ IndexQuery.java   7 Jan 2004 04:03:50 -0000       1.7
  @@ -104,75 +104,116 @@
       public static final int SW = 7;    // Starts-with
       public static final int NSW = -7;  // Not Starts-with
   
  -    protected IndexPattern pattern;
  -    protected int op;
  -    protected Value[] vals;
   
  +    protected final IndexPattern pattern;
  +    protected final int op;
  +    protected final Value[] vals;
  +
  +
  +    /**
  +     * ANY operator index query
  +     */
       public IndexQuery(IndexPattern pattern) {
           this.pattern = pattern;
           this.op = ANY;
  +        this.vals = null;
  +    }
  +
  +    /**
  +     * IN operator index query
  +     */
  +    public IndexQuery(IndexPattern pattern, Value[] vals) {
  +        this(pattern, IN, vals);
       }
   
  +    /**
  +     * Binary operator index query
  +     */
       public IndexQuery(IndexPattern pattern, int op, Value[] vals) {
           this.pattern = pattern;
           this.op = op;
           this.vals = vals;
       }
   
  -    public IndexQuery(IndexPattern pattern, Value[] vals) {
  -        this(pattern, IN, vals);
  -    }
  -
  -    public IndexQuery(IndexPattern pattern, int op, Value val1) {
  +    /**
  +     * Unary operator index query
  +     */
  +    public IndexQuery(IndexPattern pattern, int op, Value val) {
           this.pattern = pattern;
           this.op = op;
  +
           if (op == SW || op == NSW) {
  -            byte[] b = new byte[val1.getLength() + 1];
  -            System.arraycopy(val1.getData(), 0, b, 0, b.length - 1);
  -            b[b.length - 1] = 127; // TODO: Must fix this
  +            // SW and NSW operators are treated as "between" and "not 
between"
  +            // where second value is same as first value plus max byte
  +            byte[] b = new byte[val.getLength() + 1];
  +            val.copyTo(b, 0);
  +            b[b.length - 1] = Byte.MAX_VALUE;
               Value val2 = new Value(b);
  -            vals = new Value[]{val1, val2};
  -        } else
  -            vals = new Value[]{val1};
  +            this.vals = new Value[]{ val, val2 };
  +        } else {
  +            this.vals = new Value[]{ val };
  +        }
       }
   
  +    /**
  +     * EQ operator index query
  +     */
       public IndexQuery(IndexPattern pattern, Value val1) {
           this(pattern, EQ, val1);
       }
   
  +    /**
  +     * Binary operator index query
  +     */
       public IndexQuery(IndexPattern pattern, int op, Value val1, Value val2) {
           this.pattern = pattern;
           this.op = op;
  -        vals = new Value[]{val1, val2};
  +        this.vals = new Value[]{val1, val2};
       }
   
  +    /**
  +     * IN operator index query
  +     */
       public IndexQuery(IndexPattern pattern, Value val1, Value val2) {
           this(pattern, IN, val1, val2);
       }
   
  +    /**
  +     * Unary operator index query
  +     */
       public IndexQuery(IndexPattern pattern, int op, String val1) {
           this(pattern, op, new Value(val1));
       }
   
  +    /**
  +     * EQ operator index query
  +     */
       public IndexQuery(IndexPattern pattern, String val1) {
           this(pattern, new Value(val1));
       }
   
  +    /**
  +     * Binary operator index query
  +     */
       public IndexQuery(IndexPattern pattern, int op, String val1, String 
val2) {
           this(pattern, op, new Value(val1), new Value(val2));
       }
   
  +    /**
  +     * IN operator index query
  +     */
       public IndexQuery(IndexPattern pattern, String val1, String val2) {
           this(pattern, new Value(val1), new Value(val2));
       }
   
  +
       /**
        * getPattern returns the IndexPattern associated with this query.
        *
        * @return the IndexPattern
        */
       public IndexPattern getPattern() {
  -        return pattern;
  +        return this.pattern;
       }
   
       /**
  @@ -181,7 +222,7 @@
        * @return The operator
        */
       public int getOperator() {
  -        return op;
  +        return this.op;
       }
   
       /**
  @@ -191,7 +232,7 @@
        * @return The request Value
        */
       public final Value getValue(int index) {
  -        return vals[index];
  +        return this.vals[index];
       }
   
       /**
  @@ -200,7 +241,7 @@
        * @return The Value set
        */
       public Value[] getValues() {
  -        return vals;
  +        return this.vals;
       }
   
       /**
  @@ -210,7 +251,7 @@
        * @return The Value set length
        */
       public final int getLength() {
  -        return vals.length;
  +        return this.vals.length;
       }
   
   
  @@ -223,12 +264,12 @@
        * @return Whether or not the value matches
        */
       public boolean testValue(Value value) {
  -        switch (op) {
  +        switch (this.op) {
               // No Comparison (Any)
               case ANY:
                   return true;
   
  -                // Singleton Comparisons
  +            // Singleton Comparisons
               case EQ:
                   return value.equals(vals[0]);
               case NEQ:
  @@ -242,7 +283,7 @@
               case GEQ:
                   return value.compareTo(vals[0]) >= 0;
   
  -                // Range Comparisons
  +            // Range Comparisons
               case BW:
                   return value.compareTo(vals[0]) >= 0 && 
value.compareTo(vals[1]) <= 0;
               case NBW:
  @@ -252,17 +293,16 @@
               case NBWX:
                   return value.compareTo(vals[0]) < 0 || 
value.compareTo(vals[1]) > 0;
   
  -                // Set Comparisons
  +            // Set Comparisons
               case IN:
               case NIN:
                   return Arrays.binarySearch(vals, value) >= 0 ? op == IN
                           : op == NIN;
   
  -                // Other comparisons
  +            // Other comparisons
               case SW:
               case NSW:
  -                return value.startsWith(vals[0]) ? op == SW
  -                        : op == NSW;
  +                return value.startsWith(vals[0]) ? op == SW : op == NSW;
               default:
                   if (log.isWarnEnabled()) {
                       log.warn("invalid operation : " + op);
  @@ -284,4 +324,3 @@
           return testValue(new Value(value));
       }
   }
  -
  
  
  
  1.5       +4 -4      
xml-xindice/java/src/org/apache/xindice/core/indexer/Indexer.java
  
  Index: Indexer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/Indexer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Indexer.java      7 Aug 2003 20:13:21 -0000       1.4
  +++ Indexer.java      7 Jan 2004 04:03:50 -0000       1.5
  @@ -93,7 +93,7 @@
   
       /**
        * getIndexStyle returns the Index style.  Different query languages
  -     * will need to draw from different indexing styles.  For example, A
  +     * will need to draw from different indexing styles. For example, A
        * query that is written in quilt will require XPath indexing.
        *
        * @return The index style
  @@ -145,7 +145,7 @@
       void add(String value, Key key, int pos, int len, short elemID, short 
attrID) throws DBException;
   
       /**
  -     * queryMatches retrieves a set of MatchEntry instances that match
  +     * queryMatches retrieves a set of IndexMatch instances that match
        * the supplied query.  The matches are then used by the  QueryEngine
        * in co-sequential processing.  If this indexer doesn't support the
        * passed value, it should return 'null'.  If no matches are found,
  
  
  
  1.7       +14 -41    
xml-xindice/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java
  
  Index: MemValueIndexer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MemValueIndexer.java      9 Aug 2003 21:19:52 -0000       1.6
  +++ MemValueIndexer.java      7 Jan 2004 04:03:50 -0000       1.7
  @@ -346,25 +346,19 @@
   
           // perform the requested matching type
           switch (anOperator) {
  -            // unsupported operator
  -            default :
  -                throw new DBException(FaultCodes.IDX_NOT_SUPPORTED, 
"unimplemented index query operation code (code = " + anOperator + ")");
  -                //break;
  -
  -                // exact match
  -            case IndexQuery.EQ:
  +            default: // unsupported operator
  +                throw new DBException(FaultCodes.IDX_NOT_SUPPORTED,
  +                                      "Unimplemented index query operation 
code (code = " + anOperator + ")");
   
  +            case IndexQuery.EQ: // exact match
                   aLocatorSet = (TreeSet) itsValues.get(aLowEndpoint);
                   if (aLocatorSet != null) {
                       aResult = new IndexMatch[aLocatorSet.size()];
                       addMatches(aResult, 0, aLocatorSet);
                   }
  -
                   break;
   
  -                // all except exact match
  -            case IndexQuery.NEQ:
  -
  +            case IndexQuery.NEQ: // all except exact match
                   // see whether or not we even have the value to be excluded
                   TreeSet anExcludedLocatorSet = (TreeSet) 
itsValues.get(aLowEndpoint);
   
  @@ -404,11 +398,9 @@
                           }
                       }
                   }
  -
                   break;
   
               case IndexQuery.BWX: // Between (Exclusive)
  -
                   // notes on BWX and BW:
                   // TreeMap always returns a half-open range for the subMap 
operation
                   // (includes the low endpoint but excludes the high endpoint)
  @@ -442,16 +434,13 @@
                       // return locators in sub map exclusive of endpoints
                       aResult = 
getIndexMatchArray(itsValues.subMap(aLowEndpoint, aHighEndpoint));
                   }
  -
                   break;
   
               case IndexQuery.BW: // Between (Inclusive)
  -
                   aResult = getIndexMatchArray(getBWSubmap(aLowEndpoint, 
aHighEndpoint));
  -
                   break;
  -            case IndexQuery.SW: // starts-with
   
  +            case IndexQuery.SW: // starts-with
                   // handled simlar to BW case, except that we
                   // always compare against the String form of the comparator
                   // to ensure that comparisons happen as Strings as specified 
by XPath
  @@ -467,11 +456,9 @@
   
                   // get the matching submap forcing String comparisons to be 
used regardless of stored type
                   aResult = getIndexMatchArray(getBWSubmap(aLowEndpoint, 
aLowEndpoint));
  -
                   break;
   
               case IndexQuery.IN: // In the (presumed sorted) set of specified 
query values
  -
                   // this is handled as a BW query followed by include 
filtering
                   // of only those matches in the range that are contained
                   // in the set of query values (IN)
  @@ -479,24 +466,19 @@
   
                   // get the matching submap forcing String comparisons to be 
used regardless of stored type
                   aResult = getIndexMatchArray(getBWSubmap(aLowEndpoint, 
aLowEndpoint), aMatchValueArray, false); // false => include style filtering 
applied
  -
                   break;
   
               case IndexQuery.NBWX: // Not between (Exclusive)
  -
                   // implement as LT or GT
                   aResult = getIndexMatchArray(getLTSubmap(aLowEndpoint), 
getGTSubmap(aHighEndpoint));
  -
                   break;
   
               case IndexQuery.NBW: // Not between (Inclusive)
  -
                   // implement as LEQ or GEQ
                   aResult = getIndexMatchArray(getLEQSubmap(aLowEndpoint), 
getGEQSubmap(aHighEndpoint));
                   break;
   
               case IndexQuery.NSW: // Not starts-with
  -
                   // implement as LT or GT forcing String comparisons
                   // we get the raw String match value and use that instead of 
the typed value
                   // to force String comparisons (as required for starts-with)
  @@ -512,30 +494,22 @@
                   // get all matches below starts-with range and above 
starts-with range
                   // use of String key forces String matching
                   aResult = getIndexMatchArray(getLTSubmap(aLowEndpoint), 
getGTSubmap(aLowEndpoint));
  -
                   break;
   
               case IndexQuery.LT: // Less than
  -
                   aResult = getIndexMatchArray(getLTSubmap(aLowEndpoint));
  -
                   break;
   
               case IndexQuery.LEQ: // Less than or equal
  -
                   aResult = getIndexMatchArray(getLEQSubmap(aLowEndpoint));
  -
                   break;
   
               case IndexQuery.GT: // Greater than
  -
                   aResult = getIndexMatchArray(getGTSubmap(aLowEndpoint));
  -
                   break;
  -            case IndexQuery.GEQ: // Greater than or equal
   
  +            case IndexQuery.GEQ: // Greater than or equal
                   aResult = getIndexMatchArray(getGEQSubmap(aLowEndpoint));
  -
                   break;
   
               case IndexQuery.NIN: // Not in specified set of query values
  @@ -547,8 +521,7 @@
   
                   break;
   
  -            case IndexQuery.ANY:
  -                // return all values
  +            case IndexQuery.ANY: // return all values
                   aResult = getIndexMatchArray(itsValues);
                   break;
           }
  @@ -877,15 +850,15 @@
                   itsValueType = BOOLEAN;
               } else {
                   if (itsPattern.indexOf('@') != -1) {
  +                    log.warn("Unrecognized value type, defaulting to '" + 
STRING_VAL + "'");
                       itsValueType = STRING;
                   } else {
  +                    log.warn("Unrecognized value type, defaulting to '" + 
TRIMMED_VAL + "'");
                       itsValueType = TRIMMED;
                   }
               }
  -        } catch (Exception anException) {
  -            if (log.isDebugEnabled()) {
  -                log.debug("Exception while setting configuration", 
anException);
  -            }
  +        } catch (Exception e) {
  +            log.warn("Exception while setting configuration", e);
           }
       }
   
  
  
  
  1.16      +3 -3      
xml-xindice/java/src/org/apache/xindice/core/indexer/ValueIndexer.java
  
  Index: ValueIndexer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/ValueIndexer.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ValueIndexer.java 12 Aug 2003 02:57:30 -0000      1.15
  +++ ValueIndexer.java 7 Jan 2004 04:03:50 -0000       1.16
  @@ -298,7 +298,7 @@
               byte[] b = new byte[l + 13];
   
               // Write the key
  -            System.arraycopy(key.getData(), 0, b, 0, l);
  +            key.copyTo(b, 0, l);
               b[l] = 0;
   
               // Write the pos
  
  
  
  1.5       +3 -3      
xml-xindice/java/src/org/apache/xindice/core/indexer/helpers/IndexQueryANY.java
  
  Index: IndexQueryANY.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/helpers/IndexQueryANY.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IndexQueryANY.java        7 Aug 2003 20:13:22 -0000       1.4
  +++ IndexQueryANY.java        7 Jan 2004 04:03:50 -0000       1.5
  @@ -71,7 +71,7 @@
   public final class IndexQueryANY extends IndexQuery {
   
       public IndexQueryANY(IndexPattern pattern) {
  -        super(pattern);
  +        super(pattern, ANY, (Value[]) null);
       }
   
       public int getOperator() {
  
  
  

Reply via email to