当前位置: 首页>>代码示例>>Java>>正文


Java MVMap类代码示例

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


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


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