directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10465 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/profile test/org/apache/rms/je/profile
Date Sat, 01 May 2004 01:53:17 GMT
Author: akarasulu
Date: Fri Apr 30 18:53:16 2004
New Revision: 10465

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
Log:
Commit changes ...

 o completed has(String, String) overload
 o completed and passed tests for this overload
 o added monitor interface methods for both has() methods
 o implemented no-op methods in monitor adapter



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
Fri Apr 30 18:53:16 2004
@@ -135,6 +135,10 @@
     public void create( String appName, String userName, String roleName )
             throws RmsException
     {
+        DatabaseEntry key ;
+        DatabaseEntry value ;
+        OperationStatus status ;
+
         if ( has( appName, userName, roleName ) )
         {
             monitor.roleLinkExists( this, "create", appName, userName,
@@ -143,10 +147,8 @@
                 + roleName + " for application " + appName ) ;
         }
 
-
-        DatabaseEntry key = new DatabaseEntry() ;
-        DatabaseEntry value = new DatabaseEntry() ;
-        OperationStatus status = null ;
+        key = new DatabaseEntry() ;
+        value = new DatabaseEntry() ;
         JeUtils.encodeInt( sq.getNextValue(), key ) ;
 
         try
@@ -232,6 +234,7 @@
         }
         catch ( UnsupportedEncodingException e )
         {
+            monitor.failedOnHas( this, appName, userName, roleName, e ) ;
             throw new RmsException( e ) ;
         }
 
@@ -281,6 +284,7 @@
         }
         catch ( DatabaseException e )
         {
+            monitor.failedOnHas( this, appName, userName, roleName, e ) ;
             throw new RmsException( e ) ;
         }
         finally
@@ -291,12 +295,9 @@
             closeNoError( roleNameCursor ) ;
         }
 
-        if ( status != OperationStatus.SUCCESS )
-        {
-            return false ;
-        }
-
-        return true ;
+        boolean haveIt = status == OperationStatus.SUCCESS ;
+        monitor.successOnHas( this, appName, userName, roleName, haveIt ) ;
+        return haveIt ;
     }
 
 
