You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/06/02 03:41:42 UTC

svn commit: rev 20747 - in incubator/directory/rms/trunk: je/src/java/org/apache/rms/je/profile je/src/test/org/apache/rms/je/profile spi/src/java/org/apache/rms/spi

Author: akarasulu
Date: Tue Jun  1 18:41:42 2004
New Revision: 20747

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileDAO.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileDAOTest.java
   incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitor.java
   incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitorAdapter.java
Log:
Commit changes ...

 o implemented get and list functions
 o added tests which now pass after some debugging 
 o added relavent monitor methods w/ adapter noop method impls



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileDAO.java	Tue Jun  1 18:41:42 2004
@@ -26,16 +26,15 @@
 import org.apache.rms.spi.ProfileRoleLinkDAO ;
 
 import org.apache.rms.je.JeUtils ;
+import org.apache.rms.je.JeIterator ;
 import org.apache.rms.je.JeRmsException ;
-import org.apache.rms.je.JeSecondaryIterator;
-import org.apache.rms.je.JeIterator;
 import org.apache.rms.je.sequence.Sequence ;
+import org.apache.rms.je.JeSecondaryIterator ;
 
 import org.apache.commons.lang.Validate ;
+import org.apache.commons.collections.Transformer ;
 import org.apache.commons.lang.NotImplementedException ;
-import org.apache.commons.lang.exception.NestableRuntimeException;
-import org.apache.commons.collections.iterators.EmptyIterator ;
-import org.apache.commons.collections.Transformer;
+import org.apache.commons.lang.exception.NestableRuntimeException ;
 
 import java.util.List ;
 import java.util.Iterator ;
@@ -48,7 +47,8 @@
 /**
  * Je database based Profile data access object implementation.
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
  * @version $Rev$
  */
 public class JeProfileDAO implements ProfileDAO
@@ -396,10 +396,48 @@
      * @throws org.apache.rms.RmsException if there is a failure accessing
      * the underlying database
      */
