removed unused code

removed backlinks for nodes used as property values -
properties will simply return null once a node used as value
has been deleted.
This commit is contained in:
hns 2001-08-21 13:40:54 +00:00
parent 1c66a640a0
commit 93b7f729b8

View file

@ -193,43 +193,16 @@ public final class Property implements IProperty, Serializable, Cloneable {
} }
public void setNodeValue (Node value) { public void setNodeValue (Node value) {
value.checkWriteLock (); // value.checkWriteLock ();
if (type == NODE) if (type == NODE)
unregisterNode (); unregisterNode ();
if (type == JAVAOBJECT) if (type == JAVAOBJECT)
this.jvalue = null; this.jvalue = null;
registerNode (value); // registerNode (value);
type = NODE; type = NODE;
/* if (node.dbmap != null) {
Relation rel = node.dbmap.getPropertyRelation (propname);
if (rel != null && rel.other != null) {
DbMapping vmap = value.getDbMapping ();
// check if actual type matches expected type
if (rel.other != vmap && (!rel.virtual || rel.prototype != null)) {
throw new RuntimeException ("Can't assign property: expected prototype "+rel.other+", got "+vmap);
}
// check if this is a forward relation, i.e. if we point to a field in the value object
// if so, we may use something else than the object's id to refer to it.
if (!rel.virtual && rel.direction == Relation.FORWARD) {
if (rel.usesPrimaryKey ()) {
this.nvalueID = value.getID ();
nhandle = new NodeHandle (value);
} else try {
this.nvalueID = value.getString (vmap.columnNameToProperty (rel.getRemoteField()).propname, false);
nhandle = null;
} catch (Exception x) {
throw new RuntimeException ("Can't set "+propname+" to "+value+": error retrieving target property");
}
dirty = true;
return;
}
}
} */
nhandle = value.getHandle (); nhandle = value.getHandle ();
// this.nvalueID = value == null ? null : value.getID ();
dirty = true; dirty = true;
} }
@ -256,8 +229,6 @@ public final class Property implements IProperty, Serializable, Cloneable {
nvmap = node.dbmap.getPropertyMapping (propname); nvmap = node.dbmap.getPropertyMapping (propname);
nvrel = node.dbmap.getPropertyRelation (propname); nvrel = node.dbmap.getPropertyRelation (propname);
} }
// if (nvalue == null)
// nvalue = node.nmgr.getNode (nvalueID, nvmap);
if (nvalue == null) if (nvalue == null)
return; return;
@ -276,23 +247,11 @@ public final class Property implements IProperty, Serializable, Cloneable {
if (!nvalue.isAnonymous() && propname.equals (nvalue.getName()) && this.node == nvalue.getParent()) { if (!nvalue.isAnonymous() && propname.equals (nvalue.getName()) && this.node == nvalue.getParent()) {
// this is the "main" property of a named node, so handle this as a cascading delete. // this is the "main" property of a named node, so handle this as a cascading delete.
nvalue.deepRemoveNode (); nvalue.deepRemoveNode ();
} else {
nvalue.unregisterPropLinkFrom (this.node);
} }
} }
} }
/**
* Tell the value node that it is being used as a property value.
*/
protected void registerNode (Node n) {
// only need to call registerPropLink if the value node is not stored in a relational db
if (n != null && (n.dbmap == null || !n.dbmap.isRelational())) {
n.registerPropLinkFrom (this.node);
}
}
public String getStringValue () { public String getStringValue () {
switch (type) { switch (type) {
case STRING: case STRING:
@ -349,48 +308,6 @@ public final class Property implements IProperty, Serializable, Cloneable {
Node n = nhandle.getNode (node.nmgr); Node n = nhandle.getNode (node.nmgr);
if (n != null) return n; if (n != null) return n;
} }
/* DbMapping dbm = null;
//// PROVISIONAL
if (type == NODE && nvalueID != null) {
Relation rel = null;
if (dbm == null && node.dbmap != null) {
// try to get DbMap for property, if it isn't known yet
rel = node.dbmap.getPropertyRelation (propname);
// figure out db mapping from relation
if (rel != null) {
// is the property a virtual node containing objects from relational db?
if (rel.virtual && rel.other.isRelational ())
return node.nmgr.getNode (node, propname, rel);
else if (!rel.virtual && rel.direction == Relation.FORWARD)
return node.nmgr.getNode (node, nvalueID, rel);
// avoid setting dbm for virtual and groupby relations, except for
// [mountpoint] kind of prototyped virtual nodes
else if ((!rel.virtual || rel.prototype != null) && rel.groupby == null)
dbm = rel.other;
}
}
// we have what we need, now get the node from the node manager
Node retval = node.nmgr.getNode (nvalueID, dbm);
if (retval != null && retval.parentHandle == null && !"root".equalsIgnoreCase (retval.getPrototype ())) {
retval.setParent (node);
retval.setName (propname);
retval.anonymous = false;
}
if (retval != null && retval.getDbMapping () == null && rel != null && rel.virtual && rel.prototype == null) {
// a virtual node whose child nodes are not relational -
// set up dbmapping that describes subnodes and properties
DbMapping _dbm = new DbMapping ();
_dbm.setSubnodeMapping (rel.other);
_dbm.setPropertyMapping (rel.other);
_dbm.setSubnodeRelation (rel.getVirtualSubnodeRelation());
_dbm.setPropertyRelation (rel.getVirtualPropertyRelation());
retval.setDbMapping (_dbm);
}
return retval;
} */
return null; return null;
} }
@ -400,86 +317,9 @@ public final class Property implements IProperty, Serializable, Cloneable {
return null; return null;
} }
public String getEditor () {
switch (type) {
case STRING:
return "password".equalsIgnoreCase (propname) ?
"<input type=password name=\""+propname+"\" value='"+ svalue.replace ('\'', '"') +"'>" :
"<input type=text name=\""+propname+"\" value='"+ svalue.replace ('\'', '"') +"'>" ;
case BOOLEAN:
return "<select name=\""+propname+"\"><option selected value="+bvalue+">"+bvalue+"</option><option value="+!bvalue+">"+!bvalue+"</option></select>";
case INTEGER:
return "<input type=text name=\""+propname+"\" value=\""+lvalue+"\">" ;
case FLOAT:
return "<input type=text name=\""+propname+"\" value=\""+dvalue+"\">" ;
case DATE:
SimpleDateFormat format = new SimpleDateFormat ("dd.MM.yy hh:mm");
String date = format.format (new Date (lvalue));
return "<input type=text name=\""+propname+"\" value=\""+date+"\">";
}
return "";
}
private String escape (String s) {
char c[] = new char[s.length()];
s.getChars (0, c.length, c, 0);
StringBuffer b = new StringBuffer ();
int copyfrom = 0;
for (int i = 0; i < c.length; i++) {
switch (c[i]) {
case '\\':
case '"':
if (i-copyfrom > 0)
b.append (c, copyfrom, i-copyfrom);
b.append ('\\');
b.append (c[i]);
copyfrom = i+1;
}
}
if (c.length-copyfrom > 0)
b.append (c, copyfrom, c.length-copyfrom);
return b.toString ();
}
public int getType () { public int getType () {
return type; return type;
}
public String getTypeString () {
switch (type) {
case STRING:
return "string";
case BOOLEAN:
return "boolean";
case DATE:
return "date";
case INTEGER:
return "integer";
case FLOAT:
return "float";
case NODE:
return "node";
}
return "";
}
public Object clone () {
try {
Property c = (Property) super.clone();
c.propname = this.propname;
c.svalue = this.svalue;
c.bvalue = this.bvalue;
c.lvalue = this.lvalue;
c.dvalue = this.dvalue;
c.nhandle = this.nhandle;
c.type = this.type;
return c;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError ();
}
} }
} }