From commits-return-33557-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Feb 2 12:39:11 2012 Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C7FB6904F for ; Thu, 2 Feb 2012 12:39:11 +0000 (UTC) Received: (qmail 66645 invoked by uid 500); 2 Feb 2012 12:39:11 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66553 invoked by uid 500); 2 Feb 2012 12:39:11 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 66450 invoked by uid 99); 2 Feb 2012 12:39:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 12:39:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 12:39:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 666F52388A68 for ; Thu, 2 Feb 2012 12:38:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1239581 [1/9] - in /directory/apacheds/trunk/jdbm2: ./ src/ src/etc/ src/examples/ src/main/ src/main/java/ src/main/java/jdbm/ src/main/java/jdbm/btree/ src/main/java/jdbm/helper/ src/main/java/jdbm/htree/ src/main/java/jdbm/recman/ src/s... Date: Thu, 02 Feb 2012 12:38:42 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120202123846.666F52388A68@eris.apache.org> Author: elecharny Date: Thu Feb 2 12:38:39 2012 New Revision: 1239581 URL: http://svn.apache.org/viewvc?rev=1239581&view=rev Log: Added the modified JDBM taken from Selcuk's branch into trunk Added: directory/apacheds/trunk/jdbm2/ (with props) directory/apacheds/trunk/jdbm2/pom.xml directory/apacheds/trunk/jdbm2/src/ directory/apacheds/trunk/jdbm2/src/build.xml directory/apacheds/trunk/jdbm2/src/etc/ directory/apacheds/trunk/jdbm2/src/etc/MANIFEST.MF directory/apacheds/trunk/jdbm2/src/examples/ directory/apacheds/trunk/jdbm2/src/examples/FamousPeople.java directory/apacheds/trunk/jdbm2/src/examples/FruitBasket.java directory/apacheds/trunk/jdbm2/src/examples/Primes.java directory/apacheds/trunk/jdbm2/src/main/ directory/apacheds/trunk/jdbm2/src/main/java/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ActionRecordManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerFactory.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerOptions.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerProvider.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/btree/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/btree/BPage.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/btree/BTree.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/btree/package.html directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ActionContext.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ActionVersioning.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ByteArrayComparator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ByteArraySerializer.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/CacheEvictionException.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/CachePolicy.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/CachePolicyListener.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/Conversion.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/DefaultSerializer.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/EntryIO.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ExplicitList.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/FastIterator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/IntegerComparator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/IntegerSerializer.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/IterationException.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/LongComparator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/LongSerializer.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/MRU.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/ObjectBAComparator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/Serialization.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/Serializer.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/SoftCache.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/StringComparator.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/Tuple.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/TupleBrowser.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/WrappedRuntimeException.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/helper/package.html directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/HTree.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/HashBucket.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/HashDirectory.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/HashNode.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/htree/package.html directory/apacheds/trunk/jdbm2/src/main/java/jdbm/package.html directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/BlockIo.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/BlockView.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/CacheRecordManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/DataPage.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FileHeader.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FreeLogicalRowIdPage.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FreeLogicalRowIdPageManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FreePhysicalRowId.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FreePhysicalRowIdPage.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/FreePhysicalRowIdPageManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/Location.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/LogicalRowIdManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/Magic.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/PageCursor.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/PageHeader.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/PageManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/PhysicalRowId.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/PhysicalRowIdManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/Provider.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/RecordCache.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/RecordFile.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/RecordHeader.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/SnapshotRecordManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/TransactionManager.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/TranslationPage.java directory/apacheds/trunk/jdbm2/src/main/java/jdbm/recman/package.html directory/apacheds/trunk/jdbm2/src/site/ directory/apacheds/trunk/jdbm2/src/site/site.xml directory/apacheds/trunk/jdbm2/src/test/ directory/apacheds/trunk/jdbm2/src/test/java/ directory/apacheds/trunk/jdbm2/src/test/java/jdbm/ directory/apacheds/trunk/jdbm2/src/test/java/jdbm/btree/ directory/apacheds/trunk/jdbm2/src/test/java/jdbm/btree/TestBTree.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/btree/TestBTreeBrowser.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/btree/TestSnapshotBTree.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/btree/TestStreamCorrupted.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/helper/ directory/apacheds/trunk/jdbm2/src/test/java/jdbm/helper/TestActionVersioning.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/helper/TestVersionedCache.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/recman/ directory/apacheds/trunk/jdbm2/src/test/java/jdbm/recman/BlockIoTest.java directory/apacheds/trunk/jdbm2/src/test/java/jdbm/recman/LocationTest.java directory/apacheds/trunk/jdbm2/src/test/resources/ directory/apacheds/trunk/jdbm2/src/test/resources/log4j.properties Propchange: directory/apacheds/trunk/jdbm2/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Thu Feb 2 12:38:39 2012 @@ -0,0 +1,11 @@ +.project +.classpath +.settings +eclipse-classes +*.log +*.iml +*.ipr +dependency-reduced-pom.xml +META-INF +bin +target Added: directory/apacheds/trunk/jdbm2/pom.xml URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/pom.xml?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/pom.xml (added) +++ directory/apacheds/trunk/jdbm2/pom.xml Thu Feb 2 12:38:39 2012 @@ -0,0 +1,91 @@ + + + + 4.0.0 + + org.apache.directory.server + apacheds-parent + 2.0.0-M5-SNAPSHOT + + + apacheds-jdbm2 + ApacheDS JDBM implementation + bundle + + Specific JDBM Implementation + + + + org.apache.directory.junit + junit-addons + test + + + + ${project.groupId} + apacheds-i18n + + + + + + + + org.apache.rat + apache-rat-plugin + + false + + **/* + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + false + + + + + + org.apache.felix + maven-bundle-plugin + true + true + + META-INF + + ${project.groupId}.jdbm2 + + {local-packages};version=${project.version};-noimport:=true + + + + + + + Added: directory/apacheds/trunk/jdbm2/src/build.xml URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/build.xml?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/build.xml (added) +++ directory/apacheds/trunk/jdbm2/src/build.xml Thu Feb 2 12:38:39 2012 @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: directory/apacheds/trunk/jdbm2/src/etc/MANIFEST.MF URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/etc/MANIFEST.MF?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/etc/MANIFEST.MF (added) +++ directory/apacheds/trunk/jdbm2/src/etc/MANIFEST.MF Thu Feb 2 12:38:39 2012 @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Specification-Title: JDBM +Specification-Vendor: JDBM at SourceForge Project +Specification-Version: 0.09 +Implementation-Title: JDBM +Implementation-Vendor: JDBM at SourceForge Project +Implementation-Version: $VERSION$ + Added: directory/apacheds/trunk/jdbm2/src/examples/FamousPeople.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/examples/FamousPeople.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/examples/FamousPeople.java (added) +++ directory/apacheds/trunk/jdbm2/src/examples/FamousPeople.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,155 @@ +import java.util.Properties; +import jdbm.RecordManager; +import jdbm.RecordManagerFactory; + +import jdbm.helper.Tuple; +import jdbm.helper.TupleBrowser; +import jdbm.helper.StringComparator; + +import jdbm.btree.BTree; + +/** + * Famous People example. + *

