directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10411 - incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application
Date Thu, 29 Apr 2004 05:22:10 GMT
Author: akarasulu
Date: Wed Apr 28 22:22:09 2004
New Revision: 10411

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
Log:
Commit changes ...

 o completed JeApplicationDAO with last listNames() operation
 o passed all unit tests for listNames()
 o added monitor interface methods to monitor the listing operation
 o implemented new monitor methods on no-op monitor adapter
 o completed ApplicationDAOMonitor and its adapter



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
Wed Apr 28 22:22:09 2004
@@ -16,7 +16,13 @@
  */
 package org.apache.rms.je.application ;
 
+import com.sleepycat.je.Cursor;
+import com.sleepycat.je.DatabaseException;
+
 import java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.rms.je.role.JeRoleDAO;
 
 
 /**
@@ -51,7 +57,7 @@
      * Monitor callback for events where the dao successfully creates a
      * new Application.
      *
-     * @param dao the data access object that failed
+     * @param dao the data access object
      * @param appName the name of the application
      */ 
     void applicationCreated( ApplicationDAO dao, String appName ) ;
@@ -60,7 +66,7 @@
      * Monitor callback for events where the dao failed at some operation
      * on the application because the application did not exist.
      *
-     * @param dao the data access object that failed
+     * @param dao the data access object
      * @param info extra implementation specific information
      * @param op the operation performed by the dao
      * @param appName the name of the application
@@ -104,7 +110,7 @@
      * Monitors callbacks for events where the dao failed to perform some
      * operation on an application because of the existance of an application.
      *
-     * @param dao the data access object that failed
+     * @param dao the data access object
      * @param op the operation performed by the dao
      * @param appName the name of the application
      */
@@ -146,4 +152,89 @@
      */
     void failedOnRename( ApplicationDAO dao, String oldName, String newName ) ;
 
+    /**
+     * Monitors callbacks for events where the dao cleaned up a resource
+     * by performing some operation on it.
+     *
+     * @param dao the data access object
+     * @param op the operation performed on the resource to clean it up
+     * @param resource the resource being cleaned up
+     */
+    void cleanedUp( ApplicationDAO dao, String op, Object resource ) ;
+
+    /**
+     * Monitors callbacks for events where the dao failed while trying to clean
+     * up a resource by performing some operation on it.
+     *
+     * @param dao the data access object that failed
+     * @param op the operation performed on the resource to clean it up
+     * @param resource the resource being cleaned up
+     * @param fault the fault that caused the failure
+     */
+    void failedOnCleanupOperation( ApplicationDAO dao, String op,
+                                   Object resource, Throwable fault ) ;
+
+    /**
+     * Monitors callbacks for events where the dao created an empty listing
+     * of application names.
+     *
+     * @param dao the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     */
+    void listingEmpty( ApplicationDAO dao, Iterator listing ) ;
+
+    /**
+     * Monitors callbacks for events where the dao successfully created a
+     * listing of application names.
+     *
+     * @param dao the data access object
+     * @param listing the iterator containing application names as Strings
+     */
+    void listingNames( ApplicationDAO dao, Iterator listing ) ;
+
+    /**
+     * Monitors callbacks for events where the dao failed to created a
+     * listing of application names.
+     *
+     * @param dao the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     * @param fault the fault that caused the failure
+     */
+    void failedListing( ApplicationDAO dao, Iterator listing,
+                        Throwable fault ) ;
+
+    /**
+     * Monitors callbacks for events where the iterator created by the dao
+     * is consumed but has yet to return the last element.
+     *
+     * @param dao the data access object
+     * @param listing the iterator containing application names as Strings
+     * @param retVal the last value left to return for the iterator
+     */
+    void iteratorExhausted( ApplicationDAO dao, Iterator listing,
+                            Object retVal ) ;
+
+    /**
+     * Monitors callbacks for events where the iterator successfully
+     * prefetches a value.
+     *
+     * @param dao the data access object
+     * @param listing the iterator containing application names as Strings
+     * @param retVal the last value left to return for the iterator
+     * @param prefetched the prefeteched value
+     */
+    void successOnNext( ApplicationDAO dao, Iterator listing,
+                        Object retVal, Object prefetched ) ;
+
+    /**
+     * Monitors callbacks for events where the dao failed to prefetch another
+     * item over the listing of application names.
+     *
+     * @param dao the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     * @param retVal the last value to return after failing to prefetch
+     * @param fault the fault that caused the failure
+     */
+    void iteratorFailure( ApplicationDAO dao, Iterator listing,
+                          Object retVal, Throwable fault ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
Wed Apr 28 22:22:09 2004
@@ -16,7 +16,8 @@
  */
 package org.apache.rms.je.application ;
 
-import org.apache.commons.lang.NotImplementedException;
+
+import java.util.Iterator ;
 
 
 /**
@@ -204,5 +205,127 @@
     public void failedOnRename( ApplicationDAO dao, String oldName,
                                 String newName )
     {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao cleaned up a resource by
+     * performing some operation on it.
+     *
+     * @param dao      the data access object
+     * @param op       the operation performed on the resource to clean it up
+     * @param resource the resource being cleaned up
+     */
+    public void cleanedUp( ApplicationDAO dao, String op, Object resource )
+    {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao failed while trying to
+     * clean up a resource by performing some operation on it.
+     *
+     * @param dao      the data access object that failed
+     * @param op       the operation performed on the resource to clean it up
+     * @param resource the resource being cleaned up
+     * @param fault    the fault that caused the failure
+     */
+    public void failedOnCleanupOperation( ApplicationDAO dao, String op,
+                                          Object resource, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao created an empty listing of
+     * application names.
+     *
+     * @param dao     the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     */
+    public void listingEmpty( ApplicationDAO dao, Iterator listing )
+    {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao successfully created a
+     * listing of application names.
+     *
+     * @param dao     the data access object
+     * @param listing the iterator containing application names as Strings
+     */
+    public void listingNames( ApplicationDAO dao, Iterator listing )
+    {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao failed to created a listing
+     * of application names.
+     *
+     * @param dao     the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     * @param fault   the fault that caused the failure
+     */
+    public void failedListing( ApplicationDAO dao, Iterator listing,
+                               Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    /**
+     * Monitors callbacks for events where the iterator created by the dao is
+     * consumed but has yet to return the last element.
+     *
+     * @param dao     the data access object
+     * @param listing the iterator containing application names as Strings
+     * @param retVal  the last value left to return for the iterator
+     */
+    public void iteratorExhausted( ApplicationDAO dao, Iterator listing,
+                                   Object retVal )
+    {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the iterator successfully
+     * prefetches a value.
+     *
+     * @param dao        the data access object
+     * @param listing    the iterator containing application names as Strings
+     * @param retVal     the last value left to return for the iterator
+     * @param prefetched the prefeteched value
+     */
+    public void successOnNext( ApplicationDAO dao, Iterator listing,
+                               Object retVal, Object prefetched )
+    {
+    }
+
+
+    /**
+     * Monitors callbacks for events where the dao failed to prefetch another
+     * item over the listing of application names.
+     *
+     * @param dao     the data access object that failed
+     * @param listing the iterator containing application names as Strings
+     * @param retVal  the last value to return after failing to prefetch
+     * @param fault   the fault that caused the failure
+     */
+    public void iteratorFailure( ApplicationDAO dao, Iterator listing,
+                                 Object retVal, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
     }
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
Wed Apr 28 22:22:09 2004
@@ -23,7 +23,6 @@
 import org.apache.rms.je.sequence.Sequence ;
 
 import org.apache.commons.lang.Validate ;
-import org.apache.commons.lang.NotImplementedException ;
 
 import java.util.List ;
 import java.util.Iterator ;
@@ -212,7 +211,6 @@
     {
         DatabaseEntry rowId ;
         OperationStatus status = null ;
-        DatabaseEntry value = new DatabaseEntry() ;
 
         try
         {
@@ -316,7 +314,7 @@
      */
     public Iterator listNames() throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        return new JeAppNameIterator() ;
     }
 
 
@@ -363,5 +361,205 @@
         }
 
         return rowId ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Utility Methods
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Sets this Application data access object's monitor.
+     *
+     * @param monitor the event monitor callbacks are sent to
+     */
+    public void setMonitor( ApplicationDAOMonitor monitor )
+    {
+        this.monitor = monitor ;
+    }
+
+
+    /**
+     * Gets this Application data access object's monitor.
+     *
+     * @return the event monitor callbacks are sent to
+     */
+    public ApplicationDAOMonitor getMonitor()
+    {
+        return this.monitor ;
+    }
+
+
+    /**
+     * Closes a cursor without throwing an error.
+     *
+     * @param cursor the cursor to close.
+     */
+    private void closeNoError( Cursor cursor )
+    {
+        if ( cursor == null )
+        {
+            monitor.cleanedUp( this, "close", cursor ) ;
+            return ;
+        }
+
+        try
+        {
+            cursor.close() ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnCleanupOperation( this, "close", cursor, e ) ;
+        }
+    }
+
+
+    /**
+     * Closes cursor based iterators that were created by this DAO.
+     *
+     * @param list the iterator to close.
+     */
+    void close( Iterator list )
+    {
+        if ( list == null )
+        {
+            return ;
+        }
+
+        if ( list instanceof JeAppNameIterator )
+        {
+            ( ( JeAppNameIterator ) list ).close() ;
+        }
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Cursor Iterator
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Special iterator to list the String names of applications within the
+     * entire database.  This Iterator is returned by the list method.
+     */
+    class JeAppNameIterator implements Iterator
+    {
+        final DatabaseEntry key = new DatabaseEntry() ;
+        final DatabaseEntry value = new DatabaseEntry() ;
+
+        boolean hasNext = true ;
+        Object prefetched = null ;
+        SecondaryCursor cursor = null ;
+        OperationStatus status = null ;
+
+
+        JeAppNameIterator() throws RmsException
+        {
+            try
+            {
+                cursor = byAppName.openSecondaryCursor( null, null ) ;
+                status = cursor.getFirst( key, value, LockMode.DEFAULT ) ;
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    hasNext = false ;
+                    closeNoError( cursor ) ;
+                    monitor.listingEmpty( JeApplicationDAO.this, this ) ;
+                    return ;
+                }
+
+                prefetched = BINDING.getApplicationName( value ) ;
+                monitor.listingNames( JeApplicationDAO.this, this ) ;
+            }
+            catch ( DatabaseException e )
+            {
+                closeNoError( cursor ) ;
+                monitor.failedListing( JeApplicationDAO.this, this, e ) ;
+                throw new RmsException( e ) ;
+            }
+            catch ( UnsupportedEncodingException e )
+            {
+                closeNoError( cursor ) ;
+                monitor.failedListing( JeApplicationDAO.this, this, e ) ;
+                throw new RmsException( e ) ;
+            }
+            catch ( IOException e )
+            {
+                closeNoError( cursor ) ;
+                monitor.failedListing( JeApplicationDAO.this, this, e ) ;
+                throw new RmsException( e ) ;
+            }
+        }
+
+
+        public void remove()
+        {
+            throw new UnsupportedOperationException() ;
+        }
+
+
+        public boolean hasNext()
+        {
+            return hasNext ;
+        }
+
+
+        public Object next()
+        {
+            OperationStatus status = null ;
+            Object retVal = prefetched ;
+
+            try
+            {
+                status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+
+                if ( status != OperationStatus.SUCCESS )
+                {
+                    hasNext = false ;
+                    closeNoError( cursor ) ;
+                    monitor.iteratorExhausted( JeApplicationDAO.this, this,
+                            retVal ) ;
+                }
+                else
+                {
+                    prefetched = BINDING.getApplicationName( value ) ;
+                    monitor.successOnNext( JeApplicationDAO.this, this, retVal,
+                            prefetched ) ;
+                }
+            }
+            catch ( IOException e )
+            {
+                hasNext = false ;
+
+                if ( cursor != null )
+                {
+                    closeNoError( cursor ) ;
+                }
+
+                monitor.iteratorFailure( JeApplicationDAO.this, this,
+                        retVal, e ) ;
+            }
+            catch ( DatabaseException e )
+            {
+                hasNext = false ;
+                if ( cursor != null )
+                {
+                    closeNoError( cursor ) ;
+                }
+
+                monitor.iteratorFailure( JeApplicationDAO.this, this,
+                        retVal, e ) ;
+            }
+
+            return retVal ;
+        }
+
+
+        void close()
+        {
+            hasNext = false ;
+            closeNoError( cursor ) ;
+        }
     }
 }

Mime
View raw message