/** * "Snapshot" constructor for when the destination transaction is the "snapshot" transaction of the transaction * associated with the current thread and no copy cascade is needed * * <p> * This is a convenience constructor, equivalent to: * <blockquote><code> * ChangeCopier(JTransaction.getCurrent().getSnapshotTransaction()) * </code></blockquote> * * @throws IllegalStateException if this is not a snapshot instance and there is no {@link JTransaction} * associated with the current thread */ public ChangeCopier() { this(JTransaction.getCurrent().getSnapshotTransaction()); }
/** * "Snapshot" constructor for when the destination transaction is the "snapshot" transaction of the transaction * associated with the current thread. * * <p> * This is a convenience constructor, equivalent to: * <blockquote><code> * ChangeCopier(JTransaction.getCurrent().getSnapshotTransaction(), cascadeName, recursionLimit) * </code></blockquote> * * @param cascadeName cascade to use when copying objects, or null to not cascade * @param recursionLimit the maximum number of cascaded references to traverse, or -1 for infinity * @throws IllegalArgumentException if {@code recursionLimit} is less that -1 * @throws IllegalStateException if this is not a snapshot instance and there is no {@link JTransaction} * associated with the current thread */ public ChangeCopier(String cascadeName, int recursionLimit) { this(JTransaction.getCurrent().getSnapshotTransaction(), cascadeName, recursionLimit); }
@RetryTransaction @Transactional("permazenGuiTransactionManager") private JObject doCreateForEdit() { return (JObject)JTransaction.getCurrent().getSnapshotTransaction().create(this.jclass); }
return this.cascadeCopyTo(this.getTransaction().getSnapshotTransaction(), cascadeName, clone);
/** * Copy this instance and other instances it references through the specified reference paths (if any) * into the associated in-memory snapshot transaction. * * <p> * Normally this method would only be invoked on a regular database {@link JObject}. * The returned object will always be a snapshot {@link JObject}. * * <p> * This is a convenience method, and is equivalent to invoking: * <blockquote><code> * this.copyTo(this.getTransaction().getSnapshotTransaction(), new CopyState(), refPaths); * </code></blockquote> * * @param refPaths zero or more reference paths that refer to additional objects to be copied * @return the snapshot {@link JObject} copy of this instance * @throws io.permazen.core.DeletedObjectException if any copied object ends up with a reference to an object * that does not exist in {@code dest} through a reference field * {@linkplain io.permazen.annotation.JField#allowDeletedSnapshot configured} to disallow deleted assignment * in snapshot transactions * @throws IllegalArgumentException if this instance is a {@linkplain #isSnapshot snapshot instance} * @throws IllegalArgumentException if any path in {@code refPaths} is invalid * @see #copyIn copyIn() */ default JObject copyOut(String... refPaths) { return this.copyTo(this.getTransaction().getSnapshotTransaction(), new CopyState(), refPaths); }
@RetryTransaction @Transactional("permazenGuiTransactionManager") private JObject doCopyForEdit(ObjId id) { // Find object final JTransaction jtx = JTransaction.getCurrent(); final JObject jobj = jtx.get(id); if (!jobj.exists()) return null; // Copy out object and its dependencies return this.objectChooser.getJObjectContainer().copyWithRelated(jobj, jtx.getSnapshotTransaction(), new CopyState()); }