Implement readObject() and writeObject() on some key classes to
make sure storageNames are properly internalized.
This commit is contained in:
parent
c08395ae39
commit
6236eba83e
4 changed files with 65 additions and 7 deletions
|
@ -17,6 +17,10 @@
|
|||
package helma.objectmodel.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* This is the internal representation of a database key. It is constructed
|
||||
|
@ -27,14 +31,16 @@ public final class DbKey implements Key, Serializable {
|
|||
// the name of the prototype which defines the storage of this object.
|
||||
// this is the name of the object's prototype, or one of its ancestors.
|
||||
// If null, the object is stored in the embedded db.
|
||||
private final String storageName;
|
||||
private String storageName;
|
||||
|
||||
// the id that defines this key's object within the above storage space
|
||||
private final String id;
|
||||
private String id;
|
||||
|
||||
// lazily initialized hashcode
|
||||
private transient int hashcode = 0;
|
||||
|
||||
static final long serialVersionUID = 1618863960930966588L;
|
||||
|
||||
/**
|
||||
* make a key for a persistent Object, describing its datasource and id.
|
||||
*/
|
||||
|
@ -116,4 +122,23 @@ public final class DbKey implements Key, Serializable {
|
|||
public String toString() {
|
||||
return (storageName == null) ? ("[" + id + "]") : (storageName + "[" + id + "]");
|
||||
}
|
||||
|
||||
// We implement write/readObject to set storageName
|
||||
// to the interned version of the string.
|
||||
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
stream.writeObject(storageName);
|
||||
stream.writeObject(id);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream)
|
||||
throws IOException, ClassNotFoundException {
|
||||
storageName = (String) stream.readObject();
|
||||
id = (String) stream.readObject();
|
||||
// if storageName is not null, set it to the interned version
|
||||
if (storageName != null) {
|
||||
storageName = storageName.intern();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,24 +22,26 @@ package helma.objectmodel.db;
|
|||
*
|
||||
*/
|
||||
public interface Key {
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the key's parent key
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public Key getParentKey();
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the key's ID part
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public String getID();
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the key's storage id
|
||||
*
|
||||
* @return ...
|
||||
*/
|
||||
public String getStorageName();
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
package helma.objectmodel.db;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -31,14 +34,17 @@ public final class MultiKey implements Key, Serializable {
|
|||
// the name of the prototype which defines the storage of this object.
|
||||
// this is the name of the object's prototype, or one of its ancestors.
|
||||
// If null, the object is stored in the embedded db.
|
||||
private final String storageName;
|
||||
private String storageName;
|
||||
|
||||
// the id that defines this key's object within the above storage space
|
||||
private final Map parts;
|
||||
private Map parts;
|
||||
|
||||
// lazily initialized hashcode
|
||||
private transient int hashcode = 0;
|
||||
|
||||
static final long serialVersionUID = -9173409137561990089L;
|
||||
|
||||
|
||||
/**
|
||||
* make a key for a persistent Object, describing its datasource and key parts.
|
||||
*/
|
||||
|
@ -121,4 +127,23 @@ public final class MultiKey implements Key, Serializable {
|
|||
public String toString() {
|
||||
return (storageName == null) ? ("[" + parts + "]") : (storageName + "[" + parts + "]");
|
||||
}
|
||||
|
||||
// We implement write/readObject to set storageName
|
||||
// to the interned version of the string.
|
||||
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
stream.writeObject(storageName);
|
||||
stream.writeObject(parts);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream)
|
||||
throws IOException, ClassNotFoundException {
|
||||
storageName = (String) stream.readObject();
|
||||
parts = (Map) stream.readObject();
|
||||
// if storageName is not null, set it to the interned version
|
||||
if (storageName != null) {
|
||||
storageName = storageName.intern();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,12 +25,18 @@ import java.io.Serializable;
|
|||
* virtual nodes and groupby nodes.
|
||||
*/
|
||||
public final class SyntheticKey implements Key, Serializable {
|
||||
|
||||
// the parent key
|
||||
private final Key parentKey;
|
||||
|
||||
// the name relative to the parent key
|
||||
private final String name;
|
||||
|
||||
// lazily initialized hashcode
|
||||
private transient int hashcode = 0;
|
||||
|
||||
static final long serialVersionUID = -693454133259421857L;
|
||||
|
||||
/**
|
||||
* make a key for a persistent Object, describing its datasource and id.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue