static void valueCheck(byte[] value) throws ViewConstraintException { if (value != null) { throw new ViewConstraintException("Cannot store non-null value into key-only view"); } }
private static ViewConstraintException fail() { return new ViewConstraintException("Key is outside allowed range"); } }
private static ViewConstraintException fail() { return new ViewConstraintException("Unsupported key"); } }
private static ViewConstraintException fail() { return new ViewConstraintException("Unsupported key"); } }
private static ViewConstraintException fail() { return new ViewConstraintException("Key is outside allowed range"); } }
static ViewConstraintException fail() { return new ViewConstraintException("Unsupported key"); } }
@Override public OutputStream newValueOutputStream(long pos) throws IOException { throw new ViewConstraintException(); }
static ViewConstraintException fail() { return new ViewConstraintException("Key is outside allowed range"); } }
/** * Apply an inverse transformation of the given value, if supported. This method is only * called when attempting to store the value into the view. Default implementation always * throws a {@link ViewConstraintException}. * * @param tvalue nullable value to transform * @param key non-null untransformed key associated with the value * @param tkey non-null transformed key associated with the value * @return inverse transformed value, or null to delete the value * @throws ViewConstraintException if inverse transformation of given value is not supported */ public default byte[] inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey) throws ViewConstraintException, IOException { throw new ViewConstraintException("Inverse transform isn't supported"); }
@Override public void valueLength(long length) throws IOException { if (length >= 0) { throw new ViewConstraintException(); } source.store(null); }
/** * Calls the {@link #isAllowed isAllowed} method. */ @Override public default byte[] inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey) throws IOException, ViewConstraintException { if (!isAllowed(key, tvalue)) { throw new ViewConstraintException("Filtered out"); } return tvalue; } }
/** * Calls the {@link #isAllowed isAllowed} method. */ @Override public default byte[] inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey) throws IOException, ViewConstraintException { if (!isAllowed(key, tvalue)) { throw new ViewConstraintException("Filtered out"); } return tvalue; } }
/** * Calls the {@link #isAllowed isAllowed} method. */ @Override public default byte[] inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey) throws IOException, ViewConstraintException { if (!isAllowed(key, tvalue)) { throw new ViewConstraintException("Filtered out"); } return tvalue; } }
protected ViewConstraintException storeFail() { return new ViewConstraintException("Cannot separate value for " + mView.type() + " view"); } }
@Override public LockResult open(Transaction txn, byte[] tkey) throws IOException { final byte[] key = mTransformer.inverseTransformKey(tkey); if (key == null) { throw new ViewConstraintException("Unsupported key"); } return mSource.open(txn, key); } }
@Override public LockResult open(Transaction txn, byte[] tkey) throws IOException { final byte[] key = mTransformer.inverseTransformKey(tkey); if (key == null) { throw new ViewConstraintException("Unsupported key"); } return mSource.open(txn, key); } }
@Override public LockResult open(Transaction txn, byte[] key) throws IOException { if (mView.inRange(key)) { return mSource.open(txn, key); } else { throw new ViewConstraintException("Key is outside allowed range"); } } }
@Override public LockResult open(Transaction txn, byte[] key) throws IOException { if (mView.inRange(key)) { return mSource.open(txn, key); } else { throw new ViewConstraintException("Key is outside allowed range"); } } }
/** * Unconditionally associates a value with the given key. * * <p>If the entry must be locked, ownership of the key instance is transferred. The key * must not be modified after calling this method. * * @param txn optional transaction; pass null for auto-commit mode * @param key non-null key * @param value value to store; pass null to delete * @throws NullPointerException if key is null * @throws IllegalArgumentException if transaction belongs to another database instance * @throws ViewConstraintException if entry is not permitted */ public default void store(Transaction txn, byte[] key, byte[] value) throws IOException { Cursor c = newCursor(txn); try { c.autoload(false); c.find(key); if (c.key() == null) { if (value == null) { return; } throw new ViewConstraintException(); } c.store(value); } finally { c.reset(); } }
return; throw new ViewConstraintException();