private void revalidateIfNeeded(Transaction tx, ObjId id, Field<?> field, NavigableSet<ObjId> referrers) { final JTransaction jtx = (JTransaction)tx.getUserObject(); assert jtx != null && jtx.tx == tx; final JField jfield = jtx.jdb.getJField(id, field.getStorageId(), JField.class); if (jfield.requiresDefaultValidation) jtx.revalidate(referrers); } }
/** * Read a counter field. * * <p> * This method is used by generated {@link io.permazen.annotation.JField @JField} getter override methods * and not normally invoked directly by user code. * * @param id ID of the object containing the field * @param storageId storage ID of the {@link JCounterField} * @param updateVersion true to first automatically update the object's schema version, false to not change it * @return value of the counter in the object * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if the object does not exist in this transaction * @throws UnknownFieldException if no {@link JCounterField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but the object has a type * that does not exist in this instance's schema version * @throws NullPointerException if {@code id} is null */ public Counter readCounterField(ObjId id, int storageId, boolean updateVersion) { this.jdb.getJField(id, storageId, JCounterField.class); // validate field type if (updateVersion) this.tx.updateSchemaVersion(id); return new Counter(this.tx, id, storageId, updateVersion); }
/** * Read a simple field. This returns the value returned by {@link Transaction#readSimpleField Transaction.readSimpleField()} * with {@link ObjId}s converted into {@link JObject}s, etc. * * <p> * This method is used by generated {@link io.permazen.annotation.JField @JField} getter override methods * and not normally invoked directly by user code. * * @param id ID of the object containing the field * @param storageId storage ID of the {@link JSimpleField} * @param updateVersion true to first automatically update the object's schema version, false to not change it * @return value of the field in the object * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if the object does not exist in this transaction * @throws UnknownFieldException if no {@link JSimpleField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but the object has a type * that does not exist in this instance's schema version * @throws NullPointerException if {@code id} is null */ public Object readSimpleField(ObjId id, int storageId, boolean updateVersion) { return this.convert(this.jdb.getJField(id, storageId, JSimpleField.class).getConverter(this), this.tx.readSimpleField(id, storageId, updateVersion)); }
/** * Read a map field. This returns the map returned by {@link Transaction#readMapField Transaction.readMapField()} with * {@link ObjId}s converted into {@link JObject}s, etc. * * <p> * This method is used by generated {@link io.permazen.annotation.JMapField @JMapField} * getter override methods and not normally invoked directly by user code. * * @param id ID of the object containing the field * @param storageId storage ID of the {@link JMapField} * @param updateVersion true to first automatically update the object's schema version, false to not change it * @return the map field in the object with storage ID {@code storageId} * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if the object does not exist in this transaction * @throws UnknownFieldException if no {@link JMapField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but the object has a type * that does not exist in this instance's schema version * @throws NullPointerException if {@code id} is null */ public NavigableMap<?, ?> readMapField(ObjId id, int storageId, boolean updateVersion) { return this.convert(this.jdb.getJField(id, storageId, JMapField.class).getConverter(this), this.tx.readMapField(id, storageId, updateVersion)); }
/** * Read a list field. This returns the list returned by {@link Transaction#readListField Transaction.readListField()} with * {@link ObjId}s converted into {@link JObject}s, etc. * * <p> * This method is used by generated {@link io.permazen.annotation.JListField @JListField} * getter override methods and not normally invoked directly by user code. * * @param id ID of the object containing the field * @param storageId storage ID of the {@link JListField} * @param updateVersion true to first automatically update the object's schema version, false to not change it * @return the list field in the object with storage ID {@code storageId} * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if the object does not exist in this transaction * @throws UnknownFieldException if no {@link JListField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but the object has a type * that does not exist in this instance's schema version * @throws NullPointerException if {@code id} is null */ public List<?> readListField(ObjId id, int storageId, boolean updateVersion) { return this.convert(this.jdb.getJField(id, storageId, JListField.class).getConverter(this), this.tx.readListField(id, storageId, updateVersion)); }
/** * Read a set field. This returns the set returned by {@link Transaction#readSetField Transaction.readSetField()} with * {@link ObjId}s converted into {@link JObject}s, etc. * * <p> * This method is used by generated {@link io.permazen.annotation.JSetField @JSetField} * getter override methods and not normally invoked directly by user code. * * @param id ID of the object containing the field * @param storageId storage ID of the {@link JSetField} * @param updateVersion true to first automatically update the object's schema version, false to not change it * @return the set field in the object with storage ID {@code storageId} * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if the object does not exist in this transaction * @throws UnknownFieldException if no {@link JSetField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but the object has a type * that does not exist in this instance's schema version * @throws NullPointerException if {@code id} is null */ public NavigableSet<?> readSetField(ObjId id, int storageId, boolean updateVersion) { return this.convert(this.jdb.getJField(id, storageId, JSetField.class).getConverter(this), this.tx.readSetField(id, storageId, updateVersion)); }
/** * Write a simple field. This writes the value via {@link Transaction#writeSimpleField Transaction.writeSimpleField()} * after converting {@link JObject}s into {@link ObjId}s, etc. * * <p> * This method is used by generated {@link io.permazen.annotation.JField @JField} setter override methods * and not normally invoked directly by user code. * * @param jobj object containing the field * @param storageId storage ID of the {@link JSimpleField} * @param value new value for the field * @param updateVersion true to first automatically update the object's schema version, false to not change it * @throws StaleTransactionException if this transaction is no longer usable * @throws DeletedObjectException if {@code jobj} does not exist in this transaction * @throws UnknownFieldException if no {@link JSimpleField} corresponding to {@code storageId} exists * @throws TypeNotInSchemaVersionException if {@code updateVersion} is true but {@code jobj} has a type * that does not exist in this instance's schema version * @throws IllegalArgumentException if {@code value} is not an appropriate value for the field * @throws NullPointerException if {@code jobj} is null */ public void writeSimpleField(JObject jobj, int storageId, Object value, boolean updateVersion) { JTransaction.registerJObject(jobj); // handle possible re-entrant object cache load final ObjId id = jobj.getObjId(); final Converter<?, ?> converter = this.jdb.getJField(id, storageId, JSimpleField.class).getConverter(this); if (converter != null) value = this.convert(converter.reverse(), value); this.tx.writeSimpleField(id, storageId, value, updateVersion); }