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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations