directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10322 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/permissions test/org/apache/rms/je/permissions
Date Tue, 27 Apr 2004 20:03:32 GMT
Author: akarasulu
Date: Tue Apr 27 13:03:31 2004
New Revision: 10322

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitorAdapter.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/permissions/LoggingBitPermissionDAOMonitor.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
Log:
Commit changes ...

 o added constraint checks to permission DAO on create() and rename()
 o added extra parameter to monitor interface method permissionExists()
 o added two extra hasRow() methods to perform a simple check for a permission



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitor.java
Tue Apr 27 13:03:31 2004
@@ -42,16 +42,17 @@
                          Throwable fault ) ;
 
     /**
-     * Monitors events where the DAO fails to create a new BitPermission
-     * because the permission for the application by the name specified
+     * Monitors events where the DAO fails to create/or rename a BitPermission
+     * because the permission for the application by the new name specified
      * already exists.
      *
      * @param dao the data access object that failed
+     * @param op the operation that was attempted
      * @param appName the name of the application
      * @param name the name of the permission
      */
-    void permissionExists( BitPermissionDAO dao, String appName,
-                           String name ) ;
+    void permissionExists( BitPermissionDAO dao, String op,
+                           String appName, String name ) ;
 
     /**
      * Monitors event where the DAO creates a new BitPermission.

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/BitPermissionDAOMonitorAdapter.java
Tue Apr 27 13:03:31 2004
@@ -51,11 +51,12 @@
      * the name specified already exists.
      *
      * @param dao     the data access object that failed
+     * @param op the operation that was attempted
      * @param appName the name of the application
      * @param name    the name of the permission
      */
-    public void permissionExists( BitPermissionDAO dao, String appName,
-                                  String name )
+    public void permissionExists( BitPermissionDAO dao, String op,
+                                  String appName, String name )
     {
     }
 

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
Tue Apr 27 13:03:31 2004
@@ -141,9 +141,16 @@
      */
     public int create( String appName, String name ) throws RmsException
     {
+        if ( hasRow( appName, name ) )
+        {
+            monitor.permissionExists( this, "create", appName, name ) ;
+            throw new RmsException( "Permission " + name
+                    + " exists for application " + appName ) ;
+        }
+
+        OperationStatus status = null ;
         int id = seq.getNextValue() ;
         int index = indexManager.claimIndex( appName ) ;
-        OperationStatus status = null ;
         DatabaseEntry key = new DatabaseEntry( JeUtils.encodeInt( id ) ) ;
         DatabaseEntry data = new DatabaseEntry() ;
 
@@ -169,7 +176,7 @@
             return index ;
         }
 
-        monitor.permissionExists( this, appName, name ) ;
+        monitor.permissionExists( this, "create", appName, name ) ;
         throw new JeRmsException( status,
                 "Create operation failed with status: " +
                 status.toString() ) ;
@@ -256,6 +263,13 @@
      */
     public void rename( String appName, String name, String newName ) throws RmsException
     {
+        if ( hasRow( appName, newName ) )
+        {
+            monitor.permissionExists( this, "rename", appName, newName ) ;
+            throw new RmsException( "Permission " + name
+                    + " exists for application " + appName ) ;
+        }
+
         OperationStatus status = null ;
         DatabaseEntry key = null ;
         DatabaseEntry value = new DatabaseEntry() ;
@@ -645,6 +659,82 @@
      * 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
+     * @return true if such a permission exists, false otherwise
+     * @throws RmsException if there are failures accessing the underlying JE
+     * databases
+     */
+    boolean hasRow( String appName, String name ) 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 = byPermName.openSecondaryCursor( null, null ) ;
+            appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
+
+            status = nameCursor
+                    .getSearchKey( nameEntry, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            status = appNameCursor
+                    .getSearchKey( appNameEntry, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            SecondaryCursor [] secCursors = { nameCursor, appNameCursor } ;
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+        finally
+        {
+            closeNoError( cursor ) ;
+            closeNoError( nameCursor ) ;
+            closeNoError( appNameCursor ) ;
+        }
+
+        return true ;
+    }
+
+
+    /**
+     * 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
@@ -740,6 +830,83 @@
         {
             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
+     * @return true if the permission exists false otherwise
+     * @throws RmsException if there are failures accessing the underlying JE
+     * databases
+     */
+    boolean hasRow( String appName, int index ) 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 = byIdx.openSecondaryCursor( null, null ) ;
+            appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
+
+            status = intCursor
+                    .getSearchKey( intEntry, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            status = appNameCursor
+                    .getSearchKey( appNameEntry, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            SecondaryCursor [] secCursors = { intCursor, appNameCursor } ;
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+        finally
+        {
+            closeNoError( cursor ) ;
+            closeNoError( intCursor ) ;
+            closeNoError( appNameCursor ) ;
+        }
+
+        return true ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
Tue Apr 27 13:03:31 2004
@@ -23,6 +23,8 @@
 import org.apache.rms.BitPermission ;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.commons.logging.impl.Jdk14Logger;
 import com.sleepycat.bind.EntryBinding;
 import com.sleepycat.je.DatabaseEntry;
 
@@ -67,16 +69,17 @@
      * already exists.
      *
      * @param dao     the data access object that failed
+     * @param op the operation that was attempted
      * @param appName the name of the application
      * @param name    the name of the permission
      */
-    public void permissionExists( BitPermissionDAO dao, String appName,
-                                  String name )
+    public void permissionExists( BitPermissionDAO dao, String op,
+                                  String appName, String name )
     {
         if ( log.isWarnEnabled() )
         {
-            log.warn( "Creation of permission with name " + name
-                    + " for application " + appName + " failed using " + dao
+            log.warn( dao + "." + op + "() on permission " + name
+                    + " for application " + appName + " failed"
                     + " because a permission by that name already exists" ) ;
         }
     }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/permissions/JeBitPermissionDAOTest.java
Tue Apr 27 13:03:31 2004
@@ -18,17 +18,17 @@
 
 
 import org.apache.rms.RmsException ;
-import org.apache.rms.BitPermission;
+import org.apache.rms.BitPermission ;
+
+import org.apache.rms.je.JeUtils ;
 import org.apache.rms.je.AbstractJeTest ;
-import org.apache.rms.je.JeUtils;
 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.*;
-import com.sleepycat.bind.EntryBinding;
 
-import java.util.Iterator;
+import java.util.Iterator ;
 
 
 /**
@@ -77,11 +77,13 @@
 
         JeBitPermissionIndexDAO indexDAO =
                 new JeBitPermissionIndexDAO( getDb( "indexManDb" ) ) ;
+        indexDAO.setMonitor( new LoggingBitPermissionIndexDAOMonitor() ) ;
         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 ) ;
+        bitPermissionDAO.setMonitor( new LoggingBitPermissionDAOMonitor() ) ;
     }
 
 
@@ -105,7 +107,6 @@
         assertEquals( 2, bitPermissionDAO.getIndex( "app1", "perm3" ) ) ;
         assertEquals( 3, bitPermissionDAO.getIndex( "app1", "perm4" ) ) ;
 
-        EntryBinding binding = new JeBitPermissionTupleBinding() ;
         assertEquals( 1, JeUtils.decodeInt( bitPermissionDAO.getRow(
                 "app1", 0, true ) ) ) ;
         assertEquals( 2, JeUtils.decodeInt( bitPermissionDAO.getRow(

Mime
View raw message