/** * Copy this instance, and other instances it references through the specified {@code refPaths} (if any), * into the transaction associated with the current thread. * * <p> * Normally this method would only be invoked on a snapshot {@link JObject}. * The returned object will be a {@link JObject} in the currently open transaction. * * <p> * This is a convenience method, and is equivalent to invoking: * <blockquote><code> * this.copyTo(JTransaction.getCurrent(), new CopyState(), refPaths) * </code></blockquote> * * @param refPaths zero or more reference paths that refer to additional objects to be copied * @return the regular database 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 * @throws io.permazen.core.SchemaMismatchException * if the schema corresponding to this object's version is not identical in both transactions * @throws IllegalArgumentException if any path in {@code refPaths} is invalid * @see #copyOut copyOut() */ default JObject copyIn(String... refPaths) { return this.copyTo(JTransaction.getCurrent(), new CopyState(), refPaths); }
/** * 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); }
/** * Copy the given database object, and any related objects needed by any * {@link org.dellroad.stuff.vaadin7.ProvidesProperty @ProvidesProperty}-annotated methods, * into the specified transaction. * * <p> * The implementation in {@link JObjectContainer} copies {@code jobj}, and all of {@code jobj}'s related objects returned * by {@link #getRelatedObjects getRelatedObjects()}, via {@link JTransaction#copyTo(JTransaction, CopyState, Iterable)}. * * @param target the object to copy, or null (ignored) * @param dest destination transaction * @param copyState tracks what's already been copied * @return the copy of {@code target} in {@code dest}, or null if {@code target} is null * @see #getRelatedObjects getRelatedObjects() */ public JObject copyWithRelated(JObject target, JTransaction dest, CopyState copyState) { // Ignore null if (target == null) return null; // Copy out target object final JTransaction jtx = target.getTransaction(); final JObject copy = target.copyTo(dest, copyState); // Copy out target's related objects final Iterable<? extends JObject> relatedObjects = this.getRelatedObjects(target); if (relatedObjects != null) jtx.copyTo(dest, copyState, relatedObjects); // Done return copy; }
/** * Update a single item in this container by updating its backing object. * * <p> * This updates the backing object with the same object ID as {@code jobj}, if any, and then fires * {@link com.vaadin.data.Property.ValueChangeEvent}s for all properties of the corresponding * {@link com.vaadin.data.Item}. * * @param jobj updated database object */ public void updateItem(JObject jobj) { Preconditions.checkArgument(jobj != null, "null jobj"); final SimpleItem<JObject> item = (SimpleItem<JObject>)this.getItem(jobj.getObjId()); if (item != null) { jobj.copyTo(item.getObject().getTransaction(), new CopyState()); item.fireValueChange(); } }
@Override @RetryTransaction @org.springframework.transaction.annotation.Transactional("permazenGuiTransactionManager") protected boolean execute() { final ObjId id = this.objectChooser.getObjId(); if (id == null) return true; final JObject jobj = JTransaction.getCurrent().get(id); if (!jobj.exists()) { Notification.show("Object " + id + " no longer exists", null, Notification.Type.WARNING_MESSAGE); return false; } try { ReferenceFieldField.this.setValue(jobj.copyTo(ReferenceFieldField.this.dest, new CopyState())); } catch (Exception e) { Notification.show("Error: " + e, null, Notification.Type.ERROR_MESSAGE); } return true; } }
this.jobj.copyTo(jtx, new CopyState(new ObjIdMap<>(Collections.singletonMap(id, target.getObjId()))));