本文整理汇总了Java中org.h2.mvstore.MVMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java MVMap.put方法的具体用法?Java MVMap.put怎么用?Java MVMap.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.mvstore.MVMap
的用法示例。
在下文中一共展示了MVMap.put方法的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;
}
示例2: 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
}
}
}
}
示例3: storeWcaResults
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
@Override
public void storeWcaResults(String workflowId, OnlineWorkflowWcaResults results) {
Objects.requireNonNull(workflowId, "workflow id is null");
Objects.requireNonNull(results, "online workflow wca results is null");
LOGGER.info("Storing results of WCA for workflow {}", workflowId);
MVStore wfMVStore = getStore(workflowId);
// check if the results for this wf have already been stored
if (wfMVStore.hasMap(STORED_WCA_RESULTS_MAP_NAME)) {
removeWfWcaResults(workflowId, wfMVStore);
}
MVMap<String, String> storedWcaResultsMap = wfMVStore.openMap(STORED_WCA_RESULTS_MAP_NAME, mapBuilder);
// store time horizon
storedWcaResultsMap.put(STORED_RESULTS_TIMEHORIZON_KEY, results.getTimeHorizon().getName());
// store wca results for contingencies
MVMap<String, String> storedClustersMap = wfMVStore.openMap(STORED_WCA_RESULTS_CLUSTERS_MAP_NAME, mapBuilder);
MVMap<String, String> storedCausesMap = wfMVStore.openMap(STORED_WCA_RESULTS_CAUSES_MAP_NAME, mapBuilder);
for (String contingencyId : results.getContingencies()) {
storedClustersMap.put(contingencyId, Integer.toString(results.getClusterIndex(contingencyId)));
List<String> causes = results.getCauses(contingencyId);
if (causes != null && causes.size() > 0) {
storedCausesMap.put(contingencyId, causes.get(0));
}
}
wfMVStore.commit();
}
示例4: 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();
}
示例5: testKeyValueClasses
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testKeyValueClasses() {
String fileName = getBaseDir() + "/testKeyValueClasses.h3";
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
MVMap<Integer, String> is = s.openMap("intString");
is.put(1, "Hello");
MVMap<Integer, Integer> ii = s.openMap("intInt");
ii.put(1, 10);
MVMap<String, Integer> si = s.openMap("stringInt");
si.put("Test", 10);
MVMap<String, String> ss = s.openMap("stringString");
ss.put("Hello", "World");
s.close();
s = openStore(fileName);
is = s.openMap("intString");
assertEquals("Hello", is.get(1));
ii = s.openMap("intInt");
assertEquals(10, ii.get(1).intValue());
si = s.openMap("stringInt");
assertEquals(10, si.get("Test").intValue());
ss = s.openMap("stringString");
assertEquals("World", ss.get("Hello"));
s.close();
}
示例6: addRowsToBuffer
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
@Override
public void addRowsToBuffer(List<Row> rows, String bufferName) {
MVMap<Value, Value> map = openMap(bufferName);
for (Row row : rows) {
ValueArray key = convertToKey(row);
map.put(key, ValueNull.INSTANCE);
}
}
示例7: testInterruptReopen
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testInterruptReopen() throws Exception {
String fileName = "retry:nio:" + getBaseDir() + "/testInterruptReopen.h3";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().
fileName(fileName).
cacheSize(0).
open();
final Thread mainThread = Thread.currentThread();
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
mainThread.interrupt();
Thread.sleep(10);
}
}
};
try {
MVMap<Integer, byte[]> map = s.openMap("data");
task.execute();
for (int i = 0; i < 1000 && !task.isFinished(); i++) {
map.get(i % 1000);
map.put(i % 1000, new byte[1024]);
s.commit();
}
} finally {
task.get();
s.close();
}
}
示例8: testConcurrentSaveCompact
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentSaveCompact() throws Exception {
String fileName = "memFS:testConcurrentSaveCompact";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().
fileName(fileName).
cacheSize(0).
open();
try {
s.setRetentionTime(0);
final MVMap<Integer, Integer> dataMap = s.openMap("data");
Task task = new Task() {
@Override
public void call() throws Exception {
int i = 0;
while (!stop) {
s.compact(100, 1024 * 1024);
dataMap.put(i % 1000, i * 10);
s.commit();
i++;
}
}
};
task.execute();
for (int i = 0; i < 1000 && !task.isFinished(); i++) {
s.compact(100, 1024 * 1024);
dataMap.put(i % 1000, i * 10);
s.commit();
}
task.get();
} finally {
s.close();
}
}
示例9: testLargerThan2G
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testLargerThan2G() {
if (!config.big) {
return;
}
String fileName = getBaseDir() + "/testLargerThan2G.h3";
FileUtils.delete(fileName);
MVStore store = new MVStore.Builder().cacheSize(16).
fileName(fileName).open();
MVMap<Integer, String> map = store.openMap("test");
long last = System.currentTimeMillis();
String data = new String(new char[2500]).replace((char) 0, 'x');
for (int i = 0;; i++) {
map.put(i, data);
if (i % 10000 == 0) {
store.commit();
long time = System.currentTimeMillis();
if (time - last > 2000) {
long mb = store.getFileStore().size() / 1024 / 1024;
trace(mb + "/4500");
if (mb > 4500) {
break;
}
last = time;
}
}
}
store.commit();
store.close();
FileUtils.delete(fileName);
}
示例10: testConcurrentChangeAndCompact
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentChangeAndCompact() throws InterruptedException {
String fileName = "memFS:testConcurrentChangeAndBackgroundCompact";
FileUtils.delete(fileName);
final MVStore s = new MVStore.Builder().fileName(
fileName).
pageSplitSize(10).
autoCommitDisabled().open();
s.setRetentionTime(10000);
Task task = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
s.compact(100, 1024 * 1024);
}
}
};
task.execute();
Task task2 = new Task() {
@Override
public void call() throws Exception {
while (!stop) {
s.compact(100, 1024 * 1024);
}
}
};
task2.execute();
Thread.sleep(1);
for (int i = 0; !task.isFinished() && !task2.isFinished() && i < 1000; i++) {
MVMap<Integer, Integer> map = s.openMap("d" + (i % 3));
// MVMap<Integer, Integer> map = s.openMap("d" + (i % 3),
// new MVMapConcurrent.Builder<Integer, Integer>());
map.put(0, i);
map.get(0);
s.commit();
}
task.get();
task2.get();
s.close();
}
示例11: testFileFormatChange
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testFileFormatChange() {
String fileName = getBaseDir() + "/testFileFormatChange.h3";
FileUtils.delete(fileName);
MVStore s;
MVMap<Integer, Integer> m;
s = openStore(fileName);
s.setRetentionTime(Integer.MAX_VALUE);
m = s.openMap("test");
m.put(1, 1);
Map<String, Object> header = s.getStoreHeader();
int format = Integer.parseInt(header.get("format").toString());
assertEquals(1, format);
header.put("format", Integer.toString(format + 1));
// this is to ensure the file header is overwritten
// the header is written at least every 20 commits
for (int i = 0; i < 30; i++) {
if (i > 5) {
s.setRetentionTime(0);
}
m.put(10, 100 * i);
s.commit();
}
s.close();
try {
openStore(fileName).close();
fail();
} catch (IllegalStateException e) {
assertEquals(DataUtils.ERROR_UNSUPPORTED_FORMAT,
DataUtils.getErrorCode(e.getMessage()));
}
FileUtils.delete(fileName);
}
示例12: testLargeImport
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testLargeImport() {
String fileName = getBaseDir() + "/testImport.h3";
int len = 1000;
for (int j = 0; j < 5; j++) {
FileUtils.delete(fileName);
MVStore s = openStore(fileName, 40);
MVMap<Integer, Object[]> m = s.openMap("data",
new MVMap.Builder<Integer, Object[]>()
.valueType(new RowDataType(new DataType[] {
new ObjectDataType(),
StringDataType.INSTANCE,
StringDataType.INSTANCE })));
// Profiler prof = new Profiler();
// prof.startCollecting();
// long t = System.currentTimeMillis();
for (int i = 0; i < len;) {
Object[] o = new Object[3];
o[0] = i;
o[1] = "Hello World";
o[2] = "World";
m.put(i, o);
i++;
if (i % 10000 == 0) {
s.commit();
}
}
s.close();
// System.out.println(prof.getTop(5));
// System.out.println("store time " +
// (System.currentTimeMillis() - t));
// System.out.println("store size " +
// FileUtils.size(fileName));
}
}
示例13: testTruncateFile
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testTruncateFile() {
String fileName = getBaseDir() + "/testTruncate.h3";
FileUtils.delete(fileName);
MVStore s;
MVMap<Integer, String> m;
s = openStore(fileName);
m = s.openMap("data");
String data = new String(new char[10000]).replace((char) 0, 'x');
for (int i = 1; i < 10; i++) {
m.put(i, data);
s.commit();
}
s.close();
long len = FileUtils.size(fileName);
s = openStore(fileName);
s.setRetentionTime(0);
// remove 75%
m = s.openMap("data");
for (int i = 0; i < 10; i++) {
if (i % 4 != 0) {
m.remove(i);
}
}
s.commit();
assertTrue(s.compact(100, 50 * 1024));
s.close();
long len2 = FileUtils.size(fileName);
assertTrue("len2: " + len2 + " len: " + len, len2 < len);
}
示例14: testRollback
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testRollback() {
MVStore s = MVStore.open(null);
MVMap<Integer, Integer> m = s.openMap("m");
m.put(1, -1);
s.commit();
for (int i = 0; i < 10; i++) {
m.put(1, i);
s.rollback();
assertEquals(i - 1, m.get(1).intValue());
m.put(1, i);
s.commit();
}
}
示例15: testEntrySet
import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testEntrySet() {
MVStore s = new MVStore.Builder().open();
MVMap<Integer, Integer> map;
map = s.openMap("data");
for (int i = 0; i < 20; i++) {
map.put(i, i * 10);
}
int next = 0;
for (Entry<Integer, Integer> e : map.entrySet()) {
assertEquals(next, e.getKey().intValue());
assertEquals(next * 10, e.getValue().intValue());
next++;
}
}