-    public Iterator listApplicationNames( String userName )
+    public Iterator listApplicationNames( final String userName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        JeIterator iterator = null ;
+        SecondaryCursor userNameCursor = null ;
+
+        try
+        {
+            // -o- setup the user name cursor -o-
+            userNameCursor = byUserName.openSecondaryCursor( null, null ) ;
+            iterator = new JeSecondaryIterator( userNameCursor, userName ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnListApplicationNames( this, userName, e ) ;
+            throw new RmsException( e ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnListApplicationNames( this, userName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        iterator.setTransformer( new Transformer()
+        {
+            public Object transform( Object o )
+            {
+                try
+                {
+                    return binding.getApplicationName( ( DatabaseEntry ) o ) ;
+                }
+                catch ( IOException e )
+                {
+                    monitor.failedOnListApplicationNames( JeProfileDAO.this,
+                        userName, e ); ;
+                    throw new NestableRuntimeException(
+                        "JeIterator's transformer transform() failed", e ) ;
+                }
+            }
+        }) ;
+
+        return iterator ;
     }
 
 
@@ -486,7 +524,31 @@
             } ;
 
             cursor = db.join( secCursors, null ) ;
-            status = cursor.getNext( key, LockMode.DEFAULT ) ;
+
+            if ( getKey )
+            {
+                status = cursor.getNext( key, LockMode.DEFAULT ) ;
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    throw new JeRmsException( status, "profile for user "
+                            + userName
+                            + " in application " + appName
+                            + " not found due to join status of " + status )  ;
+                }
+
+                return key ;
+            }
+
+            DatabaseEntry row = new DatabaseEntry() ;
+            status = cursor.getNext( key, row, LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new JeRmsException( status, "profile for user " + userName
+                    + " in application " + appName
+                    + " not found due to join status of " + status )  ;
+            }
+            return row ;
         }
         catch ( DatabaseException e )
         {
@@ -499,15 +561,6 @@
             closeNoError( appNameCursor ) ;
             closeNoError( userNameCursor ) ;
         }
-
-        if ( status != OperationStatus.SUCCESS )
-        {
-            throw new JeRmsException( status, "profile for user " + userName
-                + " in application " + appName
-                + " not found due to join status of " + status )  ;
-        }
-
-        return key ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileDAOTest.java	(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileDAOTest.java	Tue Jun  1 18:41:42 2004
@@ -19,6 +19,8 @@
 
 import java.util.HashSet ;
 import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.HashMap;
 
 import com.sleepycat.je.Database ;
 import com.sleepycat.je.SecondaryConfig ;
@@ -27,6 +29,7 @@
 import org.apache.rms.je.sequence.Sequence ;
 import org.apache.rms.je.sequence.JeSequenceDao ;
 import org.apache.rms.je.sequence.JeSequenceFactory ;
+import org.apache.rms.*;
 import org.apache.commons.collections.CollectionUtils ;
 
 
@@ -141,6 +144,99 @@
     }
 
 
+    public void testGet() throws Exception
+    {
+        assertFalse( dao.has( "app1", "user1" ) ) ;
+        assertFalse( dao.has( "app1", "user2" ) ) ;
+        assertFalse( dao.has( "app1", "user3" ) ) ;
+        assertFalse( dao.has( "app1", "user4" ) ) ;
+        assertFalse( dao.has( "app2", "user1" ) ) ;
+        assertFalse( dao.has( "app2", "user5" ) ) ;
+
+        dao.create( "app1", "user1" ) ;
+        dao.create( "app1", "user2" ) ;
+        dao.create( "app1", "user3" ) ;
+        dao.create( "app1", "user4" ) ;
+        dao.create( "app2", "user1" ) ;
+        dao.create( "app2", "user5" ) ;
+
+        assertTrue( dao.has( "app1", "user1" ) ) ;
+        assertTrue( dao.has( "app1", "user2" ) ) ;
+        assertTrue( dao.has( "app1", "user3" ) ) ;
+        assertTrue( dao.has( "app1", "user4" ) ) ;
+        assertTrue( dao.has( "app2", "user1" ) ) ;
+        assertTrue( dao.has( "app2", "user5" ) ) ;
+
+        Application app1 = new DefaultApplication( "app1", new HashMap(),
+                new ArrayList() ) {};
+        Application app2 = new DefaultApplication( "app2", new HashMap(),
+                new ArrayList() ) {};
+
+        Profile profile = dao.get( app1, "user1" ) ;
+        assertEquals( "app1", profile.getApplicationName() ) ;
+        assertEquals( "user1", profile.getUserName() ) ;
+
+        profile = dao.get( app1, "user2" ) ;
+        assertEquals( "app1", profile.getApplicationName() ) ;
+        assertEquals( "user2", profile.getUserName() ) ;
+
+        profile = dao.get( app1, "user3" ) ;
+        assertEquals( "app1", profile.getApplicationName() ) ;
+        assertEquals( "user3", profile.getUserName() ) ;
+
+        profile = dao.get( app1, "user4" ) ;
+        assertEquals( "app1", profile.getApplicationName() ) ;
+        assertEquals( "user4", profile.getUserName() ) ;
+
+        profile = dao.get( app2, "user1" ) ;
+        assertEquals( "app2", profile.getApplicationName() ) ;
+        assertEquals( "user1", profile.getUserName() ) ;
+
+        profile = dao.get( app2, "user5" ) ;
+        assertEquals( "app2", profile.getApplicationName() ) ;
+        assertEquals( "user5", profile.getUserName() ) ;
+    }
+
+
+    public void testDelete() throws Exception
+    {
+        assertFalse( dao.has( "app1", "user1" ) ) ;
+        assertFalse( dao.has( "app1", "user2" ) ) ;
+        assertFalse( dao.has( "app1", "user3" ) ) ;
+        assertFalse( dao.has( "app1", "user4" ) ) ;
+        assertFalse( dao.has( "app2", "user1" ) ) ;
+        assertFalse( dao.has( "app2", "user5" ) ) ;
+
+        dao.create( "app1", "user1" ) ;
+        dao.create( "app1", "user2" ) ;
+        dao.create( "app1", "user3" ) ;
+        dao.create( "app1", "user4" ) ;
+        dao.create( "app2", "user1" ) ;
+        dao.create( "app2", "user5" ) ;
+
+        assertTrue( dao.has( "app1", "user1" ) ) ;
+        assertTrue( dao.has( "app1", "user2" ) ) ;
+        assertTrue( dao.has( "app1", "user3" ) ) ;
+        assertTrue( dao.has( "app1", "user4" ) ) ;
+        assertTrue( dao.has( "app2", "user1" ) ) ;
+        assertTrue( dao.has( "app2", "user5" ) ) ;
+
+        dao.delete( "app1", "user1" ) ;
+        dao.delete( "app1", "user2" ) ;
+        dao.delete( "app1", "user3" ) ;
+        dao.delete( "app1", "user4" ) ;
+        dao.delete( "app2", "user1" ) ;
+        dao.delete( "app2", "user5" ) ;
+
+        assertFalse( dao.has( "app1", "user1" ) ) ;
+        assertFalse( dao.has( "app1", "user2" ) ) ;
+        assertFalse( dao.has( "app1", "user3" ) ) ;
+        assertFalse( dao.has( "app1", "user4" ) ) ;
+        assertFalse( dao.has( "app2", "user1" ) ) ;
+        assertFalse( dao.has( "app2", "user5" ) ) ;
+    }
+
+
     public void testListUserName() throws Exception
     {
         assertFalse( dao.listUserNames( "app1" ).hasNext() ) ;
@@ -160,6 +256,29 @@
         assertTrue( set.contains( "user3" ) ) ;
         assertTrue( set.contains( "user4" ) ) ;
         assertFalse( set.contains( "user5" ) ) ;
+        assertFalse( list.hasNext() ) ;
+    }
+
+
+    public void testListApplicationNames() throws Exception
+    {
+        assertFalse( dao.listApplicationNames( "app1" ).hasNext() ) ;
+        dao.create( "app1", "user1" ) ;
+        dao.create( "app2", "user1" ) ;
+        dao.create( "app3", "user1" ) ;
+        dao.create( "app4", "user1" ) ;
+        dao.create( "app1", "user2" ) ;
+        dao.create( "app5", "user2" ) ;
+
+        HashSet set = new HashSet() ;
+        Iterator list = dao.listApplicationNames( "user1" ) ;
+        CollectionUtils.addAll( set, list ) ;
+        assertEquals( 4, set.size() ) ;
+        assertTrue( set.contains( "app1" ) ) ;
+        assertTrue( set.contains( "app2" ) ) ;
+        assertTrue( set.contains( "app3" ) ) ;
+        assertTrue( set.contains( "app4" ) ) ;
+        assertFalse( set.contains( "app5" ) ) ;
         assertFalse( list.hasNext() ) ;
     }
 }

Modified: incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitor.java	(original)
+++ incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitor.java	Tue Jun  1 18:41:42 2004
@@ -68,4 +68,8 @@
     void failedOnListUserNames( ProfileDAO dao, String appName,
                                 Throwable fault ) ;
 
+
+    void failedOnListApplicationNames( ProfileDAO dao, 
+                                       String userName, Throwable fault ) ;
+
 }

Modified: incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitorAdapter.java	(original)
+++ incubator/directory/rms/trunk/spi/src/java/org/apache/rms/spi/ProfileDAOMonitorAdapter.java	Tue Jun  1 18:41:42 2004
@@ -122,4 +122,14 @@
             fault.printStackTrace() ;
         }
     }
+
+
+    public void failedOnListApplicationNames( ProfileDAO dao, String userName,
+                                              Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
 }