Author: akarasulu
Date: Thu Sep 30 18:03:43 2004
New Revision: 47615
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/SubstringEvaluator.java
Log:
Cleaning up most of the mismatching schema problems.
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/AbstractContextPartition.java
Thu Sep 30 18:03:43 2004
@@ -187,7 +187,7 @@
underlying = engine.search( base, env, filter, searchCtls );
- return new SearchResultEnumeration( attrIds, underlying );
+ return new SearchResultEnumeration( attrIds, underlying, db );
}
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
Thu Sep 30 18:03:43 2004
@@ -30,11 +30,13 @@
import org.apache.ldap.common.filter.ScopeNode;
import org.apache.ldap.common.filter.SimpleNode;
import org.apache.ldap.common.schema.Normalizer;
+import org.apache.ldap.common.schema.AttributeType;
+import org.apache.ldap.common.schema.MatchingRule;
import org.apache.ldap.common.filter.PresenceNode;
import org.apache.ldap.common.NotImplementedException;
-import org.apache.eve.schema.NormalizerRegistry;
-import org.apache.eve.schema.ComparatorRegistry;
+import org.apache.eve.schema.OidRegistry;
+import org.apache.eve.schema.AttributeTypeRegistry;
/**
@@ -45,12 +47,20 @@
*/
public class LeafEvaluator implements Evaluator
{
+ /** equality matching type constant */
+ private static final int EQUALITY_MATCH = 0;
+ /** ordering matching type constant */
+ private static final int ORDERING_MATCH = 1;
+ /** substring matching type constant */
+ private static final int SUBSTRING_MATCH = 3;
+
+
/** Database used to evaluate leaf with */
private Database db;
- /** Normalizer registry for up value normalization */
- private NormalizerRegistry normalizerRegistry;
- /** Comparator registry for comparing normalized values */
- private ComparatorRegistry comparatorRegistry;
+ /** Oid Registry used to translate attributeIds to OIDs */
+ private OidRegistry oidRegistry;
+ /** AttributeType registry needed for normalizing and comparing values */
+ private AttributeTypeRegistry attributeTypeRegistry;
/** Substring node evaluator we depend on */
private SubstringEvaluator substringEvaluator;
/** ScopeNode evaluator we depend on */
@@ -62,20 +72,17 @@
*
* @param db
* @param scopeEvaluator
- * @param normalizerRegistry
- * @param comparatorRegistry
* @param substringEvaluator
*/
- public LeafEvaluator( Database db,
+ public LeafEvaluator( Database db, OidRegistry oidRegistry,
+ AttributeTypeRegistry attributeTypeRegistry,
ScopeEvaluator scopeEvaluator,
- NormalizerRegistry normalizerRegistry,
- ComparatorRegistry comparatorRegistry,
SubstringEvaluator substringEvaluator )
{
this.db = db;
+ this.oidRegistry = oidRegistry;
+ this.attributeTypeRegistry = attributeTypeRegistry;
this.scopeEvaluator = scopeEvaluator;
- this.normalizerRegistry = normalizerRegistry;
- this.comparatorRegistry = comparatorRegistry;
this.substringEvaluator = substringEvaluator;
}
@@ -86,18 +93,6 @@
}
- public NormalizerRegistry getNormalizerRegistry()
- {
- return normalizerRegistry;
- }
-
-
- public ComparatorRegistry getComparatorRegistry()
- {
- return comparatorRegistry;
- }
-
-
public SubstringEvaluator getSubstringEvaluator()
{
return substringEvaluator;
@@ -186,8 +181,8 @@
* We need to iterate through all values and for each value we
normalize
* and use the comparator to determine if a match exists.
*/
- Normalizer normalizer = normalizerRegistry.getEquality( attrId );
- Comparator comparator = comparatorRegistry.getEquality( attrId );
+ Normalizer normalizer = getNormalizer( attrId );
+ Comparator comparator = getComparator( attrId );
Object filterValue = normalizer.normalize( node.getValue() );
NamingEnumeration list = attr.getAll();
@@ -275,8 +270,8 @@
return idx.hasValue( node.getValue(), rec.getEntryId() );
}
- Normalizer normalizer = normalizerRegistry.getEquality(
node.getAttribute() );
- Comparator comparator = comparatorRegistry.getEquality(
node.getAttribute() );
+ Normalizer normalizer = getNormalizer( node.getAttribute() );
+ Comparator comparator = getComparator( node.getAttribute() );
/*
* Get the attribute and if it is not set in rec then resusitate it
@@ -334,5 +329,66 @@
// no match so return false
return false;
+ }
+
+
+ /**
+ * Gets the comparator for equality matching.
+ *
+ * @param attrId the attribute identifier
+ * @return the comparator for equality matching
+ * @throws NamingException if there is a failure
+ */
+ private Comparator getComparator( String attrId ) throws NamingException
+ {
+ MatchingRule mrule = getMatchingRule( attrId, EQUALITY_MATCH );
+ return mrule.getComparator();
+ }
+
+
+ /**
+ * Gets the normalizer for equality matching.
+ *
+ * @param attrId the attribute identifier
+ * @return the normalizer for equality matching
+ * @throws NamingException if there is a failure
+ */
+ private Normalizer getNormalizer( String attrId ) throws NamingException
+ {
+ MatchingRule mrule = getMatchingRule( attrId, EQUALITY_MATCH );
+ return mrule.getNormalizer();
+ }
+
+
+ /**
+ * Gets the matching rule for an attributeType.
+ *
+ * @param attrId the attribute identifier
+ * @return the matching rule
+ * @throws NamingException if there is a failure
+ */
+ private MatchingRule getMatchingRule( String attrId, int matchType )
+ throws NamingException
+ {
+ MatchingRule mrule = null;
+ String oid = oidRegistry.getOid( attrId );
+ AttributeType type = attributeTypeRegistry.lookup( oid );
+
+ switch( matchType )
+ {
+ case( EQUALITY_MATCH ):
+ mrule = type.getEquality();
+ break;
+ case( SUBSTRING_MATCH ):
+ mrule = type.getSubstr();
+ break;
+ case( ORDERING_MATCH ):
+ mrule = type.getOrdering();
+ break;
+ default:
+ throw new NamingException( "Unknown match type: " + matchType
);
+ }
+
+ return mrule;
}
}
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/SubstringEvaluator.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/SubstringEvaluator.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/SubstringEvaluator.java
Thu Sep 30 18:03:43 2004
@@ -27,9 +27,11 @@
import org.apache.ldap.common.filter.ExprNode;
import org.apache.ldap.common.schema.Normalizer;
+import org.apache.ldap.common.schema.AttributeType;
import org.apache.ldap.common.filter.SubstringNode;
-import org.apache.eve.schema.NormalizerRegistry;
+import org.apache.eve.schema.OidRegistry;
+import org.apache.eve.schema.AttributeTypeRegistry;
/**
@@ -42,14 +44,25 @@
{
/** Database used while evaluating candidates */
private Database db;
- /** Normalizer registry for up value normalization */
- private NormalizerRegistry normalizerRegistry;
+ /** Oid Registry used to translate attributeIds to OIDs */
+ private OidRegistry oidRegistry;
+ /** AttributeType registry needed for normalizing and comparing values */
+ private AttributeTypeRegistry attributeTypeRegistry;
- public SubstringEvaluator( Database db, NormalizerRegistry normReg )
+ /**
+ * Creates a new SubstringEvaluator for substring expressions.
+ *
+ * @param db the database this evaluator uses
+ * @param oidRegistry the OID registry for name to OID mapping
+ * @param attributeTypeRegistry the attributeType registry
+ */
+ public SubstringEvaluator( Database db, OidRegistry oidRegistry,
+ AttributeTypeRegistry attributeTypeRegistry )
{
this.db = db;
- this.normalizerRegistry = normReg;
+ this.oidRegistry = oidRegistry;
+ this.attributeTypeRegistry = attributeTypeRegistry;
}
@@ -110,7 +123,9 @@
// --------------------------------------------------------------------
Attribute attr = null;
- Normalizer normalizer = normalizerRegistry.getSubstring(
snode.getAttribute() );
+ String oid = oidRegistry.getOid( attr.getID() );
+ AttributeType type = attributeTypeRegistry.lookup( oid );
+ Normalizer normalizer = type.getSubstr().getNormalizer();
// resusitate the entry if it has not been and set entry in IndexRecord
if ( null == record.getAttributes() )