Search in sources :

Example 76 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorMutable method getNext.

@Override
public boolean getNext() {
    moveIfNecessary();
    if (wasDelete) {
        wasDelete = false;
        // move to remembered next
        final ByteIterable key = nextAfterRemovedKey;
        if (key != null) {
            if (traverser.moveTo(key, tree.isAllowingDuplicates() ? nextAfterRemovedValue : null)) {
                inited = true;
                return true;
            }
            return false;
        } else {
            return false;
        }
    } else {
        return super.getNext();
    }
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Example 77 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class VirtualFileSystem method deleteFile.

/**
 * Deletes existing file with the specified {@code path}.
 *
 * @param txn  {@linkplain Transaction} instance
 * @param path file path
 * @return deleted {@linkplain File} or {@code null} if no file with specified {@code path}exists.
 * @see File
 */
@Nullable
public File deleteFile(@NotNull final Transaction txn, @NotNull final String path) {
    final ArrayByteIterable key = StringBinding.stringToEntry(path);
    final ByteIterable fileMetadata;
    try (Cursor cursor = pathnames.openCursor(txn)) {
        fileMetadata = cursor.getSearchKey(key);
        if (fileMetadata != null) {
            cursor.deleteCurrent();
        }
    }
    if (fileMetadata != null) {
        final File result = new File(path, fileMetadata);
        // at first delete contents
        try (ClusterIterator iterator = new ClusterIterator(this, txn, result)) {
            while (iterator.hasCluster()) {
                iterator.deleteCurrent();
                iterator.moveToNext();
            }
        }
        return result;
    }
    return null;
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Nullable(org.jetbrains.annotations.Nullable)

Example 78 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class VirtualFileSystem method doCreateFile.

private File doCreateFile(@NotNull final Transaction txn, final long fileDescriptor, @NotNull String path) {
    path = String.format(path, fileDescriptor);
    final ArrayByteIterable key = StringBinding.stringToEntry(path);
    final ByteIterable value = pathnames.get(txn, key);
    if (value != null) {
        throw new FileExistsException(path);
    }
    final long currentTime = System.currentTimeMillis();
    final File result = new File(path, fileDescriptor, currentTime, currentTime);
    pathnames.put(txn, key, result.toByteIterable());
    saveFileDescriptorSequence(txn);
    return result;
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable)

Example 79 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class VirtualFileSystem method renameFile.

/**
 * Renames {@code origin} file to the specified {@code newPath} and returns {@code true} if the file was actually
 * renamed. Otherwise another file with the path {@code newPath} exists. File contents and file descriptor are
 * not affected.
 *
 * @param txn     {@linkplain Transaction} instance
 * @param origin  origin {@linkplain File}
 * @param newPath new name of the file
 * @return {@code true} if the file was actually renamed, otherwise another file with the path {@code newPath} exists
 * @see File
 * @see File#getDescriptor()
 */
public boolean renameFile(@NotNull final Transaction txn, @NotNull final File origin, @NotNull final String newPath) {
    final ArrayByteIterable key = StringBinding.stringToEntry(newPath);
    final ByteIterable value = pathnames.get(txn, key);
    if (value != null) {
        return false;
    }
    final File newFile = new File(newPath, origin.getDescriptor(), origin.getCreated(), System.currentTimeMillis());
    pathnames.put(txn, key, newFile.toByteIterable());
    pathnames.delete(txn, StringBinding.stringToEntry(origin.getPath()));
    return true;
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable)

Example 80 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class PersistentSequentialDictionary method getId.

public int getId(@NotNull final TxnProvider txnProvider, @NotNull final String name) {
    Integer result = cache.get(name);
    if (result != null) {
        return result;
    }
    synchronized (lock) {
        result = cache.get(name);
        if (result != null) {
            return result;
        }
        final ByteIterable idEntry = table.get(txnProvider.getTransaction().getEnvironmentTransaction(), StringBinding.stringToEntry(name));
        if (idEntry != null) {
            final int id = IntegerBinding.compressedEntryToInt(idEntry);
            putIdUnsafe(name, id);
            return id;
        }
    }
    return -1;
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Aggregations

ByteIterable (jetbrains.exodus.ByteIterable)93 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)47 Test (org.junit.Test)26 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)16 Nullable (org.jetbrains.annotations.Nullable)11 Cursor (jetbrains.exodus.env.Cursor)8 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)8 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)7 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)6 Store (jetbrains.exodus.env.Store)4 TreeSet (java.util.TreeSet)3 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)3 PersistentStoreTransaction (jetbrains.exodus.entitystore.PersistentStoreTransaction)3 Exchange (com.persistit.Exchange)2 ExodusException (jetbrains.exodus.ExodusException)2 Pair (jetbrains.exodus.core.dataStructures.Pair)2 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)2 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)2 Transaction (jetbrains.exodus.env.Transaction)2 Loggable (jetbrains.exodus.log.Loggable)2