Search in sources :

Example 1 with Transaction

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;
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) ByteIterable(jetbrains.exodus.ByteIterable)

Example 2 with Transaction

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();
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Environment(jetbrains.exodus.env.Environment)

Example 3 with Transaction

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;
    }
}
Also used : Transaction(jetbrains.exodus.env.Transaction) BlobsTable(jetbrains.exodus.entitystore.tables.BlobsTable) Store(jetbrains.exodus.env.Store) Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Transaction

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];
}
Also used : TransactionalExecutable(jetbrains.exodus.env.TransactionalExecutable) Transaction(jetbrains.exodus.env.Transaction) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable)

Example 5 with Transaction

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"));
}
Also used : Transaction(jetbrains.exodus.env.Transaction) Test(org.junit.Test)

Aggregations

Transaction (jetbrains.exodus.env.Transaction)43 Test (org.junit.Test)33 OutputStream (java.io.OutputStream)22 InputStream (java.io.InputStream)18 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)4 Store (jetbrains.exodus.env.Store)4 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)4 File (java.io.File)3 ByteIterable (jetbrains.exodus.ByteIterable)3 Cursor (jetbrains.exodus.env.Cursor)3 TestFor (jetbrains.exodus.TestFor)2 NotNull (org.jetbrains.annotations.NotNull)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 BlobsTable (jetbrains.exodus.entitystore.tables.BlobsTable)1 Environment (jetbrains.exodus.env.Environment)1