directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10353 - 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
Date Wed, 28 Apr 2004 06:29:58 GMT
Author: akarasulu
Date: Tue Apr 27 23:29:56 2004
New Revision: 10353

Added:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java   (contents,
props changed)
Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleBinding.java
Log:
Commit changes ...

 o added key creators for the application name and the role name secondary db
 o added JeRoleDAO test case
 o fixed a couple things on the JE Role tuple binding
 o added a JeApplication object
 o continuing to fill in the role DAO



Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/application/JeApplication.java
Tue Apr 27 23:29:56 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 org.apache.rms.DefaultApplication;
+
+import java.util.Map;
+import java.util.List;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeApplication extends DefaultApplication
+{
+    /**
+     * Creates a default Application.
+     *
+     * @param name the name of the Application to create
+     */
+    public JeApplication( String name )
+    {
+        super( name ) ;
+    }
+
+
+    /**
+     * Creates a populated default Application instance with Roles and
+     * BitPermissions defined.
+     *
+     * @param name    the name of the Application to create
+     * @param roles   a Map of the Roles ( where the key is the name string,
+     * and the value is the Role instance) defined for this Application
+     * @param mapping the BitPermission to index mapping array - each
+     * BitPermission instance contained in the array is place at the index
+     * it has been assigned to for fast index lookups
+     */
+    public JeApplication( String name, Map roles, List mapping )
+    {
+        super( name, roles, mapping ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleAppNameKeyCreator.java
Tue Apr 27 23:29:56 2004
@@ -0,0 +1,71 @@
+/*
+ *   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.role ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+import java.io.IOException ;
+
+import org.apache.rms.je.permissions.JeBitPermissionTupleBinding;
+
+
+/**
+ * A permission appName key creator for the appName secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeRoleAppNameKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized role */
+    private static final JeRoleBinding BINDING = new JeRoleBinding() ;
+
+    /**
+     * 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
+        {
+            name = BINDING.getApplicationName( dataEntry ) ;
+            resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new DatabaseException( e ) ;
+        }
+
+        return true ;
+    }
+}

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	Tue
Apr 27 23:29:56 2004
@@ -78,7 +78,14 @@
     {
         Application application = getApplication() ;
         String appName = tupleInput.readString() ;
-        if ( application.getName() != appName )
+
+        if ( application == null )
+        {
+            throw new IllegalStateException(
+                    "The application for this thread has not been set before "
+                    + " using this binding" ) ;
+        }
+        else if ( application.getName() != appName )
         {
             throw new IllegalStateException(
                     "Expected application by the name of " + appName

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleNameKeyCreator.java
Tue Apr 27 23:29:56 2004
@@ -0,0 +1,71 @@
+/*
+ *   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.role ;
+
+
+import com.sleepycat.je.DatabaseEntry ;
+import com.sleepycat.je.SecondaryDatabase ;
+import com.sleepycat.je.DatabaseException ;
+import com.sleepycat.je.SecondaryKeyCreator ;
+
+import java.io.IOException ;
+
+import org.apache.rms.je.permissions.JeBitPermissionTupleBinding;
+
+
+/**
+ * A permission appName key creator for the appName secondary database.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeRoleNameKeyCreator implements SecondaryKeyCreator
+{
+    /** the binding used to manipulate a serialized role */
+    private static final JeRoleBinding BINDING = new JeRoleBinding() ;
+
+    /**
+     * 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
+        {
+            name = BINDING.getRoleName( dataEntry ) ;
+            resultEntry.setData( name.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( IOException e )
+        {
+            throw new DatabaseException( e ) ;
+        }
+
+        return true ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	Tue
Apr 27 23:29:56 2004
@@ -0,0 +1,93 @@
+/*
+ *   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.role ;
+
+
+import org.apache.rms.RmsException ;
+import org.apache.rms.BitPermission ;
+import org.apache.rms.DefaultApplication;
+
+import org.apache.rms.je.JeUtils ;
+import org.apache.rms.je.AbstractJeTest ;
+import org.apache.rms.je.application.JeApplication;
+import org.apache.rms.je.permissions.*;
+import org.apache.rms.je.sequence.Sequence ;
+import org.apache.rms.je.sequence.JeSequenceDao ;
+import org.apache.rms.je.sequence.JeSequenceFactory ;
+
+import com.sleepycat.je.*;
+
+
+/**
+ * Tests the JeRoleDAO class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeRoleDAOTest extends AbstractJeTest
+{
+    JeRoleDAO roleDAO ;
+
+
+    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 JeRoleAppNameKeyCreator() ) ;
+        env.openSecondaryDatabase( null, JeRoleDAO.APP_SECDB,
+                sconf, db ) ;
+
+        sconf = new SecondaryConfig() ;
+        sconf.setAllowCreate( true ) ;
+        sconf.setAllowDuplicates( true ) ;
+        sconf.setKeyCreator( new JeRoleNameKeyCreator() ) ;
+        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.setMonitor( new LoggingRoleDAOMonitor() ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        roleDAO = null ;
+    }
+
+
+    public void testHas() throws Exception
+    {
+        assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
+
+//        DefaultApplication application = new JeApplication( "app1" ) ;
+//        roleDAO.create( application, "roleA" ) ;
+//        roleDAO.create( application, "roleB" ) ;
+//        roleDAO.create( application, "roleC" ) ;
+//        roleDAO.create( application, "roleD" ) ;
+
+    }
+}
\ No newline at end of file

Mime
View raw message