De-/serialization of attributes rewritten to be better scallable.
1.1 --- a/mdr/jmiutils/nbproject/build-impl.xml Fri Aug 06 13:46:22 2004 +0000
1.2 +++ b/mdr/jmiutils/nbproject/build-impl.xml Sun Aug 08 18:25:34 2004 +0000
1.3 @@ -15,6 +15,7 @@
1.4 - junit compilation
1.5 - junit execution
1.6 - junit debugging
1.7 + - applet
1.8 - cleanup
1.9
1.10 -->
2.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java Fri Aug 06 13:46:22 2004 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrCollection.java Sun Aug 08 18:25:34 2004 +0000
2.3 @@ -20,6 +20,7 @@
2.4 import java.io.InputStream;
2.5 import java.io.OutputStream;
2.6 import java.io.IOException;
2.7 +import java.util.ListIterator;
2.8
2.9 import javax.jmi.reflect.*;
2.10
2.11 @@ -41,7 +42,9 @@
2.12 protected transient Class type;
2.13 protected transient boolean isRefObject;
2.14 protected transient MOFID metaMofId;
2.15 - protected transient boolean isIndexed = false;
2.16 + protected transient boolean isIndexed = false;
2.17 +
2.18 + protected boolean needsUnwrap = false;
2.19
2.20 public AttrCollection() {
2.21 }
2.22 @@ -78,6 +81,18 @@
2.23 this.isRefObject = isRefObject;
2.24 this.metaMofId = metaMofId;
2.25 }
2.26 +
2.27 + protected void checkUnwrap() {
2.28 + if (needsUnwrap) {
2.29 + for (ListIterator it = ((List) inner).listIterator(); it.hasNext();) {
2.30 + Object temp = it.next();
2.31 + if (temp instanceof MOFID) {
2.32 + it.set(mdrObject.getMdrStorage().getRepository().getByMofId((MOFID) temp));
2.33 + }
2.34 + }
2.35 + needsUnwrap = false;
2.36 + }
2.37 + }
2.38
2.39 public void read(InputStream stream, StorableFeatured storable) throws IOException {
2.40 int size = IOUtils.readInt(stream);
2.41 @@ -94,6 +109,7 @@
2.42 for (int i = 0; i < size; i++) {
2.43 inner.add(IOUtils.read(stream, storable, type.getName()));
2.44 }
2.45 + needsUnwrap = this.isRefObject;
2.46 }
2.47
2.48 public void write(OutputStream stream) throws IOException {
2.49 @@ -114,7 +130,7 @@
2.50
2.51 protected RefObject getMetaElement() {
2.52 try {
2.53 - return (RefObject) mdrObject.getMdrStorage().getRepository().getHandler(mdrObject.getMdrStorage().getObject(metaMofId));
2.54 + return (RefObject) mdrObject.getMdrStorage().getRepository().getByMofId(metaMofId);
2.55 } catch (Exception e) {
2.56 return null;
2.57 }
2.58 @@ -123,6 +139,7 @@
2.59 public boolean add(Object obj) {
2.60 checkType(obj);
2.61 checkMaxSize(1);
2.62 + checkUnwrap();
2.63 mdrObject.objectWillChange();
2.64 if (isIndexed)
2.65 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
2.66 @@ -153,6 +170,7 @@
2.67 }
2.68
2.69 public Iterator iterator() {
2.70 + checkUnwrap();
2.71 return new AttrIterator(inner.iterator());
2.72 }
2.73
2.74 @@ -171,10 +189,12 @@
2.75 }
2.76
2.77 public boolean contains(Object obj) {
2.78 + checkUnwrap();
2.79 return inner.contains(obj);
2.80 }
2.81
2.82 public boolean containsAll(Collection collection) {
2.83 + checkUnwrap();
2.84 return inner.containsAll(collection);
2.85 }
2.86
2.87 @@ -183,6 +203,7 @@
2.88 }
2.89
2.90 public boolean remove(Object obj) {
2.91 + checkUnwrap();
2.92 mdrObject.objectWillChange();
2.93 if (isIndexed)
2.94 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
2.95 @@ -203,18 +224,22 @@
2.96 }
2.97
2.98 public Object[] toArray() {
2.99 + checkUnwrap();
2.100 return inner.toArray();
2.101 }
2.102
2.103 public Object[] toArray(Object[] obj) {
2.104 + checkUnwrap();
2.105 return inner.toArray(obj);
2.106 }
2.107
2.108 public boolean equals(Object o) {
2.109 + checkUnwrap();
2.110 return inner.equals(o);
2.111 }
2.112
2.113 public int hashCode() {
2.114 + checkUnwrap();
2.115 return inner.hashCode();
2.116 }
2.117
3.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java Fri Aug 06 13:46:22 2004 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrList.java Sun Aug 08 18:25:34 2004 +0000
3.3 @@ -48,7 +48,7 @@
3.4 public void add(int param, Object obj) {
3.5 checkType(obj);
3.6 checkMaxSize(1);
3.7 -
3.8 + checkUnwrap();
3.9 mdrObject.objectWillChange();
3.10
3.11 if (isIndexed)
3.12 @@ -74,26 +74,32 @@
3.13 }
3.14
3.15 public Object get(int param) {
3.16 + checkUnwrap();
3.17 return innerList.get(param);
3.18 }
3.19
3.20 public int indexOf(Object obj) {
3.21 + checkUnwrap();
3.22 return innerList.indexOf(obj);
3.23 }
3.24
3.25 public int lastIndexOf(Object obj) {
3.26 + checkUnwrap();
3.27 return innerList.lastIndexOf(obj);
3.28 }
3.29
3.30 public ListIterator listIterator() {
3.31 + checkUnwrap();
3.32 return new AttrListIterator(innerList.listIterator());
3.33 }
3.34
3.35 public ListIterator listIterator(int param) {
3.36 + checkUnwrap();
3.37 return new AttrListIterator(innerList.listIterator(param));
3.38 }
3.39
3.40 public Object remove(int param) {
3.41 + checkUnwrap();
3.42 mdrObject.objectWillChange();
3.43 if (isIndexed)
3.44 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
3.45 @@ -116,7 +122,7 @@
3.46
3.47 public Object set(int param, Object obj) {
3.48 checkType(obj);
3.49 -
3.50 + checkUnwrap();
3.51 mdrObject.objectWillChange();
3.52 if (isIndexed)
3.53 ((StorableObject) mdrObject).removeFromIndex (metaMofId);
3.54 @@ -139,6 +145,7 @@
3.55 }
3.56
3.57 public List subList(int param, int param1) {
3.58 + checkUnwrap();
3.59 return new AttrList(mdrObject, innerList.subList(param, param1), maxSize, type, attrName, isRefObject, metaMofId);
3.60 }
3.61
4.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrSet.java Fri Aug 06 13:46:22 2004 +0000
4.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrSet.java Sun Aug 08 18:25:34 2004 +0000
4.3 @@ -16,6 +16,7 @@
4.4
4.5 import javax.jmi.reflect.RefObject;
4.6 import javax.jmi.reflect.DuplicateException;
4.7 +import org.netbeans.mdr.persistence.MOFID;
4.8
4.9 import org.netbeans.mdr.persistence.StorageException;
4.10
4.11 @@ -52,4 +53,20 @@
4.12 inner = new HashSet();
4.13 }
4.14 }
4.15 +
4.16 + protected void checkUnwrap() {
4.17 + if (needsUnwrap) {
4.18 + HashSet old = (HashSet) inner;
4.19 + inner = new HashSet();
4.20 + for (Iterator it = old.iterator(); it.hasNext();) {
4.21 + Object temp = it.next();
4.22 + if (temp instanceof MOFID) {
4.23 + inner.add(mdrObject.getMdrStorage().getRepository().getByMofId((MOFID) temp));
4.24 + } else {
4.25 + inner.add(temp);
4.26 + }
4.27 + }
4.28 + needsUnwrap = false;
4.29 + }
4.30 + }
4.31 }
5.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/AttrUList.java Fri Aug 06 13:46:22 2004 +0000
5.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/AttrUList.java Sun Aug 08 18:25:34 2004 +0000
5.3 @@ -26,7 +26,7 @@
5.4 * @author Martin Matula
5.5 */
5.6 public class AttrUList extends AttrList {
5.7 - private Set innerSet = new HashSet();
5.8 + private Set innerSet = null;
5.9
5.10 public AttrUList() {
5.11 super();
5.12 @@ -39,6 +39,7 @@
5.13 public AttrUList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc, List values) throws StorageException {
5.14 super(mdrObject, desc, values);
5.15
5.16 + innerSet = new HashSet();
5.17 for (Iterator it = inner.iterator(); it.hasNext();) {
5.18 Object value = it.next();
5.19 if (!innerSet.add(value)) {
5.20 @@ -52,11 +53,13 @@
5.21 this.innerSet = innerSet;
5.22 }
5.23
5.24 - public void read(InputStream stream, StorableFeatured storable) throws IOException {
5.25 - super.read(stream, storable);
5.26 - innerSet.addAll(inner);
5.27 + protected void checkUnwrap() {
5.28 + if (innerSet == null) {
5.29 + super.checkUnwrap();
5.30 + innerSet = new HashSet(inner);
5.31 + }
5.32 }
5.33 -
5.34 +
5.35 public boolean remove(Object obj) {
5.36 super.remove(obj);
5.37 return innerSet.remove(obj);
5.38 @@ -73,14 +76,17 @@
5.39 }
5.40
5.41 public ListIterator listIterator(int param) {
5.42 + checkUnwrap();
5.43 return new AttrUListIterator(innerList.listIterator(param));
5.44 }
5.45
5.46 public Iterator iterator() {
5.47 + checkUnwrap();
5.48 return new AttrUListIterator(innerList.listIterator());
5.49 }
5.50
5.51 public ListIterator listIterator() {
5.52 + checkUnwrap();
5.53 return new AttrUListIterator(innerList.listIterator());
5.54 }
5.55
5.56 @@ -104,14 +110,17 @@
5.57 }
5.58
5.59 public List subList(int param, int param1) {
5.60 + checkUnwrap();
5.61 return new AttrUList(mdrObject, innerList.subList(param, param1), maxSize, type, attrName, isRefObject, metaMofId, innerSet);
5.62 }
5.63
5.64 public boolean contains(Object obj) {
5.65 + checkUnwrap();
5.66 return innerSet.contains(obj);
5.67 }
5.68
5.69 public boolean containsAll(Collection collection) {
5.70 + checkUnwrap();
5.71 return innerSet.containsAll(collection);
5.72 }
5.73
6.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Fri Aug 06 13:46:22 2004 +0000
6.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Sun Aug 08 18:25:34 2004 +0000
6.3 @@ -49,7 +49,7 @@
6.4 /* -- Private static constants ---------------------------------------- */
6.5 /* -------------------------------------------------------------------- */
6.6
6.7 - private static final int STORAGE_VERSION = 23;
6.8 + private static final int STORAGE_VERSION = 24;
6.9
6.10 // names of global storage indexes
6.11 static final String IDX_OBJECTS_BY_CLASSES = "ObjectsByClasses";
7.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableClass.java Fri Aug 06 13:46:22 2004 +0000
7.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableClass.java Sun Aug 08 18:25:34 2004 +0000
7.3 @@ -753,7 +753,11 @@
7.4 for (int i = 0; i < objCount; i++) {
7.5 AttributeDescriptor desc = AttributeDescriptor.readResolve(inputStream, this);
7.6 clAttrDescs.put(desc.getName(), desc);
7.7 - clAttrValues.put(desc.getName(), IOUtils.read(inputStream, this, desc.getType().getName()));
7.8 + Object value = IOUtils.read(inputStream, this, desc.getType().getName());
7.9 + if (value instanceof MOFID) {
7.10 + value = getMdrStorage().getRepository().getByMofId((MOFID) value);
7.11 + }
7.12 + clAttrValues.put(desc.getName(), value);
7.13 }
7.14
7.15 } catch (IOException e) {
8.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java Fri Aug 06 13:46:22 2004 +0000
8.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/StorableObject.java Sun Aug 08 18:25:34 2004 +0000
8.3 @@ -14,6 +14,7 @@
8.4
8.5 import org.netbeans.mdr.handlers.AssociationHandler;
8.6 import org.netbeans.mdr.handlers.BaseObjectHandler;
8.7 +import org.netbeans.mdr.persistence.MOFID;
8.8 import org.netbeans.mdr.persistence.MultivaluedIndex;
8.9 import org.netbeans.mdr.persistence.StorageException;
8.10 import org.netbeans.mdr.persistence.Streamable;
8.11 @@ -41,11 +42,11 @@
8.12 static final String INDEX_KEY_DELIMITER_2 = "#";
8.13 static final String NULL_VALUE_SUBSTITUTE = "NULL";
8.14
8.15 - private org.netbeans.mdr.persistence.MOFID classProxyId;
8.16 + private MOFID classProxyId;
8.17 private transient StorableClass classProxy = null;
8.18 /** MOFID of this object's immediate composite in case when the object is a value
8.19 * of an attribute, otherwise null. */
8.20 - private org.netbeans.mdr.persistence.MOFID attribComposite = null;
8.21 + private MOFID attribComposite = null;
8.22
8.23 protected void replaceValues(Map table) {
8.24 objectWillChange();
8.25 @@ -113,9 +114,8 @@
8.26 }
8.27
8.28 public void setAttribute(int attrIndex, Object value) throws StorageException {
8.29 - check();
8.30 + Object oldValue = getAttribute(attrIndex);
8.31 StorableClass.AttributeDescriptor attribute = getClassProxy().getAttrDesc(attrIndex);
8.32 - Object oldValue = values[attrIndex];
8.33
8.34 // if (value == oldValue || (value != null && value.equals(oldValue))) {
8.35 // return;
8.36 @@ -144,7 +144,11 @@
8.37
8.38 public Object getAttribute(int attrIndex) throws StorageException {
8.39 check();
8.40 - return values[attrIndex];
8.41 + Object result = values[attrIndex];
8.42 + if (result instanceof MOFID) {
8.43 + result = getMdrStorage().getRepository().getByMofId((MOFID) result);
8.44 + }
8.45 + return result;
8.46 }
8.47
8.48 public void verify(Collection violations) throws StorageException {
8.49 @@ -507,12 +511,13 @@
8.50 protected void deleteAttributes() throws StorageException {
8.51 for (int i = 0; i < values.length; i++) {
8.52 //modifyIndex(i, values[i], null);
8.53 - if (values[i] instanceof RefObject) {
8.54 - RefObject obj = (RefObject) values[i];
8.55 + Object value = getAttribute(i);
8.56 + if (value instanceof RefObject) {
8.57 + RefObject obj = (RefObject) value;
8.58 setAttribute(i, null);
8.59 obj.refDelete();
8.60 - } else if (values[i] instanceof Collection) {
8.61 - for (Iterator it = ((Collection)values[i]).iterator(); it.hasNext();) {
8.62 + } else if (value instanceof Collection) {
8.63 + for (Iterator it = ((Collection)value).iterator(); it.hasNext();) {
8.64 Object obj = it.next();
8.65 if (!(obj instanceof RefObject))
8.66 break;
9.1 --- a/mdr/src/org/netbeans/mdr/util/IOUtils.java Fri Aug 06 13:46:22 2004 +0000
9.2 +++ b/mdr/src/org/netbeans/mdr/util/IOUtils.java Sun Aug 08 18:25:34 2004 +0000
9.3 @@ -256,7 +256,7 @@
9.4 writeString(outputStream, ((StorableClass.ReferenceDescriptor) object).getEndName());
9.5
9.6 } else if (object instanceof RefObject) {
9.7 - outputStream.write(T_OBJECT);
9.8 + outputStream.write(T_MOFID);
9.9 writeMOFID (outputStream, ((BaseObjectHandler) object)._getDelegate().getMofId(),storable.getMdrStorage(), storable.getMofId());
9.10
9.11 } else if (object instanceof Class) {
9.12 @@ -501,13 +501,13 @@
9.13 } catch (ClassNotFoundException e) {
9.14 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
9.15 }
9.16 - } case T_OBJECT: {
9.17 - if (storable == null) Logger.getDefault().notify(Logger.INFORMATIONAL, new DebugException());
9.18 - try {
9.19 - return storable.getMdrStorage().getRepository().getHandler(storable.getMdrStorage().getObject(readMOFID(inputStream, storable.getMdrStorage(), storable.getMofId())));
9.20 - } catch (StorageException e) {
9.21 - throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
9.22 - }
9.23 +// } case T_OBJECT: {
9.24 +// if (storable == null) Logger.getDefault().notify(Logger.INFORMATIONAL, new DebugException());
9.25 +// try {
9.26 +// return storable.getMdrStorage().getRepository().getHandler(storable.getMdrStorage().getObject(readMOFID(inputStream, storable.getMdrStorage(), storable.getMofId())));
9.27 +// } catch (StorageException e) {
9.28 +// throw (DebugException) Logger.getDefault().annotate(new DebugException(), e);
9.29 +// }
9.30 } case T_MOFID: {
9.31 return readMOFID (inputStream, storable.getMdrStorage (), storable.getMofId());
9.32 /* } case T_SERIALIZABLE: {