@Override SimpleFieldIndexInfo toIndexInfo() { if (!this.indexed) return null; final JComplexField parentField = this.getParentField(); return parentField != null ? parentField.toIndexInfo(this) : new RegularSimpleFieldIndexInfo(this); }
/** * Determine whether this instance still exists in its associated transaction. * * @return true if instance exists, otherwise false * @throws io.permazen.core.StaleTransactionException * if the transaction {@linkplain #getTransaction associated with this instance} is no longer usable */ default boolean exists() { return this.getTransaction().exists(this.getObjId()); }
/** * Get the {@link JClass} of which this {@link JObject} is an instance. * * @return associated {@link JClass} * @throws io.permazen.core.TypeNotInSchemaVersionException if this instance has a type that does not exist * in this instance's schema version, i.e., this instance is an {@link UntypedJObject} */ default JClass<?> getJClass() { return this.getTransaction().getPermazen().getJClass(this.getObjId()); }
/** * Reattach the given {@link JObject} to the current transaction if it's associated with a stale transaction. */ public static JObject refresh(JObject jobj) { return !jobj.getTransaction().isValid() ? JTransaction.getCurrent().get(jobj) : jobj; }
/** * Get this instance's current schema version. Does not change this instance's schema version. * * @return the schema version of this instance * @throws io.permazen.core.DeletedObjectException * if this object does not exist in the {@link JTransaction} associated with this instance * @throws io.permazen.core.StaleTransactionException * if the transaction {@linkplain #getTransaction associated with this instance} is no longer usable */ default int getSchemaVersion() { return this.getTransaction().getSchemaVersion(this.getObjId()); }
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().getAll(jclass.getType()); } };
/** * Create a new instance of the given model class in this transaction. * * @param type Java object model type * @param <T> Java model type * @return newly created instance * @throws IllegalArgumentException if {@code type} is not a known Java object model type * @throws StaleTransactionException if this transaction is no longer usable */ public <T> T create(Class<T> type) { return this.create(this.jdb.getJClass(type)); }
/** * Determine whether this instance is a normal instance or is an in-memory "snapshot" instance associated * with a {@link SnapshotJTransaction}. * * <p> * Equvialent to {@code getTransaction().isSnapshot()}. * * @return true if instance is a snapshot instance */ default boolean isSnapshot() { return this.getTransaction().isSnapshot(); }
/** * Recreate a deleted instance, if it does not exist, in its associated transaction. * The fields of a recreated object are set to their initial values. If the object already exists, nothing changes. * * @return true if instance was recreated, false if it already existed * @throws io.permazen.core.StaleTransactionException * if the transaction {@linkplain #getTransaction associated with this instance} is no longer usable */ default boolean recreate() { return this.getTransaction().recreate(this); }
@Override public ReferencePath load(Key key) { return new ReferencePath(ReferencePathCache.this.jdb, key.getStartType(), key.getPath(), key.isWithTargetField(), key.isLastIsSubField()); } });
/** * Get "invalid annotation" error message prefix that describes the annotation on the specified method. * * @param method the method to check * @return error message prefix */ protected String getErrorPrefix(Method method) { return "invalid " + this.getAnnotationDescription() + " annotation on method " + method + " for type `" + this.jclass.getName() + "': "; } }
@Override public NavigableSetConverter<?, ?> getConverter(JTransaction jtx) { final Converter<?, ?> elementConverter = this.elementField.getConverter(jtx); return elementConverter != null ? this.createConverter(elementConverter) : null; }
@Override public Void caseJMapField(JMapField field) { if (field.getKeyField() instanceof JReferenceField) this.caseJReferenceField((JReferenceField)field.getKeyField()); if (field.getValueField() instanceof JReferenceField) this.caseJReferenceField((JReferenceField)field.getValueField()); return null; }
@Override public ListConverter<?, ?> getConverter(JTransaction jtx) { final Converter<?, ?> elementConverter = this.elementField.getConverter(jtx); return elementConverter != null ? this.createConverter(elementConverter) : null; }
@Override protected String toStringPrefix() { return super.toStringPrefix() + ",parentStorageId=" + this.getParentStorageId(); }
@Override protected Void caseJCollectionField(JCollectionField field) { if (field.getElementField() instanceof JReferenceField) this.caseJReferenceField((JReferenceField)field.getElementField()); return null; }