directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10402 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/application test/org/apache/rms/je/application
Date Thu, 29 Apr 2004 03:47:38 GMT
Author: akarasulu
Date: Wed Apr 28 20:47:37 2004
New Revision: 10402

Added:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAO.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeAppNameKeyCreator.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationBinding.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationFactory.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationDAOTest.java
  (contents, props changed)
Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
Log:
Commit changes ...

 o completed ApplicationDAO extraction from ApplicationFactory 
 o created incomplete stubbed out JeApplicationDAO
 o created incomplete stubbed out JeApplicationFactory 
 o completed JeApplicationDAO.create() and JeApplicationDAO.has()
 o completed unit tests for ApplicationDAO.create() and ApplicationDAO.has()
 o created incomplete monitor interface 
 o created incomplete no-op monitor adapter
 o completed key creator for appName secondary on application database
 o completed JE Application binding
 


Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAO.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAO.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,78 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import org.apache.rms.RmsException ;
+
+import java.util.Iterator;
+
+
+/**
+ * An Application data access object.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ApplicationDAO
+{
+    /**
+     * Creates an application.
+     *
+     * @param appName the name of the application
+     * @throws RmsException if there is a failure accessing the underlying db,
+     * or if the application already exists
+     */
+    void create( String appName ) throws RmsException ;
+
+    /**
+     * Checks to see if an application exists.
+     *
+     * @param appName the name of the application
+     * @return true if an application with the name exists false otherwise
+     * @throws RmsException if there is a failure accessing the underlying db
+     */
+    boolean has( String appName ) throws RmsException ;
+
+    /**
+     * Deletes an application.
+     *
+     * @param appName the name of the application
+     * @throws RmsException if there is a failure accessing the underlying db,
+     * or if the application does NOT exist
+     */
+    void delete( String appName ) throws RmsException ;
+
+    /**
+     * Renames an application.
+     *
+     * @param oldName the original name of the application
+     * @param newName the new name to rename the application to
+     * @throws RmsException if there is a failure accessing the underlying db,
+     * or if the application does NOT exist, or another application with the
+     * new name exists
+     */
+    void rename( String oldName, String newName ) throws RmsException ;
+
+    /**
+     * Lists the String names of all applications.
+     *
+     * @return an Iterator over the String names of application in the db
+     * @throws RmsException if there is a failure accessing the underlying db
+     */
+    Iterator listNames() throws RmsException ;
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitor.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,59 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+import com.sleepycat.je.OperationStatus;
+
+
+/**
+ * A monitor for an Application data access object.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ApplicationDAOMonitor
+{
+    /**
+     * Monitor callback for events where the dao fails while checking for
+     * the existance of an application.
+     *
+     * @param dao the data access object that failed
+     * @param appName the name of the application
+     * @param fault the fault that caused the failure
+     */
+    void failedOnHas( ApplicationDAO dao, String appName, Throwable fault ) ;
+
+    /**
+     * Monitor callback for events where the dao fails to create a new
+     * Application.
+     *
+     * @param dao the data access object that failed
+     * @param info additional implementation specific information
+     * @param appName the name of the application
+     */
+    void failedOnCreate( ApplicationDAO dao, Object info, String appName ) ;
+
+    /**
+     * Monitor callback for events where the dao successfully creates a
+     * new Application.
+     *
+     * @param dao the data access object that failed
+     * @param appName the name of the application
+     */ 
+    void applicationCreated( ApplicationDAO dao, String appName ) ;
+
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/ApplicationDAOMonitorAdapter.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+/**
+ * A no-op application data access object monitor adapter.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ApplicationDAOMonitorAdapter implements ApplicationDAOMonitor
+{
+    /**
+     * Monitor callback for events where the dao fails while checking for the
+     * existance of an application.
+     *
+     * @param dao     the data access object that failed
+     * @param appName the name of the application
+     * @param fault   the fault that caused the failure
+     */
+    public void failedOnHas( ApplicationDAO dao, String appName,
+                             Throwable fault )
+    {
+    }
+
+
+    /**
+     * Monitor callback for events where the dao fails to create a new
+     * Application.
+     *
+     * @param dao     the data access object that failed
+     * @param info    additional implementation specific information
+     * @param appName the name of the application
+     */
+    public void failedOnCreate( ApplicationDAO dao, Object info,
+                                String appName )
+    {
+    }
+
+
+    /**
+     * Monitor callback for events where the dao successfully creates a
+     * new Application.
+     *
+     * @param dao     the data access object that failed
+     * @param appName the name of the application
+     */
+    public void applicationCreated( ApplicationDAO dao, String appName )
+    {
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeAppNameKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeAppNameKeyCreator.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,79 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permission and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+//import com.sleepycat.bind.EntryBinding ;
+//
+//import java.io.IOException ;
+//
+//import org.apache.rms.je.permission.JeBitPermissionTupleBinding;
+//import org.apache.rms.je.role.JeRoleBinding;
+
+
+/**
+ * A appName key creator for the Application database's secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeAppNameKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized application */
+//    private final JeApplicationBinding BINDING = new JeApplicationBinding() ;
+
+
+    /**
+     * Sets the role appName bytes for the result entry by extracting it
+     * from the dataEntry.
+     *
+     * @param secondaryDatabase the secondary database the new key is for
+     * @param keyEntry the key in the primary
+     * @param dataEntry the data in the primary
+     * @param resultEntry the new key for the secondary
+     * @return true if a key is created, false otherwise.
+     */
+    public boolean createSecondaryKey( SecondaryDatabase secondaryDatabase,
+                                       DatabaseEntry keyEntry,
+                                       DatabaseEntry dataEntry,
+                                       DatabaseEntry resultEntry )
+        throws DatabaseException
+    {
+//        String name = null ;
+
+//        try
+//        {
+            // -- use this if it gets more complex --
+//            name = BINDING.getApplicationName( dataEntry ) ;
+//            resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
+
+            // -- for now this suffices and is much faster --
+            resultEntry.setData( dataEntry.getData() ) ;
+//        }
+//        catch ( IOException e )
+//        {
+//            throw new DatabaseException( e ) ;
+//        }
+
+        return true ;
+    }
+}

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 20:47:37 2004
@@ -37,7 +37,7 @@
  */
 public class JeApplication extends DefaultApplication implements MutableApplication
 {
-    /**
+    /**                                               
      * Creates a default Application.
      *
      * @param name the name of the Application to create

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationBinding.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationBinding.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,108 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permission and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.bind.tuple.TupleInput ;
+import com.sleepycat.bind.tuple.TupleOutput ;
+import com.sleepycat.bind.tuple.TupleBinding ;
+
+import java.io.IOException ;
+
+import org.apache.rms.Application ;
+import org.apache.rms.RmsException;
+import org.apache.rms.je.role.JeRole;
+import org.apache.rms.spi.ApplicationFactory;
+
+
+/**
+ * A JE Application object binding.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplicationBinding extends TupleBinding
+{
+
+    // -----------------------------------------------------------------------
+    // TupleBinding implementations and overrides
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * Reconstructs a Role using a serialized entry.
+     *
+     * @param tupleInput the tuple data
+     * @return the newly constructed bit permission
+     * @throws java.io.IOException if there are any failures accessing the tuple data
+     */
+    public Object entryToObject( TupleInput tupleInput ) throws IOException
+    {
+        String appName = tupleInput.readString() ;
+        Application application = new JeApplication( appName ) ;
+        return application ;
+    }
+
+
+    /**
+     * Marshals a Role into serialized Tuple data.
+     *
+     * @param o the application to marshal
+     * @param tupleOutput
+     * @throws java.io.IOException
+     */
+    public void objectToEntry( Object o, TupleOutput tupleOutput ) throws IOException
+    {
+        JeApplication application = ( JeApplication ) o ;
+
+        if ( application == null )
+        {
+            return ;
+        }
+
+        tupleOutput.writeString( application.getName() ) ;
+    }
+
+
+    /**
+     * Marshals the components of a Application into a serialized Tuple.
+     *
+     * @param entry the entry to populate
+     * @param appName the appName of the application
+     * @throws java.io.IOException if there are failures writing the data
+     */
+    public void objectToEntry( DatabaseEntry entry, String appName )
+            throws IOException
+    {
+        entry.setData( appName.getBytes( "UTF-8" ) ) ;
+    }
+
+
+    /**
+     * Gets the name of the application stored within the database entry.
+     *
+     * @param entry the database entry for the application
+     * @return the application's name field
+     * @throws IOException if there are failures reading from the entry
+     */
+    public String getApplicationName( DatabaseEntry entry ) throws IOException
+    {
+        return new String( entry.getData(), "UTF-8" ) ;
+//        TupleInput in = new TupleInput( entry.getData() ) ;
+//        return in.readString() ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationDAO.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,243 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import org.apache.rms.je.JeUtils ;
+import org.apache.rms.RmsException ;
+import org.apache.rms.je.JeRmsException ;
+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 ;
+
+import java.io.IOException ;
+import java.io.UnsupportedEncodingException ;
+
+import com.sleepycat.je.* ;
+
+
+/**
+ * A Berkeley DB Je backed Application data access object.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplicationDAO implements ApplicationDAO
+{
+    /** the name of the secondary database keyed by application name */
+    static final String APP_SECDB = "byAppName" ;
+
+    /** the tuple binding for an application */
+    private static final JeApplicationBinding BINDING =
+            new JeApplicationBinding() ;
+
+    /** the JE database to use for this DAO */
+    private final Database db ;
+    /** the sequence we use to create new role database row ids with */
+    private final Sequence seq ;
+    /** the secondary database keyed by application name */
+    private SecondaryDatabase byAppName ;
+    /** the monitor notified on important DAO operations */
+    private ApplicationDAOMonitor monitor ;
+
+
+    // ----------------------------------------------------------------------
+    // C O N S T R U C T O R S
+    // ----------------------------------------------------------------------
+
+
+    /**
+     * Creates a JE based Application DAO using a JE database.
+     *
+     * @param db the JE Database for the application DAO
+     */
+    public JeApplicationDAO( Database db, Sequence seq )
+            throws RmsException
+    {
+        Validate.notNull( db ) ;
+        Validate.notNull( seq ) ;
+
+        this.db = db ;
+        this.seq = seq ;
+        this.monitor = new ApplicationDAOMonitorAdapter() ;
+
+        List secdbs = null ;
+        try
+        {
+            secdbs = this.db.getSecondaryDatabases() ;
+            for ( int ii = 0; ii < secdbs.size(); ii++ )
+            {
+                SecondaryDatabase secdb = ( SecondaryDatabase ) secdbs.get( ii ) ;
+                if ( secdb.getDatabaseName().equals( APP_SECDB ) )
+                {
+                    byAppName = secdb ;
+                }
+            }
+        }
+        catch ( DatabaseException e )
+        {
+            throw new RmsException( e ) ;
+        }
+
+        Validate.notNull( byAppName ) ;
+    }
+
+
+    // ----------------------------------------------------------------------
+    // D A O   I M P L E M E N T A T I O N S
+    // ----------------------------------------------------------------------
+
+
+    /**
+     * Creates an application.
+     *
+     * @param appName the name of the application
+     * @throws org.apache.rms.RmsException if there is a failure accessing the
+     * underlying db, or if the application already exists
+     */
+    public void create( String appName ) throws RmsException
+    {
+        DatabaseEntry key ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        OperationStatus status = null ;
+
+        if ( has( appName ) )
+        {
+            throw new RmsException( "Application " + appName
+                    + " already exists" ) ;
+        }
+
+        try
+        {
+            BINDING.objectToEntry( value, appName ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnHas( this, appName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        int rowId = seq.getNextValue() ;
+        key = new DatabaseEntry( JeUtils.encodeInt( rowId ) ) ;
+
+        try
+        {
+            status = db.put( null, key, value ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnHas( this, appName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        if ( status != OperationStatus.SUCCESS )
+        {
+            monitor.failedOnCreate( this, status, appName ) ;
+            throw new JeRmsException( status ) ;
+        }
+
+        monitor.applicationCreated( this, appName ) ;
+    }
+
+
+    /**
+     * Checks to see if an application exists.
+     *
+     * @param appName the name of the application
+     * @return true if an application with the name exists false otherwise
+     * @throws org.apache.rms.RmsException if there is a failure accessing the
+     * underlying db
+     */
+    public boolean has( String appName ) throws RmsException
+    {
+        DatabaseEntry key ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        OperationStatus status = null ;
+
+        try
+        {
+            key = new DatabaseEntry( appName.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            monitor.failedOnHas( this, appName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        try
+        {
+            status = byAppName.get( null, key, value, LockMode.DEFAULT ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnHas( this, appName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        if ( status == OperationStatus.SUCCESS )
+        {
+            return true ;
+        }
+
+        return false ;
+    }
+
+
+    /**
+     * Deletes an application.
+     *
+     * @param appName the name of the application
+     * @throws org.apache.rms.RmsException if there is a failure accessing the
+     * underlying db, or if the application does NOT exist
+     */
+    public void delete( String appName ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Renames an application.
+     *
+     * @param oldName the original name of the application
+     * @param newName the new name to rename the application to
+     * @throws org.apache.rms.RmsException if there is a failure accessing the
+     * underlying db, or if the application does NOT exist, or another
+     * application with the new name exists
+     */
+    public void rename( String oldName, String newName ) throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Lists the String names of all applications.
+     *
+     * @return an Iterator over the String names of application in the db
+     * @throws org.apache.rms.RmsException if there is a failure accessing
+     * the underlying db
+     */
+    public Iterator listNames() throws RmsException
+    {
+        throw new NotImplementedException( "STUB" ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplicationFactory.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,145 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import org.apache.rms.RmsException ;
+import org.apache.rms.spi.ApplicationFactory ;
+import org.apache.rms.spi.MutableApplication ;
+
+import org.apache.commons.lang.NotImplementedException ;
+
+import java.util.Iterator ;
+
+
+/**
+ * A Berkeley Database JE backed Application factory.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplicationFactory implements ApplicationFactory
+{
+    /** the application data access object for Berkeley DB Je */
+    private final JeApplicationDAO dao ;
+
+
+    /**
+     * Creates an Application factory for Berkeley DB Je.
+     *
+     * @param dao the application data access object for Berkeley DB Je
+     */
+    JeApplicationFactory( JeApplicationDAO dao )
+    {
+        this.dao = dao ;
+    }
+
+
+    /**
+     * Gets an application by name.
+     *
+     * @param appName
+     * @return
+     * @throws org.apache.rms.RmsException if there are problems accessing the
+     * backing store, or the application does not exist
+     */
+    public MutableApplication getApplication( String appName )
+            throws RmsException
+    {
+        if ( dao.has( appName ) )
+        {
+            /**
+             * @todo need to build the application up with perms and roles.
+             */
+            throw new NotImplementedException( "STUB" ) ;
+            // return new JeApplication( appName ) ;
+        }
+
+        throw new RmsException( "Application " + appName + " doesn't exist" ) ;
+    }
+
+
+    /**
+     * Lists all application names.
+     *
+     * @return an iterator over the application names as Strings
+     * @throws org.apache.rms.RmsException if there are problems accessing the
+     * backing store, or the application exists
+     */
+    public Iterator getApplicationNames() throws RmsException
+    {
+        return dao.listNames() ;
+    }
+
+
+    /**
+     * Creates a new RMS application.
+     *
+     * @param appName the unique name for the RMS application
+     * @return the newly created mutable application
+     * @throws org.apache.rms.RmsException if there are problems accessing the
+     * backing store, or the application exists
+     */
+    public MutableApplication createApplication( String appName )
+            throws RmsException
+    {
+        dao.create( appName ) ;
+
+        return new JeApplication( appName ) ;
+    }
+
+
+    /**
+     * Deletes an RMS application.
+     *
+     * @param appName the unique name for the RMS application
+     * @throws org.apache.rms.RmsException if there are problems accessing the
+     * backing store, or the application does not exist
+     */
+    public void deleteApplication( String appName ) throws RmsException
+    {
+        // dao.delete( appName ) ;
+        /**
+         * @todo need to check and see if the application is in use by
+         * other role or permission objects within the database.  The
+         * delete cannot occur if other objects are using this application
+         * name.
+         */
+        throw new NotImplementedException( "STUB" ) ;
+    }
+
+
+    /**
+     * Renames an Application.
+     *
+     * @param oldName the original name of the Application
+     * @param newName the new name for the Application
+     * @throws org.apache.rms.RmsException if there are problems accessing the
+     * backing store, or the application with the old name does not exist
+     */
+    public void renameApplication( String oldName, String newName )
+            throws RmsException
+    {
+        /**
+         * @todo need to check and see if the application is in use by
+         * other role or permission objects within the database.  The
+         * rename cannot occur if other objects are using this application
+         * name.
+         */
+        throw new NotImplementedException( "STUB" ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationDAOTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/application/JeApplicationDAOTest.java
Wed Apr 28 20:47:37 2004
@@ -0,0 +1,210 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permission and
+ *   limitations under the License.
+ *
+ */
+package org.apache.rms.je.application ;
+
+
+import com.sleepycat.je.* ;
+
+import org.apache.rms.RmsException ;
+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 ;
+
+import java.util.Iterator ;
+
+
+/**
+ * Tests the JeApplicationDAO class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplicationDAOTest extends AbstractJeTest
+{
+    JeApplicationDAO dao ;
+
+
+    protected void setUp() throws Exception
+    {
+        DatabaseConfig conf = new DatabaseConfig() ;
+        conf.setAllowCreate( true ) ;
+        setupDb( "seqDb", conf ) ;
+        super.setUp() ;
+
+        SecondaryConfig sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeAppNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, JeApplicationDAO.APP_SECDB,
+                sconf, db ) ;
+
+        JeSequenceDao seqDAO = new JeSequenceDao( getDb( "seqDb" ) ) ;
+        JeSequenceFactory seqFactory = new JeSequenceFactory( seqDAO ) ;
+        Sequence seq = seqFactory.create( "applicationSeq" ) ;
+        dao = new JeApplicationDAO( db, seq ) ;
+        //dao.setMonitor( new LoggingRoleDAOMonitor() ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        dao = null ;
+    }
+
+
+    public void testCreateAndHas() throws Exception
+    {
+        assertFalse( dao.has( "app1" ) ) ;
+
+        dao.create( "app1" ) ;
+        dao.create( "app2" ) ;
+        dao.create( "app3" ) ;
+        dao.create( "app4" ) ;
+
+        assertTrue( dao.has( "app1" ) ) ;
+        assertTrue( dao.has( "app2" ) ) ;
+        assertTrue( dao.has( "app3" ) ) ;
+        assertTrue( dao.has( "app4" ) ) ;
+
+        assertFalse( dao.has( "app5" ) ) ;
+    }
+
+
+    public void testCreateHasAndDelete() throws Exception
+    {
+        assertFalse( dao.has( "app1" ) ) ;
+        assertFalse( dao.has( "app2" ) ) ;
+        assertFalse( dao.has( "app3" ) ) ;
+        assertFalse( dao.has( "app4" ) ) ;
+
+        dao.create( "app1" ) ;
+        dao.create( "app2" ) ;
+        dao.create( "app3" ) ;
+        dao.create( "app4" ) ;
+
+        assertTrue( dao.has( "app1" ) ) ;
+        assertTrue( dao.has( "app2" ) ) ;
+        assertTrue( dao.has( "app3" ) ) ;
+        assertTrue( dao.has( "app4" ) ) ;
+
+        dao.delete( "app1" ) ;
+        dao.delete( "app2" ) ;
+        dao.delete( "app3" ) ;
+        dao.delete( "app4" ) ;
+
+        assertFalse( dao.has( "app1" ) ) ;
+        assertFalse( dao.has( "app2" ) ) ;
+        assertFalse( dao.has( "app3" ) ) ;
+        assertFalse( dao.has( "app4" ) ) ;
+
+        try
+        {
+            dao.delete( "app1" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
+
+
+    public void testCreateHasAndRename() throws Exception
+    {
+        assertFalse( dao.has( "app1" ) ) ;
+        assertFalse( dao.has( "app2" ) ) ;
+        assertFalse( dao.has( "app3" ) ) ;
+        assertFalse( dao.has( "app4" ) ) ;
+
+        dao.create( "app1" ) ;
+        dao.create( "app2" ) ;
+        dao.create( "app3" ) ;
+        dao.create( "app4" ) ;
+
+        assertTrue( dao.has( "app1" ) ) ;
+        assertTrue( dao.has( "app2" ) ) ;
+        assertTrue( dao.has( "app3" ) ) ;
+        assertTrue( dao.has( "app4" ) ) ;
+
+        dao.rename( "app1", "app5" ) ;
+        dao.rename( "app2", "app6" ) ;
+        dao.rename( "app3", "app7" ) ;
+        dao.rename( "app4", "app8" ) ;
+
+        assertFalse( dao.has( "app1" ) ) ;
+        assertFalse( dao.has( "app2" ) ) ;
+        assertFalse( dao.has( "app3" ) ) ;
+        assertFalse( dao.has( "app4" ) ) ;
+
+        assertTrue( dao.has( "app5" ) ) ;
+        assertTrue( dao.has( "app6" ) ) ;
+        assertTrue( dao.has( "app7" ) ) ;
+        assertTrue( dao.has( "app8" ) ) ;
+
+        try
+        {
+            dao.rename( "app1", "app5" ) ;
+            fail( "should never get here because of an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
+
+
+    public void testCreateAndList() throws Exception
+    {
+        assertFalse( dao.has( "app1" ) ) ;
+        assertFalse( dao.has( "app2" ) ) ;
+        assertFalse( dao.has( "app3" ) ) ;
+        assertFalse( dao.has( "app4" ) ) ;
+
+        dao.create( "app1" ) ;
+        dao.create( "app2" ) ;
+        dao.create( "app3" ) ;
+        dao.create( "app4" ) ;
+
+        assertTrue( dao.has( "app1" ) ) ;
+        assertTrue( dao.has( "app2" ) ) ;
+        assertTrue( dao.has( "app3" ) ) ;
+        assertTrue( dao.has( "app4" ) ) ;
+
+        Iterator list = null ;
+        String appName = null ;
+
+        list = dao.listNames() ;
+
+        appName = ( String ) list.next() ;
+        assertNotNull( appName ) ;
+        assertEquals( "app1", appName ) ;
+
+        appName = ( String ) list.next() ;
+        assertNotNull( appName ) ;
+        assertEquals( "app2", appName ) ;
+
+        appName = ( String ) list.next() ;
+        assertNotNull( appName ) ;
+        assertEquals( "app3", appName ) ;
+
+        appName = ( String ) list.next() ;
+        assertNotNull( appName ) ;
+        assertEquals( "app4", appName ) ;
+
+        assertFalse( list.hasNext() ) ;
+    }
+}
\ No newline at end of file

Mime
View raw message