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

Java MVMap类代码示例

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

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



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

示例1: createSecurely

import org.h2.mvstore.MVMap; //导入依赖的package包/类
static MVStore createSecurely(MVStore.Builder builder, String userId, String password) {
    MVStore store = builder.open();

    try {
        if (!isNullOrEmpty(password) && !isNullOrEmpty(userId)) {
            byte[] salt = getNextSalt();
            byte[] hash = hash(password.toCharArray(), salt);
            UserCredential userCredential = new UserCredential();
            userCredential.setPasswordHash(hash);
            userCredential.setPasswordSalt(salt);

            MVMap<String, UserCredential> userMap = store.openMap(USER_MAP);
            userMap.put(userId, userCredential);
        }
    } finally {
        if (store != null) {
            store.commit();
        }
    }

    return store;
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:23,代码来源:Security.java


示例2: removeTemporaryMaps

import org.h2.mvstore.MVMap; //导入依赖的package包/类
/**
 * Remove all temporary maps.
 *
 * @param objectIds the ids of the objects to keep
 */
public void removeTemporaryMaps(BitField objectIds) {
    for (String mapName : store.getMapNames()) {
        if (mapName.startsWith("temp.")) {
            MVMap<?, ?> map = store.openMap(mapName);
            store.removeMap(map);
        } else if (mapName.startsWith("table.") || mapName.startsWith("index.")) {
            int id = Integer.parseInt(mapName.substring(1 + mapName.indexOf(".")));
            if (!objectIds.get(id)) {
                ValueDataType keyType = new ValueDataType(null, null, null);
                ValueDataType valueType = new ValueDataType(null, null, null);
                Transaction t = transactionStore.begin();
                TransactionMap<?, ?> m = t.openMap(mapName, keyType, valueType);
                transactionStore.removeMap(m);
                t.commit();
            }
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:MVTableEngine.java


示例3: openMap

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private MVMap<Value, Value> openMap(String mapName) {
    int[] sortTypes = new int[keyColumns];
    for (int i = 0; i < indexColumns.length; i++) {
        sortTypes[i] = indexColumns[i].sortType;
    }
    sortTypes[keyColumns - 1] = SortOrder.ASCENDING;
    ValueDataType keyType = new ValueDataType(
            database.getCompareMode(), database, sortTypes);
    ValueDataType valueType = new ValueDataType(null, null, null);
    MVMap.Builder<Value, Value> builder =
            new MVMap.Builder<Value, Value>().keyType(keyType).valueType(valueType);
    MVMap<Value, Value> map = database.getMvStore().
            getStore().openMap(mapName, builder);
    if (!keyType.equals(map.getKeyType())) {
        throw DbException.throwInternalError("Incompatible key type");
    }
    return map;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:MVSecondaryIndex.java


示例4: TransactionStore

import org.h2.mvstore.MVMap; //导入依赖的package包/类
/**
 * Create a new transaction store.
 *
 * @param store the store
 * @param dataType the data type for map keys and values
 */
public TransactionStore(MVStore store, DataType dataType) {
    this.store = store;
    this.dataType = dataType;
    preparedTransactions = store.openMap("openTransactions",
            new MVMap.Builder<Integer, Object[]>());
    VersionedValueType oldValueType = new VersionedValueType(dataType);
    ArrayType undoLogValueType = new ArrayType(new DataType[]{
            new ObjectDataType(), dataType, oldValueType
    });
    MVMap.Builder<Long, Object[]> builder =
            new MVMap.Builder<Long, Object[]>().
            valueType(undoLogValueType);
    undoLog = store.openMap("undoLog", builder);
    if (undoLog.getValueType() != undoLogValueType) {
        throw DataUtils.newIllegalStateException(
                DataUtils.ERROR_TRANSACTION_CORRUPT,
                "Undo map open with a different value type");
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:26,代码来源:TransactionStore.java


示例5: init

import org.h2.mvstore.MVMap; //导入依赖的package包/类
/**
 * Initialize the store. This is needed before a transaction can be opened.
 * If the transaction store is corrupt, this method can throw an exception,
 * in which case the store can only be used for reading.
 */
public synchronized void init() {
    init = true;
    // remove all temporary maps
    for (String mapName : store.getMapNames()) {
        if (mapName.startsWith("temp.")) {
            MVMap<Object, Integer> temp = openTempMap(mapName);
            store.removeMap(temp);
        }
    }
    synchronized (undoLog) {
        if (undoLog.size() > 0) {
            for (Long key : undoLog.keySet()) {
                int transactionId = getTransactionId(key);
                openTransactions.set(transactionId);
            }
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:TransactionStore.java


示例6: openMap

import org.h2.mvstore.MVMap; //导入依赖的package包/类
/**
 * Open the map with the given name.
 *
 * @param <K> the key type
 * @param name the map name
 * @param keyType the key type
 * @param valueType the value type
 * @return the map
 */
synchronized <K> MVMap<K, VersionedValue> openMap(String name,
        DataType keyType, DataType valueType) {
    if (keyType == null) {
        keyType = new ObjectDataType();
    }
    if (valueType == null) {
        valueType = new ObjectDataType();
    }
    VersionedValueType vt = new VersionedValueType(valueType);
    MVMap<K, VersionedValue> map;
    MVMap.Builder<K, VersionedValue> builder =
            new MVMap.Builder<K, VersionedValue>().
            keyType(keyType).valueType(vt);
    map = store.openMap(name, builder);
    @SuppressWarnings("unchecked")
    MVMap<Object, VersionedValue> m = (MVMap<Object, VersionedValue>) map;
    maps.put(map.getId(), m);
    return map;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:TransactionStore.java


示例7: getPostContingencyLoadflowConvergence

import org.h2.mvstore.MVMap; //导入依赖的package包/类
@Override
public Map<Integer, Boolean> getPostContingencyLoadflowConvergence(String workflowId, String contingencyId) {
    if (isWorkflowStored(workflowId)) {
        Map<Integer, Boolean> loadflowConvergence = new HashMap<Integer, Boolean>();
        MVStore wfMVStore = getStore(workflowId);
        if (wfMVStore.getMapNames().contains(STORED_PC_LOADFLOW_CONTINGENCIES_MAP_NAME)) {
            Map<String, String> storedStatesMap = wfMVStore.openMap(STORED_PC_LOADFLOW_CONTINGENCIES_MAP_NAME, mapBuilder);
            if (storedStatesMap.containsKey(contingencyId)) {
                MVMap<String, String> contingencyStateMap = wfMVStore.openMap(contingencyId + STORED_PC_LOADFLOW_STATES_MAP_SUFFIX, mapBuilder);
                for (String stateId : contingencyStateMap.keySet()) {
                    loadflowConvergence.put(Integer.valueOf(stateId), Boolean.valueOf(contingencyStateMap.get(stateId)));
                }
                return loadflowConvergence;
            } else {
                LOGGER.warn("No post contingency loadflow data for contingency {} in wf {}", contingencyId, workflowId);
                return null;
            }
        } else {
            LOGGER.warn("No post contingency loadflow data in wf {}", workflowId);
            return null;
        }
    } else {
        LOGGER.warn("No data about wf {}", workflowId);
        return null;
    }
}
 
开发者ID:itesla,项目名称:ipst,代码行数:27,代码来源:OnlineDbMVStore.java


示例8: testSaveCount

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testSaveCount() throws IOException {
    String fileName = getBaseDir() + "/testSaveCount.h3";
    FileUtils.delete(fileName);
    MVStore s = new MVStore.Builder().
            fileName(fileName).
            open();
    MVMap<Long, byte[]> map = s.openMap("data");
    StreamStore streamStore = new StreamStore(map);
    int blockSize = 256 * 1024;
    assertEquals(blockSize, streamStore.getMaxBlockSize());
    for (int i = 0; i < 8 * 16; i++) {
        streamStore.put(new RandomStream(blockSize, i));
    }
    long writeCount = s.getFileStore().getWriteCount();
    assertTrue(writeCount > 2);
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:TestStreamStore.java


示例9: testLarge

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testLarge() throws IOException {
    String fileName = getBaseDir() + "/testVeryLarge.h3";
    FileUtils.delete(fileName);
    final MVStore s = new MVStore.Builder().
            fileName(fileName).
            open();
    MVMap<Long, byte[]> map = s.openMap("data");
    final AtomicInteger count = new AtomicInteger();
    StreamStore streamStore = new StreamStore(map) {
        @Override
        protected void onStore(int len) {
            count.incrementAndGet();
            s.commit();
        }
    };
    long size = 1 * 1024 * 1024;
    streamStore.put(new RandomStream(size, 0));
    s.close();
    assertEquals(4, count.get());
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:TestStreamStore.java


示例10: verify

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void verify() {

        MVStore s;
        MVMap<Integer, byte[]> m;

        FileUtils.delete(fileName);
        s = new MVStore.Builder().
                fileName(fileName).open();
        m = s.openMap("data");
        for (int i = 0; i < 100; i++) {
            byte[] x = m.get(i);
            if (x == null) {
                break;
            }
            assertEquals(i * 100, x.length);
        }
        s.close();
    }
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:TestKillProcessWhileWriting.java


示例11: testVolatileMap

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testVolatileMap() {
    String fileName = getBaseDir() + "/testVolatile.h3";
    MVStore store = new MVStore.Builder().
            fileName(fileName).
            open();
    MVMap<String, String> map = store.openMap("test");
    assertFalse(map.isVolatile());
    map.setVolatile(true);
    assertTrue(map.isVolatile());
    map.put("1", "Hello");
    assertEquals("Hello", map.get("1"));
    assertEquals(1, map.size());
    store.close();
    store = new MVStore.Builder().
            fileName(fileName).
            open();
    assertTrue(store.hasMap("test"));
    map = store.openMap("test");
    assertEquals(0, map.size());
    store.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:22,代码来源:TestMVStore.java


示例12: testCompressEmptyPage

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testCompressEmptyPage() {
    String fileName = getBaseDir() + "/testDeletedMap.h3";
    MVStore store = new MVStore.Builder().
            cacheSize(100).fileName(fileName).
            compress().
            autoCommitBufferSize(10 * 1024).
            open();
    MVMap<String, String> map = store.openMap("test");
    store.removeMap(map);
    store.commit();
    store.close();
    store = new MVStore.Builder().
            compress().
            open();
    store.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:17,代码来源:TestMVStore.java


示例13: testVersionsToKeep

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testVersionsToKeep() throws Exception {
    MVStore s = new MVStore.Builder().open();
    MVMap<Integer, Integer> map;
    map = s.openMap("data");
    for (int i = 0; i < 20; i++) {
        long version = s.getCurrentVersion();
        map.put(i, i);
        s.commit();
        if (version >= 6) {
            map.openVersion(version - 5);
            try {
                map.openVersion(version - 6);
                fail();
            } catch (IllegalArgumentException e) {
                // expected
            }
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TestMVStore.java


示例14: testVersionsToKeep2

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testVersionsToKeep2() {
    MVStore s = new MVStore.Builder().autoCommitDisabled().open();
    s.setVersionsToKeep(2);
    final MVMap<Integer, String> m = s.openMap("data");
    s.commit();
    assertEquals(1, s.getCurrentVersion());
    m.put(1, "version 1");
    s.commit();
    assertEquals(2, s.getCurrentVersion());
    m.put(1, "version 2");
    s.commit();
    assertEquals(3, s.getCurrentVersion());
    m.put(1, "version 3");
    s.commit();
    m.put(1, "version 4");
    assertEquals("version 4", m.openVersion(4).get(1));
    assertEquals("version 3", m.openVersion(3).get(1));
    assertEquals("version 2", m.openVersion(2).get(1));
    new AssertThrows(IllegalArgumentException.class) {
        @Override
        public void test() throws Exception {
            m.openVersion(1);
        }
    };
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVStore.java


示例15: testRemoveMap

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testRemoveMap() throws Exception {
    String fileName = getBaseDir() + "/testCloseMap.h3";
    FileUtils.delete(fileName);
    MVStore s = new MVStore.Builder().
        fileName(fileName).
        open();
    MVMap<Integer, Integer> map;

    map = s.openMap("data");
    map.put(1, 1);
    assertEquals(1, map.get(1).intValue());
    s.commit();

    s.removeMap(map);
    s.commit();

    map = s.openMap("data");
    assertTrue(map.isEmpty());
    map.put(2, 2);

    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:TestMVStore.java


示例16: testCompactFully

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testCompactFully() throws Exception {
    String fileName = getBaseDir() + "/testCompactFully.h3";
    FileUtils.delete(fileName);
    MVStore s = new MVStore.Builder().
            fileName(fileName).
            autoCommitDisabled().
            open();
    MVMap<Integer, String> m;
    for (int i = 0; i < 100; i++) {
        m = s.openMap("data" + i);
        m.put(0, "Hello World");
        s.commit();
    }
    for (int i = 0; i < 100; i += 2) {
        m = s.openMap("data" + i);
        s.removeMap(m);
        s.commit();
    }
    long sizeOld = s.getFileStore().size();
    s.compactMoveChunks();
    long sizeNew = s.getFileStore().size();
    assertTrue("old: " + sizeOld + " new: " + sizeNew, sizeNew < sizeOld);
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestMVStore.java


示例17: testExample

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testExample() {
    String fileName = getBaseDir() + "/testExample.h3";
    FileUtils.delete(fileName);

    // open the store (in-memory if fileName is null)
    MVStore s = MVStore.open(fileName);

    // create/get the map named "data"
    MVMap<Integer, String> map = s.openMap("data");

    // add and read some data
    map.put(1, "Hello World");
    // System.out.println(map.get(1));

    // close the store (this will persist changes)
    s.close();

    s = MVStore.open(fileName);
    map = s.openMap("data");
    assertEquals("Hello World", map.get(1));
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:TestMVStore.java


示例18: testOldVersion

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testOldVersion() {
    MVStore s;
    for (int op = 0; op <= 1; op++) {
        for (int i = 0; i < 5; i++) {
            s = openStore(null);
            s.setVersionsToKeep(Integer.MAX_VALUE);
            MVMap<String, String> m;
            m = s.openMap("data");
            for (int j = 0; j < 5; j++) {
                if (op == 1) {
                    m.put("1", "" + s.getCurrentVersion());
                }
                s.commit();
            }
            for (int j = 0; j < s.getCurrentVersion(); j++) {
                MVMap<String, String> old = m.openVersion(j);
                if (op == 1) {
                    assertEquals("" + j, old.get("1"));
                }
            }
            s.close();
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:TestMVStore.java


示例19: removeWfWcaRulesResults

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void removeWfWcaRulesResults(String workflowId, MVStore wfMVStore) {
    LOGGER.debug("Removing existing wca rules results for workflow {}", workflowId);
    MVMap<String, String> storedRulesResultsMap = wfMVStore.openMap(STORED_WCA_RULES_RESULTS_MAP_NAME, mapBuilder);
    // remove rules results
    Collection<String> rulesContingencies = OnlineDbMVStoreUtils.jsonToContingenciesIds(
            storedRulesResultsMap.get(STORED_RULES_RESULTS_CONTINGENCIES_WITH_RULES_KEY));
    for (String contingencyId : rulesContingencies) {
        MVMap<String, String> storedStateStatusMap = wfMVStore.openMap(contingencyId + STORED_WCA_RULES_RESULTS_STATE_STATUS_MAP_SUFFIX, mapBuilder);
        wfMVStore.removeMap(storedStateStatusMap);
        MVMap<String, String> storedStateResultsMap = wfMVStore.openMap(contingencyId + STORED_WCA_RULES_RESULTS_STATE_RESULTS_MAP_SUFFIX, mapBuilder);
        wfMVStore.removeMap(storedStateResultsMap);
        MVMap<String, String> storedStateAvailableRulesMap = wfMVStore.openMap(contingencyId + STORED_WCA_RULES_RESULTS_STATE_RULES_AVAILABLE_MAP_SUFFIX, mapBuilder);
        wfMVStore.removeMap(storedStateAvailableRulesMap);
        MVMap<String, String> storedStateInvalidRulesMap = wfMVStore.openMap(contingencyId + STORED_WCA_RULES_RESULTS_STATE_INVALID_RULES_MAP_SUFFIX, mapBuilder);
        wfMVStore.removeMap(storedStateInvalidRulesMap);
    }
    // remove info about stored rules results
    wfMVStore.removeMap(storedRulesResultsMap);
    // commit removal
    wfMVStore.commit();
}
 
开发者ID:itesla,项目名称:ipst,代码行数:22,代码来源:OnlineDbMVStore.java


示例20: testReuseSpace

import org.h2.mvstore.MVMap; //导入依赖的package包/类
private void testReuseSpace() {
    String fileName = getBaseDir() + "/testReuseSpace.h3";
    FileUtils.delete(fileName);
    long initialLength = 0;
    for (int j = 0; j < 20; j++) {
        MVStore s = openStore(fileName);
        s.setRetentionTime(0);
        MVMap<Integer, String> m = s.openMap("data");
        for (int i = 0; i < 10; i++) {
            m.put(i, "Hello");
        }
        s.commit();
        for (int i = 0; i < 10; i++) {
            assertEquals("Hello", m.get(i));
            assertEquals("Hello", m.remove(i));
        }
        s.close();
        long len = FileUtils.size(fileName);
        if (initialLength == 0) {
            initialLength = len;
        } else {
            assertTrue("len: " + len + " initial: " + initialLength + " j: " + j,
                    len <= initialLength * 2);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestMVStore.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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