Package com.sleepycat.je

Examples of com.sleepycat.je.SequenceConfig


        return seq;
    }

    public synchronized SequenceConfig getSequenceConfig(String name) {
        checkOpen();
        SequenceConfig config = sequenceConfigMap.get(name);
        if (config == null) {
            config = new SequenceConfig();
            config.setInitialValue(1);
            config.setRange(1, Long.MAX_VALUE);
            config.setCacheSize(100);
            config.setAutoCommitNoSync(true);
            config.setAllowCreate(!storeConfig.getReadOnly());
            sequenceConfigMap.put(name, config);
        }
        return config;
    }
View Full Code Here


    public void testIllegal()
        throws DatabaseException {

        DatabaseEntry key = new DatabaseEntry(new byte[1]);
        SequenceConfig config = new SequenceConfig();
        config.setAllowCreate(true);

        /* Duplicates not allowed. */

        Database db = openDb("dups", true);
        Transaction txn = txnBegin();
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (IllegalArgumentException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("duplicates") >= 0);
        }
        txnCommit(txn);
        db.close();

        db = openDb("foo");
        txn = txnBegin();

        /* Range min must be less than max. */

        config.setRange(0, 0);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (IllegalArgumentException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("less than the maximum") >= 0);
        }

        /* Initial value must be within range. */

        config.setRange(-10, 10);
        config.setInitialValue(-11);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (IllegalArgumentException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("out of range") >= 0);
        }
        config.setInitialValue(11);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (IllegalArgumentException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("out of range") >= 0);
        }

        /* Cache size must be within range. */

        config.setRange(-10, 10);
        config.setCacheSize(21);
        config.setInitialValue(0);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (IllegalArgumentException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("cache size is larger") >= 0);
        }

        /* Create with legal range values. */

        config.setRange(1, 2);
        config.setInitialValue(1);
        config.setCacheSize(0);
        Sequence seq = db.openSequence(txn, key, config);

        /* Key must not exist if ExclusiveCreate=true. */

        config.setExclusiveCreate(true);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (DatabaseException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("already exists") >= 0);
        }
        config.setExclusiveCreate(false);
        seq.close();

        /* Key must exist if AllowCreate=false. */

        db.removeSequence(txn, key);
        config.setAllowCreate(false);
        try {
            db.openSequence(txn, key, config);
            fail();
        } catch (DatabaseException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("does not exist") >= 0);
        }

        /* Check wrapping not allowed. */

        db.removeSequence(txn, key);
        config.setAllowCreate(true);
        config.setRange(-5, 5);
        config.setInitialValue(-5);
        seq = db.openSequence(txn, key, config);
        for (long i = config.getRangeMin(); i <= config.getRangeMax(); i++) {
            assertEquals(i, seq.get(txn, 1));
        }
        try {
            seq.get(txn, 1);
            fail();
        } catch (DatabaseException expected) {
            String msg = expected.getMessage();
            assertTrue(msg, msg.indexOf("overflow") >= 0);
        }

        /* Check wrapping not allowed, decrement. */

        db.removeSequence(txn, key);
        config.setAllowCreate(true);
        config.setAllowCreate(true);
        config.setRange(-5, 5);
        config.setInitialValue(5);
        config.setDecrement(true);
        seq = db.openSequence(txn, key, config);
        for (long i = config.getRangeMax(); i >= config.getRangeMin(); i--) {
            assertEquals(i, seq.get(txn, 1));
        }
        try {
            seq.get(txn, 1);
            fail();
View Full Code Here

        Database db = openDb("foo");
        DatabaseEntry key = new DatabaseEntry(new byte[0]);
        DatabaseEntry data = new DatabaseEntry();

        SequenceConfig config = new SequenceConfig();
        config.setAllowCreate(true);

        Transaction txn = txnBegin();
        Sequence seq = db.openSequence(txn, key, config);
        txnCommit(txn);
View Full Code Here

        Database db = openDb("foo");
        DatabaseEntry key = new DatabaseEntry(new byte[0]);

        /* Create a sequence. */

        SequenceConfig config = new SequenceConfig();
        config.setAllowCreate(true);
        config.setDecrement(true);
        config.setRange(1, 3);
        config.setInitialValue(3);

        Transaction txn = txnBegin();
        Sequence seq = db.openSequence(txn, key, config);
        assertEquals(3, seq.get(txn, 1));
        txnCommit(txn);
View Full Code Here

                break;
            default:
                throw new IllegalStateException();
            }

            SequenceConfig config = new SequenceConfig();
            config.setAllowCreate(true);
            config.setInitialValue(incr ? min : max);
            config.setWrap(wrap);
            config.setDecrement(!incr);
            config.setRange(min, max);
            config.setCacheSize(cache);

            String msg =
                "incr=" + incr +
                " wrap=" + wrap +
                " min=" + min +
View Full Code Here

        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        Database db = env.openDatabase(null, DB_NAME, dbConfig);

        /* Create the sequence oject. */
        SequenceConfig config = new SequenceConfig();
        config.setAllowCreate(true);
        DatabaseEntry key =
            new DatabaseEntry(KEY_NAME.getBytes("UTF-8"));
        Sequence seq = db.openSequence(null, key, config);

        /* Allocate a few sequence numbers. */
 
View Full Code Here

    }

    private void createMessageMetadataSequence(final Database messageMetadataSeqDb,
                                               final long maximumMessageId)
    {
        SequenceConfig sequenceConfig = MESSAGE_METADATA_SEQ_CONFIG.setInitialValue(maximumMessageId + 1);

        Sequence messageMetadataSeq = messageMetadataSeqDb.openSequence(null, MESSAGE_METADATA_SEQ_KEY, sequenceConfig);
        messageMetadataSeq.close();
    }
View Full Code Here

        return seq;
    }

    public synchronized SequenceConfig getSequenceConfig(String name) {
        checkOpen();
        SequenceConfig config = sequenceConfigMap.get(name);
        if (config == null) {
            config = new SequenceConfig();
            config.setInitialValue(1);
            config.setRange(1, Long.MAX_VALUE);
            config.setCacheSize(100);
            config.setAutoCommitNoSync(true);
            config.setAllowCreate(!storeConfig.getReadOnly());
            sequenceConfigMap.put(name, config);
        }
        return config;
    }
View Full Code Here

    void initDb(DatabaseConfig dbConfig, Environment env) {
        //main database
        db = env.openDatabase(null, "imports", dbConfig);

        //sequence for identifiers
        SequenceConfig seqConfig = new SequenceConfig();
        seqConfig.setAllowCreate(true);
        seqDb = env.openDatabase(null, "seq", dbConfig);
        importIdSeq = seqDb.openSequence(null, new DatabaseEntry("import_id".getBytes()), seqConfig);

        dbBinding.initDb(dbConfig, env);
        importBinding = dbBinding.createImportBinding(importer);
View Full Code Here

        Configure and create the entity-related store. It is thread-safe and handles entity handling.
         */
        StoreConfig storeConfig = new StoreConfig();
        storeConfig.setAllowCreate(true);
        this.entityStore = new EntityStore(environment, "testDatabase", storeConfig);
        SequenceConfig sequenceConfig = new SequenceConfig();
        sequenceConfig.setAllowCreate(true);
        sequenceConfig.setInitialValue(1);
        this.entityStore.setSequenceConfig("ID", sequenceConfig);
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.SequenceConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.