You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/10/21 00:32:11 UTC
svn commit: r1187106 [1/2] -
/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/partition/index/
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractIndex<K, O, ID> implements Index<K, O, ID>
+{
+ /** 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractIndexCursor<V, Entry, ID> extends AbstractCursor<IndexEntry<V, ID>> implements IndexCursor<V, Entry, ID>
+{
+ /** 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<V, ID> element ) throws Exception
+ {
+ throw new UnsupportedOperationException( getUnsupportedMessage() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void before( IndexEntry<V, ID> 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<IndexEntry<V, ID>> iterator()
+ {
+ return new CursorIterator<IndexEntry<V, ID>>( 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <ID> The ID of the object
+ */
+public abstract class AbstractIndexEntry<V, ID> implements IndexEntry<V, ID>
+{
+ /** 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<V, ID> 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 <K> The key
+ * @param <V> The stored value
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractTable<K,V> implements Table<K,V>
+{
+ /** 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<K> keyComparator;
+
+ /** a value comparator for the values in this Table */
+ protected final Comparator<V> 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<K> keyComparator,
+ Comparator<V> 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<K> getKeyComparator()
+ {
+ return keyComparator;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Comparator<V> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EmptyIndexCursor<K, E, ID> extends AbstractIndexCursor<K, E, ID>
+{
+ /**
+ * {@inheritDoc}
+ */
+ public void before( IndexEntry<K, ID> element ) throws Exception
+ {
+ checkNotClosed( "before()" );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String getUnsupportedMessage()
+ {
+ return UNSUPPORTED_MSG;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void after( IndexEntry<K, ID> 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<K, ID> 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<V, ID> implements IndexComparator<V,ID>
+{
+ private Comparator<V> keyComparator;
+ private Comparator<ID> valueComparator;
+
+ public ForwardIndexComparator( Comparator<V> keyComparator, Comparator<ID> valueComparator )
+ {
+ this.keyComparator = keyComparator;
+ this.valueComparator = valueComparator;
+ }
+
+ public int compare( IndexEntry<V, ID> entry1, IndexEntry<V, ID> 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<V> getValueComparator()
+ {
+ return keyComparator;
+ }
+
+
+ public Comparator<ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <ID> The ID of the object
+ */
+public class ForwardIndexEntry<V, ID> extends AbstractIndexEntry<V, ID>
+{
+ /** The underlying Tuple */
+ private final Tuple<V, ID> tuple = new Tuple<V, ID>();
+
+
+ /**
+ * 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<V, ID> 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<V, ID> getTuple()
+ {
+ return tuple;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clear()
+ {
+ super.clear();
+ tuple.setKey( null );
+ tuple.setValue( null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void copy( IndexEntry<V, ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class GenericIndex<K, O, ID> extends AbstractIndex<K, O, ID>
+{
+ /** 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<K, O, ID> forwardCursor() throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public IndexCursor<K, O, ID> forwardCursor( K key ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public ID forwardLookup( K attrVal ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Cursor<ID> 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<K, O, ID> reverseCursor() throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public IndexCursor<K, O, ID> reverseCursor( ID id ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public K reverseLookup( ID id ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Cursor<K> reverseValueCursor( ID id ) throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public ForwardIndexComparator<K,ID> getForwardIndexEntryComparator()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ReverseIndexComparator<K,ID> 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). <br/>
+ * Cursors over indices can also be gotten to traverse the
+ * values of the index.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <K> The Indexed value type, used to retrieve an element
+ * @param <O> The indexed element type, when retrieved
+ * @param <ID> The unique identifier type in the master table
+ */
+public interface Index<K, O, ID>
+{
+ /** 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.
+ * <br/>
+ * 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.
+ * <br/>
+ * For instance, considering the ObjectClass index for an entry having
+ * three ObjectClasses (top, person, inetOrgPerson), then the reverse
+ * index will contain :
+ * <pre>
+ * [entryId, [top, person, inetOrgPerson]]
+ * </pre>
+ * and the forward index will contain many entries like :
+ * <pre>
+ * [top, [..., entryId, ...]]
+ * [person, [..., entryId, ...]]
+ * [inetOrgPerson, [..., entryId, ...]]
+ * </pre>
+ * 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 <K,ID> 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<K, O, ID> reverseCursor() throws Exception;
+
+
+ IndexCursor<K, O, ID> forwardCursor() throws Exception;
+
+
+ IndexCursor<K, O, ID> reverseCursor( ID id ) throws Exception;
+
+
+ IndexCursor<K, O, ID> forwardCursor( K key ) throws Exception;
+
+
+ Cursor<K> reverseValueCursor( ID id ) throws Exception;
+
+
+ Cursor<ID> 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<K,ID> getForwardIndexEntryComparator();
+
+ public ReverseIndexComparator<K,ID> 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<V,ID> extends Comparator<IndexEntry<V,ID>>
+{
+ public Comparator<V> getValueComparator();
+
+
+ public Comparator<ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface IndexCursor<V, E, ID> extends Cursor<IndexEntry<V, ID>>
+{
+ /**
+ * 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <V> The value stored in the Tuple, associated key for the object
+ * @param <ID> The ID of the object
+ */
+public interface IndexEntry<V, ID>
+{
+ /**
+ * 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<V, ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface MasterTable<ID, E> extends Table<ID, E>
+{
+ /** 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ParentIdAndRdn<ID extends Comparable<ID>> implements Externalizable, Comparable<ParentIdAndRdn<ID>>
+{
+ /** 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<Rdn> 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<ID> that = (ParentIdAndRdn<ID>) 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<ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ParentIdAndRdnComparator<ID extends Comparable<ID>> extends SerializableComparator<ParentIdAndRdn<ID>>
+{
+ /** 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<ID> rdn1, ParentIdAndRdn<ID> 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<V, ID> implements IndexComparator<V,ID>
+{
+ Comparator<V> keyComparator;
+ Comparator<ID> valueComparator;
+
+ public ReverseIndexComparator( Comparator<V> keyComparator, Comparator<ID> valueComparator )
+ {
+ this.keyComparator = keyComparator;
+ this.valueComparator = valueComparator;
+ }
+
+ public int compare( IndexEntry<V, ID> entry1, IndexEntry<V, ID> 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<V> getValueComparator()
+ {
+ return keyComparator;
+ }
+
+
+ public Comparator<ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <V> The value stored in the Tuple, associated key for the Entry
+ * @param <ID> The ID of the Entry
+ */
+public class ReverseIndexEntry<V, ID> extends AbstractIndexEntry<V, ID>
+{
+ /** The underlying Tuple */
+ private final Tuple<ID, V> tuple = new Tuple<ID, V>();
+
+
+ /**
+ * 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<ID, V> 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<V, ID> 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SingletonIndexCursor<V, ID> extends AbstractIndexCursor<V, Entry, ID>
+{
+ private boolean beforeFirst = true;
+ private boolean afterLast;
+ private boolean onSingleton;
+ private final IndexEntry<V, ID> singleton;
+
+
+ public SingletonIndexCursor( IndexEntry<V, ID> 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<V, ID> 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 ) );
+ }
+ }
+}