directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r659841 - in /directory/apacheds/branches/bigbang: btree-base/src/main/java/org/apache/directory/server/xdbm/ xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/
Date Sat, 24 May 2008 15:46:26 GMT
Author: akarasulu
Date: Sat May 24 08:46:26 2008
New Revision: 659841

URL: http://svn.apache.org/viewvc?rev=659841&view=rev
Log:
fixing bug where object level scope was not handled properly in search

Added:
    directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
  (with props)
    directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
  (with props)
Modified:
    directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java

Added: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java?rev=659841&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
(added)
+++ directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
Sat May 24 08:46:26 2008
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.directory.server.xdbm;
+
+
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+
+
+/**
+ * An empty Cursor implementation.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EmptyIndexCursor<K,E> extends AbstractIndexCursor<K,E>
+{
+    public boolean available()
+    {
+        return false;
+    }
+
+    public void before( IndexEntry<K,E> element ) throws Exception
+    {
+        checkClosed( "before()" );
+    }
+
+
+    public void after( IndexEntry<K,E> element ) throws Exception
+    {
+        checkClosed( "after()" );
+    }
+
+
+    public void beforeFirst() throws Exception
+    {
+        checkClosed( "beforeFirst()" );
+    }
+
+
+    public void afterLast() throws Exception
+    {
+        checkClosed( "afterLast()" );
+    }
+
+
+    public boolean first() throws Exception
+    {
+        checkClosed( "first()" );
+        return false;
+    }
+
+
+    public boolean last() throws Exception
+    {
+        checkClosed( "last()" );
+        return false;
+    }
+
+
+    public boolean previous() throws Exception
+    {
+        checkClosed( "previous()" );
+        return false;
+    }
+
+
+    public boolean next() throws Exception
+    {
+        checkClosed( "next()" );
+        return false;
+    }
+
+
+    public IndexEntry<K,E> get() throws Exception
+    {
+        checkClosed( "get()" );
+        throw new InvalidCursorPositionException( "This cursor is empty and cannot return
elements!" );
+    }
+
+
+    public boolean isElementReused()
+    {
+        return false;
+    }
+
+    public void afterValue( Long id, K indexValue ) throws Exception
+    {
+        checkClosed( "after()" );
+    }
+
+    public void beforeValue( Long id, K indexValue ) throws Exception
+    {
+        checkClosed( "after()" );
+    }
+}

Propchange: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/EmptyIndexCursor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java?rev=659841&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
(added)
+++ directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
Sat May 24 08:46:26 2008
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.directory.server.xdbm;
+
+
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+
+
+/**
+ * A Cursor over a single element.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SingletonIndexCursor<K, E> extends AbstractIndexCursor<K, E>
+{
+    private boolean beforeFirst = true;
+    private boolean afterLast;
+    private boolean onSingleton;
+    private final IndexEntry<K,E> singleton;
+
+
+    public SingletonIndexCursor( IndexEntry<K,E> singleton )
+    {
+        this.singleton = singleton;
+    }
+
+
+    public boolean available()
+    {
+        return onSingleton;
+    }
+    
+
+    public void before( IndexEntry<K,E> element ) throws Exception
+    {
+        throw new UnsupportedOperationException();
+    }
+    
+    
+    public void beforeValue( Long id, K value ) throws Exception
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    
+    public void afterValue( Long id, K value ) throws Exception
+    {
+        throw new UnsupportedOperationException();
+    }
+    
+
+    public void after( IndexEntry<K,E> element ) throws Exception
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    public void beforeFirst() throws Exception
+    {
+        checkClosed( "()" );
+        beforeFirst = true;
+        afterLast = false;
+        onSingleton = false;
+    }
+
+
+    public void afterLast() throws Exception
+    {
+        checkClosed( "()" );
+        beforeFirst = false;
+        afterLast = true;
+        onSingleton = false;
+    }
+
+
+    public boolean first() throws Exception
+    {
+        checkClosed( "()" );
+        beforeFirst = false;
+        onSingleton = true;
+        afterLast = false;
+        return true;
+    }
+
+
+    public boolean last() throws Exception
+    {
+        checkClosed( "()" );
+        beforeFirst = false;
+        onSingleton = true;
+        afterLast = false;
+        return true;
+    }
+
+
+    public boolean isFirst() throws Exception
+    {
+        checkClosed( "()" );
+        return onSingleton;
+    }
+
+
+    public boolean isLast() throws Exception
+    {
+        checkClosed( "()" );
+        return onSingleton;
+    }
+
+
+    public boolean isAfterLast() throws Exception
+    {
+        checkClosed( "()" );
+        return afterLast;
+    }
+
+
+    public boolean isBeforeFirst() throws Exception
+    {
+        checkClosed( "()" );
+        return beforeFirst;
+    }
+
+
+    public boolean previous() throws Exception
+    {
+        checkClosed( "()" );
+        if ( beforeFirst )
+        {
+            return false;
+        }
+
+        if ( afterLast )
+        {
+            beforeFirst = false;
+            onSingleton = true;
+            afterLast = false;
+            return true;
+        }
+
+        // must be on the singleton
+        beforeFirst = true;
+        onSingleton = false;
+        afterLast = false;
+        return false;
+    }
+
+
+    public boolean next() throws Exception
+    {
+        checkClosed( "()" );
+        if ( beforeFirst )
+        {
+            beforeFirst = false;
+            onSingleton = true;
+            afterLast = false;
+            return true;
+        }
+
+        if ( afterLast )
+        {
+            return false;
+        }
+
+        // must be on the singleton
+        beforeFirst = false;
+        onSingleton = false;
+        afterLast = true;
+        return false;
+    }
+
+
+    public IndexEntry<K,E> get() throws Exception
+    {
+        checkClosed( "()" );
+        if ( onSingleton )
+        {
+            return singleton;
+        }
+
+        if ( beforeFirst )
+        {
+            throw new InvalidCursorPositionException( "Cannot access element if positioned
before first." );
+        }
+        else
+        {
+            throw new InvalidCursorPositionException( "Cannot access element if positioned
after last." );
+        }
+    }
+
+
+    public boolean isElementReused()
+    {
+        return true;
+    }
+}

Propchange: directory/apacheds/branches/bigbang/btree-base/src/main/java/org/apache/directory/server/xdbm/SingletonIndexCursor.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=659841&r1=659840&r2=659841&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
(original)
+++ directory/apacheds/branches/bigbang/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
Sat May 24 08:46:26 2008
@@ -33,6 +33,8 @@
 import org.apache.directory.server.xdbm.search.Optimizer;
 import org.apache.directory.server.xdbm.search.SearchEngine;
 import org.apache.directory.server.xdbm.search.Evaluator;
+import org.apache.directory.server.core.cursor.SingletonCursor;
+import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.entry.ServerEntry;
 
 
@@ -123,6 +125,32 @@
             effectiveBase = new LdapDN( aliasedBase );
         }
         
+        // --------------------------------------------------------------------
+        // Specifically Handle Object Level Scope
+        // --------------------------------------------------------------------
+
+        if ( searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE )
+        {
+            Long effectiveBaseId = baseId;
+            if ( effectiveBase != base )
+            {
+                effectiveBaseId = db.getEntryId( effectiveBase.toNormName() ); 
+            }
+            
+            IndexEntry<Long, ServerEntry> indexEntry = new ForwardIndexEntry<Long,
ServerEntry>();
+            indexEntry.setId( effectiveBaseId );
+            Evaluator<? extends ExprNode, ServerEntry> evaluator = evaluatorBuilder.build(
filter );
+            
+            if ( evaluator.evaluate( indexEntry ) )
+            {
+                return new SingletonIndexCursor<Long,ServerEntry>( indexEntry );
+            }
+            else
+            {
+                return new EmptyIndexCursor<Long, ServerEntry>();
+            }
+        }
+        
         // Add the scope node using the effective base to the filter
         BranchNode root = new AndNode();
         ExprNode node = new ScopeNode( aliasDerefMode, effectiveBase.toString(), 



Mime
View raw message