directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20739 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/profile test/org/apache/rms/je/profile
Date Tue, 01 Jun 2004 17:44:45 GMT
Author: akarasulu
Date: Tue Jun  1 10:44:44 2004
New Revision: 20739

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
Log:
Commit changes ...
 
 o added setup body to profile dao test
 o wrote has() test method
 o changed getpk to getRow with boolean flag to get key or data
 o finished off the get() method in the DAO



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 10:44:44 2004
@@ -151,20 +151,20 @@
             appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
             status = appNameCursor
                 .getSearchKey( appNameKey, value, LockMode.DEFAULT ) ;
-            if ( status != OperationStatus.SUCCESS )
+
+            if ( status == OperationStatus.NOTFOUND )
             {
-                throw new JeRmsException( status, "application " + appName
-                    + " lookup in secondary failed with status " + status )  ;
+                return false ;
             }
 
             // -o- setup the user name cursor -o-
             userNameCursor = byUserName.openSecondaryCursor( null, null ) ;
             status = userNameCursor.getSearchKey( userNameKey, value,
                 LockMode.DEFAULT ) ;
+
             if ( status != OperationStatus.SUCCESS )
             {
-                throw new JeRmsException( status, "user " + userName
-                    + " lookup in secondary failed with status " + status )  ;
+                return false ;
             }
 
             // -o- prepare the cursor array and the join cursor -o-
@@ -266,7 +266,7 @@
 
         try
         {
-            pk = getPkEntry( appName, userName ) ;
+            pk = getRow( appName, userName, true ) ;
         }
         catch ( JeRmsException e )
         {
@@ -309,7 +309,22 @@
     public Profile get( Application application, String userName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        Profile profile = null ;
+        String appName = application.getName() ;
+        DatabaseEntry entry = getRow( appName, userName, false ) ;
+
+        try
+        {
+            JeProfileBinding.setApplication( application ) ;
+            profile = ( Profile ) binding.entryToObject( entry ) ;
+            JeProfileBinding.setApplication( null ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnLookup( this, appName, userName, e ) ;
+        }
+
+        return profile ;
     }
 
 
@@ -368,11 +383,13 @@
      *
      * @param appName  the name of the profile's application
      * @param userName the name of the profile's user
-     * @return the primary key (rowId) entry of the link record
+     * @param getKey true returns the primary key, false returns the entry data
+     * @return the primary key or entry of the record
      * @throws org.apache.rms.RmsException if there is a failure to access the
      * underlying database, or the entry does not exist
      */
-    public DatabaseEntry getPkEntry( String appName, String userName )
+    public DatabaseEntry getRow( String appName, String userName,
+                                 boolean getKey )
         throws RmsException
     {
         OperationStatus status = null ;

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 10:44:44 2004
@@ -17,24 +17,102 @@
 package org.apache.rms.je.profile ;
 
 
+import com.sleepycat.je.Database ;
+import com.sleepycat.je.SecondaryConfig ;
+
 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 ;
 
 
 /**
  * A unit test case for a Je based Profile data access object.
  * 
- * @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 JeProfileDAOTest extends AbstractJeTest
 {
     /** the Je based Profile data access object to test*/
     JeProfileDAO dao = null ;
+    JeProfileRoleLinkDAO roleLinkDao = null ;
 
 
+    /**
+     * @todo all this DAO codee needs to start to make its way into
+     * DAOFactory classes.
+     * @throws Exception
+     */
     protected void setUp() throws Exception
     {
+        setupDb( "sqDb" ) ;
+        setupDb( "roleLinkDb" ) ;
+
         super.setUp() ;
+
+        SecondaryConfig sconf = null ;
+        String name = null;
+
+
+        // --------------------------------------------------------------------
+        // Setup the role link DAO
+        // --------------------------------------------------------------------
+
+
+        // -o- create the appName secondary db -o-
+        name = JeProfileRoleLinkDAO.APPNAME_SECDB ;
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeLinkAppNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, name, sconf, getDb( "roleLinkDb" ) ) ;
+
+        // -o- create the userName secondary db -o-
+        name = JeProfileRoleLinkDAO.USERNAME_SECDB ;
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeLinkUserNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, name, sconf, getDb( "roleLinkDb" ) ) ;
+
+        // -o- create the roleName secondary db -o-
+        name = JeProfileRoleLinkDAO.ROLENAME_SECDB ;
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeLinkRoleNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, name, sconf, getDb( "roleLinkDb" ) ) ;
+
+        Database sqDb = getDb( "sqDb" ) ;
+        JeSequenceDao sqDao = new JeSequenceDao( sqDb ) ;
+        JeSequenceFactory sqFactory = new JeSequenceFactory( sqDao ) ;
+        Sequence sq = sqFactory.create( "roleLinkDbSeq" ) ;
+        roleLinkDao = new JeProfileRoleLinkDAO( getDb( "roleLinkDb" ), sq ) ;
+
+        // --------------------------------------------------------------------
+
+        JeProfileBinding binding = new JeProfileBinding( roleLinkDao ) ;
+
+        // -o- create the appName secondary db -o-
+        name = JeProfileDAO.APPNAME_SECDB ;
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeProfileAppNameKeyCreator( binding ) ) ;
+        env.openSecondaryDatabase( null, name, sconf, db ) ;
+
+        // -o- create the userName secondary db -o-
+        name = JeProfileDAO.USERNAME_SECDB ;
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeProfileUserNameKeyCreator( binding ) ) ;
+        env.openSecondaryDatabase( null, name, sconf, db ) ;
+
+        sq = sqFactory.create( "profileDbSeq" ) ;
+        dao = new JeProfileDAO( db, sq, binding, roleLinkDao ) ;
     }
 
 
@@ -42,5 +120,11 @@
     {
         super.tearDown() ;
         dao = null ;
+    }
+
+
+    public void testHas() throws Exception
+    {
+        assertFalse( dao.has( "app1", "user1" ) ) ;
     }
 }

Mime
View raw message