@Test public void testKeySize() { final String s = randomString(new Random(), 2000); wtx0(tx -> ixMap.put(tx, Key.of(s), s)); }
public Optional<T> put(Tx.Write tx, Key primaryKey, T value) { checkKeyAndValue(primaryKey, value); final Transaction txn = castTxn(tx); final ByteIterable pkBuf = primaryKey.toByteIterable(); final ByteIterable newVal = valueWithChecksum(value); final ByteIterable oldVal = getMainDb().get(txn, pkBuf); if (newVal.equals(oldVal)) { return Optional.of(value); } getMainDb().put(txn, pkBuf, newVal); if (oldVal != null) { final T oldValue = getValue(primaryKey, Bytes.toBytes(oldVal)); indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> oldIndexKeys = idxFun.apply(oldValue); final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); final Store index = getIdx(idxName); oldIndexKeys.stream() .filter(oik -> !indexKeys.contains(oik)) .forEach(oik -> { try (Cursor c = index.openCursor(txn)) { if (c.getSearchBoth(oik.toByteIterable(), pkBuf)) { c.deleteCurrent(); } } }); indexKeys.stream() .filter(ik -> !oldIndexKeys.contains(ik)) .forEach(ik -> index.put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.of(oldValue); } indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); indexKeys.forEach(ik -> getIdx(idxName).put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.empty(); }
XodusIxMap extends XodusIxBase<T> implements IxMap<T> { public Optional<T> put(Tx.Write tx, Key primaryKey, T value) { checkKeyAndValue(primaryKey, value); final Transaction txn = castTxn(tx); final ByteIterable pkBuf = primaryKey.toByteIterable(); final ByteIterable newVal = valueWithChecksum(value); final ByteIterable oldVal = getMainDb().get(txn, pkBuf); if (newVal.equals(oldVal)) { return Optional.of(value); } getMainDb().put(txn, pkBuf, newVal); if (oldVal != null) { final T oldValue = getValue(primaryKey, Bytes.toBytes(oldVal)); indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> oldIndexKeys = idxFun.apply(oldValue); final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); final Store index = getIdx(idxName); oldIndexKeys.stream() .filter(oik -> !indexKeys.contains(oik)) .forEach(oik -> { try (Cursor c = index.openCursor(txn)) { if (c.getSearchBoth(oik.toByteIterable(), pkBuf)) { c.deleteCurrent(); } } }); indexKeys.stream() .filter(ik -> !oldIndexKeys.contains(ik)) .forEach(ik -> index.put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.of(oldValue); } indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); indexKeys.forEach(ik -> getIdx(idxName).put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.empty(); } }
XodusIxMap extends XodusIxBase<T> implements IxMap<T> { public Optional<T> put(Tx.Write tx, Key primaryKey, T value) { checkKeyAndValue(primaryKey, value); final Transaction txn = castTxn(tx); final ByteIterable pkBuf = primaryKey.toByteIterable(); final ByteIterable newVal = valueWithChecksum(value); final ByteIterable oldVal = getMainDb().get(txn, pkBuf); if (newVal.equals(oldVal)) { return Optional.of(value); } getMainDb().put(txn, pkBuf, newVal); if (oldVal != null) { final T oldValue = getValue(primaryKey, Bytes.toBytes(oldVal)); indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> oldIndexKeys = idxFun.apply(oldValue); final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); final Store index = getIdx(idxName); oldIndexKeys.stream() .filter(oik -> !indexKeys.contains(oik)) .forEach(oik -> { try (Cursor c = index.openCursor(txn)) { if (c.getSearchBoth(oik.toByteIterable(), pkBuf)) { c.deleteCurrent(); } } }); indexKeys.stream() .filter(ik -> !oldIndexKeys.contains(ik)) .forEach(ik -> index.put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.of(oldValue); } indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); indexKeys.forEach(ik -> getIdx(idxName).put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.empty(); } XodusIxMap(final Xodus xodus,
                      final String name,
                      final Coder<T> coder,
                      final Map<String, Function<T, Set<Key>>> indexFunctions); }
