directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10191 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je java/org/apache/rms/je/permissions java/org/apache/rms/je/sequence test/org/apache/rms/je/permissions
Date Fri, 23 Apr 2004 01:58:24 GMT
Author: akarasulu
Date: Thu Apr 22 18:58:23 2004
New Revision: 10191

Added:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeAppNameKeyCreator.java   (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionTupleBinding.java
      - copied, changed from rev 10160, incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionTupleBinding.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeIndexKeyCreator.java   (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JePermNameKeyCreator.java   (contents, props changed)
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java   (contents, props changed)
Removed:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionMapTupleBinding.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionTupleBinding.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/BitPermissionMapTupleBindingTest.java
Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/AbstractJeTest.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeUtils.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceDao.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceFactory.java
Log:
Commit changes ...

 o added SecondaryKeyCreator for secondary permission databases
 o added JE BitPermissionDAO implementation
 o added a test case for the DAO
 o added ability to create additional databases in AbstractJeTest
 o deleted a old map bindings that are no longer used



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/AbstractJeTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/AbstractJeTest.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/AbstractJeTest.java	Thu Apr 22 18:58:23 2004
@@ -21,6 +21,9 @@
 import com.sleepycat.je.*;
 
 import java.io.File ;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 
 
 /**
@@ -43,6 +46,16 @@
     /** the database configuration */
     protected DatabaseConfig dbConfig = new DatabaseConfig() ;
 
+    // -----------------------------------------------------------------------
+    // Members used to manage extra databases
+    // -----------------------------------------------------------------------
+
+    /** Map of databases by name */
+    protected HashMap dbMap = new HashMap() ;
+    /** Map of database configurations by name */
+    protected HashMap dbConfigMap = new HashMap() ;
+
+
 
     protected void setUp() throws Exception
     {
@@ -57,20 +70,85 @@
         }
 
         env = new Environment( f, envConfig ) ;
+
+        // Create the main database
         dbConfig.setAllowCreate( true ) ;
         db = env.openDatabase( null, "testDb", dbConfig ) ;
+
+        // Create the extra databases
+        Iterator list = dbMap.keySet().iterator() ;
+        while ( list.hasNext() )
+        {
+            String name = ( String ) list.next() ;
+            Database xtraDb = null ;
+            DatabaseConfig conf = ( DatabaseConfig ) dbConfigMap.get( name ) ;
+
+            if ( conf == null )
+            {
+                conf = new DatabaseConfig() ;
+            }
+
+            conf.setAllowCreate( true ) ;
+            xtraDb = env.openDatabase( null, name, conf ) ;
+            dbMap.put( name, xtraDb ) ;
+        }
     }
 
 
     protected void tearDown() throws Exception
     {
         super.tearDown() ;
+
+        List databases = db.getSecondaryDatabases() ;
+        for ( int ii = 0; ii < databases.size(); ii++ )
+        {
+            Database secdb = ( Database ) databases.get( ii ) ;
+            String name = secdb.getDatabaseName() ;
+            secdb.close() ;
+            env.removeDatabase( null, name ) ;
+        }
+
         db.close() ;
+        db = null ;
+        dbConfig = null ;
         env.removeDatabase( null, "testDb" ) ;
+
+        // Close all the extra databases
+        Iterator list = dbMap.keySet().iterator() ;
+        while ( list.hasNext() )
+        {
+            String name = ( String ) list.next() ;
+            Database xtraDb = ( Database ) dbMap.get( name ) ;
+            xtraDb.close() ;
+            env.removeDatabase( null, name ) ;
+        }
+
         env.close() ;
 
         File f = new File( "testEnv" ) ;
         f.delete() ;
+
+        dbMap.clear() ;
+        dbConfigMap.clear() ;
+    }
+
+
+    public void setupDb( String name, DatabaseConfig config )
+    {
+        dbMap.put( name, null ) ;
+        dbConfigMap.put( name, config ) ;
+    }
+
+
+    public Database getDb( String name )
+    {
+        return ( Database ) dbMap.get( name ) ;
+    }
+
+
+    public void setupDb( String name )
+    {
+        setupDb( name, null ) ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeUtils.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeUtils.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeUtils.java	Thu Apr 22 18:58:23 2004
@@ -18,6 +18,9 @@
 
 
 import com.sleepycat.je.* ;
+import com.sleepycat.util.UtfOps;
+
+import java.io.IOException;
 
 
 /**

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAO.java	Thu Apr 22 18:58:23 2004
@@ -16,11 +16,15 @@
  */
 package org.apache.rms.je.permissions ;
 
-import org.apache.rms.RmsException;
+
+import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission ;
+
+import java.util.Iterator ;
 
 
 /**
- * Data access operations to be performed.
+ * Data access operations to be performed on BitPermissions.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -28,12 +32,122 @@
 public interface BitPermissionDAO
 {
     /**
-     * Gets the smallest available index to assign for new permissions.
+     * Creates a new BitPermission for an application.
+     *
+     * @param appName the name of the application
+     * @param name the name of the new permission
+     * @return the index the bit permission was created for
+     * @throws RmsException if there are failures accessing the backing store
+     * or the permission to create already exists for the application, or the
+     * application itself does not exist
+     */
+    int create( String appName, String name ) throws RmsException ;
+
+    /**
+     * Deletes a BitPermission for an application.
      *
-     * @param appName the name of the application for the new permission
-     * @return the smallest index that can be used for a bit permission
+     * @param appName the name of the application
+     * @param name the name of the permission to delete
+     * @throws RmsException if there are failures accessing the backing store
+     * or the permission does not exist, or the application itself does not
+     * exist
      */
-    int getSmallestAvailableIndex( String appName ) throws RmsException ;
+    void delete( String appName, String name ) throws RmsException ;
 
-//    void create( String name, int idx, String appName ) throws RmsException ;
+    /**
+     * Renames a BitBermission for an application
+     *
+     * @param newName the new name to set the permission's name to
+     * @param name the current name of the permission
+     * @param appName the name of the application
+     * @throws RmsException if there are failures accessing the backing store
+     * or the permission does not exist, or another permission with the new
+     * name already exists, or the application itself does not exist
+     */
+    void rename( String appName, String name, String newName ) throws RmsException ;
+
+    /**
+     * Gets the index of an application's permission.
+     *
+     * @param appName the name of the application
+     * @param name the name of the permission to get the index for
+     * @return the bit index the permission occupies
+     * @throws RmsException if there are failures accessing the backing store
+     * or the permission does not exist, or the application itself does not
+     * exist
+     */
+    int getIndex( String appName, String name ) throws RmsException ;
+
+    /**
+     * Gets the name of an application's permission using its index.
+     *
+     * @param appName the name of the application
+     * @param index the bit index of the permission
+     * @return the name of the application
+     * @throws RmsException if there are failures accessing the backing store
+     * or a permission at the specified index does not exist for the
+     * application, or the application itself does not exist
+     */
+    String getName( String appName, int index ) throws RmsException ;
+
+    /**
+     * Gets an application's permission by name.
+     *
+     * @param appName the name of the application
+     * @param name the name of the permission to get
+     * @return the application's BitPermission
+     * @throws RmsException if there are failures accessing the backing store
+     * or the permission does not exist, or the application itself does not
+     * exist
+     */
+    BitPermission getPermission( String appName, String name ) throws RmsException ;
+
+    /**
+     * Gets the application's permission by index.
+     *
+     * @param appName the name of the application
+     * @param index the bit index of the permission
+     * @return the application's BitPermission
+     * @throws RmsException if there are failures accessing the backing store
+     * or a permission at the specified index does not exist for the
+     * application, or the application itself does not exist
+     */
+    BitPermission getPermission( String appName, int index ) throws RmsException ;
+
+    /**
+     * Lists all the names of the permissions for an application.
+     *
+     * @param appName the name of the application to list the permissions for
+     * @return an iteration over the String names of BitPermissions
+     * @throws RmsException if there are failures accessing the backing store
+     * or the application does not exist.
+     */
+    Iterator listNames( String appName ) throws RmsException ;
+
+    /**
+     * Lists all the names of all the permissions.
+     *
+     * @return an iteration over the String names of all BitPermissions
+     * @throws RmsException if there are failures accessing the backing store
+     * or the application does not exist.
+     */
+    Iterator listNames() throws RmsException ;
+
+    /**
+     * Lists all the BitPermissions for an application.
+     *
+     * @param appName the name of the application to list the permissions for
+     * @return an iteration over the BitPermission objects for an application
+     * @throws RmsException if there are failures accessing the backing store
+     * or the application does not exist.
+     */
+    Iterator list( String appName ) throws RmsException ;
+
+    /**
+     * Lists all BitPermissions.
+     *
+     * @return an iteration over all BitPermission objects
+     * @throws RmsException if there are failures accessing the backing store
+     */
+    Iterator list() throws RmsException ;
 }

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeAppNameKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeAppNameKeyCreator.java	Thu Apr 22 18:58:23 2004
@@ -0,0 +1,70 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.rms.je.permissions ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+import java.io.IOException ;
+
+
+/**
+ * A permission appName key creator for the appName secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeAppNameKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized bit permission */
+    private static final JeBitPermissionTupleBinding BINDING =
+            new JeBitPermissionTupleBinding() ;
+
+    /**
+     * Sets the permission appName bytes for the result entry by extracting it
+     * from the dataEntry.
+     *
+     * @param secondaryDatabase the secondary database the new key is for
+     * @param keyEntry the key in the primary
+     * @param dataEntry the data in the primary
+     * @param resultEntry the new key for the secondary
+     * @return true if a key is created, false otherwise.
+     */
+    public boolean createSecondaryKey( SecondaryDatabase secondaryDatabase,
+                                       DatabaseEntry keyEntry,
+                                       DatabaseEntry dataEntry,
+                                       DatabaseEntry resultEntry )
+        throws DatabaseException
+    {
+        String name = null ;
+
+        try
+        {
+            name = BINDING.getApplicationName( dataEntry ) ;
+            resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new DatabaseException( e ) ;
+        }
+
+        return true ;
+    }
+}

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java	Thu Apr 22 18:58:23 2004
@@ -17,17 +17,21 @@
 package org.apache.rms.je.permissions ;
 
 
