directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10044 - in incubator/directory/rms/trunk/je: . src/java/org/apache/rms/je src/test/org/apache/rms/je
Date Fri, 16 Apr 2004 06:18:28 GMT
Author: akarasulu
Date: Thu Apr 15 23:18:27 2004
New Revision: 10044

Added:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/DefaultSequence.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeBitPermission.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeLoggingSequenceDaoMonitor.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceDao.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceFactory.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/LoggingSequenceDaoMonitor.java
  (contents, props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/PermTupleBinding.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/Sequence.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDao.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDaoMonitor.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceFactory.java   (contents,
props changed)
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/JeSequenceDaoTest.java   (contents,
props changed)
Modified:
   incubator/directory/rms/trunk/je/project.xml
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JePermFactory.java
Log:
o created sequence interfaces 
o have a good factory/dao/value object breakdown
o added unit tests for part of the implementation with still more to go


Modified: incubator/directory/rms/trunk/je/project.xml
==============================================================================
--- incubator/directory/rms/trunk/je/project.xml	(original)
+++ incubator/directory/rms/trunk/je/project.xml	Thu Apr 15 23:18:27 2004
@@ -35,6 +35,13 @@
     </dependency>
 
     <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>1.0.3</version>
+      <url>http://jakarta.apache.org/commons/logging</url>
+    </dependency>
+
+    <dependency>
       <groupId>bdb</groupId>
       <artifactId>je</artifactId>
       <version>1.3.0</version>
@@ -67,6 +74,7 @@
 
   <reports>
     <report>maven-changelog-plugin</report>
+    <report>maven-clover-plugin</report>
     <report>maven-developer-activity-plugin</report>
     <report>maven-file-activity-plugin</report>
     <report>maven-license-plugin</report>

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/DefaultSequence.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/DefaultSequence.java	Thu Apr
15 23:18:27 2004
@@ -0,0 +1,70 @@
+/*
+ *   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;
+
+import org.apache.rms.RmsException;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DefaultSequence implements Sequence
+{
+    /** the name of this Sequence */
+    private final String name ;
+    /** the data access object used to perform sequence ops on */
+    private final SequenceDao dao ;
+
+
+    /**
+     * Creates a persistant integer sequence starting at 0.
+     *
+     * @param name the name of the sequence
+     * @param dao the database peer used to perform sequence ops
+     */
+    DefaultSequence( String name, SequenceDao dao )
+    {
+        this.dao = dao ;
+        this.name = name ;
+    }
+
+
+    /**
+     * Gets the current value of this IntSequence which has already been used
+     * by the last caller of the getNextValue().
+     *
+     * @return the current value in use
+     */
+    public int getCurrentValue() throws RmsException
+    {
+        return dao.getCurrentValue( name ) ;
+    }
+
+
+    /**
+     * Gets the next value of this IntSequence to be used by the caller.
+     *
+     * @return the next value to use
+     */
+    public int getNextValue() throws RmsException
+    {
+        return dao.getNextValue( name ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeBitPermission.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeBitPermission.java	Thu Apr
15 23:18:27 2004
@@ -0,0 +1,55 @@
+/*
+ *   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 ;
+
+
+import org.apache.rms.DefaultBitPermission ;
+import org.apache.rms.spi.MutableBitPermission ;
+
+
+/**
+ * A mutable BitPermission implementation for this provider.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeBitPermission extends DefaultBitPermission
+        implements MutableBitPermission
+{
+    /**
+     * Creates a mutable BitPermission implementation for this provider.
+     *
+     * @param name the name of the permission
+     * @param index the bit vector index of the permission
+     * @param appName the name of application this permission is for
+     */
+    JeBitPermission( String name, int index, String appName )
+    {
+        super( name, index, appName ) ;
+    }
+
+
+    /**
+     * Sets the name of this permission.
+     *
+     * @param newName the new name for this permission
+     */
+    public void setName( String newName )
+    {
+        super.setName( newName ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeLoggingSequenceDaoMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeLoggingSequenceDaoMonitor.java
Thu Apr 15 23:18:27 2004
@@ -0,0 +1,70 @@
+/*
+ *   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 ;
+
+
+import org.apache.commons.logging.Log ;
+import org.apache.commons.logging.LogFactory ;
+import com.sleepycat.je.OperationStatus;
+
+
+/**
+ * Uses commons logging to report SequenceDao failures.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeLoggingSequenceDaoMonitor extends LoggingSequenceDaoMonitor
+{
+    public void failedOnNextValue( String name, Object info, Throwable fault )
+    {
+        OperationStatus status = ( OperationStatus ) info ;
+
+        if ( getLog().isErrorEnabled() )
+        {
+            getLog().error( "Failed to get the next sequence value " + name
+                    + "due to JE operation failure with a status of "
+                    + status, fault ) ;
+        }
+    }
+
+
+    public void failedOnCreate( String name, Object info, Throwable fault )
+    {
+        OperationStatus status = ( OperationStatus ) info ;
+
+        if ( getLog().isErrorEnabled() )
+        {
+            getLog().error( "Failed to create sequence " + name
+                    + "due to JE put operation failure with a status of "
+                    + status, fault ) ;
+        }
+    }
+
+
+    public void failedOnDelete( String name, Object info, Throwable fault )
+    {
+        OperationStatus status = ( OperationStatus ) info ;
+
+        if ( getLog().isErrorEnabled() )
+        {
+            getLog().error( "Failed to delete sequence " + name
+                    + "due to JE delete operation failure with a status of "
+                    + status, fault ) ;
+        }
+    }
+}

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JePermFactory.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JePermFactory.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JePermFactory.java	Thu Apr
15 23:18:27 2004
@@ -21,9 +21,13 @@
 import org.apache.rms.BitPermission ;
 import org.apache.rms.spi.PermissionFactory ;
 
+import org.apache.commons.lang.Validate ;
+import org.apache.commons.lang.NotImplementedException ;
+
 import java.util.List ;
 
 import com.sleepycat.je.Database ;
+import com.sleepycat.je.SecondaryDatabase;
 
 
 /**
@@ -36,6 +40,10 @@
 {
     /** the JE database to use for this factory */
     private final Database db ;
+    private final Sequence seq ;
+    private final SecondaryDatabase byIdx ;
+    private final SecondaryDatabase byName ;
+    private final SecondaryDatabase byApp ;
 
 
     /**
@@ -43,31 +51,44 @@
      *
      * @param db the JE Database for the permission factory
      */
-    JePermFactory( Database db )
+    JePermFactory( Database db, Sequence seq, SecondaryDatabase idx,
+                   SecondaryDatabase name, SecondaryDatabase app )
     {
+        Validate.notNull( db ) ;
+        Validate.notNull( seq ) ;
+        Validate.notNull( app ) ;
+        Validate.notNull( idx ) ;
+        Validate.notNull( name ) ;
+
         this.db = db ;
+        this.seq = seq ;
+        this.byApp = app ;
+        this.byIdx = idx ;
+        this.byName = name ;
     }
 
 
     public List getPermissionsMap( String appName ) throws RmsException
     {
-        return null ;
+        throw new NotImplementedException( "STUB" ) ;
     }
 
 
     public BitPermission create( String appName, String permName ) throws RmsException
     {
-        return null ;
+        throw new NotImplementedException( "STUB" ) ;
     }
 
 
     public void delete( String appName, String permName ) throws RmsException
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 
 
     public void rename( String appName, String oldPermName, String newPermName ) throws RmsException
     {
+        throw new NotImplementedException( "STUB" ) ;
     }
 }
 

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceDao.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceDao.java	Thu Apr
15 23:18:27 2004
@@ -0,0 +1,245 @@
+/*
+ *   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 ;
+
+import org.apache.rms.RmsException ;
+
+import com.sleepycat.je.* ;
+import com.sleepycat.bind.EntryBinding ;
+import com.sleepycat.bind.tuple.TupleBinding ;
+
+import java.io.IOException ;
+import java.io.UnsupportedEncodingException ;
+
+
+/**
+ * A DAO for managing persistant integer sequences.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeSequenceDao implements SequenceDao
+{
+    /** the default encoding used for sequence names */
+    private static final String ENCODING = "UTF-8" ;
+
+    /** the sequence database - persistant backing store for sequences */
+    private Database db ;
+    /** the monitor used to track activities */
+    private SequenceDaoMonitor monitor = new JeLoggingSequenceDaoMonitor() ;
+    /** the primitive Integer binding */
+    EntryBinding binding = TupleBinding.getPrimitiveBinding( Integer.class ) ;
+
+
+    /**
+     * Creates a DAO
+     * @param db
+     */
+    JeSequenceDao( Database db )
+    {
+        this.db = db ;
+    }
+
+
+    /**
+     * Creates a new integer based persistant sequence that starts at 0.
+     *
+     * @param name the unique name to use for the sequence
+     */
+    public void create( String name ) throws RmsException
+    {
+        DatabaseEntry key = buildKey( name ) ;
+        DatabaseEntry value = buildValue( new Integer( 0 ) ) ;
+        OperationStatus status = null ;
+
+        try
+        {
+            status = db.putNoOverwrite( null, key, value ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnCreate( name, status, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        if ( ! status.equals( OperationStatus.SUCCESS ) )
+        {
+            monitor.sequenceExits( name ) ;
+        }
+    }
+
+
+    /**
+     * Deletes an integer based persistant sequence.
+     *
+     * @param name the unique name for the sequence
+     */
+    public boolean delete( String name ) throws RmsException
+    {
+        DatabaseEntry key = buildKey( name ) ;
+        OperationStatus status = null ;
+
+        try
+        {
+            status = db.delete( null, key ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnDelete( name, status, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        return status.equals( OperationStatus.SUCCESS ) ;
+    }
+
+
+    /**
+     * Increments the value of a sequence and returns it.
+     *
+     * @param name the unique name for the sequence
+     */
+    public int getNextValue( String name ) throws RmsException
+    {
+        OperationStatus status = null ;
+        DatabaseEntry key = buildKey( name ) ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        Integer intObj = null ;
+
+        try
+        {
+            status = db.get( null, key, value, LockMode.DEFAULT ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnNextValue( name, status, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        try
+        {
+            intObj = ( Integer ) binding.entryToObject( value ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnNextValue( name, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        intObj = new Integer( intObj.intValue() + 1 ) ;
+        value = buildValue( intObj ) ;
+
+        try
+        {
+            status = db.put( null, key, value ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnNextValue( name, status, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        return intObj.intValue() ;
+    }
+
+
+    /**
+     * Gets the current value of a sequence.
+     *
+     * @param name the unique name for the sequence
+     */
+    public int getCurrentValue( String name ) throws RmsException
+    {
+        OperationStatus status = null ;
+        DatabaseEntry key = buildKey( name ) ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        Integer intObj = null ;
+
+        try
+        {
+            status = db.get( null, key, value, LockMode.DEFAULT ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnCurrentValue( name, status, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        try
+        {
+            intObj = ( Integer ) binding.entryToObject( value ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnCurrentValue( name, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        return intObj.intValue() ;
+    }
+
+
+    /**
+     * Builds the key from the sequence name.
+     *
+     * @param name the name of the sequence to use as the key data
+     * @return the serialized database entry
+     * @throws RmsException if there are failures while binding the key
+     */
+    private DatabaseEntry buildKey( String name ) throws RmsException
+    {
+        byte[] keyData = null ;
+
+        try
+        {
+            keyData = name.getBytes( ENCODING ) ;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            // should never happen but if it does
+            monitor.failure( e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        return new DatabaseEntry( keyData ) ;
+    }
+
+
+    /**
+     * Builds the DatabaseEntry value from an Integer.
+     *
+     * @param value the integer object value
+     * @return the serialized database entry
+     * @throws RmsException if there are failures while binding the key
+     */
+    private DatabaseEntry buildValue( Integer value )
+        throws RmsException
+    {
+        DatabaseEntry entry = new DatabaseEntry() ;
+
+        try
+        {
+            binding.objectToEntry( value, entry ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failure( e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        return entry ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/JeSequenceFactory.java	Thu
Apr 15 23:18:27 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 ;
+
+
+import org.apache.rms.RmsException ;
+
+
+/**
+ * A factory used to manage persistant integer Sequences using a JE Database
+ * backing store.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeSequenceFactory implements SequenceFactory
+{
+    /** the data access object */
+    private final JeSequenceDao dao ;
+
+    
+    /**
+     * Creates a factory used to manage Sequences using a JE Database.
+     *
+     * @param dao the data access object
+     */
+    JeSequenceFactory( JeSequenceDao dao )
+    {
+        this.dao = dao ;
+    }
+
+
+    /**
+     * Creates a new persistant integer sequence starting at 0.
+     *
+     * @param name the name of the integer sequence to create
+     * @return the newly created persistant sequence
+     * @throws org.apache.rms.RmsException if there are failures persisting the state
+     */
+    public Sequence create( String name ) throws RmsException
+    {
+        dao.create( name ) ;
+        return new DefaultSequence( name, dao ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/LoggingSequenceDaoMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/LoggingSequenceDaoMonitor.java
Thu Apr 15 23:18:27 2004
@@ -0,0 +1,121 @@
+/*
+ *   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 ;
+
+
+import org.apache.commons.logging.Log ;
+import org.apache.commons.logging.LogFactory ;
+
+
+/**
+ * Uses commons logging to report SequenceDao failures.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LoggingSequenceDaoMonitor implements SequenceDaoMonitor
+{
+    private Log log = LogFactory.getLog( "SequenceDao" ) ;
+
+
+    public void failedOnCurrentValue( String name, Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Failed to get the current value of sequence "
+                    + name, fault ) ;
+        }
+    }
+
+
+    public void sequenceExits( String name )
+    {
+        if ( log.isWarnEnabled() )
+        {
+            log.warn( "Attempted to create a sequence "
+                    + name + " which already exists" ); ;
+        }
+    }
+
+
+    public void failedOnCurrentValue( String name, Object info,
+                                      Throwable fault )
+    {
+        failedOnCurrentValue( name, fault ) ;
+    }
+
+
+    public void failedOnCreate( String name, Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Failed to create a sequence " + name, fault ) ;
+        }
+    }
+
+
+    public void failedOnCreate( String name, Object info, Throwable fault )
+    {
+        failedOnCreate( name, fault ) ;
+    }
+
+
+    public void failedOnDelete( String name, Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Failed to delete sequence " + name, fault ) ;
+        }
+    }
+
+
+    public void failedOnDelete( String name, Object info, Throwable fault )
+    {
+        failedOnDelete( name, fault ) ;
+    }
+
+
+    public void failedOnNextValue( String name, Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Failed to get the next value of sequence "
+                    + name, fault ) ;
+        }
+    }
+
+
+    public void failedOnNextValue( String name, Object info, Throwable fault )
+    {
+        failedOnNextValue( name, fault ) ;
+    }
+
+
+    public void failure( Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Failure while handling sequence operation", fault ) ;
+        }
+    }
+
+
+    protected Log getLog()
+    {
+        return log ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/PermTupleBinding.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/PermTupleBinding.java	Thu
Apr 15 23:18:27 2004
@@ -0,0 +1,74 @@
+/*
+ *   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 ;
+
+
+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.BitPermission ;
+
+
+/**
+ * A binary bit permission interface to tuple binding.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PermTupleBinding extends TupleBinding
+{
+    /**
+     * Reconstructs a bit permission using a serialized entry.
+     *
+     * @param tupleInput the tuple data
+     * @return the newly constructed bit permission
+     * @throws IOException if there are any failures accessing the tuple data
+     */
+    public Object entryToObject( TupleInput tupleInput ) throws IOException
+    {
+        String name = tupleInput.readString() ;
+        String appName = tupleInput.readString() ;
+        int index = tupleInput.readInt() ;
+
+        return new JeBitPermission( name, index, appName ) ;
+    }
+
+
+    /**
+     * Marshals a bit permission into serialized Tuple data.
+     *
+     * @param o the bit permission to marshal
+     * @param tupleOutput
+     * @throws IOException
+     */
+    public void objectToEntry( Object o, TupleOutput tupleOutput ) throws IOException
+    {
+        BitPermission perm = ( BitPermission ) o ;
+
+        if ( perm == null )
+        {
+            return ;
+        }
+
+        tupleOutput.writeString( perm.getName() ) ;
+        tupleOutput.writeString( perm.getApplication() ) ;
+        tupleOutput.writeInt( perm.getIndex() ) ;
+    }
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/Sequence.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/Sequence.java	Thu Apr 15 23:18:27
2004
@@ -0,0 +1,44 @@
+/*
+ *   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 ;
+
+import org.apache.rms.RmsException;
+
+
+/**
+ * A sequence based off of integers with a size limit of Integer.MAX_VALUE.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface Sequence
+{
+    /**
+     * Gets the current value of this IntSequence which has already
+     * been used by the last caller of the getNextValue().
+     *
+     * @return the current value in use
+     */
+    int getCurrentValue() throws RmsException ;
+
+    /**
+     * Gets the next value of this IntSequence to be used by the caller.
+     *
+     * @return the next value to use
+     */
+    int getNextValue() throws RmsException ;
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDao.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDao.java	Thu Apr 15
23:18:27 2004
@@ -0,0 +1,58 @@
+/*
+ *   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 ;
+
+
+import org.apache.rms.RmsException ;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SequenceDao
+{
+    /**
+     * Creates a new integer based persistant sequence that starts at 0.
+     *
+     * @param name the unique name to use for the sequence
+     */
+    void create( String name ) throws RmsException ;
+
+    /**
+     * Deletes an integer based persistant sequence.
+     *
+     * @param name the unique name for the sequence
+     */
+    boolean delete( String name ) throws RmsException ;
+
+    /**
+     * Increments the value of a sequence and returns it.
+     *
+     * @param name the unique name for the sequence
+     */
+    int getNextValue( String name ) throws RmsException ;
+
+    /**
+     * Gets the current value of a sequence.
+     *
+     * @param name the unique name for the sequence
+     */
+    int getCurrentValue( String name ) throws RmsException ;
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDaoMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceDaoMonitor.java	Thu
Apr 15 23:18:27 2004
@@ -0,0 +1,47 @@
+/*
+ *   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 ;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SequenceDaoMonitor
+{
+    void failedOnCreate( String name, Throwable fault ) ;
+
+    void failedOnCreate( String name, Object info, Throwable fault ) ;
+
+    void failedOnDelete( String name, Throwable fault ) ;
+
+    void failedOnDelete( String name, Object info, Throwable fault ) ;
+
+    void failedOnNextValue( String name, Object info, Throwable fault ) ;
+
+    void failedOnNextValue( String name, Throwable fault ) ;
+
+    void failure( Throwable fault ) ;
+
+    void failedOnCurrentValue( String name, Throwable fault ) ;
+
+    void failedOnCurrentValue( String name, Object info, Throwable fault ) ;
+
+    void sequenceExits( String name ) ;
+}

Added: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceFactory.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/SequenceFactory.java	Thu Apr
15 23:18:27 2004
@@ -0,0 +1,38 @@
+/*
+ *   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;
+
+import org.apache.rms.RmsException;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SequenceFactory
+{
+    /**
+     * Creates a new persistant integer sequence starting at 0.
+     *
+     * @param name the name of the integer sequence to create
+     * @return the newly created persistant sequence
+     * @throws RmsException if there are failures persisting the state
+     */
+    Sequence create( String name ) throws RmsException ;
+}

Added: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/JeSequenceDaoTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/JeSequenceDaoTest.java	Thu
Apr 15 23:18:27 2004
@@ -0,0 +1,80 @@
+/*
+ *   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 ;
+
+import org.apache.rms.RmsException ;
+
+
+/**
+ * Tests the JeSequenceDao class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JeSequenceDaoTest extends AbstractJeTest
+{
+    JeSequenceDao dao ;
+
+    protected void setUp() throws Exception
+    {
+        super.setUp() ;
+        dao = new JeSequenceDao( super.db ) ;
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        dao = null ;
+    }
+
+
+    public void testCreate() throws Exception
+    {
+        dao.create( "testSeq0" ) ;
+        assertEquals( 0, dao.getCurrentValue( "testSeq0" ) ) ;
+        dao.create( "testSeq0" ) ;
+    }
+
+
+    public void testDelete() throws Exception
+    {
+        dao.create( "testSeq0" ) ;
+        assertEquals( 0, dao.getCurrentValue( "testSeq0" ) ) ;
+        dao.delete( "testSeq0" ) ;
+
+        try
+        {
+            dao.getCurrentValue( "testSeq0" ) ;
+            fail( "we should never get here due to an exception" ) ;
+        }
+        catch ( RmsException e )
+        {
+        }
+    }
+
+
+    public void testNextValue() throws Exception
+    {
+        dao.create( "testSeq0" ) ;
+        assertEquals( 0, dao.getCurrentValue( "testSeq0" ) ) ;
+
+        for ( int ii = 1; ii < 100; ii++ )
+        {
+            assertEquals( ii, dao.getNextValue( "testSeq0" ) ) ;
+        }
+    }
+}
\ No newline at end of file

Mime
View raw message