01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.common;
12:
13: import com.versant.core.util.OIDObjectOutput;
14: import com.versant.core.util.OIDObjectInput;
15:
16: import java.io.IOException;
17:
18: /**
19: * This holds the differences between two unordered collections. It is stored
20: * in the new State when changes to an unordered collection field are persisted.
21: */
22: public class UnorderedCollectionDiff extends CollectionDiff {
23:
24: public UnorderedCollectionDiff() {
25: }
26:
27: public UnorderedCollectionDiff(VersantFieldMetaData fmd) {
28: super (fmd);
29: }
30:
31: /**
32: * The deleted values (null if none).
33: */
34: public Object[] deletedValues;
35:
36: protected Object clone() throws CloneNotSupportedException {
37: UnorderedCollectionDiff cloned = null;
38: try {
39: cloned = (UnorderedCollectionDiff) super .clone();
40: cloned.deletedValues = new Object[deletedValues.length];
41: System.arraycopy(deletedValues, 0, cloned.deletedValues, 0,
42: deletedValues.length);
43: return cloned;
44: } catch (CloneNotSupportedException e) {
45: e.printStackTrace();
46: }
47: return cloned;
48: }
49:
50: public String toString() {
51: return "<UnorderedCollectionDiff: status = " + status
52: + ": amount added ="
53: + (insertedValues != null ? insertedValues.length : -1)
54: + " deleted amount = "
55: + (deletedValues != null ? deletedValues.length : -1)
56: + ">";
57: }
58:
59: public void writeExternal(OIDObjectOutput out) throws IOException {
60: super .writeExternal(out);
61: write(out, fmd.getElementTypeCode(), fmd.isElementTypePC(),
62: deletedValues);
63: }
64:
65: public void readExternal(OIDObjectInput in) throws IOException,
66: ClassNotFoundException {
67: super .readExternal(in);
68: deletedValues = read(in, fmd.getElementTypeCode(), fmd
69: .isElementTypePC());
70: }
71:
72: public void dump() {
73: if (Debug.DEBUG) {
74: Debug.OUT.println("ToBeAdded");
75: }
76: if (insertedValues != null) {
77: for (int i = 0; i < insertedValues.length; i++) {
78: if (Debug.DEBUG) {
79: Debug.OUT
80: .println("inserted = " + insertedValues[i]);
81: }
82: }
83: }
84:
85: if (Debug.DEBUG) {
86: Debug.OUT.println("ToBeDeleted");
87: }
88: if (deletedValues != null) {
89: for (int i = 0; i < deletedValues.length; i++) {
90: if (Debug.DEBUG) {
91: Debug.OUT.println("deleted = " + deletedValues[i]);
92: }
93: }
94: }
95: }
96:
97: }
|