/** * Sets the value of the field indicated by the {@link Value} annotation on the given object. * * @param target object on which to set value * @param value Value field value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setValue(@Nonnull final Object target, @Nonnull @NotEmpty final String value) { final Value valueField = getAnnotation(target, Value.class); setFieldValue(target, valueField.value(), value); }
/** * Sets the value of the field indicated by the {@link Context} annotation on the given object. * * @param target Object on which to set context * @param context Context value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setContext(@Nonnull final Object target, @Nonnull @NotEmpty final String context) { final Context ctxField = getAnnotation(target, Context.class); setFieldValue(target, ctxField.value(), context); }
/** * Sets the value of the field indicated by the {@link Key} annotation on the given object. * * @param target Object on which to set key * @param key Key value * * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be set on the target object */ public static void setKey(@Nonnull final Object target, @Nonnull @NotEmpty final String key) { final Key keyField = getAnnotation(target, Key.class); setFieldValue(target, keyField.value(), key); }
/** {@inheritDoc} */ @Override public boolean create(@Nonnull final Object value) throws IOException { return create(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public boolean delete(@Nonnull final Object value) throws IOException { return delete(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); }
/** {@inheritDoc} */ @Override public boolean updateExpiration(@Nonnull final Object value) throws IOException { return updateExpiration(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override @Nullable public Object read(@Nonnull final Object value) throws IOException { final StorageRecord record = read(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); if (record != null) { AnnotationSupport.setValue(value, record.getValue()); AnnotationSupport.setExpiration(value, record.getExpiration()); return value; } return null; }
/** * Gets the value of the field indicated by the {@link Key} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get key * * @return Key field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Key} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getKey(@Nonnull final Object target) { final Key keyField = getAnnotation(target, Key.class); final Object value = getFieldValue(target, keyField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Context} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target object from which to get context * * @return Context field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Context} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getContext(@Nonnull final Object target) { final Context ctxField = getAnnotation(target, Context.class); final Object value = getFieldValue(target, ctxField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** * Gets the value of the field indicated by the {@link Value} annotation on the given object. * * <p>If the value is not a {@link String}, then it is converted to one * by calling {@link Object#toString()} on the object.<p> * * @param target Object from which to get value * * @return Value field value * @throws IllegalArgumentException if the target object doesn't declare a {@link Value} annotation * @throws RuntimeException if the field cannot be read on the target object */ @Nonnull @NotEmpty public static String getValue(@Nonnull final Object target) { final Value valueField = getAnnotation(target, Value.class); final Object value = getFieldValue(target, valueField.value()); if (value instanceof String) { return (String) value; } return value.toString(); }
/** {@inheritDoc} */ @Override public boolean update(@Nonnull final Object value) throws IOException { return update(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public boolean delete(@Nonnull final Object value) throws IOException { Constraint.isNotNull(value, "Value cannot be null"); return delete( AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); }
/** {@inheritDoc} */ @Override public boolean updateExpiration(@Nonnull final Object value) throws IOException { Constraint.isNotNull(value, "Value cannot be null"); return updateExpiration( AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public boolean update(@Nonnull Object value) throws IOException { Constraint.isNotNull(value, "Value cannot be null"); return update( AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public Object read(@Nonnull final Object value) throws IOException { Constraint.isNotNull(value, "Value cannot be null"); return read(AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); }
/** {@inheritDoc} */ @Override public boolean create(@Nonnull Object value) throws IOException { Constraint.isNotNull(value, "Value cannot be null"); return create( AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public boolean deleteWithVersion(@Positive final long version, @Nonnull final Object value) throws IOException, VersionMismatchException { return deleteWithVersion(version, AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); }
/** {@inheritDoc} */ @Override @Nullable public Long updateWithVersion(@Positive final long version, @Nonnull final Object value) throws IOException, VersionMismatchException { return updateWithVersion(version, AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }
/** {@inheritDoc} */ @Override public boolean deleteWithVersion(@Positive final long version, @Nonnull final Object value) throws IOException, VersionMismatchException { Constraint.isNotNull(value, "Value cannot be null"); return deleteWithVersion( version, AnnotationSupport.getContext(value), AnnotationSupport.getKey(value)); }
/** {@inheritDoc} */ @Override public Long updateWithVersion(@Positive final long version, @Nonnull final Object value) throws IOException, VersionMismatchException { Constraint.isNotNull(value, "Value cannot be null"); return updateWithVersion( version, AnnotationSupport.getContext(value), AnnotationSupport.getKey(value), AnnotationSupport.getValue(value), AnnotationSupport.getExpiration(value)); }