Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 18F0B73A2 for ; Thu, 20 Oct 2011 22:32:37 +0000 (UTC) Received: (qmail 74745 invoked by uid 500); 20 Oct 2011 22:32:37 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 74717 invoked by uid 500); 20 Oct 2011 22:32:37 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 74710 invoked by uid 99); 20 Oct 2011 22:32:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Oct 2011 22:32:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Oct 2011 22:32:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5418D2388A02 for ; Thu, 20 Oct 2011 22:32:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1187106 [1/2] - /directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ Date: Thu, 20 Oct 2011 22:32:11 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111020223212.5418D2388A02@eris.apache.org> Author: elecharny Date: Thu Oct 20 22:32:10 2011 New Revision: 1187106 URL: http://svn.apache.org/viewvc?rev=1187106&view=rev Log: Re-injected the classes that has been deleted by mistake during the merge. Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndex.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexCursor.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexEntry.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractTable.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/EmptyIndexCursor.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexComparator.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexEntry.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/GenericIndex.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Index.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexComparator.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexCursor.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexEntry.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexNotFoundException.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/MasterTable.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdn.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdnComparator.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexComparator.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexEntry.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Serializer.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/SingletonIndexCursor.java directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Table.java Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndex.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndex.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndex.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndex.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,134 @@ +/* + * 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.core.api.partition.index; + + +import org.apache.directory.server.i18n.I18n; +import org.apache.directory.shared.ldap.model.schema.AttributeType; + + +/** + * A generic index implementation that is just used to hold the index configuration + * parameters (attributeId, cacheSize, wkDirPath). All other methods are not working. + * + * @author Apache Directory Project + */ +public abstract class AbstractIndex implements Index +{ + /** The attribute identifier for this index */ + protected String attributeId; + + /** the attribute type resolved for this JdbmIndex */ + protected AttributeType attributeType; + + /** the size (number of index entries) for the cache */ + protected int cacheSize = DEFAULT_INDEX_CACHE_SIZE; + + /** whether or not this index has been initialized */ + protected boolean initialized; + + /** + * Creates a new instance of AbstractIndex. + * + * @param attributeId the attribute ID + */ + protected AbstractIndex() + { + } + + + /** + * Creates a new instance of AbstractIndex. + * + * @param attributeId the attribute ID + */ + protected AbstractIndex( String attributeId ) + { + this.attributeId = attributeId; + } + + + public String getAttributeId() + { + return attributeId; + } + + + /** + * {@inheritDoc} + */ + public AttributeType getAttribute() + { + return attributeType; + } + + + public void setAttributeId( String attributeId ) + { + protect( "attributeId" ); + this.attributeId = attributeId; + } + + + /** + * {@inheritDoc} + */ + public boolean isDupsEnabled() + { + return !attributeType.isSingleValued(); + } + + + /** + * Gets the size of the index cache in terms of the number of index entries to be cached. + * + * @return the size of the index cache + */ + public int getCacheSize() + { + return cacheSize; + } + + + /** + * Sets the size of the index cache in terms of the number of index entries to be cached. + * + * @param cacheSize the size of the index cache + */ + public void setCacheSize( int cacheSize ) + { + protect( "cacheSize" ); + this.cacheSize = cacheSize; + } + + + /** + * Protects configuration properties from being set after initialization. + * + * @param property the property to protect + */ + protected void protect( String property ) + { + if ( initialized ) + { + throw new IllegalStateException( I18n.err( I18n.ERR_575, property ) ); + } + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexCursor.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexCursor.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexCursor.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,152 @@ +/* + * 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.core.api.partition.index; + + +import java.util.Iterator; + +import org.apache.directory.shared.i18n.I18n; +import org.apache.directory.shared.ldap.model.cursor.AbstractCursor; +import org.apache.directory.shared.ldap.model.cursor.CursorIterator; + + +/** + * An abstract TupleCursor. + * + * @author Apache Directory Project + */ +public abstract class AbstractIndexCursor extends AbstractCursor> implements IndexCursor +{ + /** Tells if there are some element available in the cursor */ + private boolean available = false; + + /** The message used for unsupported operations */ + protected static final String UNSUPPORTED_MSG = "Unsupported operation"; + + /** + * {@inheritDoc} + */ + public boolean available() + { + return available; + } + + + /** + * Gets the message to return for operations that are not supported + * + * @return The Unsupported message + */ + protected abstract String getUnsupportedMessage(); + + + /** + * {@inheritDoc} + */ + public void after( IndexEntry element ) throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + /** + * {@inheritDoc} + */ + public void before( IndexEntry element ) throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + /** + * {@inheritDoc} + */ + public void afterValue( ID id, V value ) throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + /** + * {@inheritDoc} + */ + public void beforeValue( ID id, V value ) throws Exception + { + throw new UnsupportedOperationException( getUnsupportedMessage() ); + } + + + /** + * {@inheritDoc} + */ + protected boolean setAvailable( boolean available ) + { + return this.available = available; + } + + + /** + * {@inheritDoc} + */ + public Iterator> iterator() + { + return new CursorIterator>( this ); + } + + + /** + * {@inheritDoc} + */ + public boolean isAfterLast() throws Exception + { + throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName() + .concat( "." ).concat( "isAfterLast()" ) ) ); + } + + + /** + * {@inheritDoc} + */ + public boolean isBeforeFirst() throws Exception + { + throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName() + .concat( "." ).concat( "isBeforeFirst()" ) ) ); + } + + + /** + * {@inheritDoc} + */ + public boolean isFirst() throws Exception + { + throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName() + .concat( "." ).concat( "isFirst()" ) ) ); + } + + + /** + * {@inheritDoc} + */ + public boolean isLast() throws Exception + { + throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName() + .concat( "." ).concat( "isLast()" ) ) ); + } +} \ No newline at end of file Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexEntry.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexEntry.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractIndexEntry.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,113 @@ +/* + * 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.core.api.partition.index; + +import org.apache.directory.shared.ldap.model.cursor.Tuple; +import org.apache.directory.shared.ldap.model.entry.Entry; + + +/** + * Abstract class managing the object for index entries. + * + * @author Apache Directory Project + * @param The value stored in the Tuple, associated key for the object + * @param The ID of the object + */ +public abstract class AbstractIndexEntry implements IndexEntry +{ + /** The referenced Entry if loaded from the store */ + private Entry entry; + + /** + * Creates an instance of AbstractIndexEntry + * + * @param object The interned Entry + */ + protected AbstractIndexEntry( Entry entry ) + { + this.entry = entry; + } + + + /** + * {@inheritDoc} + */ + public abstract V getValue(); + + + /** + * {@inheritDoc} + */ + public abstract void setValue( V value ); + + + /** + * {@inheritDoc} + */ + public abstract ID getId(); + + + /** + * {@inheritDoc} + */ + public abstract void setId( ID id ); + + + /** + * {@inheritDoc} + */ + public Entry getEntry() + { + return entry; + } + + + /** + * {@inheritDoc} + */ + public abstract Tuple getTuple(); + + + /** + * {@inheritDoc} + */ + public void setEntry( Entry entry ) + { + this.entry = entry; + } + + + /** + * {@inheritDoc} + */ + public void clear() + { + entry = null; + } + + + /** + * {@inheritDoc} + */ + public void copy( IndexEntry entry ) + { + this.entry = entry.getEntry(); + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractTable.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractTable.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractTable.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/AbstractTable.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,114 @@ +/* + * 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.core.api.partition.index; + +import java.io.IOException; +import java.util.Comparator; + +import org.apache.directory.server.i18n.I18n; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; + +/** + * A Abstract Table implementation aggregating the methods comon with all the + * different Table implementation. + * + * @param The key + * @param The stored value + * @author Apache Directory Project + */ +public abstract class AbstractTable implements Table +{ + /** the name of this table */ + protected final String name; + + /** The global SchemaManager */ + protected SchemaManager schemaManager; + + /** a key comparator for the keys in this Table */ + protected final Comparator keyComparator; + + /** a value comparator for the values in this Table */ + protected final Comparator valueComparator; + + /** the current count of entries in this Table */ + protected int count; + + /** + * Create an instance of Table + * + * @param schemaManager The server schemaManager + * @param name the name of the table + * @param keyComparator a key comparator + * @param valueComparator a value comparator + */ + protected AbstractTable( SchemaManager schemaManager, String name, Comparator keyComparator, + Comparator valueComparator ) + { + this.schemaManager = schemaManager; + this.name = name; + + if ( keyComparator == null ) + { + throw new IllegalArgumentException( I18n.err( I18n.ERR_591 ) ); + } + else + { + this.keyComparator = keyComparator; + } + + this.valueComparator = valueComparator; + } + + + /** + * {@inheritDoc} + */ + public Comparator getKeyComparator() + { + return keyComparator; + } + + + /** + * {@inheritDoc} + */ + public Comparator getValueComparator() + { + return valueComparator; + } + + + /** + * {@inheritDoc} + */ + public String getName() + { + return name; + } + + + /** + * {@inheritDoc} + */ + public int count() throws IOException + { + return count; + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/EmptyIndexCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/EmptyIndexCursor.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/EmptyIndexCursor.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/EmptyIndexCursor.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,123 @@ +/* + * 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.core.api.partition.index; + + +import org.apache.directory.server.i18n.I18n; +import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException; + + +/** + * An empty Cursor implementation. + * + * @author Apache Directory Project + */ +public class EmptyIndexCursor extends AbstractIndexCursor +{ + /** + * {@inheritDoc} + */ + public void before( IndexEntry element ) throws Exception + { + checkNotClosed( "before()" ); + } + + + /** + * {@inheritDoc} + */ + protected String getUnsupportedMessage() + { + return UNSUPPORTED_MSG; + } + + + /** + * {@inheritDoc} + */ + public void after( IndexEntry element ) throws Exception + { + checkNotClosed( "after()" ); + } + + + public void beforeFirst() throws Exception + { + checkNotClosed( "beforeFirst()" ); + } + + + public void afterLast() throws Exception + { + checkNotClosed( "afterLast()" ); + } + + + public boolean first() throws Exception + { + checkNotClosed( "first()" ); + return false; + } + + + public boolean last() throws Exception + { + checkNotClosed( "last()" ); + return false; + } + + + public boolean previous() throws Exception + { + checkNotClosed( "previous()" ); + return false; + } + + + public boolean next() throws Exception + { + checkNotClosed( "next()" ); + return false; + } + + + public IndexEntry get() throws Exception + { + checkNotClosed( "get()" ); + throw new InvalidCursorPositionException( I18n.err( I18n.ERR_703 ) ); + } + + + /** + * {@inheritDoc} + */ + public void afterValue( ID id, K indexValue ) throws Exception + { + checkNotClosed( "after()" ); + } + + + /** + * {@inheritDoc} + */ + public void beforeValue( ID id, K indexValue ) throws Exception + { + checkNotClosed( "after()" ); + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexComparator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexComparator.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexComparator.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexComparator.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,59 @@ + +package org.apache.directory.server.core.api.partition.index; + +import java.util.Comparator; + +public class ForwardIndexComparator implements IndexComparator +{ + private Comparator keyComparator; + private Comparator valueComparator; + + public ForwardIndexComparator( Comparator keyComparator, Comparator valueComparator ) + { + this.keyComparator = keyComparator; + this.valueComparator = valueComparator; + } + + public int compare( IndexEntry entry1, IndexEntry entry2 ) + { + V value1 = entry1.getValue(); + V value2 = entry2.getValue(); + ID id1 = entry1.getId(); + ID id2 = entry2.getId(); + + int result = keyComparator.compare( value1, value2 ); + + if ( result == 0 ) + { + if ( id1 == id2 ) + { + result = 0; + } + else if ( id1 == null ) + { + result = -1; + } + else if ( id2 == null ) + { + result = 1; + } + else + { + result = valueComparator.compare( id1, id2 ); + } + } + + return result; + } + + public Comparator getValueComparator() + { + return keyComparator; + } + + + public Comparator getIDComparator() + { + return valueComparator; + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexEntry.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexEntry.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ForwardIndexEntry.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,146 @@ +/* + * 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.core.api.partition.index; + +import org.apache.directory.shared.ldap.model.cursor.Tuple; +import org.apache.directory.shared.ldap.model.entry.Entry; + + +/** + * An index id value pair based on a Tuple which can optionally reference the + * indexed Entry if one has already been loaded. + * + * @author Apache Directory Project + * @param The value stored in the Tuple, associated key for the object + * @param The ID of the object + */ +public class ForwardIndexEntry extends AbstractIndexEntry +{ + /** The underlying Tuple */ + private final Tuple tuple = new Tuple(); + + + /** + * Creates a ForwardIndexEntry instance + */ + public ForwardIndexEntry() + { + super( null ); + } + + + /** + * Sets the key value tuple represented by this ForwardIndexEntry optionally + * setting the Entry associated with the id if one was loaded from the + * master table. + * + * @param tuple the tuple for the ForwardIndexEntry + * @param entry the resuscitated Entry if any + */ + public void setTuple( Tuple tuple, Entry entry ) + { + setEntry( entry ); + this.tuple.setKey( tuple.getKey() ); + this.tuple.setValue( tuple.getValue() ); + } + + + /** + * {@inheritDoc} + */ + public ID getId() + { + return tuple.getValue(); + } + + + /** + * {@inheritDoc} + */ + public V getValue() + { + return tuple.getKey(); + } + + + /** + * {@inheritDoc} + */ + public void setId( ID id ) + { + tuple.setValue( id ); + } + + + /** + * {@inheritDoc} + */ + public void setValue( V value ) + { + tuple.setKey( value ); + } + + + /** + * {@inheritDoc} + */ + public Tuple getTuple() + { + return tuple; + } + + + /** + * {@inheritDoc} + */ + public void clear() + { + super.clear(); + tuple.setKey( null ); + tuple.setValue( null ); + } + + + /** + * {@inheritDoc} + */ + public void copy( IndexEntry entry ) + { + super.copy( entry ); + tuple.setKey( entry.getValue() ); + tuple.setValue( entry.getId() ); + } + + + /** + * {@inheritDoc} + */ + public String toString() + { + StringBuilder buf = new StringBuilder(); + buf.append( "ForwardIndexEntry[ " ); + buf.append( tuple.getKey() ); + buf.append( ", " ); + buf.append( tuple.getValue() ); + buf.append( " ]" ); + + return buf.toString(); + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/GenericIndex.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/GenericIndex.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/GenericIndex.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/GenericIndex.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,295 @@ +/* + * 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.core.api.partition.index; + + +import java.net.URI; + +import org.apache.directory.shared.ldap.model.cursor.Cursor; +import org.apache.directory.shared.ldap.model.schema.AttributeType; + + +/** + * A generic index implementation that is just used to hold the index configuration + * parameters (attributeId, cacheSize, wkDirPath). All other methods are not working. + * + * @author Apache Directory Project + */ +public class GenericIndex extends AbstractIndex +{ + /** Index working directory */ + protected URI wkDirPath; + + + /** + * Creates a new instance of GenericIndex. + * + * @param attributeId the attribute ID + */ + public GenericIndex( String attributeId ) + { + this( attributeId, DEFAULT_INDEX_CACHE_SIZE, null ); + } + + + /** + * Creates a new instance of GenericIndex. + * + * @param attributeId the attribute ID + * @param cacheSize the cache size + */ + public GenericIndex( String attributeId, int cacheSize ) + { + this( attributeId, cacheSize, null ); + } + + + /** + * Creates a new instance of GenericIndex. + * + * @param attributeId the attribute ID + * @param cacheSize the cache size + * @param wkDirPath the working directory + */ + public GenericIndex( String attributeId, int cacheSize, URI wkDirPath ) + { + super( attributeId ); + this.cacheSize = cacheSize; + this.wkDirPath = wkDirPath; + } + + + public void add( K attrVal, ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public void close() throws Exception + { + throw new UnsupportedOperationException(); + } + + + public int count() throws Exception + { + throw new UnsupportedOperationException(); + } + + + public int count( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public void drop( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public void drop( K attrVal, ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public IndexCursor forwardCursor() throws Exception + { + throw new UnsupportedOperationException(); + } + + + public IndexCursor forwardCursor( K key ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public ID forwardLookup( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public Cursor forwardValueCursor( K key ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forward( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forward( K attrVal, ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverse( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverse( ID id, K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forwardGreaterOrEq( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forwardGreaterOrEq( K attrVal, ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverseGreaterOrEq( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverseGreaterOrEq( ID id, K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forwardLessOrEq( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean forwardLessOrEq( K attrVal, ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverseLessOrEq( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public boolean reverseLessOrEq( ID id, K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public AttributeType getAttribute() + { + throw new UnsupportedOperationException(); + } + + + public K getNormalized( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public URI getWkDirPath() + { + return wkDirPath; + } + + + public int greaterThanCount( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public int lessThanCount( K attrVal ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public IndexCursor reverseCursor() throws Exception + { + throw new UnsupportedOperationException(); + } + + + public IndexCursor reverseCursor( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public K reverseLookup( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public Cursor reverseValueCursor( ID id ) throws Exception + { + throw new UnsupportedOperationException(); + } + + + public ForwardIndexComparator getForwardIndexEntryComparator() + { + throw new UnsupportedOperationException(); + } + + public ReverseIndexComparator getReverseIndexEntryComparator() + { + throw new UnsupportedOperationException(); + } + + + public void setWkDirPath( URI wkDirPath ) + { + this.wkDirPath = wkDirPath; + } + + + public void sync() throws Exception + { + throw new UnsupportedOperationException(); + } + + + /** + * {@inheritDoc} + */ + public boolean isDupsEnabled() + { + return false; + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Index.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Index.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Index.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Index.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,277 @@ +/* + * 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.core.api.partition.index; + + +import java.net.URI; + +import org.apache.directory.shared.ldap.model.cursor.Cursor; +import org.apache.directory.shared.ldap.model.schema.AttributeType; + + +/** + * An index used to retrieve elements into the master table. Each stored element that is + * indexed has a unique identifier (ID). We may have more than one element associated with + * a value (K). We may cache the retrieved element (O).
+ * Cursors over indices can also be gotten to traverse the + * values of the index. + * + * @author Apache Directory Project + * @param The Indexed value type, used to retrieve an element + * @param The indexed element type, when retrieved + * @param The unique identifier type in the master table + */ +public interface Index +{ + /** The default cache size (ie, the number of elements we stored in the cache) */ + int DEFAULT_INDEX_CACHE_SIZE = 100; + + + // ----------------------------------------------------------------------- + // C O N F I G U R A T I O N M E T H O D S + // ----------------------------------------------------------------------- + + /** + * Gets the attribute identifier set at configuration time for this index which may not + * be the OID but an alias name for the attributeType associated with this Index + * + * @return configured attribute oid or alias name + */ + String getAttributeId(); + + + /** + * Sets the attribute identifier set at configuration time for this index which may not + * be the OID but an alias name for the attributeType associated with this Index + * + * @param attributeId configured attribute oid or alias name + */ + void setAttributeId( String attributeId ); + + + /** + * Gets the size of the index cache in terms of the number of index entries to be cached. + * + * @return the size of the index cache + */ + int getCacheSize(); + + + /** + * Sets the size of the index cache in terms of the number of index entries to be cached. + * + * @param cacheSize the size of the index cache + */ + void setCacheSize( int cacheSize ); + + + /** + * Sets the working directory path to something other than the default. Sometimes more + * performance is gained by locating indices on separate disk spindles. + * + * @param wkDirPath optional working directory path + */ + void setWkDirPath( URI wkDirPath ); + + + /** + * Gets the working directory path to something other than the default. Sometimes more + * performance is gained by locating indices on separate disk spindles. + * + * @return optional working directory path + */ + URI getWkDirPath(); + + + // ----------------------------------------------------------------------- + // E N D C O N F I G U R A T I O N M E T H O D S + // ----------------------------------------------------------------------- + + /** + * Gets the attribute this Index is built upon. + * + * @return the id of the Index's attribute + */ + AttributeType getAttribute(); + + + /** + * Gets the normalized value for an attribute. + * + * @param attrVal the user provided value to normalize + * @return the normalized value. + * @throws Exception if something goes wrong. + */ + K getNormalized( K attrVal ) throws Exception; + + + /** + * Gets the total scan count for this index. + * + * @return the number of key/value pairs in this index + * @throws Exception on failure to access index db files + */ + int count() throws Exception; + + + /** + * Gets the scan count for the occurrence of a specific attribute value + * within the index. + * + * @param attrVal the value of the attribute to get a scan count for + * @return the number of key/value pairs in this index with the value value + * @throws Exception on failure to access index db files + */ + int count( K attrVal ) throws Exception; + + + int greaterThanCount( K attrVal ) throws Exception; + + + int lessThanCount( K attrVal ) throws Exception; + + + ID forwardLookup( K attrVal ) throws Exception; + + + K reverseLookup( ID id ) throws Exception; + + + /** + * Add an entry into the index, associated with the element ID. The added + * value is the key to retrieve the element having the given ID. + * + * @param attrVal The added value + * @param id The element ID pointed by the added value + * @throws Exception If the addition can't be done + */ + void add( K attrVal, ID id ) throws Exception; + + + /** + * Remove all the reference to an entry from the index. + *
+ * As an entry might be referenced more than once in the forward index, + * depending on which index we are dealing with, we need to iterate + * over all the values contained into the reverse index for this entryId. + *
+ * For instance, considering the ObjectClass index for an entry having + * three ObjectClasses (top, person, inetOrgPerson), then the reverse + * index will contain : + *
+     * [entryId, [top, person, inetOrgPerson]]
+     * 
+ * and the forward index will contain many entries like : + *
+     * [top, [..., entryId, ...]]
+     * [person,  [..., entryId, ...]]
+     * [inetOrgPerson,  [..., entryId, ...]]
+     * 
+ * So dropping the entryId means that we must first get all the values from + * the reverse index (and we will get [top, person, inetOrgPerson]) then to + * iterate through all those values to remove entryId from the associated + * list of entryIds. + * + * @param entryId The master table entry ID to remove + * @throws Exception + */ + void drop( ID entryId ) throws Exception; + + + /** + * Remove the pair from the index for the given value and id. + * + * @param attrVal The value we want to remove from the index + * @param id The associated ID + * @throws Exception If the removal can't be done + */ + void drop( K attrVal, ID id ) throws Exception; + + + IndexCursor reverseCursor() throws Exception; + + + IndexCursor forwardCursor() throws Exception; + + + IndexCursor reverseCursor( ID id ) throws Exception; + + + IndexCursor forwardCursor( K key ) throws Exception; + + + Cursor reverseValueCursor( ID id ) throws Exception; + + + Cursor forwardValueCursor( K key ) throws Exception; + + + boolean forward( K attrVal ) throws Exception; + + + boolean forward( K attrVal, ID id ) throws Exception; + + + boolean reverse( ID id ) throws Exception; + + + boolean reverse( ID id, K attrVal ) throws Exception; + + + boolean forwardGreaterOrEq( K attrVal ) throws Exception; + + + boolean forwardGreaterOrEq( K attrVal, ID id ) throws Exception; + + + boolean reverseGreaterOrEq( ID id ) throws Exception; + + + boolean reverseGreaterOrEq( ID id, K attrVal ) throws Exception; + + + boolean forwardLessOrEq( K attrVal ) throws Exception; + + + boolean forwardLessOrEq( K attrVal, ID id ) throws Exception; + + + boolean reverseLessOrEq( ID id ) throws Exception; + + + boolean reverseLessOrEq( ID id, K attrVal ) throws Exception; + + public ForwardIndexComparator getForwardIndexEntryComparator(); + + public ReverseIndexComparator getReverseIndexEntryComparator(); + + void close() throws Exception; + + + void sync() throws Exception; + + + /** + * tells whether the Index implementation supports storing duplicate keys + * + * @return true if duplicate keys are allowed false otherwise + */ + boolean isDupsEnabled(); +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexComparator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexComparator.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexComparator.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexComparator.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,12 @@ + +package org.apache.directory.server.core.api.partition.index; + +import java.util.Comparator; + +public interface IndexComparator extends Comparator> +{ + public Comparator getValueComparator(); + + + public Comparator getIDComparator(); +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexCursor.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexCursor.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexCursor.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,58 @@ +/* + * 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.core.api.partition.index; + + +import org.apache.directory.shared.ldap.model.cursor.Cursor; + + +/** + * A Cursor introducing new advance methods designed to reduce some + * inefficiencies encountered when scanning over Tuples. + * + * @author Apache Directory Project + */ +public interface IndexCursor extends Cursor> +{ + /** + * An alternative to calling before(IndexEntry) which often may require + * wrapping an id and value in a newly created IndexEntry object that may + * be an unnecessary object creation. Some implementations may not + * support this operation and may throw an UnsupportedOperationEception. + * + * @param id the id for the entry + * @param indexValue the value to advance just before + * @throws Exception if there are faults performing this operation + */ + void beforeValue( ID id, V indexValue ) throws Exception; + + + /** + * An alternative to calling after(IndexEntry) which often may require + * wrapping an id and value in a newly created IndexEntry object that may + * be an unnecessary object creation. Some implementations may not + * support this operation and may throw an UnsupportedOperationEception. + * + * @param id the id for the entry + * @param indexValue the value to advance just after the last value + * @throws Exception if there are faults performing this operation + */ + void afterValue( ID id, V indexValue ) throws Exception; +} \ No newline at end of file Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexEntry.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexEntry.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexEntry.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,105 @@ +/* + * 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.core.api.partition.index; + +import org.apache.directory.shared.ldap.model.cursor.Tuple; +import org.apache.directory.shared.ldap.model.entry.Entry; + + +/** + * Interface for index entries. An index entry associate an Entry with + * a value (the key) and the Entry ID in the table where it's stored. The Entry + * may be present in this instance once we read it from the table. + * + * @author Apache Directory Project + * @param The value stored in the Tuple, associated key for the object + * @param The ID of the object + */ +public interface IndexEntry +{ + /** + * Gets the value referred to by this IndexEntry. + * + * @return the value of the Entry referred to + */ + V getValue(); + + + /** + * Sets the value referred to by this IndexEntry. + * + * @param value the value of the Entry referred to + */ + void setValue( V value ); + + + /** + * Gets the id of the indexed Entry. + * + * @return the id of the indexed Entry + */ + ID getId(); + + + /** + * Sets the id of the indexed.Entry + * + * @param id the id of the indexed Entry + */ + void setId( ID id ); + + + /** + * Gets the Entry indexed if found. + * + * @return the indexed Entry + */ + Entry getEntry(); + + + /** + * Gets access to the underlying tuple. + * + * @return the underlying tuple + */ + Tuple getTuple(); + + + /** + * Sets the indexed Entry. + * + * @param entry the indexed Entry + */ + void setEntry( Entry entry ); + + + /** + * Clears the id, value and Entry in this IndexEntry. + */ + void clear(); + + + /** + * Copies the values of another IndexEntry into this IndexEntry. + * + * @param entry the entry to copy fields of + */ + void copy( IndexEntry entry ); +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexNotFoundException.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexNotFoundException.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexNotFoundException.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/IndexNotFoundException.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,90 @@ +/* + * 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.core.api.partition.index; + + +import javax.naming.NamingException; + +import org.apache.directory.server.i18n.I18n; + + +/** + * NamingException for missing indicies if full table scans are disallowed. + * + * @author Apache Directory Project + */ +public class IndexNotFoundException extends NamingException +{ + private static final long serialVersionUID = 3906088970608981815L; + + /** the name of the index that was not found */ + private final String indexName; + + + /** + * Constructs an Exception with a detailed message. + * + * @param indexName the name of the index that was not found + */ + public IndexNotFoundException( String indexName ) + { + super( I18n.err( I18n.ERR_704, indexName ) ); + this.indexName = indexName; + } + + + /** + * Constructs an Exception with a detailed message. + * + * @param message the message associated with the exception. + * @param indexName the name of the index that was not found + */ + public IndexNotFoundException( String message, String indexName ) + { + super( message ); + this.indexName = indexName; + } + + + /** + * Constructs an Exception with a detailed message and a root cause + * exception. + * + * @param message the message associated with the exception. + * @param indexName the name of the index that was not found + * @param rootCause the root cause of this exception + */ + public IndexNotFoundException( String message, String indexName, Throwable rootCause ) + { + this( message, indexName ); + setRootCause( rootCause ); + } + + + /** + * Gets the name of the attribute the index was missing for. + * + * @return the name of the attribute the index was missing for. + */ + public String getIndexName() + { + return indexName; + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/MasterTable.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/MasterTable.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/MasterTable.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/MasterTable.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,55 @@ +/* + * 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.core.api.partition.index; + + +/** + * A master table used to store indexable entries. + * + * @author Apache Directory Project + */ +public interface MasterTable extends Table +{ + /** the base name for the db file for this table */ + String DBF = "master"; + + /** the sequence key - stores last sequence value in the admin table */ + String SEQPROP_KEY = "__sequence__"; + + + /** + * Gets the next value from the sequence of this MasterTable. This has + * the side-effect of incrementing the sequence values permanently. + * + * @param entry the entry in case the id is derived from the entry. + * @return the current value of this MasterTable's sequence incremented by one + * @throws Exception on failure to update the id sequence + */ + ID getNextId( E entry ) throws Exception; + + + /** + * Resets the root ID to 0, this method should be called after deleting the + * context entry of the partition + * + * @throws Exception in case of any failure while resetting the root id value + */ + void resetCounter() throws Exception; +} \ No newline at end of file Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdn.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdn.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdn.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdn.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,267 @@ +/* + * 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.core.api.partition.index; + + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Arrays; +import java.util.List; + +import org.apache.directory.shared.ldap.model.name.Rdn; + + +/** + * A wrapper for the tuple of parentId and Rdn, used for the Rdn index. + * + * If the refered entry is a ContextEntry, we may have more than one Rdn stored + * + * @author Apache Directory Project + */ +public class ParentIdAndRdn> implements Externalizable, Comparable> +{ + /** The entry ID */ + protected ID parentId; + + /** The list of Rdn for this instance */ + protected Rdn[] rdns; + + + /** + * Serializable constructor. + */ + public ParentIdAndRdn() + { + } + + + /** + * Creates a new instance of ParentIdAndRdn. + * + * @param parentId the parent ID + * @param rdns the RDNs + */ + public ParentIdAndRdn( ID parentId, Rdn... rdns ) + { + this.parentId = parentId; + this.rdns = rdns; + } + + + /** + * Creates a new instance of ParentIdAndRdn. + * + * @param parentId the parent ID + * @param rdns the RDNs + */ + public ParentIdAndRdn( ID parentId, List rdns ) + { + this.parentId = parentId; + this.rdns = rdns.toArray( new Rdn[rdns.size()] ); + } + + + /** + * Gets the parent ID. + * + * @return the parent ID + */ + public ID getParentId() + { + return parentId; + } + + + /** + * Sets the parent ID. + * + * @param parentId the new parent ID + */ + public void setParentId( ID parentId ) + { + this.parentId = parentId; + } + + + /** + * Gets the RDNs. + * + * @return the RDNs + */ + public Rdn[] getRdns() + { + return rdns; + } + + + /** + * Sets the Rdn. + * + * @param rdns the new Rdn + */ + public void setRdns( Rdn[] rdns ) + { + this.rdns = rdns; + } + + + @Override + public int hashCode() + { + int h = 37; + h = h*17 + ( ( parentId == null ) ? 0 : parentId.hashCode() ); + h = h*17 + Arrays.hashCode( rdns ); + + return h; + } + + + @Override + @SuppressWarnings("unchecked") + public boolean equals( Object obj ) + { + // Shortcut + if ( this == obj ) + { + return true; + } + + if ( !( obj instanceof ParentIdAndRdn ) ) + { + return false; + } + + ParentIdAndRdn that = (ParentIdAndRdn) obj; + + if ( rdns == null ) + { + return that.rdns == null; + } + else if ( that.rdns == null ) + { + return false; + } + + if ( rdns.length != that.rdns.length ) + { + return false; + } + + for ( int i = 0; i < rdns.length; i++ ) + { + if ( !rdns[i].equals( that.rdns[i] ) ) + { + return false; + } + } + + return true; + } + + + /** + * {@inheritDoc} + */ + public int compareTo( ParentIdAndRdn that ) + { + int val = this.rdns.length - that.rdns.length; + + if ( val != 0 ) + { + return val; + } + + for ( int i = 0; i < this.rdns.length; i++ ) + { + val = this.rdns[i].getNormName().compareTo( that.rdns[i].getNormName() ); + + if ( val != 0 ) + { + return val; + } + } + + val = this.getParentId().compareTo( that.getParentId() ); + + return val; + } + + + public void writeExternal( ObjectOutput out ) throws IOException + { + out.writeObject( parentId ); + out.writeInt( rdns.length ); + + for ( Rdn rdn : rdns ) + { + rdn.writeExternal( out ); + } + } + + + @SuppressWarnings("unchecked") + public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException + { + parentId = ( ID ) in.readObject(); + int size = in.readInt(); + rdns = new Rdn[size]; + + for ( int i = 0; i < size; i++ ) + { + Rdn rdn = new Rdn(); + rdn.readExternal( in ); + rdns[i] = rdn; + } + } + + + /** + * {@inheritDoc} + */ + public String toString() + { + StringBuilder sb = new StringBuilder(); + + sb.append( "ParentIdAndRdn<" ); + sb.append( parentId ).append( ", '" ); + + boolean isFirst = true; + + for ( Rdn rdn : rdns ) + { + if ( isFirst ) + { + isFirst = false; + } + else + { + sb.append( "," ); + } + + sb.append( rdn ); + } + + sb.append( "'>" ); + + return sb.toString(); + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdnComparator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdnComparator.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdnComparator.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ParentIdAndRdnComparator.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,56 @@ +/* + * 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.core.api.partition.index; + + +import org.apache.directory.shared.ldap.model.schema.comparators.SerializableComparator; + + +/** + * A comparator used to compare {@link ParentIdAndRdn} stored in the Rdn index. + * + * @author Apache Directory Project + */ +public class ParentIdAndRdnComparator> extends SerializableComparator> +{ + /** The serial version UID */ + private static final long serialVersionUID = 2L; + + /** + * Creates a new instance of ParentIdAndRdnComparator. + * + * @param matchingRuleOid The associated MatchingRule + */ + public ParentIdAndRdnComparator( String matchingRuleOid ) + { + super( matchingRuleOid ); + } + + + /** + * {@inheritDoc} + */ + @Override + public int compare( ParentIdAndRdn rdn1, ParentIdAndRdn rdn2 ) + { + return rdn1.compareTo( rdn2 ); + } +} \ No newline at end of file Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexComparator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexComparator.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexComparator.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexComparator.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,59 @@ + +package org.apache.directory.server.core.api.partition.index; + +import java.util.Comparator; + +public class ReverseIndexComparator implements IndexComparator +{ + Comparator keyComparator; + Comparator valueComparator; + + public ReverseIndexComparator( Comparator keyComparator, Comparator valueComparator ) + { + this.keyComparator = keyComparator; + this.valueComparator = valueComparator; + } + + public int compare( IndexEntry entry1, IndexEntry entry2 ) + { + V value1 = entry1.getValue(); + V value2 = entry2.getValue(); + ID id1 = entry1.getId(); + ID id2 = entry2.getId(); + + int result = valueComparator.compare( id1, id2 ); + + if ( result == 0 ) + { + if ( value1 == value2 ) + { + result = 0; + } + else if ( value1 == null ) + { + result = -1; + } + else if ( value2 == null ) + { + result = 1; + } + else + { + result = keyComparator.compare( value1, value2 ); + } + } + + return result; + } + + public Comparator getValueComparator() + { + return keyComparator; + } + + + public Comparator getIDComparator() + { + return valueComparator; + } +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexEntry.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexEntry.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexEntry.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/ReverseIndexEntry.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,147 @@ +/* + * 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.core.api.partition.index; + +import org.apache.directory.shared.ldap.model.cursor.Tuple; +import org.apache.directory.shared.ldap.model.entry.Entry; + + +/** + * An index id value pair which can optionally reference the indexed Entry + * if one has already been loaded. + * + * @author Apache Directory Project + * @param The value stored in the Tuple, associated key for the Entry + * @param The ID of the Entry + */ +public class ReverseIndexEntry extends AbstractIndexEntry +{ + /** The underlying Tuple */ + private final Tuple tuple = new Tuple(); + + + /** + * Creates a ForwardIndexEntry instance + */ + public ReverseIndexEntry() + { + super( null ); + } + + + + /** + * Sets the Tuple value represented by this ReverseIndexEntry optionally + * setting the Entry associated with the id if one was loaded from the + * master table. + * + * @param tuple the tuple for the ReverseIndexEntry + * @param obj the resusitated Entry that is indexed if any + */ + public void setTuple( Tuple tuple, Entry entry ) + { + setEntry( entry ); + this.tuple.setKey( tuple.getKey() ); + this.tuple.setValue( tuple.getValue() ); + } + + + /** + * {@inheritDoc} + */ + public ID getId() + { + return tuple.getKey(); + } + + + /** + * {@inheritDoc} + */ + public V getValue() + { + return tuple.getValue(); + } + + + /** + * {@inheritDoc} + */ + public void setId( ID id ) + { + tuple.setKey( id ); + } + + + /** + * {@inheritDoc} + */ + public void setValue( V key ) + { + tuple.setValue( key ); + } + + + /** + * {@inheritDoc} + */ + public Tuple getTuple() + { + return tuple; + } + + + /** + * {@inheritDoc} + */ + public void clear() + { + super.clear(); + tuple.setKey( null ); + tuple.setValue( null ); + } + + + /** + * {@inheritDoc} + */ + public void copy( IndexEntry entry ) + { + setEntry( entry.getEntry() ); + tuple.setKey( entry.getId() ); + tuple.setValue( entry.getValue() ); + } + + + /** + * {@inheritDoc} + */ + public String toString() + { + StringBuilder buf = new StringBuilder(); + buf.append( "ReverseIndexEntry[ " ); + buf.append( tuple.getValue() ); + buf.append( ", " ); + buf.append( tuple.getKey() ); + buf.append( " ]" ); + + return buf.toString(); + } +} \ No newline at end of file Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Serializer.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Serializer.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Serializer.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/Serializer.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,25 @@ + +package org.apache.directory.server.core.api.partition.index; + +import java.io.IOException; +import java.io.Serializable; + +public interface Serializer +{ + /** + * Serialize the content of an object into a byte array. + * + * @param obj Object to serialize + * @return a byte array representing the object's state + */ + public byte[] serialize( Object obj ) throws IOException; + + + /** + * Deserialize the content of an object from a byte array. + * + * @param serialized Byte array representation of the object + * @return deserialized object + */ + public Object deserialize( byte[] serialized ) throws IOException; +} Added: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/SingletonIndexCursor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/SingletonIndexCursor.java?rev=1187106&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/SingletonIndexCursor.java (added) +++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/SingletonIndexCursor.java Thu Oct 20 22:32:10 2011 @@ -0,0 +1,193 @@ +/* + * 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.core.api.partition.index; + + +import org.apache.directory.server.i18n.I18n; +import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException; +import org.apache.directory.shared.ldap.model.entry.Entry; + + +/** + * A Cursor over a single element. + * + * @author Apache Directory Project + */ +public class SingletonIndexCursor extends AbstractIndexCursor +{ + private boolean beforeFirst = true; + private boolean afterLast; + private boolean onSingleton; + private final IndexEntry singleton; + + + public SingletonIndexCursor( IndexEntry singleton ) + { + this.singleton = singleton; + } + + + /** + * {@inheritDoc} + */ + protected String getUnsupportedMessage() + { + return UNSUPPORTED_MSG; + } + + + public boolean available() + { + return onSingleton; + } + + + public void beforeFirst() throws Exception + { + checkNotClosed( "()" ); + beforeFirst = true; + afterLast = false; + onSingleton = false; + } + + + public void afterLast() throws Exception + { + checkNotClosed( "()" ); + beforeFirst = false; + afterLast = true; + onSingleton = false; + } + + + public boolean first() throws Exception + { + checkNotClosed( "()" ); + beforeFirst = false; + onSingleton = true; + afterLast = false; + return true; + } + + + public boolean last() throws Exception + { + checkNotClosed( "()" ); + beforeFirst = false; + onSingleton = true; + afterLast = false; + return true; + } + + + public boolean isFirst() throws Exception + { + checkNotClosed( "()" ); + return onSingleton; + } + + + public boolean isLast() throws Exception + { + checkNotClosed( "()" ); + return onSingleton; + } + + + public boolean isAfterLast() throws Exception + { + checkNotClosed( "()" ); + return afterLast; + } + + + public boolean isBeforeFirst() throws Exception + { + checkNotClosed( "()" ); + return beforeFirst; + } + + + public boolean previous() throws Exception + { + checkNotClosed( "()" ); + 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 + { + checkNotClosed( "()" ); + 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 get() throws Exception + { + checkNotClosed( "()" ); + + if ( onSingleton ) + { + return singleton; + } + + if ( beforeFirst ) + { + throw new InvalidCursorPositionException( I18n.err( I18n.ERR_705 ) ); + } + else + { + throw new InvalidCursorPositionException( I18n.err( I18n.ERR_706 ) ); + } + } +}