directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10361 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/role test/org/apache/rms/je/role
Date Wed, 28 Apr 2004 15:33:08 GMT
Author: akarasulu
Date: Wed Apr 28 08:33:07 2004
New Revision: 10361

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
Log:
Commit changes ...

 o completed JeRoleDAO.delete()
 o completed unit test for JeRoleDAO.delete()
 o added monitor interface methods for JeRoleDAO.delete()
 o implemented no-op monitor adapter methods



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	Wed Apr
28 08:33:07 2004
@@ -20,7 +20,6 @@
 import org.apache.rms.Role ;
 import org.apache.rms.Application ;
 import org.apache.rms.RmsException ;
-import org.apache.rms.BitPermission;
 
 import org.apache.rms.je.JeUtils ;
 import org.apache.rms.je.JeRmsException ;
@@ -73,9 +72,9 @@
 
 
     /**
-     * Creates a JE based permission DAO using a JE database.
+     * Creates a JE based role DAO using a JE database.
      *
-     * @param db the JE Database for the permission DAO
+     * @param db the JE Database for the role DAO
      */
     public JeRoleDAO( Database db, Sequence seq ) throws RmsException
     {
@@ -186,7 +185,56 @@
      */
     public void delete( String appName, String roleName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        OperationStatus status = null ;
+        DatabaseEntry key = null ;
+        DatabaseEntry value = new DatabaseEntry() ;
+
+        try
+        {
+            key = getRow( appName, roleName, true ) ;
+        }
+        catch ( JeRmsException e )
+        {
+            if ( e.getStatus() == OperationStatus.NOTFOUND )
+            {
+                monitor.roleDoesNotExist( this, "delete", appName, roleName ) ;
+            }
+
+            throw e ;
+        }
+
+        try
+        {
+            status = db.get( null, key, value, LockMode.DEFAULT ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                monitor.roleDoesNotExist( this, "delete", appName,
+                        roleName ) ;
+                throw new JeRmsException( status,
+                        "failed to get record for role "
+                        + roleName + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+
+            status = db.delete( null, key ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                monitor.roleDoesNotExist( this, "delete", appName,
+                        roleName ) ;
+                throw new JeRmsException( status,
+                        "failed to delete role " + roleName
+                        + " for application " + appName
+                        + " with status of " + status.toString() ) ;
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.deleteFailed( this, appName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        monitor.roleDeleted( this, appName, roleName ) ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	Wed
Apr 28 08:33:07 2004
@@ -20,6 +20,8 @@
 
 import java.io.IOException;
 
+import com.sleepycat.je.DatabaseException;
+
 
 /**
  * A monitor interface for Role data access objects.
@@ -113,4 +115,24 @@
      * @param role the application role that is looked up
      */
     void roleLookedUp( JeRoleDAO dao, Role role ) ;
+
+    /**
+     * Monitors events where a role for an application is successfully deleted.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     */
+    void roleDeleted( JeRoleDAO dao, String appName, String roleName ) ;
+
+    /**
+     * Monitors events where an application role deletion fails.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param fault the fault that caused the failure
+     */
+    void deleteFailed( JeRoleDAO dao, String appName, String roleName,
+                       Throwable fault ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
Wed Apr 28 08:33:07 2004
@@ -150,4 +150,34 @@
     public void roleLookedUp( JeRoleDAO dao, Role role )
     {
     }
+
+
+    /**
+     * Monitors events where a role for an application is successfully deleted.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     */
+    public void roleDeleted( JeRoleDAO dao, String appName, String roleName )
+    {
+    }
+
+
+    /**
+     * Monitors events where an application role deletion fails.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param fault    the fault that caused the failure
+     */
+    public void deleteFailed( JeRoleDAO dao, String appName, String roleName,
+                              Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
 }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	Wed
Apr 28 08:33:07 2004
@@ -137,4 +137,43 @@
         assertEquals( "roleD", role.getName() ) ;
         assertFalse( role.getGrants().hasNext() ) ;
     }
+
+
+    public void testCreateHasAndDelete() throws Exception
+    {
+        assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleB" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleC" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleD" ) ) ;
+
+        DefaultApplication application = new JeApplication( "app1" ) ;
+        roleDAO.create( application, "roleA" ) ;
+        roleDAO.create( application, "roleB" ) ;
+        roleDAO.create( application, "roleC" ) ;
+        roleDAO.create( application, "roleD" ) ;
+
+        assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+        roleDAO.delete( application.getName(), "roleA" ) ;
+        roleDAO.delete( application.getName(), "roleB" ) ;
+        roleDAO.delete( application.getName(), "roleC" ) ;
+        roleDAO.delete( application.getName(), "roleD" ) ;
+
+        assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleB" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleC" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleD" ) ) ;
+
+        try
+        {
+            roleDAO.delete( application.getName(), "roleA" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
 }

Mime
View raw message