本文整理汇总了Java中jetbrains.exodus.env.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于jetbrains.exodus.env包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVisitDate
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public Date getVisitDate(User user, PullRequest request) {
Environment env = getEnv(request.getTargetProject().getId().toString());
Store store = getStore(env, PULL_REQUEST_STORE);
return env.computeInTransaction(new TransactionalComputable<Date>() {
@Override
public Date compute(Transaction txn) {
byte[] bytes = getBytes(store.get(txn, new StringPairByteIterable(user.getUUID(), request.getUUID())));
if (bytes != null)
return new Date(bytesToLong(bytes));
else
return null;
}
});
}
示例2: getContributions
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public int getContributions(ProjectFacade project, UserFacade user, String path) {
if (user.getEmail() != null) {
Environment env = getEnv(project.getId().toString());
Store store = getStore(env, CONTRIBUTIONS_STORE);
return env.computeInReadonlyTransaction(new TransactionalComputable<Integer>() {
@Override
public Integer compute(Transaction tx) {
byte[] contributionKey = getContributionKey(user.getEmail(), path);
byte[] bytes = getBytes(store.get(tx, new ArrayByteIterable(contributionKey)));
if (bytes != null)
return ByteBuffer.wrap(bytes).getInt();
else
return 0;
}
});
} else {
return 0;
}
}
示例3: getCommitCount
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public int getCommitCount(Project project) {
Integer commitCount = commitCountCache.get(project.getId());
if (commitCount == null) {
Environment env = getEnv(project.getId().toString());
Store store = getStore(env, DEFAULT_STORE);
commitCount = env.computeInReadonlyTransaction(new TransactionalComputable<Integer>() {
@Override
public Integer compute(Transaction txn) {
byte[] bytes = getBytes(store.get(txn, COMMIT_COUNT_KEY));
if (bytes != null) {
return (Integer) SerializationUtils.deserialize(bytes);
} else {
return 0;
}
}
});
commitCountCache.put(project.getId(), commitCount);
}
return commitCount;
}
示例4: getLastCommit
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Nullable
@Override
public ObjectId getLastCommit(Project project) {
Environment env = getEnv(project.getId().toString());
Store defaultStore = getStore(env, DEFAULT_STORE);
return env.computeInTransaction(new TransactionalComputable<ObjectId>() {
@Override
public ObjectId compute(Transaction txn) {
byte[] bytes = getBytes(defaultStore.get(txn, LAST_COMMIT_KEY));
return bytes != null? ObjectId.fromRaw(bytes): null;
}
});
}
示例5: getVisitDate
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public Date getVisitDate(UserFacade user, ProjectFacade project) {
Environment env = getEnv(user.getId().toString());
Store store = getStore(env, VISIT_STORE);
return env.computeInTransaction(new TransactionalComputable<Date>() {
@Override
public Date compute(Transaction txn) {
byte[] bytes = getBytes(store.get(txn, new StringByteIterable(project.getUUID())));
if (bytes != null)
return new Date(bytesToLong(bytes));
else
return null;
}
});
}
示例6: getVerifications
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public Map<String, Verification> getVerifications(Project project, String commit) {
Environment env = getEnv(project.getId().toString());
Store store = getStore(env, VERIFICATIONS_STORE);
return env.computeInTransaction(new TransactionalComputable<Map<String, Verification>>() {
@SuppressWarnings("unchecked")
@Override
public Map<String, Verification> compute(Transaction txn) {
byte[] bytes = getBytes(store.get(txn, new StringByteIterable(commit)));
if (bytes != null)
return (Map<String, Verification>) SerializationUtils.deserialize(bytes);
else
return new HashMap<>();
}
});
}
示例7: getVerificationNames
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Override
public Collection<String> getVerificationNames(Project project) {
Environment env = getEnv(project.getId().toString());
Store store = getStore(env, DEFAULT_STORE);
return env.computeInTransaction(new TransactionalComputable<Collection<String>>() {
@SuppressWarnings("unchecked")
@Override
public Collection<String> compute(Transaction txn) {
byte[] bytes = getBytes(store.get(txn, new StringByteIterable(VERIFICATION_NAMES_KEY)));
if (bytes != null)
return ((Map<String, Date>) SerializationUtils.deserialize(bytes)).keySet();
else
return null;
}
});
}
示例8: getStringContent
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
/**
* Returns string content of blob identified by specified blob handle. String contents cache is used.
*
* @param blobHandle blob handle
* @param txn {@linkplain Transaction} instance
* @return string content of blob identified by specified blob handle
* @throws IOException if something went wrong
*/
@Nullable
public final String getStringContent(final long blobHandle, @NotNull final Transaction txn) throws IOException {
String result;
result = stringContentCache.tryKey(this, blobHandle);
if (result == null) {
final InputStream content = getContent(blobHandle, txn);
result = content == null ? null : UTFUtil.readUTF(content);
if (result != null && result.length() <= config.getBlobStringsCacheMaxValueSize()) {
if (stringContentCache.getObject(this, blobHandle) == null) {
stringContentCache.cacheObject(this, blobHandle, result);
}
}
}
return result;
}
示例9: testCreateExistingFile
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void testCreateExistingFile() {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final File file0 = vfs.createFile(txn, "file0");
txn.flush();
Assert.assertEquals(0L, file0.getDescriptor());
TestUtil.runWithExpectedException(new Runnable() {
@Override
public void run() {
vfs.createFile(txn, "file0");
}
}, FileExistsException.class);
}
});
}
示例10: testCreateExistingFile2
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void testCreateExistingFile2() {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final File file0 = vfs.openFile(txn, "file0", true);
txn.flush();
Assert.assertNotNull(file0);
Assert.assertEquals(0L, file0.getDescriptor());
TestUtil.runWithExpectedException(new Runnable() {
@Override
public void run() {
vfs.createFile(txn, "file0");
}
}, FileExistsException.class);
}
});
}
示例11: testRenameFile
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void testRenameFile() throws InterruptedException {
testFileCreation();
final Transaction txn = env.beginTransaction();
File file0 = vfs.openFile(txn, "file0", false);
txn.revert();
Assert.assertNotNull(file0);
final long fd = file0.getDescriptor();
final long created = file0.getCreated();
final long lastModified = file0.getLastModified();
Thread.sleep(50);
vfs.renameFile(txn, file0, "file1");
txn.flush();
file0 = vfs.openFile(txn, "file0", false);
File file1 = vfs.openFile(txn, "file1", false);
txn.abort();
Assert.assertNull(file0);
Assert.assertNotNull(file1);
Assert.assertEquals(fd, file1.getDescriptor());
Assert.assertEquals(created, file1.getCreated());
Assert.assertTrue(file1.getLastModified() > lastModified);
}
示例12: testDeleteFile4
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void testDeleteFile4() throws IOException {
final Transaction txn = env.beginTransaction();
for (int i = 0; i < 50; ++i) {
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.writeFile(txn, file0);
for (int j = 0; j < i; ++j) {
outputStream.write(new byte[vfs.getConfig().getClusteringStrategy().getFirstClusterSize()]);
}
outputStream.write("vain bytes to be deleted".getBytes());
for (int j = 0; j < i + 1; ++j) {
outputStream.write(new byte[vfs.getConfig().getClusteringStrategy().getFirstClusterSize()]);
}
outputStream.close();
txn.flush();
Assert.assertNotNull(vfs.deleteFile(txn, "file0"));
txn.flush();
}
Assert.assertEquals(0L, vfs.getContents().count(txn));
txn.commit();
}
示例13: testTouchFile
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void testTouchFile() throws InterruptedException {
final Transaction txn = env.beginTransaction();
vfs.createFile(txn, "file0");
txn.flush();
File file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertEquals(file0.getCreated(), file0.getLastModified());
Thread.sleep(100);
vfs.touchFile(txn, file0);
txn.flush();
file0 = vfs.openFile(txn, "file0", false);
Assert.assertNotNull(file0);
Assert.assertTrue(file0.getCreated() + 50 < file0.getLastModified());
txn.commit();
}
示例14: writeRandomAccessRead
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void writeRandomAccessRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
final OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write((HOEGAARDEN + HOEGAARDEN + HOEGAARDEN + HOEGAARDEN).getBytes(UTF_8));
outputStream.close();
txn.flush();
InputStream inputStream = vfs.readFile(txn, file0, 0);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN + HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 10);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 20);
Assert.assertEquals(HOEGAARDEN + HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
inputStream = vfs.readFile(txn, file0, 30);
Assert.assertEquals(HOEGAARDEN, streamAsString(inputStream));
inputStream.close();
txn.abort();
}
示例15: writeOverwriteRead
import jetbrains.exodus.env.Transaction; //导入依赖的package包/类
@Test
public void writeOverwriteRead() throws IOException {
final Transaction txn = env.beginTransaction();
final File file0 = vfs.createFile(txn, "file0");
OutputStream outputStream = vfs.appendFile(txn, file0);
outputStream.write(HOEGAARDEN.getBytes(UTF_8));
outputStream.close();
txn.flush();
outputStream = vfs.writeFile(txn, file0);
outputStream.write("x".getBytes(UTF_8));
outputStream.close();
txn.flush();
final InputStream inputStream = vfs.readFile(txn, file0);
Assert.assertEquals('x' + HOEGAARDEN.substring(1), streamAsString(inputStream));
inputStream.close();
txn.abort();
}