public interface DiffMergeable
DiffMergeable
is the interface to be implemented by all
def objects that want to use ADFbc's differ/merger framework.
It must know how to identify itself by a short-name and the full-name. The full-name should be able to identify the def object uniquely.
It needs to give its XML element type (the value that would be returned by XML Node.getNodeName()).
It needs to implement methods to diff two objects, 'this' against
the original def (orgDef
) of this definition
type, and methods to apply changes as merge conflicts are resolved.
The diffing process starts with the document-level def object. It
diffs its scalar values and then traverse into its children, which
themselves are DiffMergeable
defs. Hence, the diffing
process traverses down the def containership.
DifferBase
,
DifferDetails
,
DifferChildren
Modifier and Type | Method and Description |
---|---|
void |
applyDiffChildren(DifferDetails dif,
DiffResolver resolver)
Applies changes to children defs.
|
void |
applyDiffContents(DifferDetails dif,
DiffResolver resolver)
When diff/merge operation is requested, we have the following
three def objects:
|
DifferDetails |
beginDiffObjects(DiffMergeable docDef,
DiffMergeable orgDef,
DifferDetails difDetails)
This method is the entry point call when the diffing process
begins on the document-level def.
|
DifferDetails |
diffChildren(DiffMergeable docDef,
DiffMergeable orgDef,
DifferDetails difDetails)
Performs diff of children defs.
|
DifferDetails |
diffContents(DiffMergeable docDef,
DiffMergeable orgDef,
DifferDetails difDetails)
Performs diff of scalar values.
|
DifferDetails |
diffObjects(DiffMergeable docDef,
DiffMergeable orgDef,
DifferDetails difDetails)
The work-horse method performing diff between two defs of this
def type.
|
DifferDetails |
ensureDifferDetails(DifferDetails difDetails)
Ensures that we have a valid
DifferDetails . |
java.lang.String |
getDefTypeName()
Returns the XML def type name of this defintion object, e.g.,
"PDefEntityObject".
|
java.lang.String |
getMergeableFullName()
Returns the fully qualified name of the diff-mergeable definition object.
|
java.lang.String |
getMergeableName()
Returns the diff-mergeable definition's name (short form).
|
java.lang.String getMergeableName()
java.lang.String getMergeableFullName()
java.lang.String getDefTypeName()
DifferDetails ensureDifferDetails(DifferDetails difDetails)
DifferDetails
.
This method is to create a DifferDetails
object to
be used for diffing if necessary. The difDetails
may come in
as null
. By calling this method, we can ensure that
a non-null difDetails
is there. So, instead of
writing:
if (difDetails == null) { difDetails = new DifferDetails(..); } difDetails.addDiffDetail(..);we can write
(difDetails = diffMergeable.ensureDifferDetails(difDetails)).addDiffDetail(..);
difDetails
- the incoming DifferDetails
. It may
be null
.difDetails
if it wasn't
null
coming in, or a new DifferDetails
if
the incoming difDetails
was null
DifferDetails beginDiffObjects(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails)
DiffMergeable
's. 'this'
object is the
changed definition.
docDef
- the document-level definitionorgDef
- the original definition. It could be
null
if the definition did not exist originallydifDetails
- the DifferDetails
that accumulate
the details of diff from the document-level (top-level) defDifferDetails
that has all the details
of diffDifferDetails diffObjects(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails)
diffContents
to diff scalar values and diffChildren
to diff
children objects. The children objects themselves are expected
to be DiffMergeable
. 'this'
object is the
changed definition.
docDef
- the document-level definitionorgDef
- the original definition. It could be
null
if the definition did not exist originallydifDetails
- the DifferDetails
that accumulate
the details of diff from the document-level (top-level) defDifferDetails
that has all the details
of diffDifferDetails diffContents(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails)
orgDef
. Then, help
methods on DifferBase
can be used to diff the attr values
and accumulate the details of diff in difDetails
.
Here is example code snippet:
private static final String DIFF_STRING_ELEMS[] = { "MyStringVal1", "MyStringVal2" }; private static final String DIFF_INT_ELEMS[] = { "MyIntVal", } public DifferDetails diffContents(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails) {orgDefImpl = ( ) orgDef; final String editStringValues[] = { this.getMyStringVal1(), this.getMyStringVal2() }; String orgStringValues[] = null; if (orgDef != null) { String orgV[] = { orgDefImpl.getMyStringVal1(), orgDefImpl.getMyStringVal2() }; orgStringValues = orgV; } final int editIntValues[] = { this.getMyIntVal(), }; int orgIntValues[] = null; if (orgDef != null) { int orgV[] = { orgDefImpl.getMyIntVal() }; orgIntValues = orgV; } difDetails = DifferBase.diffStringArray(this, DIFF_STRING_ELEMS, editStringValues, orgStringValues, difDetails); difDetails = DifferBase.diffIntArray(this, DIFF_INT_ELEMS, editIntValues, orgIntValues, difDetails); return difDetails; }
docDef
- the document-level definitionorgDef
- the original definition. It could be
null
if the definition did not exist originallydifDetails
- the DifferDetails
that accumulate
the details of diff from the document-level (top-level) defDifferDetails
that has all the details
of diffDifferDetails diffChildren(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails)
difDetails
and
return it at the end.
For example, if this def has Child1 and Child2, its implementation should look something like:
public DifferDetails diffChildren(DiffMergeable docDef, DiffMergeable orgDef, DifferDetails difDetails) { difDetails = diffChildrenChild1(docDef, orgDef, difDetails); difDetails = diffChildrenChild1(docDef, orgDef, difDetails); return difDetails; }
where diffChildrenChild1()
uses DifferChildren
's
helper method diffChildrenList
to diff the child defs.
docDef
- the document-level definitionorgDef
- the original definition. It could be
null
if the definition did not exist originallydifDetails
- the DifferDetails
that accumulate
the details of diff from the document-level (top-level) defDifferDetails
that has all the details
of diffvoid applyDiffContents(DifferDetails dif, DiffResolver resolver)
orgDef - original def object (from the branch point)
editDef - def object into which changes are to be merge
toMergeDef - def object to be merged (source of changes)
For sandbox refresh operation, orgDef
comes from the branch
point, editDef
from the sandbox, toMergeDef
from the
mainline of the repos. With these three defs, we first diff editDef
against orgDef
, producing editDifDetails
.
Similarly, toMergeDef
is diffed against orgDef
,
producing toMergeDifDetails
. The diff engine then
walks through these two sets of diffs and identifies conflicts.
After the conflicts are all resolved, we apply appropriate
changes to editDef
.
applyDiffContents
is called to apply changes to
scalar values. dif
contains the changed values to
be applied to 'this'
object. Use sample code like
the following:
public void applyDiffContents(DifferDetails dif, DiffResolver resolver) { DifferChangeMap detailMap = dif.getDetailMap(); Object[] updValues; // DIFF_STRING_ELEMS from the above example code for (int j = 0; j < DIFF_STRING_ELEMS.length; j++) { if ((updValues = (Object[]) detailMap.getValue(DIFF_STRING_ELEMS[j])) != null) { switch(j) { case 0: setMyStringVal1((String) updValues[0]); break; case 1: setMyStringVal2((String) updValues[0]); break; } } } for (int j = 0; j < DIFF_INT_ELEMS.length; j++) { if ((updValues = (Object[]) detailMap.getValue(DIFF_INT_ELEMS[j])) != null) { switch(j) { case 0: setMyIntVal((Integer) updValues[0]); break; } } } }
Notice that the index specified in the case
statement is the array index of the attr in the String, int,
or boolean array.
dif
- changes to be applied to 'this'
defresolver
- the diff resolver used in diff/merge operationvoid applyDiffChildren(DifferDetails dif, DiffResolver resolver)
dif
contains the
changes to be applied to the children. For each child def, this method
should first retrieve the diff details for the child, which is of type
DifferChildren
. Then, it should call
DifferChildren.applyDiffChanges(oracle.jbo.mom.DiffChildrenMerge, oracle.jbo.mom.DiffResolver)
to perform
the change operation.
applyChanges()
requires a
DiffChildrenMerge
object, which has the insert,
update, and remove methods. 'this'
def object must
provide implmementation of these operations.
Here is a sample:
public void applyDiffChildren(DifferDetails dif, DiffResolver resolver) { DifferChangeMap detailMap = dif.getDetailMap(); if (detailMap != null) { DifferChildren difChild1 = (DifferChildren) detailMap.getValue(); if (difVCs != null) { DiffChildrenMerge dm = new DiffChildrenMerge() { public void insertChild(Object id, Object value) { .. perform insert op for Child1 .. } public void updateChild(Object id, Object value, Object oldValue) { .. perform update op for Child1 .. } public void removeChild(Object id) { .. perform remove op for Child1 .. } }; difChild1.applyDiffChanges(dm, resolver); } // Similarly for Child2 } }