@Override public byte[] get(byte[] key) { key.getClass(); Preconditions.checkState(!this.closed.get(), "transaction closed"); final ByteIterable bytes = this.store.get(this.tx, new ArrayByteIterable(key)); return bytes != null ? XodusKVStore.get(bytes, true) : null; }
@Override public void execute(Transaction txn) { store.delete(txn, new LongByteIterable(buildId)); }
@Override public CloseableIterator<KVPair> getRange(byte[] minKey, byte[] maxKey, boolean reverse) { Preconditions.checkState(!this.closed.get(), "transaction closed"); return new XodusIter(this.store.openCursor(this.tx), minKey, maxKey, reverse); }
protected void writeBoolean(Store store, Transaction txn, ByteIterable key, boolean value) { byte[] bytes = new byte[] {(byte)(value?1:0)}; store.put(txn, key, new ArrayByteIterable(bytes)); }
@LocalDB.WriteOperation public boolean putIfAbsent( final LocalDB.DB db, final String key, final String value ) throws LocalDBException { checkStatus( true ); return environment.computeInTransaction( transaction -> { final ByteIterable k = bindMachine.keyToEntry( key ); final ByteIterable v = bindMachine.valueToEntry( value ); final Store store = getStore( db ); final ByteIterable existingValue = store.get( transaction, k ); if ( existingValue != null ) { return false; } return store.put( transaction, k, v ); } ); }
if (!indexTable.getDatabase().add(txn.getEnvironmentTransaction(), propsEntry, LongBinding.longToCompressedEntry(entity.getId().getLocalId()))) { ByteIterable oldEntityIdEntry = indexTable.getDatabase().get(txn.getEnvironmentTransaction(), propsEntry); assert oldEntityIdEntry != null; long oldEntityId = LongBinding.compressedEntryToLong(oldEntityIdEntry);
@Override public long size( final LocalDB.DB db ) throws LocalDBException { checkStatus( false ); return environment.computeInReadonlyTransaction( transaction -> { final Store store = getStore( db ); return store.count( transaction ); } ); }
public void insertUniqueKey(@NotNull final PersistentStoreTransaction txn, @NotNull final Index index, @NotNull final List<Comparable> propValues, @NotNull final Entity entity) { final PropertyTypes propertyTypes = persistentStore.getPropertyTypes(); final int propCount = index.getFields().size(); if (propCount != propValues.size()) { throw new IllegalArgumentException("Number of fields differs from the number of property values"); } final Store indexTable = getUniqueKeyIndex(txn, index); if (!indexTable.add(txn.getEnvironmentTransaction(), propertyTypes.dataArrayToEntry(propValues.toArray(new Comparable[propCount])), LongBinding.longToCompressedEntry(entity.getId().getLocalId()))) { throw new InsertConstraintException("Failed to insert unique key (already exists). Index: " + index); } }
protected void writeInt(Store store, Transaction txn, ByteIterable key, int value) { byte[] bytes = ByteBuffer.allocate(Integer.BYTES).putInt(value).array(); store.put(txn, key, new ArrayByteIterable(bytes)); }
protected void writeLong(Store store, Transaction txn, ByteIterable key, long value) { byte[] bytes = ByteBuffer.allocate(Long.BYTES).putLong(value).array(); store.put(txn, key, new ArrayByteIterable(bytes)); }
@Nullable protected byte[] readBytes(Store store, Transaction txn, ByteIterable key) { ByteIterable value = store.get(txn, key); if (value != null) return Arrays.copyOf(value.getBytesUnsafe(), value.getLength()); else return null; }
InnerIterator( final LocalDB.DB db ) { this.transaction = environment.beginReadonlyTransaction(); this.cursor = getStore( db ).openCursor( transaction ); doNext(); }
@Override public void remove(byte[] key) { key.getClass(); Preconditions.checkState(!this.closed.get(), "transaction closed"); Preconditions.checkState(!this.txType.isReadOnly(), "read-only transaction"); this.store.delete(this.tx, new ArrayByteIterable(key)); }
protected void writeLongs(Store store, Transaction txn, ByteIterable key, Collection<Long> collection) { store.put(txn, key, new LongsByteIterable(collection)); }
@Benchmark public void readKey(final Reader r, final Blackhole bh) { for (final int key : r.keys) { if (r.intKey) { final ByteIterable val = r.store.get(r.tx, intToEntry(key)); if (val != null) { bh.consume(val.getBytesUnsafe()); } } else { final ByteIterable val = r.store.get(r.tx, stringToEntry(r.padKey(key))); if (val != null) { bh.consume(val.getBytesUnsafe()); } } } }
@Benchmark public void readCrc(final Reader r, final Blackhole bh) { r.crc.reset(); try (Cursor c = r.store.openCursor(r.tx)) { while (c.getNext()) { r.crc.update(c.getKey().getBytesUnsafe(), 0, r.keySize); r.crc.update(c.getValue().getBytesUnsafe(), 0, r.valSize); } } bh.consume(r.crc.getValue()); }
public void deleteUniqueKey(@NotNull final PersistentStoreTransaction txn, @NotNull final Index index, @NotNull final List<Comparable> propValues) { final PropertyTypes propertyTypes = persistentStore.getPropertyTypes(); final int propCount = index.getFields().size(); if (propCount != propValues.size()) { throw new IllegalArgumentException("Number of fields differs from the number of property values"); } getUniqueKeyIndex(txn, index).delete(txn.getEnvironmentTransaction(), propertyTypes.dataArrayToEntry(propValues.toArray(new Comparable[propCount]))); }
@Override public void put(byte[] key, byte[] value) { key.getClass(); value.getClass(); Preconditions.checkState(!this.closed.get(), "transaction closed"); Preconditions.checkState(!this.txType.isReadOnly(), "read-only transaction"); this.store.put(this.tx, new ArrayByteIterable(key), new ArrayByteIterable(value)); }
@Override public String get( final LocalDB.DB db, final String key ) throws LocalDBException { checkStatus( false ); return environment.computeInReadonlyTransaction( transaction -> { final Store store = getStore( db ); final ByteIterable returnValue = store.get( transaction, bindMachine.keyToEntry( key ) ); if ( returnValue != null ) { return bindMachine.entryToValue( returnValue ); } return null; } ); }
@Override public void removeRange(byte[] minKey, byte[] maxKey) { Preconditions.checkState(!this.closed.get(), "transaction closed"); Preconditions.checkState(!this.txType.isReadOnly(), "read-only transaction"); try (final Cursor cursor = this.store.openCursor(this.tx)) { boolean found = minKey != null && minKey.length > 0 ? cursor.getSearchKeyRange(new ArrayByteIterable(minKey)) != null : cursor.getNext(); while (found) { if (maxKey != null && ByteUtil.compare(XodusKVStore.get(cursor.getKey(), false), maxKey) >= 0) break; cursor.deleteCurrent(); found = cursor.getNext(); } } }