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/04/28 19:43:18 UTC
svn commit: rev 10365 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/application java/org/apache/rms/je/role test/org/apache/rms/je/role
Author: akarasulu
Date: Wed Apr 28 10:43:18 2004
New Revision: 10365
Modified:
incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java
incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java
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/JeRoleNameKeyCreator.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 fixed binding to reference a application factory - need for list ops
o removed ThreadLocal to pass Application which doesn't work for list ops
o key creators for 2ndary dbs now have constructor that requires a binding
o completed JeRoleDAO.list()
o completed JeRoleDAO.listNames()
o completed JeRoleDAO.list(String)
o completed JeRoleDAO.listNames(String)
o completed unit tests for all these new JeRoleDAO list operations
o made JeApplication mutable although the mutable ops are not implemented
these ops throw NotImplementedExceptions but may be changed to just
throw UnsupportedOperationExceptions if we decide not to implement them
Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java (original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java Wed Apr 28 10:43:18 2004
@@ -14,21 +14,28 @@
* limitations under the License.
*
*/
-package org.apache.rms.je.application;
+package org.apache.rms.je.application ;
-import org.apache.rms.DefaultApplication;
-import java.util.Map;
-import java.util.List;
+import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission ;
+import org.apache.rms.spi.MutableRole ;
+import org.apache.rms.DefaultApplication ;
+import org.apache.rms.spi.MutableApplication ;
+import org.apache.rms.spi.MutableBitPermission ;
+import org.apache.commons.lang.NotImplementedException ;
+
+import java.util.Map ;
+import java.util.List ;
/**
- * Put some documentation here.
+ * A mutable Je based Application implementation.
*
* @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
* @version $Rev$
*/
-public class JeApplication extends DefaultApplication
+public class JeApplication extends DefaultApplication implements MutableApplication
{
/**
* Creates a default Application.
@@ -55,5 +62,125 @@
public JeApplication( String name, Map roles, List mapping )
{
super( name, roles, mapping ) ;
+ }
+
+
+ /**
+ * Creates a permission associated with this Application.
+ *
+ * @param permName the name of the permission to create
+ * @return the permission created
+ */
+ public MutableBitPermission createPermission( String permName )
+ throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Deletes a permission associated with this Application.
+ *
+ * @param perm the binary permission to delete
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store, and when the permission is not defined within this Application
+ */
+ public void deletePermission( BitPermission perm ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Deletes a permission associated with this Application.
+ *
+ * @param permName the name of the binary permission to delete
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store, and when the permission is not defined within this Application
+ */
+ public void deletePermission( String permName ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Renames a permission.
+ *
+ * @param oldPermName original permission name
+ * @param newPermName new permission name
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store
+ */
+ public void renamePermission( String oldPermName, String newPermName )
+ throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Renames a permission.
+ *
+ * @param perm the permission being renamed
+ * @param newPermName new permission name
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store
+ */
+ public void renamePermission( MutableBitPermission perm,
+ String newPermName ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Creates a Role associated with this Application.
+ *
+ * @param roleName the name of the role to create
+ * @return the permission created
+ */
+ public MutableRole createRole( String roleName ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Deletes a role associated with this Application.
+ *
+ * @param role the role to delete
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store, and when the role is not defined within this Application
+ */
+ public void deleteRole( MutableRole role ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Deletes a role associated with this Application.
+ *
+ * @param roleName the name of the role to delete
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store, and when the role is not defined within this Application
+ */
+ public void deleteRole( String roleName ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+
+ /**
+ * Renames this Application.
+ *
+ * @param name the new name to rename this Application to
+ * @throws org.apache.rms.RmsException on failures to effect the backing
+ * store, and when the role is not defined within this Application
+ */
+ public void rename( String name ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
}
}
Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java (original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java Wed Apr 28 10:43:18 2004
@@ -36,7 +36,19 @@
public class JeRoleAppNameKeyCreator implements SecondaryKeyCreator
{
/** the binding used to manipulate a serialized role */
- private static final JeRoleBinding BINDING = new JeRoleBinding() ;
+ private final JeRoleBinding binding ;
+
+
+ /**
+ * Creates a application name key creator based on a role binding.
+ *
+ * @param binding the role binding
+ */
+ JeRoleAppNameKeyCreator( JeRoleBinding binding )
+ {
+ this.binding = binding ;
+ }
+
/**
* Sets the role appName bytes for the result entry by extracting it
@@ -58,7 +70,7 @@
try
{
- name = BINDING.getApplicationName( dataEntry ) ;
+ name = binding.getApplicationName( dataEntry ) ;
resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
}
catch ( IOException e )
Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java (original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java Wed Apr 28 10:43:18 2004
@@ -24,6 +24,8 @@
import java.io.IOException ;
import org.apache.rms.Application ;
+import org.apache.rms.RmsException;
+import org.apache.rms.spi.ApplicationFactory;
/**
@@ -36,29 +38,20 @@
*/
public class JeRoleBinding extends TupleBinding
{
- private static ThreadLocal applications = new ThreadLocal() ;
+ private final ApplicationFactory factory ;
/**
- * Sets the application associated with the current thread for access by
- * the binding.
+ * Creates a RoleBinding that uses an application factory to resolve
+ * applications.
*
- * @param application the application associated with the role
+ * @param factory
*/
- static void setApplication( Application application )
+ public JeRoleBinding( ApplicationFactory factory )
{
- applications.set( application ) ;
- }
-
+ super() ;
- /**
- * Gets the current Thread's application associated with the role.
- *
- * @return the application associated with the role.
- */
- static Application getApplication()
- {
- return ( Application ) applications.get() ;
+ this.factory = factory ;
}
@@ -76,8 +69,19 @@
*/
public Object entryToObject( TupleInput tupleInput ) throws IOException
{
- Application application = getApplication() ;
String appName = tupleInput.readString() ;
+ Application application = null ;
+
+ try
+ {
+ application = factory.getApplication( appName ) ;
+ }
+ catch ( RmsException e )
+ {
+ throw new IllegalStateException( "An application by the name of "
+ + appName + " does not exist" ) ;
+ }
+
if ( application == null )
{
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 10:43:18 2004
@@ -27,7 +27,6 @@
import org.apache.commons.lang.Validate ;
import org.apache.commons.lang.ArrayUtils ;
-import org.apache.commons.lang.NotImplementedException ;
import java.util.List ;
import java.util.Iterator ;
@@ -35,7 +34,7 @@
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
-import com.sleepycat.je.*;
+import com.sleepycat.je.* ;
/**
@@ -52,8 +51,7 @@
static final String ROLE_SECDB = "byRoleName" ;
/** A Role binding */
- private static final JeRoleBinding BINDING = new JeRoleBinding() ;
-
+ private final JeRoleBinding binding ;
/** the JE database to use for this DAO */
private final Database db ;
/** the sequence we use to create new role database row ids with */
@@ -76,7 +74,8 @@
*
* @param db the JE Database for the role DAO
*/
- public JeRoleDAO( Database db, Sequence seq ) throws RmsException
+ public JeRoleDAO( Database db, Sequence seq, JeRoleBinding binding )
+ throws RmsException
{
Validate.notNull( db ) ;
Validate.notNull( seq ) ;
@@ -84,6 +83,7 @@
this.db = db ;
this.seq = seq ;
this.monitor = new RoleDAOMonitorAdapter() ;
+ this.binding = binding ;
List secdbs = null ;
try
@@ -145,7 +145,7 @@
try
{
- BINDING.objectToEntry( data, appName, roleName,
+ binding.objectToEntry( data, appName, roleName,
ArrayUtils.EMPTY_BYTE_ARRAY ) ;
status = db.put( null, key, data ) ;
}
@@ -281,10 +281,10 @@
status = db.get( null, key, value, LockMode.DEFAULT ) ;
// extract the grants from the record
- byte[] grants = BINDING.getGrants( value ) ;
+ byte[] grants = binding.getGrants( value ) ;
// use grants, appName and new role name to construct new record
- BINDING.objectToEntry( value, appName, newName, grants ) ;
+ binding.objectToEntry( value, appName, newName, grants ) ;
// put data record into primary overwriting the old data record
status = db.put( null, key, value ) ;
@@ -346,9 +346,7 @@
try
{
- JeRoleBinding.setApplication( application ) ;
- role = ( Role ) BINDING.entryToObject( data ) ;
- JeRoleBinding.setApplication( null ) ;
+ role = ( Role ) binding.entryToObject( data ) ;
}
catch ( IOException e )
{
@@ -454,7 +452,7 @@
try
{
DatabaseEntry data = getRow( appName, roleName, false ) ;
- grants = BINDING.getGrants( data ) ;
+ grants = binding.getGrants( data ) ;
}
catch ( IOException e )
{
@@ -512,7 +510,7 @@
status = db.get( null, key, value, LockMode.DEFAULT ) ;
// use appName, roleName and new role grants to construct new record
- BINDING.objectToEntry( value, appName, roleName, grants ) ;
+ binding.objectToEntry( value, appName, roleName, grants ) ;
// put data record into primary overwriting the old data record
status = db.put( null, key, value ) ;
@@ -551,7 +549,7 @@
*/
public Iterator list() throws RmsException
{
- throw new NotImplementedException( "STUB" ) ;
+ return new JeAppRoleIterator( false ) ;
}
@@ -565,7 +563,7 @@
*/
public Iterator list( String appName ) throws RmsException
{
- throw new NotImplementedException( "STUB" ) ;
+ return new JeAppRoleIterator( appName, false ) ;
}
@@ -578,7 +576,7 @@
*/
public Iterator listNames() throws RmsException
{
- throw new NotImplementedException( "STUB" ) ;
+ return new JeAppRoleIterator( true ) ;
}
@@ -592,7 +590,7 @@
*/
public Iterator listNames( String appName ) throws RmsException
{
- throw new NotImplementedException( "STUB" ) ;
+ return new JeAppRoleIterator( appName, true ) ;
}
@@ -602,6 +600,25 @@
/**
+ * 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 JeAppRoleIterator )
+ {
+ ( ( JeAppRoleIterator ) list ).close() ;
+ }
+ }
+
+
+ /**
* Gets the key or value of an entry within the primary role database.
*
* @param appName the roleName of the application
@@ -747,6 +764,230 @@
catch ( DatabaseException e )
{
monitor.failedOnCleanupOperation( this, "close", cursor, e ) ;
+ }
+ }
+
+
+ // -----------------------------------------------------------------------
+ // Cursor Iterator
+ // -----------------------------------------------------------------------
+
+
+ /**
+ * Special iterator to list the String names or Roles of an
+ * application or the entire database. This Iterator is primarily
+ * returned by DAO list methods.
+ */
+ class JeAppRoleIterator implements Iterator
+ {
+ final DatabaseEntry key = new DatabaseEntry() ;
+ final DatabaseEntry value = new DatabaseEntry() ;
+
+ final String appName ;
+ final boolean onlyNames ;
+ final boolean fullScan ;
+
+ boolean hasNext = true ;
+ Object prefetched = null ;
+ SecondaryCursor cursor = null ;
+ OperationStatus status = null ;
+
+
+ JeAppRoleIterator( String appName, boolean onlyNames ) throws RmsException
+ {
+ this.fullScan = false ;
+ this.appName = appName ;
+ this.onlyNames = onlyNames ;
+
+ try
+ {
+ key.setData( appName.getBytes( "UTF-8" ) ) ;
+ cursor = byAppName.openSecondaryCursor( null, null ) ;
+ status = cursor.getSearchKey( key, value, LockMode.DEFAULT ) ;
+
+ if ( status != OperationStatus.SUCCESS )
+ {
+ hasNext = false ;
+ closeNoError( cursor ) ;
+ monitor.listingEmpty( JeRoleDAO.this, this, appName,
+ onlyNames ) ;
+ return ;
+ }
+
+ if ( onlyNames )
+ {
+ prefetched = binding.getRoleName( value ) ;
+ monitor.listingNamesOnly( JeRoleDAO.this, this, appName ) ;
+ }
+ else
+ {
+ prefetched = binding.entryToObject( value ) ;
+ monitor.listingRoles( JeRoleDAO.this, this, appName ) ;
+ }
+ }
+ catch ( DatabaseException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, e ) ;
+ throw new RmsException( e ) ;
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, e ) ;
+ throw new RmsException( e ) ;
+ }
+ catch ( IOException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, e ) ;
+ throw new RmsException( e ) ;
+ }
+ }
+
+
+ JeAppRoleIterator( boolean onlyNames ) throws RmsException
+ {
+ this.fullScan = true ;
+ this.appName = null ;
+ this.onlyNames = onlyNames ;
+
+ try
+ {
+ cursor = byAppName.openSecondaryCursor( null, null ) ;
+ status = cursor.getFirst( key, value, LockMode.DEFAULT ) ;
+
+ if ( status != OperationStatus.SUCCESS )
+ {
+ hasNext = false ;
+ closeNoError( cursor ) ;
+ monitor.listingEmpty( JeRoleDAO.this, this, appName,
+ onlyNames ) ;
+ return ;
+ }
+
+ if ( onlyNames )
+ {
+ prefetched = binding.getRoleName( value ) ;
+ monitor.listingNamesOnly( JeRoleDAO.this, this, appName ) ;
+ }
+ else
+ {
+ prefetched = binding.entryToObject( value ) ;
+ monitor.listingRoles( JeRoleDAO.this, this, appName ) ;
+ }
+ }
+ catch ( DatabaseException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, e ) ;
+ throw new RmsException( e ) ;
+ }
+ catch ( UnsupportedEncodingException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, e ) ;
+ throw new RmsException( e ) ;
+ }
+ catch ( IOException e )
+ {
+ closeNoError( cursor ) ;
+ monitor.failedListing( JeRoleDAO.this, this, appName,
+ onlyNames, 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
+ {
+ if ( fullScan )
+ {
+ status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+ }
+ else
+ {
+ status = cursor.getNextDup( key, value,
+ LockMode.DEFAULT ) ;
+ }
+
+ if ( status != OperationStatus.SUCCESS )
+ {
+ hasNext = false ;
+ closeNoError( cursor ) ;
+ monitor.iteratorExhausted( JeRoleDAO.this, this, appName,
+ onlyNames, retVal ) ;
+ }
+ else
+ {
+ if ( onlyNames )
+ {
+ prefetched = binding.getRoleName( value ) ;
+ monitor.successOnNextName( JeRoleDAO.this, this,
+ appName, retVal, prefetched ) ;
+ }
+ else
+ {
+ prefetched = binding.entryToObject( value ) ;
+ monitor.successOnNextRole( JeRoleDAO.this, this,
+ appName, retVal, prefetched ) ;
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ hasNext = false ;
+
+ if ( cursor != null )
+ {
+ closeNoError( cursor ) ;
+ }
+
+ monitor.iteratorFailure( JeRoleDAO.this, this, appName,
+ onlyNames, retVal, e ) ;
+ }
+ catch ( DatabaseException e )
+ {
+ hasNext = false ;
+ if ( cursor != null )
+ {
+ closeNoError( cursor ) ;
+ }
+
+ monitor.iteratorFailure( JeRoleDAO.this, this, appName,
+ onlyNames, retVal, e ) ;
+ }
+
+ return retVal ;
+ }
+
+
+ void close()
+ {
+ hasNext = false ;
+ closeNoError( cursor ) ;
}
}
}
Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java (original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java Wed Apr 28 10:43:18 2004
@@ -36,7 +36,19 @@
public class JeRoleNameKeyCreator implements SecondaryKeyCreator
{
/** the binding used to manipulate a serialized role */
- private static final JeRoleBinding BINDING = new JeRoleBinding() ;
+ private final JeRoleBinding binding ;
+
+
+ /**
+ * Creates a application role name key creator based on a role binding.
+ *
+ * @param binding the role binding
+ */
+ JeRoleNameKeyCreator( JeRoleBinding binding )
+ {
+ this.binding = binding ;
+ }
+
/**
* Sets the role appName bytes for the result entry by extracting it
@@ -58,7 +70,7 @@
try
{
- name = BINDING.getRoleName( dataEntry ) ;
+ name = binding.getRoleName( dataEntry ) ;
resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
}
catch ( IOException e )
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 10:43:18 2004
@@ -17,6 +17,8 @@
package org.apache.rms.je.role ;
+import java.util.Iterator ;
+
import org.apache.rms.Role ;
@@ -205,4 +207,105 @@
*/
void failedOnSetGrants( JeRoleDAO dao, String appName, String roleName,
Throwable fault ) ;
+
+ /**
+ * Monitors events where an empty list is returned on a role [name]
+ * listing.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if the
+ * Iterator returns role objects
+ */
+
+ void listingEmpty( JeRoleDAO dao, Iterator listing, String appName,
+ boolean onlyNames ) ;
+
+ /**
+ * Monitors events when an Iterator over the list of role names
+ * is sucessful.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ */
+ void listingNamesOnly( JeRoleDAO dao, Iterator listing, String appName ) ;
+
+ /**
+ * Monitors events when an Iterator over the list of role objects
+ * is sucessful.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ */
+ void listingRoles( JeRoleDAO dao, Iterator listing, String appName ) ;
+
+ /**
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if
+ * the Iterator return role objects
+ * @param fault the fault that caused the failure
+ */
+ void failedListing( JeRoleDAO dao, Iterator listing, String appName,
+ boolean onlyNames, Throwable fault ) ;
+
+ /**
+ * Monitors events where the iterator runs out of elements to prefetch.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if
+ * the Iterator returns role objects
+ * @param lastVal the last value to be returned on the subsequent
+ * (final) next() call
+ */
+ void iteratorExhausted( JeRoleDAO dao, Iterator listing, String appName,
+ boolean onlyNames, Object lastVal ) ;
+
+ /**
+ * Monitors the successful prefetch of the next role name.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param retVal the next value to be returned
+ * @param prefetched the prefetched value if this Iterator prefetches
+ * the next value
+ */
+ void successOnNextName( JeRoleDAO dao, Iterator listing, String appName,
+ Object retVal, Object prefetched ) ;
+
+ /**
+ * Monitors the successful prefetch of the next role.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param retVal the next value to be returned
+ * @param prefetched the prefetched value if this Iterator prefetches
+ * the next value
+ */
+ void successOnNextRole( JeRoleDAO dao, Iterator listing, String appName,
+ Object retVal, Object prefetched ) ;
+
+ /**
+ * Monitors events where the iterator fails to return the next element,
+ * or fails to prefetch an element to return on a subsequent next method
+ * call.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if the
+ * Iterator return role objects
+ * @param retVal the next value to be returned
+ * @param fault the fault that caused the failure
+ */
+ void iteratorFailure( JeRoleDAO dao, Iterator listing, String appName,
+ boolean onlyNames, Object retVal, 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 10:43:18 2004
@@ -19,6 +19,8 @@
import org.apache.rms.Role ;
+import java.util.Iterator;
+
/**
* A do nothing adapter for a RoleDAO monitor. At a bare minimum this adapter
@@ -279,5 +281,144 @@
{
fault.printStackTrace() ;
}
+ }
+
+
+ /**
+ * Monitors events where an empty list is returned on a role [name]
+ * listing.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if the
+ * Iterator returns role objects
+ */
+ public void listingEmpty( JeRoleDAO dao, Iterator listing,
+ String appName, boolean onlyNames )
+ {
+ }
+
+
+ /**
+ * Monitors events when an Iterator over the list of role names
+ * is sucessful.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ */
+ public void listingNamesOnly( JeRoleDAO dao, Iterator listing,
+ String appName )
+ {
+ }
+
+
+ /**
+ * Monitors events when an Iterator over the list of role objects
+ * is sucessful.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ */
+ public void listingRoles( JeRoleDAO dao, Iterator listing,
+ String appName )
+ {
+ }
+
+
+ /**
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if
+ * the Iterator return role objects
+ * @param fault the fault that caused the failure
+ */
+ public void failedListing( JeRoleDAO dao, Iterator listing,
+ String appName, boolean onlyNames,
+ Throwable fault )
+ {
+ if ( fault != null )
+ {
+ fault.printStackTrace() ;
+ }
+ }
+
+
+ /**
+ * Monitors the successful prefetch of the next role name.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param retVal the next value to be returned
+ * @param prefetched the prefetched value if this Iterator prefetches
+ * the next value
+ */
+ public void successOnNextName( JeRoleDAO dao, Iterator listing,
+ String appName, Object retVal,
+ Object prefetched )
+ {
+ }
+
+
+ /**
+ * Monitors the successful prefetch of the next role.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param retVal the next value to be returned
+ * @param prefetched the prefetched value if this Iterator prefetches
+ * the next value
+ */
+ public void successOnNextRole( JeRoleDAO dao, Iterator listing,
+ String appName, Object retVal,
+ Object prefetched )
+ {
+ }
+
+
+ /**
+ * Monitors events where the iterator fails to return the next element,
+ * or fails to prefetch an element to return on a subsequent next method
+ * call.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if the
+ * Iterator return role objects
+ * @param retVal the next value to be returned
+ * @param fault the fault that caused the failure
+ */
+ public void iteratorFailure( JeRoleDAO dao, Iterator listing,
+ String appName, boolean onlyNames,
+ Object retVal, Throwable fault )
+ {
+ if ( fault != null )
+ {
+ fault.printStackTrace() ;
+ }
+ }
+
+
+ /**
+ * Monitors events where the iterator runs out of elements to prefetch.
+ *
+ * @param dao the data access object that failed
+ * @param listing the Iterator created
+ * @param appName the name of the application
+ * @param onlyNames true if the Iterator was to return names false if
+ * the Iterator returns role objects
+ * @param lastVal the last value to be returned on the subsequent
+ * (final) next() call
+ */
+ public void iteratorExhausted( JeRoleDAO dao, Iterator listing,
+ String appName, boolean onlyNames,
+ Object lastVal )
+ {
}
}
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 10:43:18 2004
@@ -22,13 +22,19 @@
import org.apache.rms.Role ;
import org.apache.rms.RmsException ;
import org.apache.rms.DefaultApplication ;
+import org.apache.rms.spi.ApplicationFactory ;
+import org.apache.rms.spi.MutableApplication ;
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.application.JeApplication ;
import org.apache.rms.je.sequence.JeSequenceFactory ;
-import org.apache.commons.lang.ArrayUtils;
+
+import org.apache.commons.lang.ArrayUtils ;
+import org.apache.commons.lang.NotImplementedException ;
+
+import java.util.Iterator ;
/**
@@ -44,6 +50,9 @@
protected void setUp() throws Exception
{
+ ApplicationFactory factory = new DummyFactory() ;
+ JeRoleBinding binding = new JeRoleBinding( factory ) ;
+
DatabaseConfig conf = new DatabaseConfig() ;
conf.setAllowCreate( true ) ;
setupDb( "seqDb", conf ) ;
@@ -52,21 +61,21 @@
SecondaryConfig sconf = new SecondaryConfig() ;
sconf.setAllowCreate( true ) ;
sconf.setAllowDuplicates( true ) ;
- sconf.setKeyCreator( new JeRoleAppNameKeyCreator() ) ;
+ sconf.setKeyCreator( new JeRoleAppNameKeyCreator( binding ) ) ;
env.openSecondaryDatabase( null, JeRoleDAO.APP_SECDB,
sconf, db ) ;
sconf = new SecondaryConfig() ;
sconf.setAllowCreate( true ) ;
sconf.setAllowDuplicates( true ) ;
- sconf.setKeyCreator( new JeRoleNameKeyCreator() ) ;
+ sconf.setKeyCreator( new JeRoleNameKeyCreator( binding ) ) ;
env.openSecondaryDatabase( null, JeRoleDAO.ROLE_SECDB,
sconf, db ) ;
JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
Sequence seq = seqFactory.create( "roleSeq" ) ;
- roleDAO = new JeRoleDAO( db, seq ) ;
+ roleDAO = new JeRoleDAO( db, seq, binding ) ;
//roleDAO.setMonitor( new LoggingRoleDAOMonitor() ) ;
}
@@ -282,5 +291,321 @@
assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
grants ) ) ;
assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+ }
+
+
+ public void testCreateAndList() 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" ) ;
+
+ application = new JeApplication( "app2" ) ;
+ roleDAO.create( application, "roleA" ) ;
+ roleDAO.create( application, "roleB" ) ;
+ roleDAO.create( application, "roleY" ) ;
+ roleDAO.create( application, "roleZ" ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+ assertTrue( roleDAO.has( "app2", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleY" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleZ" ) ) ;
+
+ Iterator list = null ;
+ JeRole role = null ;
+
+ list = roleDAO.list() ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app1", role.getApplicationName() ) ;
+ assertEquals( "roleA", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app1", role.getApplicationName() ) ;
+ assertEquals( "roleB", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app1", role.getApplicationName() ) ;
+ assertEquals( "roleC", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app1", role.getApplicationName() ) ;
+ assertEquals( "roleD", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleA", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleB", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleY", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleZ", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ assertFalse( list.hasNext() ) ;
+ }
+
+
+ public void testCreateAndListString() 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" ) ;
+
+ application = new JeApplication( "app2" ) ;
+ roleDAO.create( application, "roleA" ) ;
+ roleDAO.create( application, "roleB" ) ;
+ roleDAO.create( application, "roleY" ) ;
+ roleDAO.create( application, "roleZ" ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+ assertTrue( roleDAO.has( "app2", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleY" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleZ" ) ) ;
+
+ Iterator list = null ;
+ JeRole role = null ;
+
+ list = roleDAO.list( "app2" ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleA", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleB", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleY", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ role = ( JeRole ) list.next() ;
+ assertNotNull( role ) ;
+ assertEquals( "app2", role.getApplicationName() ) ;
+ assertEquals( "roleZ", role.getName() ) ;
+ assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+ role.getGrantBits() ) ) ;
+
+ assertFalse( list.hasNext() ) ;
+ }
+
+
+ public void testCreateAndListNames() 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" ) ;
+
+ application = new JeApplication( "app2" ) ;
+ roleDAO.create( application, "roleA" ) ;
+ roleDAO.create( application, "roleB" ) ;
+ roleDAO.create( application, "roleY" ) ;
+ roleDAO.create( application, "roleZ" ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+ assertTrue( roleDAO.has( "app2", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleY" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleZ" ) ) ;
+
+ Iterator list = null ;
+ String roleName = null ;
+
+ list = roleDAO.listNames() ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleA", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleB", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleC", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleD", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleA", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleB", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleY", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleZ", roleName ) ;
+
+ assertFalse( list.hasNext() ) ;
+ }
+
+
+ public void testCreateAndListNamesString() 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" ) ;
+
+ application = new JeApplication( "app2" ) ;
+ roleDAO.create( application, "roleA" ) ;
+ roleDAO.create( application, "roleB" ) ;
+ roleDAO.create( application, "roleY" ) ;
+ roleDAO.create( application, "roleZ" ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+ assertTrue( roleDAO.has( "app2", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleY" ) ) ;
+ assertTrue( roleDAO.has( "app2", "roleZ" ) ) ;
+
+ Iterator list = null ;
+ String roleName = null ;
+
+ list = roleDAO.listNames( "app2" ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleA", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleB", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleY", roleName ) ;
+
+ roleName = ( String ) list.next() ;
+ assertNotNull( roleName ) ;
+ assertEquals( "roleZ", roleName ) ;
+
+ assertFalse( list.hasNext() ) ;
+ }
+
+
+ class DummyFactory implements ApplicationFactory
+ {
+ public MutableApplication getApplication( String appName )
+ throws RmsException
+ {
+ return new JeApplication( appName ) ;
+ }
+
+ public Iterator getApplicationNames() throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+ public MutableApplication createApplication( String appName )
+ throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+ public void deleteApplication( String appName ) throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
+
+ public void renameApplication( String oldName, String newName )
+ throws RmsException
+ {
+ throw new NotImplementedException( "STUB" ) ;
+ }
}
}