use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class PersistentSequentialDictionary method getOrAllocateId.
public int getOrAllocateId(@NotNull final TxnProvider txnProvider, @NotNull final String name) {
Integer result = cache.get(name);
if (result != null && result >= 0) {
return result;
}
synchronized (lock) {
result = cache.get(name);
if (result != null && result >= 0) {
return result;
}
final ByteIterable nameEntry = StringBinding.stringToEntry(name);
final PersistentStoreTransaction txn = txnProvider.getTransaction();
final ByteIterable idEntry = table.get(txn.getEnvironmentTransaction(), nameEntry);
final int id = idEntry == null ? (int) sequence.increment() : IntegerBinding.compressedEntryToInt(idEntry);
putIdUnsafe(name, id);
if (idEntry == null) {
operationsLog.add(new DictionaryOperation() {
@Override
public void persist(final Transaction txn) {
table.put(txn, nameEntry, IntegerBinding.intToCompressedEntry(id));
}
});
created(txn, id);
}
return id;
}
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VFSBlobVault method refactorFromFS.
public void refactorFromFS(@NotNull final PersistentEntityStoreImpl store) throws IOException {
final BlobVault sourceVault = new FileSystemBlobVaultOld(store.getConfig(), store.getLocation(), "blobs", ".blob", BlobHandleGenerator.IMMUTABLE);
final LongSet allBlobs = store.computeInReadonlyTransaction(new StoreTransactionalComputable<LongSet>() {
@Override
public LongSet compute(@NotNull final StoreTransaction txn) {
return loadAllBlobs(store, (PersistentStoreTransaction) txn);
}
});
final Environment env = fs.getEnvironment();
final Transaction txn = env.beginTransaction();
try {
int i = 0;
for (final long blobId : allBlobs) {
if (i++ % 100 == 0) {
txn.flush();
}
final InputStream content = sourceVault.getContent(blobId, txn);
if (content != null) {
importBlob(txn, blobId, content);
}
}
txn.flush();
} catch (final IOException ioe) {
throw new EntityStoreException(ioe);
} finally {
txn.abort();
}
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VFSBlobVault method loadAllBlobs.
@NotNull
private static LongSet loadAllBlobs(@NotNull final PersistentEntityStoreImpl store, @NotNull final PersistentStoreTransaction txn) {
final LongSet result = new PackedLongHashSet();
final Transaction envTxn = txn.getEnvironmentTransaction();
try (Cursor entityTypesCursor = store.getEntityTypesTable().getSecondIndexCursor(envTxn)) {
while (entityTypesCursor.getNext()) {
final int entityTypeId = IntegerBinding.compressedEntryToInt(entityTypesCursor.getKey());
final BlobsTable blobs = store.getBlobsTable(txn, entityTypeId);
final Store primary = blobs.getPrimaryIndex();
try (Cursor blobsCursor = primary.openCursor(envTxn)) {
while (blobsCursor.getNext()) {
final long blobId = LongBinding.compressedEntryToLong(blobsCursor.getValue());
result.add(blobId);
}
}
}
return result;
}
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsSettings method get.
ByteIterable get(@Nullable final Transaction txn, @NotNull final String settingName) {
final ArrayByteIterable key = StringBinding.stringToEntry(settingName);
if (txn != null) {
return settingStore.get(txn, key);
}
final ByteIterable[] result = new ByteIterable[1];
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
result[0] = settingStore.get(txn, key);
}
});
return result[0];
}
use of jetbrains.exodus.env.Transaction in project xodus by JetBrains.
the class VfsFileTests method testCreateUniqueFile.
@Test
public void testCreateUniqueFile() {
final Transaction txn = env.beginTransaction();
final File file = vfs.createUniqueFile(txn, "file");
txn.commit();
Assert.assertEquals(0L, file.getDescriptor());
Assert.assertTrue(file.getPath().startsWith("file"));
}
Aggregations