1 2 12 package com.versant.core.common; 13 14 import com.versant.core.metadata.MDStatics; 15 import com.versant.core.util.OIDObjectInput; 16 import com.versant.core.util.OIDObjectOutput; 17 import com.versant.core.util.FastExternalizable; 18 19 import java.io.*; 20 21 22 27 public abstract class CollectionDiff implements FastExternalizable, Cloneable { 28 29 public static final Object [] EMPTY_OBJECT_ARRAY = new Object [0]; 30 31 public VersantFieldMetaData fmd; 32 33 37 public static final int STATUS_NEW = 1; 38 39 public int status; 40 41 44 public Object [] insertedValues; 45 46 public CollectionDiff() { 47 } 48 49 public CollectionDiff(VersantFieldMetaData fmd) { 50 this.fmd = fmd; 51 } 52 53 public String toString() { 54 return "<CollectionDiff: status = " + status + ": amount added =" 55 + (insertedValues != null ? insertedValues.length : -1) + ">"; 56 } 57 58 protected void write(OIDObjectOutput out, int typeCode, boolean pc, 59 Object [] data) 60 throws IOException { 61 int n = data == null ? 0 : data.length; 62 out.writeInt(n); 64 if (pc) { 65 for (int i = 0; i < n; i++) { 66 out.write((OID)data[i]); 67 } 68 } else { 69 for (int i = 0; i < n; i++) { 70 out.writeObject(data[i]); 71 } 72 } 73 } 74 75 protected Object [] read(OIDObjectInput in, int typeCode, boolean pc) 76 throws IOException, ClassNotFoundException { 77 int n = in.readInt(); 78 if (n <= 0) { 80 return null; 81 } 82 Object [] data = new Object [n]; 83 if (pc) { 84 for (int i = 0; i < n; i++) { 85 data[i] = in.readOID(); 86 } 87 } else { 88 for (int i = 0; i < n; i++) { 89 data[i] = in.readObject(); 90 } 91 } 92 return data; 93 } 94 95 public void writeExternal(OIDObjectOutput out) throws IOException { 96 out.writeByte(status); 97 write(out, fmd.getElementTypeCode(), fmd.isElementTypePC(), 98 insertedValues); 99 } 100 101 public void readExternal(OIDObjectInput in) throws IOException, 102 ClassNotFoundException { 103 status = in.readByte(); 104 insertedValues = read(in, fmd.getElementTypeCode(), 105 fmd.isElementTypePC()); 106 } 107 108 protected Object clone() throws CloneNotSupportedException { 109 CollectionDiff cloned = (CollectionDiff)super.clone(); 110 cloned.insertedValues = new Object [insertedValues.length]; 111 System.arraycopy(insertedValues, 0, cloned.insertedValues, 0, 112 insertedValues.length); 113 return cloned; 114 } 115 116 public void dump() { 117 } 118 119 } 120 | Popular Tags |