-import com.sleepycat.je.*;
+import com.sleepycat.je.* ;
+
+
+import java.util.List ;
+import java.util.Iterator ;
+
+import java.io.IOException ;
+import java.io.UnsupportedEncodingException ;
 
 import org.apache.commons.lang.Validate ;
-import org.apache.commons.lang.NotImplementedException;
 
+import org.apache.rms.je.JeUtils ;
 import org.apache.rms.RmsException ;
-import org.apache.rms.je.permissions.BitPermissionDAO;
-import org.apache.rms.je.sequence.Sequence;
-import org.apache.rms.je.sequence.Sequence;
-
-import java.io.UnsupportedEncodingException;
+import org.apache.rms.BitPermission ;
+import org.apache.rms.je.sequence.Sequence ;
 
 
 /**
@@ -38,18 +42,24 @@
  */
 public class JeBitPermissionDAO implements BitPermissionDAO
 {
-    private final BitPermissionTupleBinding permBinding =
-            new BitPermissionTupleBinding() ;
+    static final String APP_SECDB = "byApp" ;
+    static final String PERM_SECDB = "byName" ;
+    static final String INDEX_SECDB = "byIdx" ;
+
+    /** A BitPermission binding */
+    private static final JeBitPermissionTupleBinding BINDING =
+            new JeBitPermissionTupleBinding() ;
+
     /** the JE database to use for this DAP */
     private final Database db ;
     /** the sequence we use to create new permission row ids with */
     private final Sequence seq ;
-    /** the secondary database used to index permissions by vector indices */
-    private final SecondaryDatabase byIdx ;
-    /** the secondary database used to index permission by name */
-    private final SecondaryDatabase byName ;
-    /** the secondary database used to index permission by app name */
-    private final SecondaryDatabase byApp ;
+    /** the index manager used to track index availabilities */
+    private final BitPermissionIndexManager indexManager ;
+
+    private SecondaryDatabase byIdx ;
+    private SecondaryDatabase byApp ;
+    private SecondaryDatabase byName ;
 
 
     /**
@@ -57,66 +67,528 @@
      *
      * @param db the JE Database for the permission DAO
      */
-    JeBitPermissionDAO( Database db, Sequence seq, SecondaryDatabase idx,
-                   SecondaryDatabase name, SecondaryDatabase app )
+    public JeBitPermissionDAO( Database db, Sequence seq,
+                        BitPermissionIndexManager indexManager )
+        throws RmsException
     {
         Validate.notNull( db ) ;
         Validate.notNull( seq ) ;
-        Validate.notNull( app ) ;
-        Validate.notNull( idx ) ;
-        Validate.notNull( name ) ;
+        Validate.notNull( indexManager ) ;
 
         this.db = db ;
         this.seq = seq ;
-        this.byApp = app ;
-        this.byIdx = idx ;
-        this.byName = name ;
+        this.indexManager = indexManager ;
+
+        List secdbs = null ;
+        try
+        {
+            secdbs = this.db.getSecondaryDatabases() ;
+            for ( int ii = 0; ii < secdbs.size(); ii++ )
+            {
+                SecondaryDatabase secdb = ( SecondaryDatabase ) secdbs.get( ii ) ;
+                if ( secdb.getDatabaseName().equals( APP_SECDB ) )
+                {
+                    byApp = secdb ;
+                }
+                else if ( secdb.getDatabaseName().equals( INDEX_SECDB ) )
+                {
+                    byIdx = secdb ;
+                }
+                else if ( secdb.getDatabaseName().equals( PERM_SECDB ) )
+                {
+                    byName = secdb ;
+                }
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+
+        Validate.notNull( byApp ) ;
+        Validate.notNull( byIdx ) ;
+        Validate.notNull( byName ) ;
     }
 
 
     /**
-     * Gets the smallest available index to assign for new permissions.
+     * Creates a new BitPermission for an application.
      *
-     * @return the smallest index that can be used for a bit permission
+     * @param appName the name of the application
+     * @param name    the name of the new permission
+     * @return the index the bit permission was created for
+     * @throws org.apache.rms.RmsException if there are failures accessing the
+     * backing store or the permission to create already exists for the
+     * application, or the application itself does not exist
      */
-    public int getSmallestAvailableIndex( String appName ) throws RmsException
+    public int create( String appName, String name ) throws RmsException
+    {
+        int id = seq.getNextValue() ;
+        int index = indexManager.claimIndex( appName ) ;
+        OperationStatus status = null ;
+        DatabaseEntry key = new DatabaseEntry( JeUtils.encodeInt( id ) ) ;
+        DatabaseEntry data = new DatabaseEntry() ;
+
+        try
+        {
+            BINDING.objectToEntry(  data, appName, name, index ) ;
+            status = db.put( null, key, data ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new RmsException( e ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+
+        if ( status == OperationStatus.SUCCESS )
+        {
+            return index ;
+        }
+
+        throw new RmsException( "Create operation failed with status: " +
+                status.toString() ) ;
+    }
+
+
+    /**
+     * Deletes a BitPermission for an application.
+     *
+     * @param appName the name of the application
+     * @param name    the name of the permission to delete
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the permission does not exist, or the application
+     * itself does not exist
+     */
+    public void delete( String appName, String name ) throws RmsException
+    {
+        OperationStatus status = null ;
+        DatabaseEntry key = getRow( appName, name, true ) ;
+        DatabaseEntry value = new DatabaseEntry() ;
+
+        try
+        {
+            status = db.get( null, key, value, LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to get record for permission "
+                        + name + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+
+            status = db.delete( null, key ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to delete permission "
+                        + name + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+
+            indexManager.releaseIndex( appName,
+                    BINDING.getPermissionIndex( value ) ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+    }
+
+
+    /**
+     * Renames a BitBermission for an application
+     *
+     * @param newName the new name to set the permission's name to
+     * @param name    the current name of the permission
+     * @param appName the name of the application
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the permission does not exist, or another
+     * permission with the new name already exists, or the application
+     * itself does not exist
+     */
+    public void rename( String appName, String name, String newName ) throws RmsException
     {
-        /*
-         * Need to create a cursor over the byName secondary index and
-         * perform lookups on the byIdx secondary to find holes.  The
-         * first lookup to fail on the byIdx secondary is the hole.
-         */
-        int idx = 0 ;
-        SecondaryCursor cursor = null ;
-        DatabaseEntry appKey = new DatabaseEntry() ;
-        DatabaseEntry rowId = new DatabaseEntry() ;
         OperationStatus status = null ;
+        DatabaseEntry key = getRow( appName, name, true ) ;
+        DatabaseEntry value = new DatabaseEntry() ;
+
+        try
+        {
+            db.get( null, key, value, LockMode.DEFAULT ) ;
+            int index = BINDING.getPermissionIndex( value ) ;
+            BINDING.objectToEntry( value, appName, newName, index ) ;
+            status = db.put( null, key, value ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to rename permission "
+                        + name + " to " + newName + " for application "
+                        + appName + " with status of " + status.toString() ) ;
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new RmsException( e ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+    }
+
+
+    /**
+     * Gets the index of an application's permission.
+     *
+     * @param appName the name of the application
+     * @param name    the name of the permission to get the index for
+     * @return the bit index the permission occupies
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the permission does not exist, or the application
+     * itself does not exist
+     */
+    public int getIndex( String appName, String name ) throws RmsException
+    {
+        DatabaseEntry value = getRow( appName, name, false ) ;
+        return BINDING.getPermissionIndex( value ) ;
+    }
+
+
+    /**
+     * Gets an application's permission by name.
+     *
+     * @param appName the name of the application
+     * @param name    the name of the permission to get
+     * @return the application's BitPermission
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the permission does not exist, or the application
+     * itself does not exist
+     */
+    public BitPermission getPermission( String appName, String name ) throws RmsException
+    {
+        BitPermission perm = null ;
+        DatabaseEntry entry = getRow( appName, name, false ) ;
+
+        try
+        {
+            perm = ( BitPermission ) BINDING.entryToObject( entry ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new RmsException( e ) ;
+        }
+
+        return perm ;
+    }
+
+
+    /**
+     * Gets the name of an application's permission using its index.
+     *
+     * @param appName the name of the application
+     * @param index   the bit index of the permission
+     * @return the name of the application
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or a permission at the specified index does not exist
+     * for the application, or the application itself does not exist
+     */
+    public String getName( String appName, int index ) throws RmsException
+    {
+        DatabaseEntry value = getRow( appName, index, false ) ;
+
+        try
+        {
+            return BINDING.getPermissionName( value ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new RmsException( e ) ;
+        }
+    }
+
+
+    /**
+     * Gets the application's permission by index.
+     *
+     * @param appName the name of the application
+     * @param index   the bit index of the permission
+     * @return the application's BitPermission
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or a permission at the specified index does not
+     * exist for the application, or the application itself does not exist
+     */
+    public BitPermission getPermission( String appName, int index ) throws RmsException
+    {
+        DatabaseEntry value = getRow( appName, index, false ) ;
 
         try
         {
-            cursor = byApp.openSecondaryCursor( null, null ) ;
-            appKey.setData( appName.getBytes( "UTF-8" ) ) ;
-            status = cursor.getSearchKey( appKey, rowId, LockMode.DEFAULT ) ;
+            return ( BitPermission ) BINDING.entryToObject( value ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new RmsException( e ) ;
+        }
+    }
+
+
+    /**
+     * Lists all the names of the permissions for an application.
+     *
+     * @param appName the name of the application to list the permissions for
+     * @return an iteration over the String names of BitPermissions
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the application does not exist.
+     */
+    public Iterator listNames( String appName ) throws RmsException
+    {
+        return new JeApplicationPermissionIterator( appName, true ) ;
+    }
+
 
+    /**
+     * Lists all BitPermission names.
+     *
+     * @return an iteration over all permission names as Strings
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store
+     */
+    public Iterator listNames() throws RmsException
+    {
+        return new JeApplicationPermissionIterator( true ) ;
+    }
+
+
+    /**
+     * Lists all the BitPermissions for an application.
+     *
+     * @param appName the name of the application to list the permissions for
+     * @return an iteration over the BitPermission objects for an application
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store or the application does not exist.
+     */
+    public Iterator list( String appName ) throws RmsException
+    {
+        return new JeApplicationPermissionIterator( appName, false ) ;
+    }
+
+
+    /**
+     * Lists all BitPermissions.
+     *
+     * @return an iteration over all BitPermission objects
+     * @throws org.apache.rms.RmsException if there are failures accessing
+     * the backing store
+     */
+    public Iterator list() throws RmsException
+    {
+        return new JeApplicationPermissionIterator( false ) ;
+    }
+
+
+    /**
+     * Gets the key or value of an entry within the primary bit permission database.
+     *
+     * @param appName the name of the application
+     * @param name the name of the permission
+     * @param getKey if true gets the key, if false gets the value
+     * @return the key of the entry in the primary database
+     * @throws RmsException if there are failures accessing the underlying JE
+     * databases, or the application and/or the permission name does not exist
+     */
+    private DatabaseEntry getRow( String appName, String name, boolean getKey ) throws RmsException
+    {
+        DatabaseEntry key = new DatabaseEntry() ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        DatabaseEntry nameEntry = new DatabaseEntry() ;
+        DatabaseEntry appNameEntry = new DatabaseEntry() ;
+        OperationStatus status = null ;
+
+        try
+        {
+            nameEntry.setData( name.getBytes( "UTF-8" ) ) ;
+            appNameEntry.setData( appName.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            throw new RmsException( e ) ;
+        }
+
+        JoinCursor cursor = null ;
+        SecondaryCursor nameCursor = null ;
+        SecondaryCursor appNameCursor = null ;
+
+        try
+        {
+            nameCursor = byName.openSecondaryCursor( null, null ) ;
+            appNameCursor = byApp.openSecondaryCursor( null, null ) ;
+
+            status = nameCursor
+                    .getSearchKey( nameEntry, value, LockMode.DEFAULT ) ;
+            if ( status == OperationStatus.NOTFOUND )
+            {
+                throw new RmsException( "A permission by the name of "
+                        + name + " does not exist" ) ;
+            }
+            else if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to position name cursor "
+                        + "with status of " + status.toString() ) ;
+            }
+
+            status = appNameCursor
+                    .getSearchKey( appNameEntry, value, LockMode.DEFAULT ) ;
             if ( status == OperationStatus.NOTFOUND )
             {
-                return 0 ;
+                throw new RmsException( "An application by the name of "
+                        + appName + " does not exist" ) ;
             }
             else if ( status != OperationStatus.SUCCESS )
             {
-                throw new RmsException( "Failed to place cursor on " + appName ) ;
+                throw new RmsException( "failed to position app cursor "
+                        + "with status of " + status.toString() ) ;
             }
 
-            while ( cursor.getNextDup( appKey, rowId, LockMode.DEFAULT )
-                    == OperationStatus.SUCCESS )
+            SecondaryCursor [] secCursors = { nameCursor, appNameCursor } ;
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to get permission rowId "
+                        + name + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+        finally
+        {
+            if ( cursor != null )
             {
-                // keep going until getNextDup is not successful
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
             }
+            if ( nameCursor != null )
+            {
+                try
+                {
+                    nameCursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
+            }
+            if ( appNameCursor != null )
+            {
+                try
+                {
+                    appNameCursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
+            }
+        }
+
+
+        if ( getKey )
+        {
+            return key ;
+        }
+        else
+        {
+            return value ;
+        }
+    }
+
+
+    /**
+     * Gets the key or value of an entry within the primary bit permission database.
+     *
+     * @param appName the name of the application
+     * @param index the index of the permission
+     * @param getKey if true gets the key, if false gets the value
+     * @return the key of the entry in the primary database
+     * @throws RmsException if there are failures accessing the underlying JE
+     * databases, or the application and/or the permission name does not exist
+     */
+    private DatabaseEntry getRow( String appName, int index, boolean getKey ) throws RmsException
+    {
+        DatabaseEntry key = new DatabaseEntry() ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        DatabaseEntry intEntry = new DatabaseEntry() ;
+        DatabaseEntry appNameEntry = new DatabaseEntry() ;
+        OperationStatus status = null ;
+
+        JeUtils.encodeInt( index, intEntry ) ;
+
+        try
+        {
+            appNameEntry.setData( appName.getBytes( "UTF-8" ) ) ;
         }
         catch ( UnsupportedEncodingException e )
         {
             throw new RmsException( e ) ;
         }
+
+        JoinCursor cursor = null ;
+        SecondaryCursor intCursor = null ;
+        SecondaryCursor appNameCursor = null ;
+
+        try
+        {
+            intCursor = byName.openSecondaryCursor( null, null ) ;
+            appNameCursor = byApp.openSecondaryCursor( null, null ) ;
+
+            status = intCursor
+                    .getSearchKey( intEntry, value, LockMode.DEFAULT ) ;
+            if ( status == OperationStatus.NOTFOUND )
+            {
+                throw new RmsException( "A permission with an index of "
+                        + index + " does not exist" ) ;
+            }
+            else if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to position index cursor "
+                        + "with status of " + status.toString() ) ;
+            }
+
+            status = appNameCursor
+                    .getSearchKey( appNameEntry, value, LockMode.DEFAULT ) ;
+            if ( status == OperationStatus.NOTFOUND )
+            {
+                throw new RmsException( "An application by the name of "
+                        + appName + " does not exist" ) ;
+            }
+            else if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to position app cursor "
+                        + "with status of " + status.toString() ) ;
+            }
+
+            SecondaryCursor [] secCursors = { intCursor, appNameCursor } ;
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new RmsException( "failed to get permission with index "
+                        + index + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+        }
         catch ( DatabaseException e )
         {
             throw new RmsException( e ) ;
@@ -125,10 +597,291 @@
         {
             if ( cursor != null )
             {
-                try { cursor.close() ; } catch ( DatabaseException e )  {}
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
+            }
+            if ( intCursor != null )
+            {
+                try
+                {
+                    intCursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
+            }
+            if ( appNameCursor != null )
+            {
+                try
+                {
+                    appNameCursor.close() ;
+                }
+                catch ( DatabaseException e )
+                {
+                    throw new RmsException( e ) ;
+                }
             }
         }
 
-        throw new NotImplementedException( "STUB" ) ;
+
+        if ( getKey )
+        {
+            return key ;
+        }
+        else
+        {
+            return value ;
+        }
+    }
+
+
+    class JeApplicationPermissionIterator implements Iterator
+    {
+        final DatabaseEntry key = new DatabaseEntry() ;
+        final DatabaseEntry value = new DatabaseEntry() ;
+
+        final String appName ;
+        final boolean onlyNames ;
+        final boolean fullScan ;
+
+        boolean hasNext = true ;
+        Object prefetched = null ;
+        SecondaryCursor cursor = null ;
+        OperationStatus status = null ;
+
+
+        JeApplicationPermissionIterator( String appName, boolean onlyNames ) throws RmsException
+        {
+            this.fullScan = false ;
+            this.appName = appName ;
+            this.onlyNames = onlyNames ;
+
+            try
+            {
+                key.setData( appName.getBytes( "UTF-8" ) ) ;
+                cursor = byApp.openSecondaryCursor( null, null ) ;
+                status = cursor.getSearchKey( key, value, LockMode.DEFAULT ) ;
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    hasNext = false ;
+                    cursor.close() ;
+                    return ;
+                }
+
+                if ( onlyNames )
+                {
+                    prefetched = BINDING.getPermissionName( value ) ;
+                }
+                else
+                {
+                    prefetched = BINDING.entryToObject( value ) ;
+                }
+            }
+            catch ( DatabaseException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+            catch ( IOException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+        }
+
+
+        JeApplicationPermissionIterator( boolean onlyNames ) throws RmsException
+        {
+            this.fullScan = true ;
+            this.appName = null ;
+            this.onlyNames = onlyNames ;
+
+            try
+            {
+                cursor = byApp.openSecondaryCursor( null, null ) ;
+                status = cursor.getFirst( key, value, LockMode.DEFAULT ) ;
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    hasNext = false ;
+                    cursor.close() ;
+                    return ;
+                }
+
+                if ( onlyNames )
+                {
+                    prefetched = BINDING.getPermissionName( value ) ;
+                }
+                else
+                {
+                    prefetched = BINDING.entryToObject( value ) ;
+                }
+            }
+            catch ( DatabaseException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+            catch ( IOException e )
+            {
+                try
+                {
+                    cursor.close() ;
+                }
+                catch ( DatabaseException e1 )
+                {
+                    // @todo need to log this
+                    e1.printStackTrace();
+                }
+                throw new RmsException( e ) ;
+            }
+        }
+
+
+        public void remove()
+        {
+            throw new UnsupportedOperationException() ;
+        }
+
+
+        public boolean hasNext()
+        {
+            return hasNext ;
+        }
+
+
+        public Object next()
+        {
+            OperationStatus status = null ;
+            Object retVal = prefetched ;
+
+            try
+            {
+                if ( fullScan )
+                {
+                    status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+                }
+                else
+                {
+                    status = cursor.getNextDup( key, value, LockMode.DEFAULT ) ;
+                }
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    hasNext = false ;
+                    cursor.close() ;
+                }
+                else
+                {
+                    if ( onlyNames )
+                    {
+                        prefetched = BINDING.getPermissionName( value ) ;
+                    }
+                    else
+                    {
+                        prefetched = BINDING.entryToObject( value ) ;
+                    }
+                }
+            }
+            catch ( IOException e )
+            {
+                hasNext = false ;
+
+                if ( cursor != null )
+                {
+                    try
+                    {
+                        cursor.close() ;
+                    }
+                    catch ( DatabaseException e1 )
+                    {
+                        // @todo need to log this
+                        e1.printStackTrace();
+                    }
+                }
+
+                // @todo need to log this
+                e.printStackTrace() ;
+            }
+            catch ( DatabaseException e )
+            {
+                hasNext = false ;
+                if ( cursor != null )
+                {
+                    try
+                    {
+                        cursor.close() ;
+                    }
+                    catch ( DatabaseException e1 )
+                    {
+                        // @todo need to log this
+                        e1.printStackTrace();
+                    }
+                }
+
+                // @todo need to log this
+                e.printStackTrace() ;
+            }
+
+            return retVal ;
+        }
     }
 }

Copied: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionTupleBinding.java (from rev 10160, incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionTupleBinding.java)
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionTupleBinding.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionTupleBinding.java	Thu Apr 22 18:58:23 2004
@@ -17,14 +17,16 @@
 package org.apache.rms.je.permissions ;
 
 
+import com.sleepycat.je.DatabaseEntry ;
+
 import com.sleepycat.bind.tuple.TupleInput ;
 import com.sleepycat.bind.tuple.TupleOutput ;
 import com.sleepycat.bind.tuple.TupleBinding ;
 
 import java.io.IOException ;
 
+import org.apache.rms.je.JeUtils ;
 import org.apache.rms.BitPermission ;
-import org.apache.rms.je.permissions.JeBitPermission;
 
 
 /**
@@ -33,7 +35,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BitPermissionTupleBinding extends TupleBinding
+public class JeBitPermissionTupleBinding extends TupleBinding
 {
     /**
      * Reconstructs a bit permission using a serialized entry.
@@ -44,9 +46,9 @@
      */
     public Object entryToObject( TupleInput tupleInput ) throws IOException
     {
+        int index = tupleInput.readInt() ;
         String name = tupleInput.readString() ;
         String appName = tupleInput.readString() ;
-        int index = tupleInput.readInt() ;
 
         return new JeBitPermission( name, index, appName ) ;
     }
@@ -68,8 +70,91 @@
             return ;
         }
 
+        tupleOutput.writeInt( perm.getIndex() ) ;
         tupleOutput.writeString( perm.getName() ) ;
         tupleOutput.writeString( perm.getApplication() ) ;
-        tupleOutput.writeInt( perm.getIndex() ) ;
+    }
+
+
+    /**
+     * Marshals the components of a bit permission into a serialized Tuple.
+     *
+     * @param entry the entry to populate
+     * @param appName the name of the application
+     * @param name the name of the permission
+     * @param index the index of the permission
+     * @throws IOException if there are failures writing the data
+     */
+    public void objectToEntry( DatabaseEntry entry, String appName,
+                               String name, int index ) throws IOException
+    {
+        TupleOutput output = new TupleOutput() ;
+        output.writeInt( index ) ;
+        output.writeString( name ) ;
+        output.writeString( appName ) ;
+        entry.setData( output.getBufferBytes(), output.getBufferOffset(),
+                output.getBufferLength() ) ;
+    }
+
+
+    /**
+     * Efficiently gets the index value stored within a serialized permission.
+     *
+     * @param entry the entry to read the int from
+     * @return the index of the bit permission
+     */
+    public int getPermissionIndex( DatabaseEntry entry )
+    {
+        return JeUtils.decodeInt( entry.getData() ) ;
+    }
+
+
+    /**
+     * Efficiently gets the index bytes stored within a serialized permission.
+     *
+     * @param entry the entry to read the int from
+     * @return the index of the bit permission
+     */
+    public byte[] getPermissionIndexBytes( DatabaseEntry entry )
+    {
+        byte[] entryBytes = entry.getData() ;
+        byte[] indexBytes = new byte[4] ;
+        indexBytes[0] = entryBytes[0] ;
+        indexBytes[1] = entryBytes[1] ;
+        indexBytes[2] = entryBytes[2] ;
+        indexBytes[3] = entryBytes[3] ;
+        return indexBytes ;
+    }
+
+
+    /**
+     * Gets the name of a bit permission stored within the database entry.
+     *
+     * @param entry the database entry for the bit permission
+     * @return the name of the bit permission's name field
+     * @throws IOException if there are failures reading from the entry
+     */
+    public String getPermissionName( DatabaseEntry entry ) throws IOException
+    {
+        TupleInput in = new TupleInput( entry.getData() ) ;
+        in.readInt() ;
+        return in.readString() ;
+    }
+
+
+    /**
+     * Gets the name of a bit permission's application stored within the
+     * database entry.
+     *
+     * @param entry the database entry for the bit permission
+     * @return the name of the bit permission's application name field
+     * @throws IOException if there are failures reading from the entry
+     */
+    public String getApplicationName( DatabaseEntry entry ) throws IOException
+    {
+        TupleInput in = new TupleInput( entry.getData() ) ;
+        in.readInt() ;
+        in.readString() ;
+        return in.readString() ;
     }
 }

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeIndexKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeIndexKeyCreator.java	Thu Apr 22 18:58:23 2004
@@ -0,0 +1,57 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.rms.je.permissions ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+
+/**
+ * A index integer key creator for the index secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeIndexKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized bit permission */
+    private static final JeBitPermissionTupleBinding BINDING =
+            new JeBitPermissionTupleBinding() ;
+
+    /**
+     * Sets the permission index bytes for the result entry by extracting it
+     * from the dataEntry.
+     *
+     * @param secondaryDatabase the secondary database the new key is for
+     * @param keyEntry the key in the primary
+     * @param dataEntry the data in the primary
+     * @param resultEntry the new key for the secondary
+     * @return true if a key is created, false otherwise.
+     */
+    public boolean createSecondaryKey( SecondaryDatabase secondaryDatabase,
+                                       DatabaseEntry keyEntry,
+                                       DatabaseEntry dataEntry,
+                                       DatabaseEntry resultEntry )
+        throws DatabaseException
+    {
+        resultEntry.setData( BINDING.getPermissionIndexBytes( dataEntry ) ) ;
+        return true ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JePermNameKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JePermNameKeyCreator.java	Thu Apr 22 18:58:23 2004
@@ -0,0 +1,70 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.rms.je.permissions ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+import java.io.IOException ;
+
+
+/**
+ * A permission name key creator for the name secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JePermNameKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized bit permission */
+    private static final JeBitPermissionTupleBinding BINDING =
+            new JeBitPermissionTupleBinding() ;
+
+    /**
+     * Sets the permission name bytes for the result entry by extracting it
+     * from the dataEntry.
+     *
+     * @param secondaryDatabase the secondary database the new key is for
+     * @param keyEntry the key in the primary
+     * @param dataEntry the data in the primary
+     * @param resultEntry the new key for the secondary
+     * @return true if a key is created, false otherwise.
+     */
+    public boolean createSecondaryKey( SecondaryDatabase secondaryDatabase,
+                                       DatabaseEntry keyEntry,
+                                       DatabaseEntry dataEntry,
+                                       DatabaseEntry resultEntry )
+        throws DatabaseException
+    {
+        String name = null ;
+
+        try
+        {
+            name = BINDING.getPermissionName( dataEntry ) ;
+            resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new DatabaseException( e ) ;
+        }
+
+        return true ;
+    }
+}

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceDao.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceDao.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceDao.java	Thu Apr 22 18:58:23 2004
@@ -45,7 +45,7 @@
      * Creates a DAO
      * @param db
      */
-    JeSequenceDao( Database db )
+    public JeSequenceDao( Database db )
     {
         this.db = db ;
     }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceFactory.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceFactory.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/sequence/JeSequenceFactory.java	Thu Apr 22 18:58:23 2004
@@ -40,7 +40,7 @@
      *
      * @param dao the data access object
      */
-    JeSequenceFactory( JeSequenceDao dao )
+    public JeSequenceFactory( JeSequenceDao dao )
     {
         this.dao = dao ;
     }

Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java	Thu Apr 22 18:58:23 2004
@@ -0,0 +1,182 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.rms.je.permissions ;
+
+
+import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission;
+import org.apache.rms.je.AbstractJeTest ;
+import org.apache.rms.je.sequence.Sequence ;
+import org.apache.rms.je.sequence.JeSequenceDao ;
+import org.apache.rms.je.sequence.JeSequenceFactory ;
+
+import com.sleepycat.je.DatabaseConfig ;
+import com.sleepycat.je.SecondaryConfig ;
+
+import java.util.Iterator;
+
+
+/**
+ * Tests the JeBitPermissionDAO class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeBitPermissionDAOTest extends AbstractJeTest
+{
+    BitPermissionDAO bitPermissionDAO ;
+    BitPermissionIndexManager indexManager ;
+
+
+    protected void setUp() throws Exception
+    {
+        DatabaseConfig conf = new DatabaseConfig() ;
+        conf.setAllowCreate( true ) ;
+        conf.setAllowDuplicates( true ) ;
+        setupDb( "indexManDb", conf ) ;
+        conf = new DatabaseConfig() ;
+        conf.setAllowCreate( true ) ;
+        setupDb( "seqDb", conf ) ;
+        super.setUp() ;
+
+        SecondaryConfig sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeIndexKeyCreator() ) ;
+        env.openSecondaryDatabase( null, JeBitPermissionDAO.INDEX_SECDB,
+                sconf, db ) ;
+
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JePermNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, JeBitPermissionDAO.PERM_SECDB,
+                sconf, db ) ;
+
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeAppNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, JeBitPermissionDAO.APP_SECDB,
+                sconf, db ) ;
+
+        JeBitPermissionIndexDAO indexDAO =
+                new JeBitPermissionIndexDAO( getDb( "indexManDb" ) ) ;
+        indexManager = new JeBitPermissionIndexManager( indexDAO ) ;
+        JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
+        JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
+        Sequence seq = seqFactory.create( "indexSeq" ) ;
+        bitPermissionDAO = new JeBitPermissionDAO( db, seq, indexManager ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        bitPermissionDAO = null ;
+        indexManager = null ;
+    }
+
+
+    public void testAll() throws Exception
+    {
+        bitPermissionDAO.create( "app1", "perm1" ) ;
+        bitPermissionDAO.create( "app1", "perm2" ) ;
+        bitPermissionDAO.create( "app1", "perm3" ) ;
+        bitPermissionDAO.create( "app1", "perm4" ) ;
+
+        assertEquals( 0, bitPermissionDAO.getIndex( "app1", "perm1" ) ) ;
+        assertEquals( 1, bitPermissionDAO.getIndex( "app1", "perm2" ) ) ;
+        assertEquals( 2, bitPermissionDAO.getIndex( "app1", "perm3" ) ) ;
+        assertEquals( 3, bitPermissionDAO.getIndex( "app1", "perm4" ) ) ;
+
+        try
+        {
+            bitPermissionDAO.getIndex( "asdf", "asdf" ) ;
+            fail( "this above should not succeed" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        bitPermissionDAO.delete( "app1", "perm1" ) ;
+        try
+        {
+            bitPermissionDAO.getIndex( "app1", "perm1" ) ;
+            fail( "this above should not succeed" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        bitPermissionDAO.create( "app1", "perm5" ) ;
+        assertEquals( 0, bitPermissionDAO.getIndex( "app1", "perm5" ) ) ;
+        bitPermissionDAO.create( "app1", "perm1" ) ;
+        assertEquals( 4, bitPermissionDAO.getIndex( "app1", "perm1" ) ) ;
+        bitPermissionDAO.rename( "app1", "perm1", "perm6" ) ;
+        assertEquals( 4, bitPermissionDAO.getIndex( "app1", "perm6" ) ) ;
+
+        try
+        {
+            bitPermissionDAO.getIndex( "app1", "perm1" ) ;
+            fail( "this above should not succeed" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+
+        assertEquals( 4, bitPermissionDAO.getPermission( "app1",
+                "perm6" ).getIndex() ) ;
+
+        bitPermissionDAO.create( "app2", "permA" ) ;
+        assertEquals( 0, bitPermissionDAO.getIndex( "app2", "permA" ) ) ;
+
+        Iterator list = null ;
+        BitPermission perm = null ;
+        String name = null ;
+
+        list = bitPermissionDAO.list() ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "perm2", perm.getName() ) ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "perm3", perm.getName() ) ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "perm4", perm.getName() ) ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "perm5", perm.getName() ) ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "perm6", perm.getName() ) ;
+        perm = ( BitPermission ) list.next() ;
+        assertEquals( "permA", perm.getName() ) ;
+        assertFalse( list.hasNext() ) ;
+
+        list = bitPermissionDAO.listNames() ;
+        name = ( String ) list.next() ;
+        assertEquals( "perm2", name ) ;
+        name = ( String ) list.next() ;
+        assertEquals( "perm3", name ) ;
+        name = ( String ) list.next() ;
+        assertEquals( "perm4", name ) ;
+        name = ( String ) list.next() ;
+        assertEquals( "perm5", name ) ;
+        name = ( String ) list.next() ;
+        assertEquals( "perm6", name ) ;
+        name = ( String ) list.next() ;
+        assertEquals( "permA", name ) ;
+        assertFalse( list.hasNext() ) ;
+    }
+}
\ No newline at end of file

Mime
View raw message