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/23 06:25:22 UTC
svn commit: rev 10192 - incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions
Author: akarasulu
Date: Thu Apr 22 21:25:21 2004
New Revision: 10192
Modified:
incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
Log:
minor refactoring
Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java (original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/JeBitPermissionDAO.java Thu Apr 22 21:25:21 2004
@@ -42,8 +42,11 @@
*/
public class JeBitPermissionDAO implements BitPermissionDAO
{
- static final String APP_SECDB = "byApp" ;
- static final String PERM_SECDB = "byName" ;
+ /** the name of the secondary database keyed by application name */
+ static final String APP_SECDB = "byAppName" ;
+ /** the name of the secondary database keyed by permission name */
+ static final String PERM_SECDB = "byPermName" ;
+ /** the name of the secondary database keyed by permission */
static final String INDEX_SECDB = "byIdx" ;
/** A BitPermission binding */
@@ -56,10 +59,17 @@
private final Sequence seq ;
/** the index manager used to track index availabilities */
private final BitPermissionIndexManager indexManager ;
-
+ /** the secondary database keyed by index */
private SecondaryDatabase byIdx ;
- private SecondaryDatabase byApp ;
- private SecondaryDatabase byName ;
+ /** the secondary database keyed by application name */
+ private SecondaryDatabase byAppName ;
+ /** the secondary database keyed by permission name*/
+ private SecondaryDatabase byPermName ;
+
+
+ // ----------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ----------------------------------------------------------------------
/**
@@ -68,7 +78,7 @@
* @param db the JE Database for the permission DAO
*/
public JeBitPermissionDAO( Database db, Sequence seq,
- BitPermissionIndexManager indexManager )
+ BitPermissionIndexManager indexManager )
throws RmsException
{
Validate.notNull( db ) ;
@@ -88,7 +98,7 @@
SecondaryDatabase secdb = ( SecondaryDatabase ) secdbs.get( ii ) ;
if ( secdb.getDatabaseName().equals( APP_SECDB ) )
{
- byApp = secdb ;
+ byAppName = secdb ;
}
else if ( secdb.getDatabaseName().equals( INDEX_SECDB ) )
{
@@ -96,7 +106,7 @@
}
else if ( secdb.getDatabaseName().equals( PERM_SECDB ) )
{
- byName = secdb ;
+ byPermName = secdb ;
}
}
}
@@ -105,12 +115,17 @@
throw new RmsException( e ) ;
}
- Validate.notNull( byApp ) ;
+ Validate.notNull( byAppName ) ;
Validate.notNull( byIdx ) ;
- Validate.notNull( byName ) ;
+ Validate.notNull( byPermName ) ;
}
+ // ----------------------------------------------------------------------
+ // D A O I M P L E M E N T A T I O N S
+ // ----------------------------------------------------------------------
+
+
/**
* Creates a new BitPermission for an application.
*
@@ -343,7 +358,7 @@
*/
public Iterator listNames( String appName ) throws RmsException
{
- return new JeApplicationPermissionIterator( appName, true ) ;
+ return new JeAppPermIterator( appName, true ) ;
}
@@ -356,7 +371,7 @@
*/
public Iterator listNames() throws RmsException
{
- return new JeApplicationPermissionIterator( true ) ;
+ return new JeAppPermIterator( true ) ;
}
@@ -370,7 +385,7 @@
*/
public Iterator list( String appName ) throws RmsException
{
- return new JeApplicationPermissionIterator( appName, false ) ;
+ return new JeAppPermIterator( appName, false ) ;
}
@@ -383,10 +398,15 @@
*/
public Iterator list() throws RmsException
{
- return new JeApplicationPermissionIterator( false ) ;
+ return new JeAppPermIterator( false ) ;
}
+ // ----------------------------------------------------------------------
+ // J O I N O P E R A T I O N S
+ // ----------------------------------------------------------------------
+
+
/**
* Gets the key or value of an entry within the primary bit permission database.
*
@@ -421,8 +441,8 @@
try
{
- nameCursor = byName.openSecondaryCursor( null, null ) ;
- appNameCursor = byApp.openSecondaryCursor( null, null ) ;
+ nameCursor = byPermName.openSecondaryCursor( null, null ) ;
+ appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
status = nameCursor
.getSearchKey( nameEntry, value, LockMode.DEFAULT ) ;
@@ -467,39 +487,9 @@
}
finally
{
- if ( cursor != null )
- {
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
- if ( nameCursor != null )
- {
- try
- {
- nameCursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
- if ( appNameCursor != null )
- {
- try
- {
- appNameCursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
+ closeNoError( cursor ) ;
+ closeNoError( nameCursor ) ;
+ closeNoError( appNameCursor ) ;
}
@@ -549,8 +539,8 @@
try
{
- intCursor = byName.openSecondaryCursor( null, null ) ;
- appNameCursor = byApp.openSecondaryCursor( null, null ) ;
+ intCursor = byPermName.openSecondaryCursor( null, null ) ;
+ appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
status = intCursor
.getSearchKey( intEntry, value, LockMode.DEFAULT ) ;
@@ -595,42 +585,11 @@
}
finally
{
- if ( cursor != null )
- {
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
- if ( intCursor != null )
- {
- try
- {
- intCursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
- if ( appNameCursor != null )
- {
- try
- {
- appNameCursor.close() ;
- }
- catch ( DatabaseException e )
- {
- throw new RmsException( e ) ;
- }
- }
+ closeNoError( cursor ) ;
+ closeNoError( intCursor ) ;
+ closeNoError( appNameCursor ) ;
}
-
if ( getKey )
{
return key ;
@@ -642,7 +601,59 @@
}
- class JeApplicationPermissionIterator implements Iterator
+ /**
+ * Closes a cursor without throwing an error.
+ *
+ * @param cursor the cursor to close.
+ */
+ private void closeNoError( Cursor cursor )
+ {
+ if ( cursor == null )
+ {
+ return ;
+ }
+
+ try
+ {
+ cursor.close() ;
+ }
+ catch ( DatabaseException e )
+ {
+ // @todo need to log this
+ e.printStackTrace() ;
+ }
+ }
+
+
+ /**
+ * Closes a cursor without throwing an error.
+ *
+ * @param cursor the cursor to close.
+ */
+ private void closeNoError( JoinCursor cursor )
+ {
+ if ( cursor == null )
+ {
+ return ;
+ }
+
+ try
+ {
+ cursor.close() ;
+ }
+ catch ( DatabaseException e )
+ {
+ // @todo need to log this
+ e.printStackTrace() ;
+ }
+ }
+
+
+ /**
+ * Special iterator to list the String names or BitPermission of an
+ * application or the entire database.
+ */
+ class JeAppPermIterator implements Iterator
{
final DatabaseEntry key = new DatabaseEntry() ;
final DatabaseEntry value = new DatabaseEntry() ;
@@ -657,7 +668,7 @@
OperationStatus status = null ;
- JeApplicationPermissionIterator( String appName, boolean onlyNames ) throws RmsException
+ JeAppPermIterator( String appName, boolean onlyNames ) throws RmsException
{
this.fullScan = false ;
this.appName = appName ;
@@ -666,13 +677,13 @@
try
{
key.setData( appName.getBytes( "UTF-8" ) ) ;
- cursor = byApp.openSecondaryCursor( null, null ) ;
+ cursor = byAppName.openSecondaryCursor( null, null ) ;
status = cursor.getSearchKey( key, value, LockMode.DEFAULT ) ;
if ( status != OperationStatus.SUCCESS )
{
hasNext = false ;
- cursor.close() ;
+ closeNoError( cursor ) ;
return ;
}
@@ -687,47 +698,23 @@
}
catch ( DatabaseException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
catch ( UnsupportedEncodingException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
catch ( IOException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
}
- JeApplicationPermissionIterator( boolean onlyNames ) throws RmsException
+ JeAppPermIterator( boolean onlyNames ) throws RmsException
{
this.fullScan = true ;
this.appName = null ;
@@ -735,13 +722,13 @@
try
{
- cursor = byApp.openSecondaryCursor( null, null ) ;
+ cursor = byAppName.openSecondaryCursor( null, null ) ;
status = cursor.getFirst( key, value, LockMode.DEFAULT ) ;
if ( status != OperationStatus.SUCCESS )
{
hasNext = false ;
- cursor.close() ;
+ closeNoError( cursor ) ;
return ;
}
@@ -756,41 +743,17 @@
}
catch ( DatabaseException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
catch ( UnsupportedEncodingException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
catch ( IOException e )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
throw new RmsException( e ) ;
}
}
@@ -827,7 +790,7 @@
if ( status != OperationStatus.SUCCESS )
{
hasNext = false ;
- cursor.close() ;
+ closeNoError( cursor ) ;
}
else
{
@@ -847,15 +810,7 @@
if ( cursor != null )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
}
// @todo need to log this
@@ -866,15 +821,7 @@
hasNext = false ;
if ( cursor != null )
{
- try
- {
- cursor.close() ;
- }
- catch ( DatabaseException e1 )
- {
- // @todo need to log this
- e1.printStackTrace();
- }
+ closeNoError( cursor ) ;
}
// @todo need to log this