+ * Demonstrates the use of B+Tree data structure to manage a list of + * people and their occupation. The example covers insertion, + * ordered traversal, reverse traversal and range lookup of records. + * + * @author Alex Boisvert + */ +public class FamousPeople { + + static String DATABASE = "people"; + static String BTREE_NAME = "FamousPeople"; + + static String[] people = + { "Greenspan, Alan", + "Williams-Byrd, Julie", + "Picasso, Pablo", + "Stallman, Richard", + "Fort, Paul", + "S�ndergaard, Ole", + "Schwarzenegger, Arnold", + "Dulkinys, Susanna" }; + + static String[] occupations = + { "Federal Reserve Board Chairman", + "Engineer", + "Painter", + "Programmer", + "Poet", + "Typographer", + "Actor", + "Designer" }; + + static String PREFIX = "S"; + + /** + * Example main entrypoint. + */ + public static void main( String[] args ) { + RecordManager recman; + long recid; + Tuple tuple = new Tuple(); + TupleBrowser browser; + BTree tree; + Properties props; + + props = new Properties(); + + try { + // open database and setup an object cache + recman = RecordManagerFactory.createRecordManager( DATABASE, props ); + + // try to reload an existing B+Tree + recid = recman.getNamedObject( BTREE_NAME ); + if ( recid != 0 ) { + tree = BTree.load( recman, recid ); + System.out.println( "Reloaded existing BTree with " + tree.size() + + " famous people." ); + } else { + // create a new B+Tree data structure and use a StringComparator + // to order the records based on people's name. + tree = BTree.createInstance( recman, new StringComparator() ); + recman.setNamedObject( BTREE_NAME, tree.getRecid() ); + System.out.println( "Created a new empty BTree" ); + } + + // insert people with their respective occupation + System.out.println(); + for ( int i=0; i 0 ) { + buf.append( ' ' ); + } + return buf.toString(); + } + +} Added: directory/apacheds/trunk/jdbm2/src/examples/FruitBasket.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/examples/FruitBasket.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/examples/FruitBasket.java (added) +++ directory/apacheds/trunk/jdbm2/src/examples/FruitBasket.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,120 @@ +import jdbm.RecordManager; +import jdbm.RecordManagerFactory; +import jdbm.helper.FastIterator; +import jdbm.htree.HTree; + +import java.io.IOException; +import java.util.Properties; + +/** + * Sample JDBM application to demonstrate the use of basic JDBM operations. + * + * @author Alex Boisvert + */ +public class FruitBasket +{ + RecordManager recman; + HTree hashtable; + FastIterator iter; + String fruit; + String color; + + + public FruitBasket() + throws IOException + { + // create or open fruits record manager + Properties props = new Properties(); + recman = RecordManagerFactory.createRecordManager( "fruits", props ); + + // create or load fruit basket (hashtable of fruits) + long recid = recman.getNamedObject( "basket" ); + if ( recid != 0 ) { + System.out.println( "Reloading existing fruit basket..." ); + hashtable = HTree.load( recman, recid ); + showBasket(); + } else { + System.out.println( "Creating new fruit basket..." ); + hashtable = HTree.createInstance( recman ); + recman.setNamedObject( "basket", hashtable.getRecid() ); + } + } + + + public void runDemo() + throws IOException + { + // insert keys and values + System.out.println(); + System.out.println( "Adding fruits to the basket..." ); + hashtable.put( "bananas", "yellow" ); + hashtable.put( "strawberries", "red" ); + hashtable.put( "kiwis", "green" ); + + showBasket(); + + + // display color of a specific fruit + System.out.println(); + System.out.println( "Get the color of bananas..." ); + String bananasColor = (String) hashtable.get( "bananas" ); + System.out.println( "bananas are " + bananasColor ); + + recman.commit(); + + try { + // Thread.sleep( 10 * 1000 ); + } catch ( Exception except ) { + // ignore + } + + // remove a specific fruit from hashtable + System.out.println(); + System.out.print( "Removing bananas from the basket..." ); + hashtable.remove( "bananas" ); + recman.commit(); + System.out.println( " done." ); + + // iterate over remaining objects + System.out.println(); + System.out.println( "Remaining fruit colors:" ); + iter = hashtable.keys(); + fruit = (String) iter.next(); + while ( fruit != null ) { + color = (String) hashtable.get( fruit ); + System.out.println( fruit + " are " + color ); + fruit = (String) iter.next(); + } + + // cleanup + recman.close(); + } + + + public void showBasket() + throws IOException + { + // Display content of fruit basket + System.out.println(); + System.out.print( "Fruit basket contains: " ); + iter = hashtable.keys(); + fruit = (String) iter.next(); + while ( fruit != null ) { + System.out.print( " " + fruit ); + fruit = (String) iter.next(); + } + System.out.println(); + } + + + public static void main( String[] args ) + { + try { + FruitBasket basket = new FruitBasket(); + basket.runDemo(); + } catch ( IOException ioe ) { + ioe.printStackTrace(); + } + } + +} Added: directory/apacheds/trunk/jdbm2/src/examples/Primes.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/examples/Primes.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/examples/Primes.java (added) +++ directory/apacheds/trunk/jdbm2/src/examples/Primes.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,275 @@ +import jdbm.RecordManager; +import jdbm.RecordManagerFactory; +import jdbm.RecordManagerOptions; + +import jdbm.btree.BTree; + +import jdbm.helper.LongComparator; +import jdbm.helper.Tuple; +import jdbm.helper.TupleBrowser; + +import java.util.Properties; +import java.util.Random; +import java.io.IOException; + +/** + * Example program dealing with B+Trees and Prime numbers. + */ +public class Primes +{ + + /** + * Default number of prime number to populate in the database (if not specified on command-line) + */ + public static int DEFAULT_POPULATE = 100; + + + /** + * Default number of random lookups (if not specified on command-line) + */ + public static int DEFAULT_LOOKUPS = 100; + + + /** + * Record Manager used for persistence. + */ + private RecordManager _recman; + + + /** + * B+Tree holding prime numbers. + */ + private BTree _primes; + + + /** + * Random number generator. + */ + private static Random _random = new Random(); + + + /** + * Main constructor + */ + public Primes( String[] args ) + throws IOException + { + long recid; + Properties props; + + // open database and setup an object cache + props = new Properties(); + props.put( RecordManagerOptions.CACHE_SIZE, "10000" ); + _recman = RecordManagerFactory.createRecordManager( "primes", props ); + + recid = _recman.getNamedObject( "primes" ); + if ( recid == 0 ) { + System.out.println( "Creating a new primes B+Tree." ); + _primes = BTree.createInstance( _recman, new LongComparator() ); + _recman.setNamedObject( "primes", _primes.getRecid() ); + } else { + _primes = BTree.load( _recman, recid ); + System.out.println( "B+Tree already contains " + _primes.size() + " primes." ); + } + _recman.commit(); + } + + + /** + * Get the largest prime number in the database. + */ + public Long getLargestPrime() + throws IOException + { + Tuple tuple; + TupleBrowser browser; + Long largest = null; + + tuple = new Tuple(); + browser = _primes.browse( null ); + if ( browser.getPrevious( tuple ) ) { + largest = (Long) tuple.getValue(); + System.out.println( "Largest prime: " + largest ); + } else { + System.out.println( "No prime number in the database." ); + } + return largest; + } + + + /** + * Populate the database with more prime numbers. + * + * @param count Number of primes to add to database. + */ + void populate( int count ) + throws IOException + { + Long current; + Long largest; + + System.out.println( "Populating prime B+Tree..." ); + + // start after the largest known prime + largest = getLargestPrime(); + if ( largest == null ) { + largest = new Long( 0 ); + } + + current = new Long( largest.longValue() + 1L ); + while ( count > 0 ) { + if ( isPrime( current ) ) { + _primes.insert( current, current, false ); + System.out.println( "Found prime #" + _primes.size() + ": " + current ); + count--; + } + current = new Long( current.longValue() + 1 ); + } + _recman.commit(); + } + + + /** + * Returns true if a number is prime. + */ + boolean isPrime( Long number ) + throws IOException + { + Tuple tuple; + TupleBrowser browser; + Long largest; + Long current; + + if ( number.longValue() <= 0L ) { + throw new IllegalArgumentException( "Number must be greater than zero" ); + } + if ( number.longValue() == 1 ) { + return true; + } + tuple = new Tuple(); + browser = _primes.browse(); + while ( browser.getNext( tuple ) ) { + current = (Long) tuple.getValue(); + if ( current.longValue() != 1 && ( number.longValue() % current.longValue() ) == 0 ) { + // not a prime because it is divisibe by a prime + return false; + } + } + // this is a prime + return true; + } + + + /** + * Display a number of random prime numbers. + */ + void random( int count ) + throws IOException + { + Tuple tuple; + TupleBrowser browser; + Long largest; + Long number; + + tuple = new Tuple(); + largest = getLargestPrime(); + + System.out.println( "Looking up " + count + " random primes...." ); + long start = System.currentTimeMillis(); + for ( int i=0; i primes.getLargestPrime().longValue() ) { + throw new IllegalArgumentException( "Number is larger than largest known prime in database." ); + } + if ( primes.isPrime( number ) ) { + System.out.println( "The number " + number + " is a prime." ); + } else { + System.out.println( "The number " + number + " is not a prime." ); + } + } else if ( args[i].equalsIgnoreCase( "-random" ) ) { + if ( ++i < args.length ) { + count = Integer.parseInt( args[i] ); + } else { + count = DEFAULT_LOOKUPS; + } + primes.random( count ); + } + } + if ( args.length == 0 ) { + System.out.println( "Usage: java Prime [action] [args]" ); + System.out.println( "" ); + System.out.println( "Actions:" ); + System.out.println( " -populate [number] Populate database with prime numbers" ); + System.out.println( " -check [number] Check if a number is a prime" ); + System.out.println( " -random [number] Display random prime numbers" ); + System.out.println( "" ); + } + } catch ( IOException except ) { + except.printStackTrace(); + } + } +} Added: directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ActionRecordManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ActionRecordManager.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ActionRecordManager.java (added) +++ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/ActionRecordManager.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 jdbm; + +import jdbm.helper.ActionContext; + +/** + * Extends the RecordManager to allow callers to group their RecordManager interface + * calls into actions. Actions operate in isolation. + * + * Each thread has a current action context associated with it. Threads can switch + * between different action context using set/unsetActionContext calls. + * + * @author Apache Directory Project + */ +public interface ActionRecordManager extends RecordManager +{ + /** + * Initializes the context for the action. Implicity sets the + * context as the current action. + * + * @param readOnly true if action does not do any modification + * @param whoStarted caller can use this for debugging + * @return The created action context + */ + ActionContext beginAction( boolean readOnly, String whoStarted ); + + + /** + * Ends the action associated with the context. + * ReadWrite actions' changes are made visible + * to readers. + * + * @param context identifies the action to end + */ + void endAction( ActionContext context ); + + + /** + * Aborts the given action. For write actions, actions's changes + * should not be made visible to readers. + * + * @param context identifies the action to abort + */ + void abortAction( ActionContext context ); + + + /** + * Set the context as the current action context for + * the given thread + * + * @param context identifies the context + */ + public void setCurrentActionContext( ActionContext context ); + + + /** + * Unsets the context as the current action context. + * Given context should be current action context for the + * calling thread. + * + * @param context identifies the context. + */ + public void unsetCurrentActionContext( ActionContext context ); +} Added: directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManager.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManager.java (added) +++ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManager.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,193 @@ +/** + * JDBM LICENSE v1.00 + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "JDBM" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Cees de Groot. For written permission, + * please contact cg@cdegroot.com. + * + * 4. Products derived from this Software may not be called "JDBM" + * nor may "JDBM" appear in their names without prior written + * permission of Cees de Groot. + * + * 5. Due credit should be given to the JDBM Project + * (http://jdbm.sourceforge.net/). + * + * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 2000 (C) Cees de Groot. All Rights Reserved. + * Copyright 2000-2001 (C) Alex Boisvert. All Rights Reserved. + * Contributions are Copyright (C) 2000 by their associated contributors. + * + * $Id: RecordManager.java,v 1.3 2005/06/25 23:12:31 doomdark Exp $ + */ +package jdbm; + + +import java.io.IOException; +import jdbm.helper.Serializer; + + +/** + * An interface to manages records, which are uninterpreted blobs of data. + *

+ * The set of record operations is simple: fetch, insert, update and delete. + * Each record is identified using a "rowid" and contains a byte[] data block. + * Rowids are returned on inserts and you can store them someplace safe + * to be able to get back to them. Data blocks can be as long as you wish, + * and may have lengths different from the original when updating. + * + * @author Alex Boisvert + * @author Cees de Groot + */ +public interface RecordManager +{ + /** Reserved slot for name directory. */ + int NAME_DIRECTORY_ROOT = 0; + + + /** + * Inserts a new record using standard java object serialization. + * + * @param obj the object for the new record. + * @return the rowid for the new record. + * @throws IOException when one of the underlying I/O operations fails. + */ + long insert( Object obj ) throws IOException; + + + /** + * Inserts a new record using a custom serializer. + * + * @param obj the object for the new record. + * @param serializer a custom serializer + * @return the rowid for the new record. + * @throws IOException when one of the underlying I/O operations fails. + */ + long insert( Object obj, Serializer serializer ) throws IOException; + + + /** + * Deletes a record. + * + * @param recid the rowid for the record that should be deleted. + * @throws IOException when one of the underlying I/O operations fails. + */ + void delete( long recid ) throws IOException; + + + /** + * Updates a record using standard java object serialization. + * + * @param recid the recid for the record that is to be updated. + * @param obj the new object for the record. + * @throws IOException when one of the underlying I/O operations fails. + */ + void update( long recid, Object obj ) throws IOException; + + + /** + * Updates a record using a custom serializer. + * + * @param recid the recid for the record that is to be updated. + * @param obj the new object for the record. + * @param serializer a custom serializer + * @throws IOException when one of the underlying I/O operations fails. + */ + void update( long recid, Object obj, Serializer serializer ) throws IOException; + + + /** + * Fetches a record using standard java object serialization. + * + * @param recid the recid for the record that must be fetched. + * @return the object contained in the record. + * @throws IOException when one of the underlying I/O operations fails. + */ + Object fetch( long recid ) throws IOException; + + + /** + * Fetches a record using a custom serializer. + * + * @param recid the recid for the record that must be fetched. + * @param serializer a custom serializer + * @return the object contained in the record. + * @throws IOException when one of the underlying I/O operations fails. + */ + Object fetch( long recid, Serializer serializer ) throws IOException; + + + /** + * Closes the record manager. + * + * @throws IOException when one of the underlying I/O operations fails. + */ + void close() throws IOException; + + + /** + * Returns the number of slots available for "root" rowids. These slots + * can be used to store special rowids, like rowids that point to + * other rowids. Root rowids are useful for bootstrapping access to + * a set of data. + */ + int getRootCount(); + + + /** + * Returns the indicated root rowid. + * + * @see #getRootCount + */ + long getRoot( int id ) throws IOException; + + + /** + * Sets the indicated root rowid. + * + * @see #getRootCount + */ + void setRoot( int id, long rowid ) throws IOException; + + + /** Commit (make persistent) all changes since beginning of transaction. */ + void commit() throws IOException; + + + /** Rollback (cancel) all changes since beginning of transaction. */ + void rollback() throws IOException; + + + /** Obtain the record id of a named object. Returns 0 if named object doesn't exist. */ + long getNamedObject( String name ) throws IOException; + + + /** Set the record id of a named object. */ + void setNamedObject( String name, long recid ) throws IOException; +} + Added: directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerFactory.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerFactory.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerFactory.java (added) +++ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerFactory.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,115 @@ +/** + * JDBM LICENSE v1.00 + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "JDBM" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Cees de Groot. For written permission, + * please contact cg@cdegroot.com. + * + * 4. Products derived from this Software may not be called "JDBM" + * nor may "JDBM" appear in their names without prior written + * permission of Cees de Groot. + * + * 5. Due credit should be given to the JDBM Project + * (http://jdbm.sourceforge.net/). + * + * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 2000 (C) Cees de Groot. All Rights Reserved. + * Copyright 2000-2001 (C) Alex Boisvert. All Rights Reserved. + * Contributions are Copyright (C) 2000 by their associated contributors. + * + * $Id: RecordManagerFactory.java,v 1.2 2005/06/25 23:12:31 doomdark Exp $ + */ +package jdbm; + + +import java.io.IOException; +import java.util.Properties; + +import org.apache.directory.server.i18n.I18n; + + +/** + * This is the factory class to use for instantiating {@link RecordManager} + * instances. + * + * @author Alex Boisvert + * @author Cees de Groot + */ +public final class RecordManagerFactory +{ + + /** + * Create a record manager. + * + * @param name Name of the record file. + * @throws IOException if an I/O related exception occurs while creating + * or opening the record manager. + * @throws UnsupportedOperationException if some options are not supported by the + * implementation. + * @throws IllegalArgumentException if some options are invalid. + */ + public static RecordManager createRecordManager( String name ) throws IOException + { + return createRecordManager( name, new Properties() ); + } + + + /** + * Create a record manager. + * + * @param name Name of the record file. + * @param options Record manager options. + * @throws IOException if an I/O related exception occurs while creating + * or opening the record manager. + * @throws UnsupportedOperationException if some options are not supported by the + * implementation. + * @throws IllegalArgumentException if some options are invalid. + */ + public static RecordManager createRecordManager( String name, Properties options ) throws IOException + { + String provider; + Class clazz; + RecordManagerProvider factory; + + provider = options.getProperty( RecordManagerOptions.PROVIDER_FACTORY, "jdbm.recman.Provider" ); + + try + { + clazz = Thread.currentThread().getContextClassLoader().loadClass( provider ); + factory = ( RecordManagerProvider ) clazz.newInstance(); + } + catch ( Exception except ) + { + throw new IllegalArgumentException( I18n.err( I18n.ERR_567, provider, except.getClass().getName(), + except.getLocalizedMessage() ) ); + } + + return factory.createRecordManager( name, options ); + } +} Added: directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerOptions.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerOptions.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerOptions.java (added) +++ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerOptions.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,118 @@ +/** + * JDBM LICENSE v1.00 + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "JDBM" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Cees de Groot. For written permission, + * please contact cg@cdegroot.com. + * + * 4. Products derived from this Software may not be called "JDBM" + * nor may "JDBM" appear in their names without prior written + * permission of Cees de Groot. + * + * 5. Due credit should be given to the JDBM Project + * (http://jdbm.sourceforge.net/). + * + * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 2000 (C) Cees de Groot. All Rights Reserved. + * Copyright 2000-2001 (C) Alex Boisvert. All Rights Reserved. + * Contributions are Copyright (C) 2000 by their associated contributors. + * + * $Id: RecordManagerOptions.java,v 1.1 2002/05/31 06:33:20 boisvert Exp $ + */ +package jdbm; + + +/** + * Standard options for RecordManager. + * Final reference -> class shouldn't be extended + * + * @author Alex Boisvert + * @author Cees de Groot + */ +public final class RecordManagerOptions +{ + /** + * Ensures no construction of this class, also ensures there is no need for final keyword above + * (Implicit super constructor is not visible for default constructor), + * but is still self documenting. + */ + private RecordManagerOptions() + { + } + + /** Option to create a thread-safe record manager. */ + public final static String PROVIDER_FACTORY = "jdbm.provider"; + + + /** Option to create a thread-safe record manager. */ + public final static String THREAD_SAFE = "jdbm.threadSafe"; + + + /** Option to automatically commit data after each operation. */ + public final static String AUTO_COMMIT = "jdbm.autoCommit"; + + + /** + * Option to disable transaction (to increase performance at the cost of + * potential data loss). + */ + public final static String DISABLE_TRANSACTIONS = "jdbm.disableTransactions"; + + + /** Cache type. */ + public final static String CACHE_TYPE = "jdbm.cache.type"; + + + /** Cache size (when applicable) */ + public final static String CACHE_SIZE = "jdbm.cache.size"; + + + /** Use normal (strong) object references for the record cache. */ + public final static String NORMAL_CACHE = "normal"; + + + /** + * Use soft references {$link java.lang.ref.SoftReference} for the record + * cache instead of the default normal object references. + *

+ * Soft references are cleared at the discretion of the garbage collector + * in response to memory demand. + */ + public final static String SOFT_REF_CACHE = "soft"; + + + /** + * Use weak references {$link java.lang.ref.WeakReference} for the record + * cache instead of the default normal object references. + *

+ * Weak references do not prevent their referents from being made + * finalizable, finalized, and then reclaimed. + */ + public final static String WEAK_REF_CACHE = "weak"; +} Added: directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerProvider.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerProvider.java?rev=1239581&view=auto ============================================================================== --- directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerProvider.java (added) +++ directory/apacheds/trunk/jdbm2/src/main/java/jdbm/RecordManagerProvider.java Thu Feb 2 12:38:39 2012 @@ -0,0 +1,76 @@ +/** + * JDBM LICENSE v1.00 + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided + * that the following conditions are met: + * + * 1. Redistributions of source code must retain copyright + * statements and notices. Redistributions must also contain a + * copy of this document. + * + * 2. Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. The name "JDBM" must not be used to endorse or promote + * products derived from this Software without prior written + * permission of Cees de Groot. For written permission, + * please contact cg@cdegroot.com. + * + * 4. Products derived from this Software may not be called "JDBM" + * nor may "JDBM" appear in their names without prior written + * permission of Cees de Groot. + * + * 5. Due credit should be given to the JDBM Project + * (http://jdbm.sourceforge.net/). + * + * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Copyright 2000 (C) Cees de Groot. All Rights Reserved. + * Copyright 2000-2001 (C) Alex Boisvert. All Rights Reserved. + * Contributions are Copyright (C) 2000 by their associated contributors. + * + * $Id: RecordManagerProvider.java,v 1.2 2005/06/25 23:12:31 doomdark Exp $ + */ +package jdbm; + + +import java.io.IOException; +import java.util.Properties; + + +/** + * Provider of RecordManager implementation. Classes implementing this + * interface act as a factory to provide implementations of RecordManager. + * + * @author Alex Boisvert + */ +public interface RecordManagerProvider +{ + + /** + * Create a record manager. + * + * @param filename Base filename of the record file. + * @param options Record manager options. + * @throws IOException if an I/O related exception occurs while creating + * or opening the record manager. + * @throws UnsupportedOperationException if some options are not supported by the + * implementation. + * @throws IllegalArgumentException if some options are invalid. + */ + RecordManager createRecordManager( String filename, Properties options ) throws IOException; +}