• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sequence类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.sleepycat.je.Sequence的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sequence类属于com.sleepycat.je包,在下文中一共展示了Sequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public synchronized Sequence getSequence(String name)
    throws DatabaseException {

    checkOpen();

    if (storeConfig.getReadOnly()) {
        throw new IllegalStateException("Store is read-only");
    }

    Sequence seq = sequenceMap.get(name);
    if (seq == null) {
        if (sequenceDb == null) {
            String dbName = storePrefix + SEQUENCE_DB;
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(storeConfig.getTransactional());
            dbConfig.setAllowCreate(true);
            sequenceDb = env.openDatabase(null, dbName, dbConfig);
        }
        DatabaseEntry entry = new DatabaseEntry();
        StringBinding.stringToEntry(name, entry);
        seq = sequenceDb.openSequence(null, entry, getSequenceConfig(name));
        sequenceMap.put(name, seq);
    }
    return seq;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:26,代码来源:Store.java


示例2: doOne

import com.sleepycat.je.Sequence; //导入依赖的package包/类
private void doOne(String msg,
                   Sequence seq,
                   Transaction txn,
                   int delta,
                   long expectValue,
                   boolean expectCached)
    throws DatabaseException {

    msg += " value=" + expectValue;

    try {
        assertEquals(msg, expectValue, seq.get(txn, delta));
    } catch (DatabaseException e) {
        fail(msg + ' ' + e);
    }

    StatsConfig clearConfig = new StatsConfig();
    clearConfig.setFast(true);
    clearConfig.setClear(true);
    SequenceStats stats = seq.getStats(clearConfig);

    assertEquals(msg, 1, stats.getNGets());
    assertEquals(msg, expectCached ? 1 : 0, stats.getNCachedGets());
}
 
开发者ID:nologic,项目名称:nabs,代码行数:25,代码来源:SequenceTest.java


示例3: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public synchronized Sequence getSequence(String name)
    throws DatabaseException {

    checkOpen();

    if (storeConfig.getReadOnly()) {
        throw new IllegalStateException("Store is read-only");
    }
    
    Sequence seq = sequenceMap.get(name);
    if (seq == null) {
        if (sequenceDb == null) {
            String dbName = storePrefix + SEQUENCE_DB;
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(storeConfig.getTransactional());
            dbConfig.setAllowCreate(true);
            sequenceDb = env.openDatabase(null, dbName, dbConfig);
        }
        DatabaseEntry entry = new DatabaseEntry();
        StringBinding.stringToEntry(name, entry);
        seq = sequenceDb.openSequence(null, entry, getSequenceConfig(name));
        sequenceMap.put(name, seq);
    }
    return seq;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:26,代码来源:Store.java


示例4: openSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
/**
 * Opens or creates a sequence.
 * 
 * This method tries to open an existing sequence or create a new sequence with starting value
 * of the next available id number in the specified index.
 * 
 * @param entityStore The store that contains the sequence.
 * @param index The index which is used to initialize the starting value.
 * @param sequenceName The name of the sequence.
 * @return The opened or created sequence.
 */
public static Sequence openSequence(EntityStore entityStore, EntityIndex<Long, ?> index, 
        String sequenceName) {
    Sequence seq = null;
    try {
        seq = entityStore.getSequence(sequenceName);
    } catch (SequenceNotFoundException ex) {
        // Establish current value
        long initialValue = DatabaseUtils.getMaxId(index) +  1;

        entityStore.setSequenceConfig(sequenceName, 
                SequenceConfig.DEFAULT.setAllowCreate(true).setInitialValue(initialValue));
        seq = entityStore.getSequence(sequenceName);
    } finally {
        if (seq == null) {
            throw new RuntimeException("Could not open sequence localIdSequence.");
        }

        return seq;
    }
}
 
开发者ID:MTA-SZTAKI,项目名称:longneck-bdb,代码行数:32,代码来源:DatabaseUtils.java


示例5: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
/**
 * Returns a {@link Sequence} instance with given configuration or {@link Berkeley#defaultSequenceConfig()} if null
 */
public Sequence getSequence(String sequenceKey, SequenceConfig sequenceConfig) {
    Sequence sequence = sequences.get(checkNotNull(sequenceKey));
    if (null == sequence) {
        sequence = sequenceDB().openSequence(null, 
                sequenceDB().getEntry(sequenceKey), firstNonNull(sequenceConfig, defaultSequenceConfig()));
        sequences.put(sequenceKey, sequence);
    }
    
    return sequence;
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:14,代码来源:Berkeley.java


示例6: run

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public void run(File envHomeDirectory)
    throws DatabaseException, IOException {

    /* Create the environment object. */
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    Environment env = new Environment(envHomeDirectory, envConfig);

    /* Create the database object. */
    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. */
    for (int i = 0; i < 10; i++) {
        long seqnum = seq.get(null, 1);
        System.out.println("Got sequence number: " + seqnum);
    }

    /* Close all. */
    seq.close();
    db.close();
    env.close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:32,代码来源:SequenceExample.java


示例7: PersistKeyAssigner

import com.sleepycat.je.Sequence; //导入依赖的package包/类
PersistKeyAssigner(PersistKeyBinding keyBinding,
                   PersistEntityBinding entityBinding,
                   Sequence sequence) {
    catalog = keyBinding.catalog;
    /* getSequenceKeyFormat will validate the field type for a sequence. */
    keyFieldFormat = keyBinding.keyFormat.getSequenceKeyFormat();
    entityFormat = entityBinding.entityFormat;
    rawAccess = entityBinding.rawAccess;
    this.sequence = sequence;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:11,代码来源:PersistKeyAssigner.java


示例8: testMultipleHandles

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public void testMultipleHandles()
    throws DatabaseException {

    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);

    /* Open another handle on the same sequence -- config should match. */

    txn = txnBegin();
    Sequence seq2 = db.openSequence(txn, key, config);
    assertEquals(2, seq2.get(txn, 1));
    txnCommit(txn);

    SequenceStats stats = seq2.getStats(null);
    assertEquals(1, stats.getCurrent());
    assertEquals(1, stats.getMin());
    assertEquals(3, stats.getMax());

    /* Values are assigned from a single sequence for both handles. */

    assertEquals(1, seq.get(null, 1));

    seq.close();
    seq2.close();
    db.close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:40,代码来源:SequenceTest.java


示例9: PersistKeyAssigner

import com.sleepycat.je.Sequence; //导入依赖的package包/类
PersistKeyAssigner(PersistKeyBinding keyBinding,
                   PersistEntityBinding entityBinding,
                   Sequence sequence) {
    catalog = keyBinding.catalog;
    keyFormat = keyBinding.keyFormat;
    entityFormat = entityBinding.entityFormat;
    rawAccess = entityBinding.rawAccess;
    this.sequence = sequence;
}
 
开发者ID:nologic,项目名称:nabs,代码行数:10,代码来源:PersistKeyAssigner.java


示例10: openSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
/**
 * @see SecondaryDatabase#openSequence(Transaction, DatabaseEntry, SequenceConfig)
 */
public Sequence openSequence(final Transaction txn, final DatabaseEntry key,
                             final SequenceConfig config) throws SequenceNotFoundException,
        SequenceExistsException {
    return delegate().openSequence(txn, key, config);
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:9,代码来源:Berkeley.java


示例11: testBasic

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public void testBasic()
    throws DatabaseException {

    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);

    txn = txnBegin();

    /* Check default values before calling get(). */

    SequenceStats stats = seq.getStats(null);
    assertEquals(0, stats.getCurrent());
    assertEquals(0, stats.getCacheSize());
    assertEquals(0, stats.getNGets());
    assertEquals(Long.MIN_VALUE, stats.getMin());
    assertEquals(Long.MAX_VALUE, stats.getMax());

    /* Get the first value. */

    long val = seq.get(txn, 1);
    assertEquals(0, val);
    stats = seq.getStats(null);
    assertEquals(1, stats.getCurrent());
    assertEquals(1, stats.getValue());
    assertEquals(0, stats.getLastValue());
    assertEquals(1, stats.getNGets());

    /* Use deltas greater than one. */

    assertEquals(1, seq.get(txn, 2));
    assertEquals(3, seq.get(txn, 3));
    assertEquals(6, seq.get(txn, 1));
    assertEquals(7, seq.get(txn, 1));

    /* Remove a sequence and expect the key to be deleted. */

    seq.close();
    db.removeSequence(txn, key);
    assertEquals(OperationStatus.NOTFOUND, db.get(txn, key, data, null));
    txnCommit(txn);
    assertEquals(OperationStatus.NOTFOUND, db.get(null, key, data, null));

    db.close();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:53,代码来源:SequenceTest.java


示例12: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public synchronized Sequence getSequence(String name)
    throws DatabaseException {

    checkOpen();

    if (storeConfig.getReadOnly()) {
        throw new IllegalStateException("Store is read-only");
    }

    Sequence seq = sequenceMap.get(name);
    if (seq == null) {
        if (sequenceDb == null) {
            String[] fileAndDbNames =
                parseDbName(storePrefix + SEQUENCE_DB);
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(storeConfig.getTransactional());
            dbConfig.setAllowCreate(true);
            /* <!-- begin JE only --> */
            dbConfig.setReplicated(storeConfig.getReplicated());
            dbConfig.setTemporary(storeConfig.getTemporary());
            /* <!-- end JE only --> */
            DbCompat.setTypeBtree(dbConfig);
            sequenceDb = DbCompat.openDatabase
                (env, null /*txn*/, fileAndDbNames[0], fileAndDbNames[1],
                 dbConfig);
            assert sequenceDb != null;
        }

        DatabaseEntry entry = new DatabaseEntry();
        StringBinding.stringToEntry(name, entry);
        /* <!-- begin JE only --> */
        try {
        /* <!-- end JE only --> */
            seq = sequenceDb.openSequence(null /*txn*/, entry,
                                          getSequenceConfig(name));
        /* <!-- begin JE only --> */
        } catch (SequenceExistsException e) {
            /* Should never happen, ExclusiveCreate is false. */
            throw DbCompat.unexpectedException(e);
        } catch (SequenceNotFoundException e) {
            /* Should never happen, ALlowCreate is true. */
            throw DbCompat.unexpectedException(e);
        }
        /* <!-- end JE only --> */
        sequenceMap.put(name, seq);
    }
    return seq;
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:49,代码来源:Store.java


示例13: increment

import com.sleepycat.je.Sequence; //导入依赖的package包/类
public long increment(byte[] key) {
    Transaction tx = getTx();
    Sequence sequence = db.openSequence(tx, new DatabaseEntry(key), conf);
    return sequence.get(tx, 1);
}
 
开发者ID:deephacks,项目名称:confit,代码行数:6,代码来源:TxDatabase.java


示例14: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
/**
 * Returns a named sequence for using Berkeley DB engine API directly,
 * opening it if necessary.
 *
 * @param name the sequence name, which is normally defined using the
 * {@link PrimaryKey#sequence} annotation property.
 *
 * @return the open sequence for the given sequence name.
 */
public Sequence getSequence(String name)
    throws DatabaseException {

    return store.getSequence(name);
}
 
开发者ID:nologic,项目名称:nabs,代码行数:15,代码来源:EntityStore.java


示例15: getSequence

import com.sleepycat.je.Sequence; //导入依赖的package包/类
/**
 * Returns a named sequence for using Berkeley DB engine API directly,
 * opening it if necessary.
 *
 * @param name the sequence name, which is normally defined using the
 * {@link PrimaryKey#sequence} annotation property.
 *
 * @return the open sequence for the given sequence name.
 *
 * @throws DatabaseException the base class for all BDB exceptions.
 */
public Sequence getSequence(String name)
    throws DatabaseException {

    return store.getSequence(name);
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:17,代码来源:EntityStore.java



注:本文中的com.sleepycat.je.Sequence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LinkedUndirectedGraph类代码示例发布时间:2022-05-23
下一篇:
Java ServiceContext类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap