void copyIdStreamTo(JTransaction dest, CopyState copyState, Stream<ObjId> ids) { // Sanity check Preconditions.checkArgument(dest != null, "null dest"); Preconditions.checkArgument(copyState != null, "null copyState"); Preconditions.checkArgument(ids != null, "null ids"); // Reset deleted assignments copyState.deletedAssignments.clear(); // Copy objects ids.forEachOrdered(id -> this.copyTo(copyState, dest, id, true, 0, new int[0])); // Check for any remaining deleted assignments copyState.checkDeletedAssignments(this); }
/** * Copy the specified objects into the specified destination transaction. * * <p> * This is a convenience method; equivalent to: * <blockquote> * {@link #copyTo(JTransaction, CopyState, Stream) copyTo}{@code * (dest, copyState, }{@link Streams#stream(Iterable) Streams.stream}{@code (jobjs))} * </blockquote> * * @param dest destination transaction * @param copyState tracks which objects have already been copied and whether to remap object ID's * @param jobjs {@link Iterable} returning the objects to copy; null values are ignored * @throws DeletedObjectException if any object to be copied does not actually exist * @throws DeletedObjectException if any copied object ends up with a reference to an object that does not exist * in {@code dest} through a reference field configured to disallow deleted assignment * @throws io.permazen.core.SchemaMismatchException * if the schema corresponding to any copied object is not identical in both this instance and {@code dest} * @throws StaleTransactionException if this transaction or {@code dest} is no longer usable * @throws IllegalArgumentException if any parameter is null */ public void copyTo(JTransaction dest, CopyState copyState, Iterable<? extends JObject> jobjs) { Preconditions.checkArgument(jobjs != null, "null jobjs"); this.copyTo(dest, copyState, Streams.stream(jobjs)); }
return this.getTransaction().copyTo(dest, this, copyState, refPaths);
/** * Recurse on this reference sub-field during a copy between transactions. Copies all objects referred to by * this sub-field in the given object from {@code srcTx} to {@code dstTx}. * * <p> * This method assumes that this indexed field is a reference field. * * @param copyState copy state * @param srcTx source transaction * @param dstTx destination transaction * @param id ID of the object containing the complex field and sub-field in {@code srcTx} * @param fieldIndex next index into {@code fieldIds} * @param fields fields to follow in the reference path */ public void copyRecurse(CopyState copyState, JTransaction srcTx, JTransaction dstTx, ObjId id, int fieldIndex, int[] fields) { assert this.getFieldType() instanceof ReferenceFieldType; for (Object obj : this.iterateReferences(srcTx.tx, id)) { if (obj != null) srcTx.copyTo(copyState, dstTx, (ObjId)obj, false, fieldIndex, fields); } }
/** * 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; }
/** * Copy the given {@link JObject} into the destination transaction. * * <p> * The implementation in {@link ChangeCopier} copies {@code jobj} and objects reachable via the configured copy cascade, * unless {@code jobj} does not exist, in which case it is not copied (but the * {@linkplain JTransaction#get(ObjId) corresponding} {@link JObject} is still returned). * Subclasses may override as needed. * * @param jobj original object * @return copied object in {@link #dest} * @throws IllegalArgumentException if {@code jobj} is null */ @SuppressWarnings("unchecked") protected JObject copy(JObject jobj) { Preconditions.checkArgument(jobj != null, "null jobj"); final ObjId id = jobj.getObjId(); if (jobj.exists()) { final JTransaction jtx = jobj.getTransaction(); jtx.copyTo(this.dest, this.copyState, jtx.cascadeFindAll(id, this.cascadeName, this.recursionLimit)); } return dest.get(this.copyState.getDestinationId(id)); } }
final ObjId referrent = (ObjId)this.tx.readSimpleField(srcId, storageId, false); if (referrent != null) this.copyTo(copyState, dest, referrent, false, fieldIndex, fields);
final ObjIdSet ids = jtx.cascadeFindAll(id, cascadeName, recursionLimit); final CopyState copyState = clone ? new CopyState(dest.createClones(ids)) : new CopyState(); jtx.copyTo(dest, copyState, ids); return dest.get(copyState.getDestinationId(id));