Guide‎ > ‎Logic Design Patterns‎ > ‎Insert Into From‎ > ‎

Insert Into Operation

Given the functionality for deep copy, this is a complex operation, particularly on the boundary conditions around the recursion.  This trace is terse, and is internals documentation: it presumes you are reading the code.


This uses the BusLogicIntro jUnit test Purchaseorder_clone_test#clonePurchaseorder().  Recall this initiates the test by setting doClone = true, and issuing the update.  This activates the PurchaseorderLogic#actionClonePurchaseorder():

public void actionClonePurchaseorder() {
    if (purchaseorder.doClone == true && logicContext.logicNestLevel == 0) {
      String[] deepCopy = ["lineitems"];
      Purchaseorder clonedPO = BusinessLogic.insertChildFrom(
class, logicContext, deepCopy);

Finally, recall there is a self-relationship from PO to cloned PO, to support this operation.  From a business sense, it might be useful to find the source a clone PO, or conversely the POs cloned from a source.



creates NewPO[# 6]

attachChildToParent(SourcePO[# 4])

copyAttributesFromTo (SourcePO => NewPO, doSave (NewPO)]

copy Scalar attributes - includes null parent role properties (eg, customer)

doSave (newPO)

deepCopyCollections (here, lineItems)

for eachCopiedRole

For eachRow (lineitems for SourcePO)

new Instance (eg, lineitem)

attachChildToParent (eg, to NewPO)

copyAttributesFromTo (oldLineItem =>newLineItem, doSave) // recurse

save (NewPO)