@@ -311,7 +312,71 @@
      */
     public boolean has( String appName, String roleName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        OperationStatus status = null ;
+        DatabaseEntry key = new DatabaseEntry() ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        DatabaseEntry appNameKey = new DatabaseEntry() ;
+        DatabaseEntry roleNameKey = new DatabaseEntry() ;
+
+        try
+        {
+            appNameKey.setData( appName.getBytes( "UTF-8" ) ) ;
+            roleNameKey.setData( roleName.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            monitor.failedOnHas( this, appName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        JoinCursor cursor = null ;
+        SecondaryCursor appNameCursor = null ;
+        SecondaryCursor roleNameCursor = null ;
+
+        try
+        {
+            // -o- setup the application name cursor -o-
+            appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
+            status = appNameCursor
+                    .getSearchKey( appNameKey, value, LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            // -o- setup the role name cursor -o-
+            roleNameCursor = byRoleName.openSecondaryCursor( null, null ) ;
+            status = roleNameCursor.getSearchKey( roleNameKey, value,
+                    LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                return false ;
+            }
+
+            // -o- prepare the cursor array and the join cursor -o-
+            SecondaryCursor [] secCursors = {
+                appNameCursor,
+                roleNameCursor
+            } ;
+
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnHas( this, appName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+        finally
+        {
+            closeNoError( cursor ) ;
+            closeNoError( appNameCursor ) ;
+            closeNoError( roleNameCursor ) ;
+        }
+
+        boolean haveIt = status == OperationStatus.SUCCESS ;
+        monitor.successOnHas( this, appName, roleName, haveIt ) ;
+        return haveIt ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
Fri Apr 30 18:53:16 2004
@@ -17,6 +17,9 @@
 package org.apache.rms.je.profile ;
 
 
+import com.sleepycat.je.DatabaseException;
+
+
 /**
  * A monitor interface for the Profile to Role link data access object.
  * 
@@ -67,7 +70,7 @@
     /**
      * Monitor callback notified when role links fail to be created.
      *
-     * @param dao the data access object that failed to create the role link
+     * @param dao the data access object performing that failed to create
      * @param appName the name of the application
      * @param userName the name of the user
      * @param roleName the name of the role
@@ -79,8 +82,8 @@
     /**
      * Monitor callback notified when role links fail to be created.
      *
-     * @param dao
-     * @param info
+     * @param dao the data access object that failed to create the role link
+     * @param info extra implementation specific information about the failure
      * @param appName the name of the application
      * @param userName the name of the user
      * @param roleName the name of the role
@@ -88,10 +91,72 @@
     void failedOnCreate( ProfileRoleLinkDAO dao, Object info, String appName,
                          String userName, String roleName ) ;
 
-
+    /**
+     * Monitors DAO successful resource cleanup events.
+     *
+     * @param dao the data access object performing the cleanup
+     * @param op the cleanup operation being performed
+     * @param resource the resource being cleaned up
+     */
     void cleanedUp( ProfileRoleLinkDAO dao, String op, Object resource ) ;
 
-
+    /**
+     * Monitors DAO failures while attempting to cleanup a resource via some
+     * operation.
+     *
+     * @param dao the data access object performing the cleanup
+     * @param op the cleanup operation being performed
+     * @param resource the resource being cleaned up
+     * @param fault the faulting condition that caused the failure
+     */
     void failedOnCleanupOperation( ProfileRoleLinkDAO dao, String op,
                                    Object resource, Throwable fault ) ;
+
+    /**
+     * Monitors DAO failures while checking for a link on a DAO has()
+     * operation.
+     *
+     * @param dao the data access object performing the lookup
+     * @param appName the name of the application
+     * @param userName the name of the user
+     * @param roleName the name of the role
+     * @param fault the faulting condition that caused the failure
+     */
+    void failedOnHas( ProfileRoleLinkDAO dao, String appName, String userName,
+                      String roleName, Throwable fault ) ;
+
+    /**
+     * Monitors DAO failures while checking for a link on a DAO has()
+     * operation.
+     *
+     * @param dao the data access object performing the lookup
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param fault the faulting condition that caused the failure
+     */
+    void failedOnHas( ProfileRoleLinkDAO dao, String appName,
+                      String roleName, Throwable fault ) ;
+
+    /**
+     * Monitors DAO has() checks to lookup whether or not a role link exists.
+     *
+     * @param dao the data access object performing the lookup
+     * @param appName the name of the application
+     * @param userName the name of the user
+     * @param roleName the name of the role
+     * @param haveIt whether or not a role link was found
+     */
+    void successOnHas( ProfileRoleLinkDAO dao, String appName, String userName,
+                       String roleName, boolean haveIt ) ;
+
+    /**
+     * Monitors DAO has() checks to lookup whether or not a role link exists.
+     *
+     * @param dao the data access object performing the lookup
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param haveIt whether or not a role link was found
+     */
+    void successOnHas( ProfileRoleLinkDAO dao, String appName,
+                       String roleName, boolean haveIt ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
Fri Apr 30 18:53:16 2004
@@ -38,6 +38,10 @@
                                    String appName, String userName,
                                    String roleName, Throwable fault )
     {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
     }
 
 
@@ -51,6 +55,10 @@
                                 String userName, String roleName,
                                 Throwable fault )
     {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
     }
 
 
@@ -68,6 +76,44 @@
 
     public void failedOnCleanupOperation( ProfileRoleLinkDAO dao, String op,
                                           Object resource, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    public void failedOnHas( ProfileRoleLinkDAO dao, String appName,
+                             String userName, String roleName,
+                             Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    public void successOnHas( ProfileRoleLinkDAO dao, String appName,
+                              String userName, String roleName,
+                              boolean haveIt )
+    {
+    }
+
+
+    public void failedOnHas( ProfileRoleLinkDAO dao, String appName,
+                             String roleName, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    public void successOnHas( ProfileRoleLinkDAO dao, String appName,
+                              String roleName, boolean haveIt )
     {
     }
 }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
Fri Apr 30 18:53:16 2004
@@ -89,8 +89,11 @@
     {
         assertFalse( dao.has( "app1", "user1", "roleA" ) ) ;
         assertFalse( dao.has( "app1", "user2", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+
         assertFalse( dao.has( "app2", "user1", "roleB" ) ) ;
         assertFalse( dao.has( "app2", "user2", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "roleA" ) ) ;
 
         dao.create( "app1", "user1", "roleA" ) ;
         dao.create( "app1", "user2", "roleA" ) ;
@@ -99,7 +102,12 @@
 
         assertTrue( dao.has( "app1", "user1", "roleA" ) ) ;
         assertTrue( dao.has( "app1", "user2", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+
         assertTrue( dao.has( "app2", "user1", "roleB" ) ) ;
         assertTrue( dao.has( "app2", "user2", "roleB" ) ) ;
+        assertTrue( dao.has( "app2", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "roleA" ) ) ;
     }
 }

Mime
View raw message