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 17:46:00 UTC
svn commit: rev 10362 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/role test/org/apache/rms/je/role
Author: akarasulu
Date: Wed Apr 28 08:45:59 2004
New Revision: 10362
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/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 completed JeRoleDAO.rename()
o completed unit test for JeRoleDAO.rename()
o added monitor methods for JeRoleDAO.rename()
o implemented no-op added monitor methods for JeRoleDAO.rename() in adapter
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 08:45:59 2004
@@ -250,7 +250,67 @@
*/
public void rename( String appName, String oldName, String newName ) throws RmsException
{
- throw new NotImplementedException( "STUB" ) ;
+ if ( has( appName, newName ) )
+ {
+ monitor.roleExists( this, "rename", appName, newName ) ;
+ throw new RmsException( "Role " + newName
+ + " exists for application " + appName ) ;
+ }
+
+ OperationStatus status = null ;
+ DatabaseEntry key = null ;
+ DatabaseEntry value = new DatabaseEntry() ;
+
+ try
+ {
+ key = getRow( appName, oldName, true ) ;
+ }
+ catch ( JeRmsException e )
+ {
+ if ( e.getStatus() == OperationStatus.NOTFOUND )
+ {
+ monitor.roleDoesNotExist( this, "rename", appName, oldName ) ;
+ }
+
+ throw e ;
+ }
+
+ try
+ {
+ // Get the full data record from primary
+ status = db.get( null, key, value, LockMode.DEFAULT ) ;
+
+ // extract the grants from the record
+ byte[] grants = BINDING.getGrants( value ) ;
+
+ // use grants, appName and new role name to construct new record
+ BINDING.objectToEntry( value, appName, newName, grants ) ;
+
+ // put data record into primary overwriting the old data record
+ status = db.put( null, key, value ) ;
+
+ if ( status != OperationStatus.SUCCESS )
+ {
+ RmsException e = new JeRmsException( status,
+ "failed to rename role " + oldName + " to " + newName
+ + " for application " + appName + " with status of "
+ + status.toString() ) ;
+ monitor.failedOnRename( this, appName, oldName, newName, e ) ;
+ throw e ;
+ }
+ }
+ catch ( IOException e )
+ {
+ monitor.failedOnRename( this, appName, oldName, newName, e ) ;
+ throw new RmsException( e ) ;
+ }
+ catch ( DatabaseException e )
+ {
+ monitor.failedOnRename( this, appName, oldName, newName, e ) ;
+ throw new RmsException( e ) ;
+ }
+
+ monitor.roleRenamed( this, appName, oldName, newName ) ;
}
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 08:45:59 2004
@@ -17,6 +17,7 @@
package org.apache.rms.je.role ;
import org.apache.rms.Role;
+import org.apache.rms.RmsException;
import java.io.IOException;
@@ -135,4 +136,29 @@
*/
void deleteFailed( JeRoleDAO dao, String appName, String roleName,
Throwable fault ) ;
+
+ /**
+ * Monitors events where the name of an application role is successfully
+ * altered.
+ *
+ * @param dao the data access object
+ * @param appName the name of the application
+ * @param oldName the original name of the role
+ * @param newName the new name to set for the role
+ */
+ void roleRenamed( JeRoleDAO dao, String appName, String oldName,
+ String newName ) ;
+
+ /**
+ * Monitors events where an attept to alter the name of an application
+ * role fails.
+ *
+ * @param dao the data access object
+ * @param appName the name of the application
+ * @param oldName the original name of the role
+ * @param newName the new name to set for the role
+ * @param fault the fault that caused the failure
+ */
+ void failedOnRename( JeRoleDAO dao, String appName, String oldName,
+ String newName, 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 08:45:59 2004
@@ -180,4 +180,39 @@
fault.printStackTrace() ;
}
}
+
+
+ /**
+ * Monitors events where the name of an application role is
+ * successfully altered.
+ *
+ * @param dao the data access object
+ * @param appName the name of the application
+ * @param oldName the original name of the role
+ * @param newName the new name to set for the role
+ */
+ public void roleRenamed( JeRoleDAO dao, String appName, String oldName,
+ String newName )
+ {
+ }
+
+
+ /**
+ * Monitors events where an attept to alter the name of an application
+ * role fails.
+ *
+ * @param dao the data access object
+ * @param appName the name of the application
+ * @param oldName the original name of the role
+ * @param newName the new name to set for the role
+ * @param fault the fault that caused the failure
+ */
+ public void failedOnRename( JeRoleDAO dao, String appName, String oldName,
+ String newName, Throwable fault )
+ {
+ if ( fault != null )
+ {
+ fault.printStackTrace() ;
+ }
+ }
}
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 08:45:59 2004
@@ -176,4 +176,48 @@
{
}
}
+
+
+ public void testCreateHasAndRename() 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" ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+ roleDAO.rename( application.getName(), "roleA", "roleW" ) ;
+ roleDAO.rename( application.getName(), "roleB", "roleX" ) ;
+ roleDAO.rename( application.getName(), "roleC", "roleY" ) ;
+ roleDAO.rename( application.getName(), "roleD", "roleZ" ) ;
+
+ assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
+ assertFalse( roleDAO.has( "app1", "roleB" ) ) ;
+ assertFalse( roleDAO.has( "app1", "roleC" ) ) ;
+ assertFalse( roleDAO.has( "app1", "roleD" ) ) ;
+
+ assertTrue( roleDAO.has( "app1", "roleW" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleX" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleY" ) ) ;
+ assertTrue( roleDAO.has( "app1", "roleZ" ) ) ;
+
+ try
+ {
+ roleDAO.rename( application.getName(), "roleA", "roleW" ) ;
+ fail( "should never get here because of an exception" ) ;
+ }
+ catch ( RmsException e )
+ {
+ }
+ }
}