XodusIxMap extends XodusIxBase<T> implements IxMap<T> { public Optional<T> put(Tx.Write tx, Key primaryKey, T value) { checkKeyAndValue(primaryKey, value); final Transaction txn = castTxn(tx); final ByteIterable pkBuf = primaryKey.toByteIterable(); final ByteIterable newVal = valueWithChecksum(value); final ByteIterable oldVal = getMainDb().get(txn, pkBuf); if (newVal.equals(oldVal)) { return Optional.of(value); } getMainDb().put(txn, pkBuf, newVal); if (oldVal != null) { final T oldValue = getValue(primaryKey, Bytes.toBytes(oldVal)); indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> oldIndexKeys = idxFun.apply(oldValue); final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); final Store index = getIdx(idxName); oldIndexKeys.stream() .filter(oik -> !indexKeys.contains(oik)) .forEach(oik -> { try (Cursor c = index.openCursor(txn)) { if (c.getSearchBoth(oik.toByteIterable(), pkBuf)) { c.deleteCurrent(); } } }); indexKeys.stream() .filter(ik -> !oldIndexKeys.contains(ik)) .forEach(ik -> index.put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.of(oldValue); } indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); indexKeys.forEach(ik -> getIdx(idxName).put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.empty(); } XodusIxMap(final Xodus xodus,
                      final String name,
                      final Coder<T> coder,
                      final Map<String, Function<T, Set<Key>>> indexFunctions); Optional<T> get(Key primaryKey); Optional<T> get(Tx.Read tx, Key primaryKey); List<T> get(Tx.Read txn, Set<Key> primaryKeys); Optional<T> put(Tx.Write tx, Key primaryKey, T value); boolean modify(Tx.Write tx, Key primaryKey, Consumer<T> modifyValue); void delete(Tx.Write tx, Key primaryKey); Map<Key, T> getByIndex(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> values(Tx.Read tx, Set<Key> pks); Set<Key> getPkByIndex(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIndexLessThan(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIndexNotLessThan(String indexName, Tx.Read tx, Key indexKey); Set<Key> getPkByIndexLessThan(String indexName, Tx.Read tx, Key indexKey); Set<Key> getPkByIndexGreaterThan(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIdxDescendingWhere(String indexName, Tx.Read tx, Predicate<T> p); Map<Key, T> getByIdxAscendingWhere(String indexName, Tx.Read tx, Predicate<T> p); void onDelete(BiConsumer<Tx.Write, Key> bf); @Override void clear(Tx.Write tx); @Override T toValue(byte[] bb); @Override XodusIxBase.Sizes sizeInfo(Tx.Read tx); }
XodusIxMap extends XodusIxBase<T> implements IxMap<T> { public Optional<T> put(Tx.Write tx, Key primaryKey, T value) { checkKeyAndValue(primaryKey, value); final Transaction txn = castTxn(tx); final ByteIterable pkBuf = primaryKey.toByteIterable(); final ByteIterable newVal = valueWithChecksum(value); final ByteIterable oldVal = getMainDb().get(txn, pkBuf); if (newVal.equals(oldVal)) { return Optional.of(value); } getMainDb().put(txn, pkBuf, newVal); if (oldVal != null) { final T oldValue = getValue(primaryKey, Bytes.toBytes(oldVal)); indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> oldIndexKeys = idxFun.apply(oldValue); final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); final Store index = getIdx(idxName); oldIndexKeys.stream() .filter(oik -> !indexKeys.contains(oik)) .forEach(oik -> { try (Cursor c = index.openCursor(txn)) { if (c.getSearchBoth(oik.toByteIterable(), pkBuf)) { c.deleteCurrent(); } } }); indexKeys.stream() .filter(ik -> !oldIndexKeys.contains(ik)) .forEach(ik -> index.put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.of(oldValue); } indexFunctions.forEach((idxName, idxFun) -> { final Set<Key> indexKeys = idxFun.apply(value).stream() .filter(Objects::nonNull) .collect(Collectors.toSet()); indexKeys.forEach(ik -> getIdx(idxName).put(txn, ik.toByteIterable(), pkBuf)); }); return Optional.empty(); } XodusIxMap(final Xodus xodus,
                      final String name,
                      final Coder<T> coder,
                      final Map<String, Function<T, Set<Key>>> indexFunctions); Optional<T> get(Key primaryKey); Optional<T> get(Tx.Read tx, Key primaryKey); List<T> get(Tx.Read txn, Set<Key> primaryKeys); Optional<T> put(Tx.Write tx, Key primaryKey, T value); boolean modify(Tx.Write tx, Key primaryKey, Consumer<T> modifyValue); void delete(Tx.Write tx, Key primaryKey); Map<Key, T> getByIndex(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> values(Tx.Read tx, Set<Key> pks); Set<Key> getPkByIndex(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIndexLessThan(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIndexNotLessThan(String indexName, Tx.Read tx, Key indexKey); Set<Key> getPkByIndexLessThan(String indexName, Tx.Read tx, Key indexKey); Set<Key> getPkByIndexGreaterThan(String indexName, Tx.Read tx, Key indexKey); Map<Key, T> getByIdxDescendingWhere(String indexName, Tx.Read tx, Predicate<T> p); Map<Key, T> getByIdxAscendingWhere(String indexName, Tx.Read tx, Predicate<T> p); void onDelete(BiConsumer<Tx.Write, Key> bf); @Override void clear(Tx.Write tx); @Override T toValue(byte[] bb); @Override XodusIxBase.Sizes sizeInfo(Tx.Read tx);  }