Take id field from parent prototype if it isn't defined in this one.

This commit is contained in:
hns 2002-04-26 15:30:54 +00:00
parent e74c9b22f2
commit fd82482a03

View file

@ -54,7 +54,7 @@ public class DbMapping implements Updatable {
HashMap db2prop; HashMap db2prop;
// db field used as primary key // db field used as primary key
String idField; private String idField;
// db field used as object name // db field used as object name
String nameField; String nameField;
// db field used to identify name of prototype to use for object instantiation // db field used to identify name of prototype to use for object instantiation
@ -94,9 +94,8 @@ public class DbMapping implements Updatable {
db2prop = new HashMap (); db2prop = new HashMap ();
parent = null; parent = null;
// subnodes = null;
// properties = null; idField = null;
idField = "ID";
} }
/** /**
@ -111,9 +110,8 @@ public class DbMapping implements Updatable {
db2prop = new HashMap (); db2prop = new HashMap ();
parent = null; parent = null;
// subnodes = null;
// properties = null; idField = null;
idField = "ID";
this.props = props; this.props = props;
update (); update ();
@ -160,8 +158,9 @@ public class DbMapping implements Updatable {
} }
} }
// id field must not be null, default is "id" // if id field is null, we assume "ID" as default. We don't set it
idField = props.getProperty ("_id", "ID"); // however, so that if null we check the parent prototype first.
idField = props.getProperty ("_id");
nameField = props.getProperty ("_name"); nameField = props.getProperty ("_name");
@ -367,7 +366,7 @@ public class DbMapping implements Updatable {
public String getIDField () { public String getIDField () {
if (idField == null && parentMapping != null) if (idField == null && parentMapping != null)
return parentMapping.getIDField (); return parentMapping.getIDField ();
return idField; return idField == null ? "ID" : idField;
} }
/** /**
@ -632,7 +631,7 @@ public class DbMapping implements Updatable {
KeyDef k = keydef; KeyDef k = keydef;
if (k != null) if (k != null)
return k; return k;
keydef = new KeyDef ().addAttrib (idField); keydef = new KeyDef ().addAttrib (getIDField ());
return keydef; return keydef;
} }