|
|
Modified:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL:
http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
---
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
(original)
+++
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
Tue Jan 8 16:41:31 2008
@@ -27,9 +27,9 @@
import org.apache.directory.server.core.partition.Oid;
import org.apache.directory.server.core.partition.impl.btree.Index;
import org.apache.directory.server.core.partition.impl.btree.IndexAssertion;
-import
org.apache.directory.server.core.partition.impl.btree.IndexAssertionEnumeration;
import
org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
import org.apache.directory.server.core.partition.impl.btree.IndexRecord;
+import org.apache.directory.server.core.cursor.Cursor;
import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
import org.apache.directory.server.schema.registries.OidRegistry;
import org.apache.directory.server.schema.registries.Registries;
@@ -45,6 +45,7 @@
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.util.AttributeUtils;
import org.apache.directory.shared.ldap.util.NamespaceTools;
+import org.apache.directory.shared.ldap.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -93,19 +94,19 @@
private boolean isSyncOnWrite = true;
/** the normalized distinguished name index */
- private JdbmIndex ndnIdx;
+ private JdbmIndex<String> ndnIdx;
/** the user provided distinguished name index */
- private JdbmIndex updnIdx;
+ private JdbmIndex<String> updnIdx;
/** the attribute existance index */
private JdbmIndex existanceIdx;
/** the parent child relationship index */
- private JdbmIndex hierarchyIdx;
+ private JdbmIndex<Long> hierarchyIdx;
/** the one level scope alias index */
- private JdbmIndex oneAliasIdx;
+ private JdbmIndex<Long> oneAliasIdx;
/** the subtree scope alias index */
- private JdbmIndex subAliasIdx;
+ private JdbmIndex<Long> subAliasIdx;
/** a system index on aliasedObjectName attribute */
- private JdbmIndex aliasIdx;
+ private JdbmIndex<String> aliasIdx;
/** Two static declaration to avoid lookup all over the code */
private static AttributeType OBJECT_CLASS_AT;
@@ -270,10 +271,11 @@
*
* @param oidRegistry an OID registry to resolve numeric identifiers from
names
* @param attributeTypeRegistry an attributeType specification registry to
lookup type specs
- * @throws NamingException on failure to create proper database files
+ * @throws NamingException on failure to lookup elements in registries
+ * @throws IOException on failure to create database files
*/
public synchronized void init( OidRegistry oidRegistry,
AttributeTypeRegistry attributeTypeRegistry )
- throws NamingException
+ throws IOException, NamingException
{
this.oidRegistry = oidRegistry;
this.attributeTypeRegistry = attributeTypeRegistry;
@@ -335,7 +337,7 @@
}
- private void setupSystemIndices() throws NamingException
+ private void setupSystemIndices() throws NamingException, IOException
{
if ( systemIndices.size() > 0 )
{
@@ -351,7 +353,7 @@
if ( ndnIdx == null )
{
- ndnIdx = new JdbmIndex();
+ ndnIdx = new JdbmIndex<String>();
ndnIdx.setAttributeId( Oid.NDN );
systemIndices.put( Oid.NDN, ndnIdx );
ndnIdx.init( attributeTypeRegistry.lookup( Oid.NDN ),
workingDirectory );
@@ -359,7 +361,7 @@
if ( updnIdx == null )
{
- updnIdx = new JdbmIndex();
+ updnIdx = new JdbmIndex<String>();
updnIdx.setAttributeId( Oid.UPDN );
systemIndices.put( Oid.UPDN, updnIdx );
updnIdx.init( attributeTypeRegistry.lookup( Oid.UPDN ),
workingDirectory );
@@ -375,7 +377,7 @@
if ( hierarchyIdx == null )
{
- hierarchyIdx = new JdbmIndex();
+ hierarchyIdx = new JdbmIndex<Long>();
hierarchyIdx.setAttributeId( Oid.HIERARCHY );
systemIndices.put( Oid.HIERARCHY, hierarchyIdx );
hierarchyIdx.init( attributeTypeRegistry.lookup( Oid.HIERARCHY ),
workingDirectory );
@@ -383,7 +385,7 @@
if ( oneAliasIdx == null )
{
- oneAliasIdx = new JdbmIndex();
+ oneAliasIdx = new JdbmIndex<Long>();
oneAliasIdx.setAttributeId( Oid.ONEALIAS );
systemIndices.put( Oid.ONEALIAS, oneAliasIdx );
oneAliasIdx.init( attributeTypeRegistry.lookup( Oid.ONEALIAS ),
workingDirectory );
@@ -391,7 +393,7 @@
if ( subAliasIdx == null )
{
- subAliasIdx = new JdbmIndex();
+ subAliasIdx = new JdbmIndex<Long>();
subAliasIdx.setAttributeId( Oid.SUBALIAS );
systemIndices.put( Oid.SUBALIAS, subAliasIdx );
subAliasIdx.init( attributeTypeRegistry.lookup( Oid.SUBALIAS ),
workingDirectory );
@@ -399,7 +401,7 @@
if ( aliasIdx == null )
{
- aliasIdx = new JdbmIndex();
+ aliasIdx = new JdbmIndex<String>();
aliasIdx.setAttributeId( Oid.ALIAS );
systemIndices.put( Oid.ALIAS, aliasIdx );
aliasIdx.init( attributeTypeRegistry.lookup( Oid.ALIAS ),
workingDirectory );
@@ -407,7 +409,7 @@
}
- private void setupUserIndices() throws NamingException
+ private void setupUserIndices() throws NamingException, IOException
{
if ( userIndices != null && userIndices.size() > 0 )
{
@@ -434,8 +436,9 @@
* @param suffix the suffix for the store
* @param entry the root entry of the store
* @throws NamingException on failre to add the root entry
+ * @throws IOException failure to access btrees
*/
- protected void initSuffixEntry3( String suffix, Attributes entry ) throws
NamingException
+ protected void initSuffixEntry3( String suffix, Attributes entry ) throws
NamingException, IOException
{
// add entry for context, if it does not exist
Attributes suffixOnDisk = getSuffixEntry();
@@ -551,9 +554,9 @@
* This method is called when the synch thread is waking up, to write
* the modified data.
*
- * @throws NamingException on failures to sync to disk
+ * @throws IOException on failures to sync database files to disk
*/
- public synchronized void sync() throws NamingException
+ public synchronized void sync() throws IOException
{
if ( !initialized )
{
@@ -573,27 +576,11 @@
// Sync all user defined userIndices
for ( Index idx:array )
{
- try
- {
- idx.sync();
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ idx.sync();
}
master.sync();
-
- try
- {
- recMan.commit();
- }
- catch ( Throwable t )
- {
- throw ( NamingException ) new NamingException( "Failed to commit
changes to the record manager." )
- .initCause( t );
- }
+ recMan.commit();
}
@@ -628,7 +615,7 @@
}
- public void setHierarchyIndex( JdbmIndex index ) throws NamingException
+ public void setHierarchyIndex( JdbmIndex<Long> index ) throws
NamingException
{
protect( "hierarchyIndex" );
hierarchyIdx = index;
@@ -642,7 +629,7 @@
}
- public void setAliasIndex( JdbmIndex index ) throws NamingException
+ public void setAliasIndex( JdbmIndex<String> index ) throws NamingException
{
protect( "aliasIndex" );
aliasIdx = index;
@@ -656,7 +643,7 @@
}
- public void setOneAliasIndex( JdbmIndex index ) throws NamingException
+ public void setOneAliasIndex( JdbmIndex<Long> index ) throws
NamingException
{
protect( "oneAliasIndex" );
oneAliasIdx = index;
@@ -670,7 +657,7 @@
}
- public void setSubAliasIndex( JdbmIndex index ) throws NamingException
+ public void setSubAliasIndex( JdbmIndex<Long> index ) throws
NamingException
{
protect( "subAliasIndex" );
subAliasIdx = index;
@@ -684,7 +671,7 @@
}
- public void setUpdnIndex( JdbmIndex index ) throws NamingException
+ public void setUpdnIndex( JdbmIndex<String> index ) throws NamingException
{
protect( "updnIndex" );
updnIdx = index;
@@ -698,7 +685,7 @@
}
- public void setNdnIndex( JdbmIndex index ) throws NamingException
+ public void setNdnIndex( JdbmIndex<String> index ) throws NamingException
{
protect( "ndnIndex" );
ndnIdx = index;
@@ -805,110 +792,47 @@
}
- public Long getEntryId( String dn ) throws NamingException
+ public Long getEntryId( String dn ) throws IOException
{
- try
- {
- return ndnIdx.forwardLookup( dn );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return ndnIdx.forwardLookup( dn );
}
- public String getEntryDn( Long id ) throws NamingException
+ public String getEntryDn( Long id ) throws IOException
{
- try
- {
- return ( String ) ndnIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return ndnIdx.reverseLookup( id );
}
- public Long getParentId( String dn ) throws NamingException
+ public Long getParentId( String dn ) throws IOException
{
- try
- {
- Long childId = ndnIdx.forwardLookup( dn );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- return ( Long ) hierarchyIdx.reverseLookup( childId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Long childId = ndnIdx.forwardLookup( dn );
+ return hierarchyIdx.reverseLookup( childId );
}
- public Long getParentId( Long childId ) throws NamingException
+ public Long getParentId( Long childId ) throws IOException
{
- try
- {
- return ( Long ) hierarchyIdx.reverseLookup( childId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return hierarchyIdx.reverseLookup( childId );
}
- public String getEntryUpdn( Long id ) throws NamingException
+ public String getEntryUpdn( Long id ) throws IOException
{
- try
- {
- return ( String ) updnIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return updnIdx.reverseLookup( id );
}
- public String getEntryUpdn( String dn ) throws NamingException
+ public String getEntryUpdn( String dn ) throws IOException
{
- try
- {
- Long id = ndnIdx.forwardLookup( dn );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- return ( String ) updnIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Long id = ndnIdx.forwardLookup( dn );
+ return updnIdx.reverseLookup( id );
}
- public int count() throws NamingException
+ public int count() throws IOException
{
- try
- {
- return master.count();
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return master.count();
}
@@ -918,18 +842,12 @@
*
* @todo Optimize this by walking the hierarchy index instead of the name
* @param aliasId the id of the alias entry in the master table
- * @throws NamingException if we cannot delete the userIndices
+ * @throws NamingException if we cannot parse ldap names
+ * @throws IOException if we cannot delete index values in the database
*/
- private void dropAliasIndices( Long aliasId ) throws NamingException
+ private void dropAliasIndices( Long aliasId ) throws NamingException,
IOException
{
- try
- {
- String targetDn = ( String ) aliasIdx.reverseLookup( aliasId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ String targetDn = aliasIdx.reverseLookup( aliasId );
Long targetId = getEntryId( targetDn );
String aliasDn = getEntryDn( aliasId );
LdapDN ancestorDn = ( LdapDN ) new LdapDN( aliasDn ).getPrefix( 1 );
@@ -946,47 +864,19 @@
* subtree scope alias. We only need to do this for the direct parent
* of the alias on the one level subtree.
*/
- try
- {
- oneAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- subAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ oneAliasIdx.drop( ancestorId, targetId );
+ subAliasIdx.drop( ancestorId, targetId );
while ( !ancestorDn.equals( normSuffix ) )
{
ancestorDn = ( LdapDN ) ancestorDn.getPrefix( 1 );
ancestorId = getEntryId( ancestorDn.toString() );
- try
- {
- subAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ subAliasIdx.drop( ancestorId, targetId );
}
// Drops all alias tuples pointing to the id of the alias to be deleted
- try
- {
- aliasIdx.drop( aliasId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ aliasIdx.drop( aliasId );
}
@@ -997,10 +887,11 @@
* @param aliasDn normalized distinguished name for the alias entry
* @param aliasTarget the user provided aliased entry dn as a string
* @param aliasId the id of alias entry to add
- * @throws NamingException if index addition fails, of the alias is not
- * allowed due to chaining or cycle formation.
+ * @throws NamingException if index addition fails, and if the alias is
+ * not allowed due to chaining or cycle formation.
+ * @throws IOException if the underlying btrees cannot be altered
*/
- private void addAliasIndices( Long aliasId, LdapDN aliasDn, String
aliasTarget ) throws NamingException
+ private void addAliasIndices( Long aliasId, LdapDN aliasDn, String
aliasTarget ) throws IOException, NamingException
{
LdapDN normalizedAliasTargetDn; // Name value of aliasedObjectName
Long targetId; // Id of the aliasedObjectName
@@ -1050,14 +941,7 @@
}
// L O O K U P T A R G E T I D
- try
- {
- targetId = ndnIdx.forwardLookup(
normalizedAliasTargetDn.toNormName() );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ targetId = ndnIdx.forwardLookup( normalizedAliasTargetDn.toNormName()
);
/*
* Check For Target Existance
@@ -1083,29 +967,15 @@
* then we have a situation where an alias chain is being created.
* Alias chaining is not allowed so we throw and exception.
*/
- try
+ if ( null != aliasIdx.reverseLookup( targetId ) )
{
- if ( null != aliasIdx.reverseLookup( targetId ) )
- {
- // Complain about illegal alias chain
- throw new NamingException( "[36] aliasDereferencingProblem -"
- + " the alias points to another alias. Alias chaining is"
+ " not supported by this backend." );
- }
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ // Complain about illegal alias chain
+ throw new NamingException( "[36] aliasDereferencingProblem -"
+ + " the alias points to another alias. Alias chaining is" + "
not supported by this backend." );
}
// Add the alias to the simple alias index
- try
- {
- aliasIdx.add( normalizedAliasTargetDn.getNormName(), aliasId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ aliasIdx.add( normalizedAliasTargetDn.getNormName(), aliasId );
/*
* Handle One Level Scope Alias Index
@@ -1120,14 +990,7 @@
if ( !NamespaceTools.isSibling( normalizedAliasTargetDn, aliasDn ) )
{
- try
- {
- oneAliasIdx.add( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ oneAliasIdx.add( ancestorId, targetId );
}
/*
@@ -1144,14 +1007,7 @@
{
if ( !NamespaceTools.isDescendant( ancestorDn,
normalizedAliasTargetDn ) )
{
- try
- {
- subAliasIdx.add( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
- }
+ subAliasIdx.add( ancestorId, targetId );
}
ancestorDn.remove( ancestorDn.size() - 1 );
@@ -1160,7 +1016,7 @@
}
- public void add( LdapDN normName, Attributes entry ) throws NamingException
+ public void add( LdapDN normName, Attributes entry ) throws
NamingException, IOException
{
Long id;
Long parentId;
@@ -1216,30 +1072,9 @@
}
- try
- {
- ndnIdx.add( normName.toNormName(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- updnIdx.add( normName.getUpName(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- hierarchyIdx.add( parentId, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ ndnIdx.add( normName.toNormName(), id );
+ updnIdx.add( normName.getUpName(), id );
+ hierarchyIdx.add( parentId, id );
// Now work on the user defined userIndices
NamingEnumeration<String> list = entry.getIDs();
@@ -1259,25 +1094,11 @@
while ( values.hasMore() )
{
- try
- {
- idx.add( values.next(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
- }
+ idx.add( values.next(), id );
}
// Adds only those attributes that are indexed
- try
- {
- existanceIdx.add( attributeOid, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
- }
+ existanceIdx.add( attributeOid, id );
}
}
@@ -1290,20 +1111,13 @@
}
- public Attributes lookup( Long id ) throws NamingException
+ public Attributes lookup( Long id ) throws IOException
{
- try
- {
- return master.get( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return master.get( id );
}
- public void delete( Long id ) throws NamingException
+ public void delete( Long id ) throws IOException, NamingException
{
Attributes entry = lookup( id );
Long parentId = getParentId( id );
@@ -1316,42 +1130,14 @@
dropAliasIndices( id );
}
- try
- {
- ndnIdx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- updnIdx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- hierarchyIdx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ ndnIdx.drop( id );
+ updnIdx.drop( id );
+ hierarchyIdx.drop( id );
// Remove parent's reference to entry only if entry is not the upSuffix
if ( !parentId.equals( 0L ) )
{
- try
- {
- hierarchyIdx.drop( parentId, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ hierarchyIdx.drop( parentId, id );
}
while ( attrs.hasMore() )
@@ -1369,24 +1155,10 @@
while ( values.hasMore() )
{
- try
- {
- index.drop( values.next(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
- }
+ index.drop( values.next(), id );
}
- try
- {
- existanceIdx.drop( attributeOid, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
- }
+ existanceIdx.drop( attributeOid, id );
}
}
@@ -1399,29 +1171,19 @@
}
- public NamingEnumeration<?> list( Long id ) throws NamingException
+ public Cursor<IndexRecord> list( Long id ) throws IOException
{
- try
- {
- return hierarchyIdx.listIndices( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Cursor<IndexRecord> cursor = hierarchyIdx.cursor();
+ IndexRecord record = new IndexRecord();
+ record.setEntryId( id );
+ cursor.before( record );
+ return cursor;
}
- public int getChildCount( Long id ) throws NamingException
+ public int getChildCount( Long id ) throws IOException
{
- try
- {
- return hierarchyIdx.count( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ return hierarchyIdx.count( id );
}
@@ -1430,13 +1192,14 @@
return normSuffix;
}
+
public LdapDN getUpSuffix()
{
return upSuffix;
}
- public Attributes getSuffixEntry() throws NamingException
+ public Attributes getSuffixEntry() throws IOException
{
Long id = getEntryId( normSuffix.toNormName() );
@@ -1449,19 +1212,19 @@
}
- public void setProperty( String propertyName, String propertyValue )
throws NamingException
+ public void setProperty( String propertyName, String propertyValue )
throws IOException
{
master.setProperty( propertyName, propertyValue );
}
- public String getProperty( String propertyName ) throws NamingException
+ public String getProperty( String propertyName ) throws IOException
{
return master.getProperty( propertyName );
}
- public Attributes getIndices( Long id ) throws NamingException
+ public Attributes getIndices( Long id ) throws IOException, NamingException
{
Attributes attributes = new AttributesImpl();
@@ -1473,18 +1236,14 @@
// Get all standard index attribute to value mappings
for ( Index index:this.userIndices.values() )
{
- try
- {
- NamingEnumeration<IndexRecord> list =
index.listReverseIndices( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ Cursor<IndexRecord> list = index.reverseCursor();
+ IndexRecord record = new IndexRecord();
+ record.setEntryId( id );
+ list.before( record );
- while ( list.hasMore() )
+ while ( list.next() )
{
- IndexRecord rec = list.next();
+ IndexRecord rec = list.get();
Object val = rec.getIndexKey();
String attrId = index.getAttribute().getName();
Attribute attr = attributes.get( attrId );
@@ -1501,19 +1260,15 @@
// Get all existance mappings for this id creating a special key
// that looks like so 'existance[attribute]' and the value is set to id
- try
- {
- NamingEnumeration<IndexRecord> list =
existanceIdx.listReverseIndices( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Cursor<IndexRecord> list = existanceIdx.reverseCursor();
+ IndexRecord record = new IndexRecord();
+ record.setEntryId( id );
+ list.before( record );
StringBuffer val = new StringBuffer();
- while ( list.hasMore() )
+ while ( list.next() )
{
- IndexRecord rec = list.next();
+ IndexRecord rec = list.get();
val.append( "_existance[" );
val.append( rec.getIndexKey() );
val.append( "]" );
@@ -1533,20 +1288,17 @@
// Get all parent child mappings for this entry as the parent using the
// key 'child' with many entries following it.
- try
- {
- list = hierarchyIdx.listIndices( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ list = hierarchyIdx.cursor();
+ record = new IndexRecord();
+ record.setEntryId( id );
+ list.before( record );
+
Attribute childAttr = new AttributeImpl( "_child" );
attributes.put( childAttr );
- while ( list.hasMore() )
+ while ( list.next() )
{
- IndexRecord rec = ( IndexRecord ) list.next();
+ IndexRecord rec = list.get();
childAttr.add( rec.getEntryId() );
}
@@ -1565,40 +1317,19 @@
* @throws NamingException if index alteration or attribute addition
* fails.
*/
- private void add( Long id, Attributes entry, Attribute mods ) throws
NamingException
+ private void add( Long id, Attributes entry, Attribute mods ) throws
IOException, NamingException
{
String modsOid = oidRegistry.getOid( mods.getID() );
if ( hasUserIndexOn( modsOid ) )
{
Index idx = getUserIndex( modsOid );
- try
- {
- idx.add( mods, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ idx.add( mods, id );
// If the attr didn't exist for this id add it to existance index
- try
+ if ( !existanceIdx.hasValue( modsOid, id ) )
{
- if ( !existanceIdx.hasValue( modsOid, id ) )
- {
- try
- {
- existanceIdx.add( modsOid, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
- }
- }
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ existanceIdx.add( modsOid, id );
}
}
@@ -1619,14 +1350,7 @@
if ( modsOid.equals( oidRegistry.getOid(
SchemaConstants.ALIASED_OBJECT_NAME_AT ) ) )
{
- try
- {
- String ndnStr = ( String ) ndnIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ String ndnStr = ndnIdx.reverseLookup( id );
addAliasIndices( id, new LdapDN( ndnStr ), ( String ) mods.get() );
}
}
@@ -1646,36 +1370,22 @@
* @throws NamingException if index alteration or attribute modification
* fails.
*/
- private void remove( Long id, Attributes entry, Attribute mods ) throws
NamingException
+ private void remove( Long id, Attributes entry, Attribute mods ) throws
NamingException, IOException
{
String modsOid = oidRegistry.getOid( mods.getID() );
if ( hasUserIndexOn( modsOid ) )
{
Index idx = getUserIndex( modsOid );
- try
- {
- idx.drop( mods, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ idx.drop( mods, id );
/*
* If no attribute values exist for this entryId in the index then
* we remove the existance index entry for the removed attribute.
*/
- try
- {
- if ( null == idx.reverseLookup( id ) )
- {
- existanceIdx.drop( modsOid, id );
- }
- }
- catch ( IOException e )
+ if ( null == idx.reverseLookup( id ) )
{
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ existanceIdx.drop( modsOid, id );
}
}
@@ -1727,7 +1437,7 @@
* @throws NamingException if index alteration or attribute modification
* fails.
*/
- private void replace( Long id, Attributes entry, Attribute mods ) throws
NamingException
+ private void replace( Long id, Attributes entry, Attribute mods ) throws
NamingException, IOException
{
String modsOid = oidRegistry.getOid( mods.getID() );
@@ -1736,37 +1446,16 @@
Index idx = getUserIndex( modsOid );
// Drop all existing attribute value index entries and add new ones
- try
- {
- idx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
- try
- {
- idx.add( mods, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ idx.drop( id );
+ idx.add( mods, id );
/*
* If no attribute values exist for this entryId in the index then
* we remove the existance index entry for the removed attribute.
*/
- try
- {
- if ( null == idx.reverseLookup( id ) )
- {
- existanceIdx.drop( modsOid, id );
- }
- }
- catch ( IOException e )
+ if ( null == idx.reverseLookup( id ) )
{
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ existanceIdx.drop( modsOid, id );
}
}
@@ -1789,31 +1478,17 @@
if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 )
{
- try
- {
- String ndnStr = ( String ) ndnIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ String ndnStr = ndnIdx.reverseLookup( id );
addAliasIndices( id, new LdapDN( ndnStr ), ( String ) mods.get() );
}
}
- public void modify( LdapDN dn, int modOp, Attributes mods ) throws
NamingException
+ public void modify( LdapDN dn, int modOp, Attributes mods ) throws
NamingException, IOException
{
NamingEnumeration<String> attrs;
Long id = getEntryId( dn.toString() );
- try
- {
- Attributes entry = master.get( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Attributes entry = master.get( id );
switch ( modOp )
{
@@ -1866,17 +1541,10 @@
}
- public void modify( LdapDN dn, List<ModificationItemImpl> mods ) throws
NamingException
+ public void modify( LdapDN dn, List<ModificationItemImpl> mods ) throws
NamingException, IOException
{
Long id = getEntryId( dn.toString() );
- try
- {
- Attributes entry = master.get( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ Attributes entry = master.get( id );
for ( ModificationItem mod : mods )
{
@@ -1927,7 +1595,7 @@
* @throws NamingException if there are any errors propagating the name
* changes.
*/
- public void rename( LdapDN dn, Rdn newRdn, boolean deleteOldRdn ) throws
NamingException
+ public void rename( LdapDN dn, Rdn newRdn, boolean deleteOldRdn ) throws
NamingException, IOException
{
String newRdnAttr = newRdn.getNormType();
String newRdnValue = ( String ) newRdn.getValue();
@@ -1963,33 +1631,12 @@
if ( hasUserIndexOn( newRdn.getNormType() ) )
{
Index idx = getUserIndex( newRdn.getNormType() );
- try
- {
- idx.add( newRdnValue, id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ idx.add( newRdnValue, id );
// Make sure the altered entry shows the existance of the new
attrib
- try
- {
- if ( !existanceIdx.hasValue( newRdn.getNormType(), id ) )
- {
- try
- {
- existanceIdx.add( newRdn.getNormType(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.
- }
- }
- }
- catch ( IOException e )
+ if ( !existanceIdx.hasValue( newRdn.getNormType(), id ) )
{
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
+ existanceIdx.add( newRdn.getNormType(), id );
}
}
@@ -2018,29 +1665,15 @@
if ( hasUserIndexOn( oldRdn.getNormType() ) )
{
Index idx = getUserIndex( oldRdn.getNormType() );
- try
- {
- idx.drop( oldRdn.getValue(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
- }
+ idx.drop( oldRdn.getValue(), id );
/*
* If there is no value for id in this index due to our
* drop above we remove the oldRdnAttr from the existance idx
*/
- try
- {
- if ( null == idx.reverseLookup( id ) )
- {
- existanceIdx.drop( oldRdn.getNormType(), id );
- }
- }
- catch ( IOException e )
+ if ( null == idx.reverseLookup( id ) )
{
- e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ existanceIdx.drop( oldRdn.getNormType(), id );
}
}
}
@@ -2089,50 +1722,21 @@
* which affects alias userIndices.
* @throws NamingException if something goes wrong
*/
- private void modifyDn( Long id, LdapDN updn, boolean isMove ) throws
NamingException
+ private void modifyDn( Long id, LdapDN updn, boolean isMove ) throws
NamingException, IOException
{
String aliasTarget;
// Now we can handle the appropriate name userIndices for all cases
- try
- {
- ndnIdx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ ndnIdx.drop( id );
if ( ! updn.isNormalized() )
{
updn.normalize( attributeTypeRegistry.getNormalizerMapping() );
}
- try
- {
- ndnIdx.add( ndnIdx.getNormalized( updn.toNormName() ), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
-
- try
- {
- updnIdx.drop( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
- try
- {
- updnIdx.add( updn.getUpName(), id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ ndnIdx.add( ndnIdx.getNormalized( updn.toNormName() ), id );
+ updnIdx.drop( id );
+ updnIdx.add( updn.getUpName(), id );
/*
* Read Alias Index Tuples
@@ -2146,14 +1750,7 @@
*/
if ( isMove )
{
- try
- {
- aliasTarget = ( String ) aliasIdx.reverseLookup( id );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ aliasTarget = ( String ) aliasIdx.reverseLookup( id );
if ( null != aliasTarget )
{
@@ -2161,12 +1758,12 @@
}
}
- NamingEnumeration children = list( id );
- while ( children.hasMore() )
+ Cursor<IndexRecord> children = list( id );
+ while ( children.next() )
{
// Get the child and its id
- IndexRecord rec = ( IndexRecord ) children.next();
- Long childId = ( Long ) rec.getEntryId();
+ IndexRecord rec = children.get();
+ Long childId = rec.getEntryId();
/*
* Calculate the Dn for the child's new name by copying the parents
@@ -2186,7 +1783,8 @@
}
- public void move( LdapDN oldChildDn, LdapDN newParentDn, Rdn newRdn,
boolean deleteOldRdn ) throws NamingException
+ public void move( LdapDN oldChildDn, LdapDN newParentDn, Rdn newRdn,
boolean deleteOldRdn )
+ throws NamingException, IOException
{
Long childId = getEntryId( oldChildDn.toString() );
rename( oldChildDn, newRdn, deleteOldRdn );
@@ -2199,7 +1797,7 @@
}
- public void move( LdapDN oldChildDn, LdapDN newParentDn ) throws
NamingException
+ public void move( LdapDN oldChildDn, LdapDN newParentDn ) throws
NamingException, IOException
{
Long childId = getEntryId( oldChildDn.toString() );
move( oldChildDn, childId, newParentDn );
@@ -2225,7 +1823,7 @@
* @param newParentDn the normalized dn of the new parent for the child
* @throws NamingException if something goes wrong
*/
- private void move( LdapDN oldChildDn, Long childId, LdapDN newParentDn )
throws NamingException
+ private void move( LdapDN oldChildDn, Long childId, LdapDN newParentDn )
throws NamingException, IOException
{
// Get the child and the new parent to be entries and Ids
Long newParentId = getEntryId( newParentDn.toString() );
@@ -2285,47 +1883,43 @@
* @param movedBase the base at which the move occured - the moved node
* @throws NamingException if system userIndices fail
*/
- private void dropMovedAliasIndices( final LdapDN movedBase ) throws
NamingException
+ private void dropMovedAliasIndices( final LdapDN movedBase ) throws
NamingException, IOException
{
// Find all the aliases from movedBase down
IndexAssertion isBaseDescendant = new IndexAssertion()
{
public boolean assertCandidate( IndexRecord rec ) throws
NamingException
{
- String dn = getEntryDn( (Long)rec.getEntryId() );
+ String dn = null;
+ try
+ {
+ dn = getEntryDn( (Long)rec.getEntryId() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace(); //To change body of catch statement
use File | Settings | File Templates.
+ }
return dn.endsWith( movedBase.toString() );
}
};
Long movedBaseId = getEntryId( movedBase.toString() );
- try
- {
- if ( aliasIdx.reverseLookup( movedBaseId ) != null )
- {
- dropAliasIndices( movedBaseId, movedBase );
- }
- }
- catch ( IOException e )
+ if ( aliasIdx.reverseLookup( movedBaseId ) != null )
{
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ dropAliasIndices( movedBaseId, movedBase );
}
- try
- {
- NamingEnumeration<IndexRecord> aliases = new
IndexAssertionEnumeration( aliasIdx.listIndices( movedBase.toString(), true ),
- isBaseDescendant );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ throw new NotImplementedException( "Fix the code below this line" );
- while ( aliases.hasMore() )
- {
- IndexRecord entry = aliases.next();
- dropAliasIndices( (Long)entry.getEntryId(), movedBase );
- }
+// NamingEnumeration<IndexRecord> aliases =
+// new IndexAssertionEnumeration( aliasIdx.listIndices(
movedBase.toString(), true ), isBaseDescendant );
+//
+// while ( aliases.hasMore() )
+// {
+// IndexRecord entry = aliases.next();
+// dropAliasIndices( (Long)entry.getEntryId(), movedBase );
+// }
}
@@ -2337,16 +1931,9 @@
* @param movedBase the base where the move occured
* @throws NamingException if userIndices fail
*/
- private void dropAliasIndices( Long aliasId, LdapDN movedBase ) throws
NamingException
+ private void dropAliasIndices( Long aliasId, LdapDN movedBase ) throws
NamingException, IOException
{
- try
- {
- String targetDn = ( String ) aliasIdx.reverseLookup( aliasId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ String targetDn = aliasIdx.reverseLookup( aliasId );
Long targetId = getEntryId( targetDn );
String aliasDn = getEntryDn( aliasId );
@@ -2371,38 +1958,17 @@
*/
if ( aliasDn.equals( movedBase.toString() ) )
{
- try
- {
- oneAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ oneAliasIdx.drop( ancestorId, targetId );
}
- try
- {
- subAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
- }
+ subAliasIdx.drop( ancestorId, targetId );
while ( !ancestorDn.equals( upSuffix ) )
{
ancestorDn = ( LdapDN ) ancestorDn.getPrefix( 1 );
ancestorId = getEntryId( ancestorDn.toString() );
- try
- {
- subAliasIdx.drop( ancestorId, targetId );
- }
- catch ( IOException e )
- {
- e.printStackTrace(); //To change body of catch statement use
File | Settings | File Templates.
- }
+ subAliasIdx.drop( ancestorId, targetId );
}
}
Modified:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL:
http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
---
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Tue Jan 8 16:41:31 2008
@@ -28,7 +28,6 @@
import org.apache.directory.server.core.partition.impl.btree.*;
import org.apache.directory.server.schema.SerializableComparator;
-import javax.naming.NamingException;
import java.io.IOException;
import java.util.*;
@@ -41,31 +40,31 @@
*/
public class JdbmTable<K,V> implements Table<K,V>
{
- /** */
- private static final String SZSUFFIX = "_btree_sz";
-
private static final byte[] EMPTY_BYTES = new byte[0];
- /** */
+ /** the key to store and retreive the count information */
+ private static final String SZSUFFIX = "_btree_sz";
+
+ /** the name of this table */
private final String name;
- /** */
+ /** the JDBM record manager for the file this table is managed in */
private final RecordManager recMan;
- /** */
+ /** whether or not this table allows for duplicates */
private final boolean allowsDuplicates;
- /** */
- private final TupleComparator comparator;
+ /** a pair of comparators for the keys and values in this Table */
+ private final TupleComparator<K,V> comparator;
- /** */
+ /** the current count of entries in this Table */
private int count;
- /** */
+ /** the underlying JDBM btree used in this Table */
private BTree bt;
- /** */
+ /** the renderer to use for btree tuples */
private TupleRenderer renderer;
-
+ /** the limit at which we start using btree redirection for duplicates */
private int numDupLimit = JdbmIndex.DEFAULT_DUPLICATE_LIMIT;
-
+ /** @TODO should really be a cache of duplicate BTrees */
private Map<Long, BTree> duplicateBtrees = new HashMap<Long, BTree>();
@@ -73,6 +72,7 @@
// C O N S T R U C T O R
// ------------------------------------------------------------------------
+
/**
* Creates a Jdbm BTree based tuple Table abstraction that enables
* duplicates.
@@ -87,12 +87,12 @@
* default Java serialization which could be very expensive
* @param valueSerializer a serializer to use for the values instead of
* using default Java serialization which could be very expensive
- * @throws NamingException if the table's file cannot be created
+ * @throws IOException if the table's file cannot be created
*/
public JdbmTable( String name, boolean allowsDuplicates, int numDupLimit,
- RecordManager manager, TupleComparator comparator, Serializer
keySerializer,
+ RecordManager manager, TupleComparator<K,V> comparator, Serializer
keySerializer,
Serializer valueSerializer )
- throws NamingException
+ throws IOException
{
/*System.out.println( "Creating BTree for " + name + ", key serializer
= " +
(keySerializer == null ? "null" :
keySerializer.getClass().getName()) +
@@ -104,46 +104,25 @@
this.comparator = comparator;
this.allowsDuplicates = allowsDuplicates;
- long recId;
+ long recId = recMan.getNamedObject( name );
- try
- {
- recId = recMan.getNamedObject( name );
- }
- catch ( IOException e )
- {
- NamingException ne = new NamingException();
- ne.setRootCause( e );
- throw ne;
- }
+ //
+ // Load existing BTree
+ //
- try
+ if ( recId != 0 )
{
-
- //
- // Load existing BTree
- //
-
- if ( recId != 0 )
- {
- bt = BTree.load( recMan, recId );
- recId = recMan.getNamedObject( name + SZSUFFIX );
- count = ( Integer ) recMan.fetch( recId );
- }
- else
- {
- bt = BTree.createInstance( recMan,
comparator.getKeyComparator(), keySerializer, valueSerializer );
- recId = bt.getRecid();
- recMan.setNamedObject( name, recId );
- recId = recMan.insert( 0 );
- recMan.setNamedObject( name + SZSUFFIX, recId );
- }
+ bt = BTree.load( recMan, recId );
+ recId = recMan.getNamedObject( name + SZSUFFIX );
+ count = ( Integer ) recMan.fetch( recId );
}
- catch ( IOException e )
- {
- NamingException ne = new NamingException();
- ne.setRootCause( e );
- throw ne;
+ else
+ {
+ bt = BTree.createInstance( recMan, comparator.getKeyComparator(),
keySerializer, valueSerializer );
+ recId = bt.getRecid();
+ recMan.setNamedObject( name, recId );
+ recId = recMan.insert( 0 );
+ recMan.setNamedObject( name + SZSUFFIX, recId );
}
}
@@ -159,13 +138,13 @@
* default Java serialization which could be very expensive
* @param valueSerializer a serializer to use for the values instead of
* using default Java serialization which could be very expensive
- * @throws NamingException if the table's file cannot be created
+ * @throws IOException if the table's file cannot be created
*/
- public JdbmTable( String name, RecordManager manager,
SerializableComparator keyComparator,
+ public JdbmTable( String name, RecordManager manager,
SerializableComparator<K> keyComparator,
Serializer keySerializer, Serializer valueSerializer )
- throws NamingException
+ throws IOException
{
- this( name, false, Integer.MAX_VALUE, manager, new KeyOnlyComparator(
keyComparator ),
+ this( name, false, Integer.MAX_VALUE, manager, new
KeyOnlyComparator<K,V>( keyComparator ),
keySerializer, valueSerializer );
}
@@ -178,7 +157,7 @@
/**
* @see
org.apache.directory.server.core.partition.impl.btree.Table#getComparator()
*/
- public TupleComparator getComparator()
+ public TupleComparator<K,V> getComparator()
{
return comparator;
}
@@ -212,34 +191,39 @@
/**
- * @see Table#setRenderer(
- * TupleRenderer)
+ * @see Table#setRenderer(TupleRenderer)
*/
public void setRenderer( TupleRenderer renderer )
{
this.renderer = renderer;
}
-
- /**
- * @see Table#isSortedDupsEnabled()
- */
- public boolean isSortedDupsEnabled()
+
+ public boolean isCountExact()
{
- // If duplicates are enabled than duplicates will be maintained in
- // sorted order.
- return allowsDuplicates;
+ return false;
}
-
+
// ------------------------------------------------------------------------
// Count Overloads
// ------------------------------------------------------------------------
+
+ /**
+ * @see Table#greaterThanCount(Object)
+ */
+ public int greaterThanCount( K key ) throws IOException
+ {
+ // take a best guess
+ return count;
+ }
+
+
/**
- * @see Table#count(java.lang.Object, boolean)
+ * @see Table#lessThanCount(Object)
*/
- public int count( K key, boolean isGreaterThan ) throws IOException
+ public int lessThanCount( K key ) throws IOException
{
// take a best guess
return count;
@@ -375,12 +359,12 @@
return true;
}
// val >= val and test is for greater then return true
- else if ( comparator.compareValue( rval, val ) >= 1 &&
isGreaterThan )
+ else if ( comparator.compareValue( ( V ) rval, val ) >= 1 &&
isGreaterThan )
{
return true;
}
// val <= val and test is for lesser then return true
- else if ( comparator.compareValue( rval, val ) <= 1 &&
!isGreaterThan )
+ else if ( comparator.compareValue( ( V ) rval, val ) <= 1 &&
!isGreaterThan )
{
return true;
}
@@ -437,7 +421,8 @@
jdbm.helper.Tuple tuple = bt.findGreaterOrEqual( key );
// Test for equality first since it satisfies both greater/less than
- if ( null != tuple && comparator.compareKey( tuple.getKey(), key ) ==
0 )
+ //noinspection unchecked
+ if ( null != tuple && comparator.compareKey( ( K ) tuple.getKey(), key
) == 0 )
{
return true;
}
@@ -472,7 +457,8 @@
// comparator.
if ( browser.getNext( tuple ) )
{
- return comparator.compareKey( tuple.getKey(), key ) <= 0;
+ //noinspection unchecked
+ return comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0;
}
}
else
@@ -485,7 +471,8 @@
// The above call positions the browser just before the given
// key so we need to step forward once then back. Remember this
// key represents a key greater than or equal to key.
- if ( comparator.compareKey( tuple.getKey(), key ) <= 0 )
+ //noinspection unchecked
+ if ( comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0 )
{
return true;
}
@@ -497,7 +484,8 @@
// unneccessarily looping is nil since values get smaller.
while ( browser.getPrevious( tuple ) )
{
- if ( comparator.compareKey( tuple.getKey(), key ) <= 0 )
+ //noinspection unchecked
+ if ( comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0 )
{
return true;
}
@@ -1077,7 +1065,13 @@
success = browser.getNext( tuple );
if ( success )
{
- Object biggerKey = tuple.getKey();
+ /*
+ * Note that keys in these embedded BTrees really store
+ * duplicate values of similar keys in this BTree.
+ */
+
+ //noinspection unchecked
+ V biggerKey = ( V ) tuple.getKey();
if ( comparator.compareValue( key, biggerKey ) == 0 )
{
return true;
@@ -1097,7 +1091,13 @@
boolean success = browser.getNext( tuple );
if ( success )
{
- if ( comparator.compareValue( key, tuple.getKey() ) == 0 )
+ /*
+ * Note that keys in these embedded BTrees really store
+ * duplicate values of similar keys in this BTree.
+ */
+
+ //noinspection unchecked
+ if ( comparator.compareValue( key, ( V ) tuple.getKey() ) == 0 )
{
return true;
}
Added:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL:
http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=610243&view=auto
==============================================================================
---
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
(added)
+++
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
Tue Jan 8 16:41:31 2008
@@ -0,0 +1,239 @@
+/*
+ * 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.partition.impl.btree.jdbm;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.directory.server.core.partition.impl.btree.Table;
+import org.apache.directory.server.core.partition.impl.btree.TupleRenderer;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+
+import java.io.File;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import jdbm.RecordManager;
+import jdbm.helper.StringComparator;
+import jdbm.recman.BaseRecordManager;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx">Apache Directory
Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmTableNoDuplicatesTest
+{
+ private static final Logger LOG = LoggerFactory.getLogger(
KeyCursorTest.class.getSimpleName() );
+ private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+ transient Table<String,String> table;
+ transient File dbFile;
+ transient RecordManager recman;
+
+
+ @Before
+ public void createTable() throws Exception
+ {
+ File tmpDir = null;
+ if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+ {
+ tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+ }
+
+ dbFile = File.createTempFile( "test", "db", tmpDir );
+ recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+
+ // gosh this is a terrible use of a global static variable
+ SerializableComparator.setRegistry( new TestComparatorRegistry() );
+ table = new JdbmTable<String,String>( "test", recman, new
SerializableComparator<String>( "" ), null, null );
+ LOG.debug( "Created new table and populated it with data" );
+ }
+
+
+ @After
+ public void destryTable() throws Exception
+ {
+ table.close();
+ table = null;
+ recman.close();
+ recman = null;
+ dbFile.deleteOnExit();
+ dbFile = null;
+ }
+
+
+ @Test
+ public void testCloseReopen() throws Exception
+ {
+ table.put( "key", "value" );
+ table.close();
+ table = new JdbmTable<String,String>( "test", recman, new
SerializableComparator<String>( "" ), null, null );
+ assertEquals( "value", table.get( "key" ) );
+ }
+
+
+ @Test
+ public void testConfigMethods() throws Exception
+ {
+ assertFalse( table.isDupsEnabled() );
+ assertNull( table.getRenderer() );
+ table.setRenderer( new TupleRenderer() {
+ public String getKeyString( Object key )
+ {
+ return null;
+ }
+ public String getValueString( Object value )
+ {
+ return null;
+ }}
+ );
+ assertNotNull( table.getRenderer() );
+ table.setRenderer( null );
+ assertNull( table.getRenderer() );
+ assertEquals( "test", table.getName() );
+ assertNotNull( table.getComparator() );
+ }
+
+
+ @Test
+ public void testWhenEmpty() throws Exception
+ {
+ // Test the count methods
+ assertEquals( 0, table.count() );
+ assertEquals( 0, table.count( "1" ) );
+
+ // Test get method
+ assertNull( table.get( "0" ) );
+
+ // Test remove methods
+ assertNull( table.remove( "1" ) );
+
+ // Test has operations
+ assertFalse( table.has( "1" ) );
+ assertFalse( table.has( "1", "0" ) );
+ assertFalse( table.has( "1", true ) );
+ assertFalse( table.has( "1", false ) );
+ assertFalse( table.has( "1", "0", true ) );
+ assertFalse( table.has( "1", "0", false ) );
+ }
+
+
+ @Test
+ public void testLoadData() throws Exception
+ {
+ // add some data to it
+ table.put( "0", "zero" );
+ table.put( "1", "one" );
+ table.put( "2", "two" );
+ table.put( "3", "three" );
+ table.put( "4", "four" );
+ table.put( "5", "five" );
+ table.put( "6", "six" );
+ table.put( "7", "seven" );
+ table.put( "8", "eight" );
+ table.put( "9", "nine" );
+
+ assertEquals( 10, table.count() );
+ assertEquals( 1, table.count( "0" ) );
+
+ /*
+ * If counts are exact then we can test for exact values. Again this
+ * is not a critical function but one used for optimization so worst
+ * case guesses are allowed.
+ */
+
+ if ( table.isCountExact() )
+ {
+ assertEquals( 5, table.lessThanCount( "5" ) );
+ assertEquals( 4, table.greaterThanCount( "5" ) );
+ }
+ else
+ {
+ assertEquals( 10, table.lessThanCount( "5" ) );
+ assertEquals( 10, table.greaterThanCount( "5" ) );
+ }
+ }
+
+
+ private class TestComparatorRegistry implements ComparatorRegistry
+ {
+ private StringComparator comparator = new StringComparator();
+
+ public String getSchemaName( String oid ) throws NamingException
+ {
+ return null;
+ }
+
+
+ public void register( ComparatorDescription description, Comparator
comparator ) throws NamingException
+ {
+ }
+
+
+ public Comparator lookup( String oid ) throws NamingException
+ {
+ return comparator;
+ }
+
+
+ public boolean hasComparator( String oid )
+ {
+ return true;
+ }
+
+
+ public Iterator<String> oidIterator()
+ {
+ return null;
+ }
+
+
+ public Iterator<ComparatorDescription> comparatorDescriptionIterator()
+ {
+ return null;
+ }
+
+
+ public void unregister( String oid ) throws NamingException
+ {
+ }
+
+
+ public void unregisterSchemaElements( String schemaName )
+ {
+ }
+
+
+ public void renameSchema( String originalSchemaName, String
newSchemaName )
+ {
+ }
+ }
+}
Propchange:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
------------------------------------------------------------------------------
svn:executable = *
Added:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL:
http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=610243&view=auto
==============================================================================
---
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
(added)
+++
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
Tue Jan 8 16:41:31 2008
@@ -0,0 +1,246 @@
+/*
+ * 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.partition.impl.btree.jdbm;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.apache.directory.server.core.partition.impl.btree.Table;
+import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
+import
org.apache.directory.server.core.partition.impl.btree.DefaultTupleComparator;
+import org.apache.directory.server.core.partition.impl.btree.TupleRenderer;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import jdbm.RecordManager;
+import jdbm.helper.StringComparator;
+import jdbm.recman.BaseRecordManager;
+
+import javax.naming.NamingException;
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx">Apache Directory
Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmTableWithDuplicatesTest
+{
+ private static final Logger LOG = LoggerFactory.getLogger(
KeyCursorTest.class.getSimpleName() );
+ private static final String EMPTY_STRING = "";
+ private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+ transient Table<String,String> table;
+ transient File dbFile;
+ transient RecordManager recman;
+
+ @Before
+ public void createTable() throws Exception
+ {
+ File tmpDir = null;
+ if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+ {
+ tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+ }
+
+ dbFile = File.createTempFile( "test", "db", tmpDir );
+ recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+
+ // gosh this is a terrible use of a global static variable
+ SerializableComparator.setRegistry( new TestComparatorRegistry() );
+
+ TupleComparator<String,String> comparator =
+ new DefaultTupleComparator<String,String>(
+ new SerializableComparator<String>( "" ),
+ new SerializableComparator<String>( "" ) );
+ table = new JdbmTable<String,String>( "test", true, 100, recman,
comparator, null, null );
+ LOG.debug( "Created new table and populated it with data" );
+ }
+
+
+ @After
+ public void destryTable() throws Exception
+ {
+ table.close();
+ table = null;
+ recman.close();
+ recman = null;
+ dbFile.deleteOnExit();
+ dbFile = null;
+ }
+
+
+ public void loadDataNoDupKeys() throws IOException
+ {
+ // add some data to it
+ table.put( "0", EMPTY_STRING );
+ table.put( "1", EMPTY_STRING );
+ table.put( "2", EMPTY_STRING );
+ table.put( "3", EMPTY_STRING );
+ table.put( "4", EMPTY_STRING );
+ table.put( "5", EMPTY_STRING );
+ table.put( "6", EMPTY_STRING );
+ table.put( "7", EMPTY_STRING );
+ table.put( "8", EMPTY_STRING );
+ table.put( "9", EMPTY_STRING );
+ }
+
+
+ public void loadDataWithDupKeys() throws IOException
+ {
+ // add some data to it
+ table.put( "0", "0" );
+ table.put( "1", "0" );
+ table.put( "1", "1" );
+ table.put( "1", "2" );
+ table.put( "4", "4" );
+ table.put( "5", "5" );
+ table.put( "6", "6" );
+ table.put( "7", "7" );
+ table.put( "8", "8" );
+ table.put( "9", "9" );
+ }
+
+
+ @Test
+ public void testCloseReopen() throws Exception
+ {
+ table.put( "key", "value" );
+ table.close();
+ TupleComparator<String,String> comparator =
+ new DefaultTupleComparator<String,String>(
+ new SerializableComparator<String>( "" ),
+ new SerializableComparator<String>( "" ) );
+ table = new JdbmTable<String,String>( "test", true, 100, recman,
comparator, null, null );
+ assertEquals( "value", table.get( "key" ) );
+ }
+
+
+ @Test
+ public void testConfigMethods() throws Exception
+ {
+ assertTrue( table.isDupsEnabled() );
+ assertNull( table.getRenderer() );
+ table.setRenderer( new TupleRenderer() {
+ public String getKeyString( Object key )
+ {
+ return null;
+ }
+ public String getValueString( Object value )
+ {
+ return null;
+ }}
+ );
+ assertNotNull( table.getRenderer() );
+ table.setRenderer( null );
+ assertNull( table.getRenderer() );
+ assertEquals( "test", table.getName() );
+ assertNotNull( table.getComparator() );
+ }
+
+
+ @Test
+ public void testWhenEmpty() throws Exception
+ {
+ // Test the count methods
+ assertEquals( 0, table.count() );
+ assertEquals( 0, table.count( "1" ) );
+
+ // Test get method
+ assertNull( table.get( "0" ) );
+
+ // Test remove methods
+ assertNull( table.remove( "1" ) );
+
+ // Test has operations
+ assertFalse( table.has( "1" ) );
+ assertFalse( table.has( "1", "0" ) );
+ assertFalse( table.has( "1", true ) );
+ assertFalse( table.has( "1", false ) );
+ assertFalse( table.has( "1", "0", true ) );
+ assertFalse( table.has( "1", "0", false ) );
+ }
+
+
+ private class TestComparatorRegistry implements ComparatorRegistry
+ {
+ private StringComparator comparator = new StringComparator();
+
+ public String getSchemaName( String oid ) throws NamingException
+ {
+ return null;
+ }
+
+
+ public void register( ComparatorDescription description, Comparator
comparator ) throws NamingException
+ {
+ }
+
+
+ public Comparator lookup( String oid ) throws NamingException
+ {
+ return comparator;
+ }
+
+
+ public boolean hasComparator( String oid )
+ {
+ return true;
+ }
+
+
+ public Iterator<String> oidIterator()
+ {
+ return null;
+ }
+
+
+ public Iterator<ComparatorDescription> comparatorDescriptionIterator()
+ {
+ return null;
+ }
+
+
+ public void unregister( String oid ) throws NamingException
+ {
+ }
+
+
+ public void unregisterSchemaElements( String schemaName )
+ {
+ }
+
+
+ public void renameSchema( String originalSchemaName, String
newSchemaName )
+ {
+ }
+ }
+}
Modified:
directory/sandbox/akarasulu/bigbang/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/SerializableComparator.java
URL:
http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/SerializableComparator.java?rev=610243&r1=610242&r2=610243&view=diff
==============================================================================
---
directory/sandbox/akarasulu/bigbang/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/SerializableComparator.java
(original)
+++
directory/sandbox/akarasulu/bigbang/apacheds/schema-registries/src/main/java/org/apache/directory/server/schema/SerializableComparator.java
Tue Jan 8 16:41:31 2008
@@ -36,16 +36,16 @@
* @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx">Apache Directory
Project</a>
* @version $Rev$
*/
-public class SerializableComparator implements Comparator, Serializable
+public class SerializableComparator<E> implements Comparator<E>, Serializable
{
private static final long serialVersionUID = 3257566226288162870L;
/** the system global Comparator registry */
- private static ComparatorRegistry registry = null;
+ private static ComparatorRegistry registry;
/** the OID of the matchingRule for this comparator */
private String matchingRuleOid;
/** the transient wrapped comparator */
- private transient Comparator wrapped;
+ private transient Comparator<E> wrapped;
// ------------------------------------------------------------------------
@@ -67,6 +67,7 @@
// C O N T R U C T O R S
// ------------------------------------------------------------------------
+
public SerializableComparator( String matchingRuleOid )
{
this.matchingRuleOid = matchingRuleOid;
@@ -81,7 +82,7 @@
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
- public int compare( Object o1, Object o2 )
+ public int compare( E o1, E o2 )
{
if ( wrapped == null )
{
|
|