Removed support for old type.properties db mapping.
This commit is contained in:
parent
fae1c98f1c
commit
e7a17d20ab
2 changed files with 25 additions and 265 deletions
|
@ -26,7 +26,7 @@ public class DbMapping implements Updatable {
|
|||
// prototype name of this mapping
|
||||
String typename;
|
||||
|
||||
int version;
|
||||
// int version;
|
||||
|
||||
// properties from where the mapping is read
|
||||
SystemProperties props;
|
||||
|
@ -135,13 +135,13 @@ public class DbMapping implements Updatable {
|
|||
public synchronized void update () {
|
||||
|
||||
// determin file format version of type.properties file
|
||||
String versionInfo = props.getProperty ("_version");
|
||||
/* String versionInfo = props.getProperty ("_version");
|
||||
if ("1.2".equals (versionInfo))
|
||||
version = 1;
|
||||
else
|
||||
version = 0;
|
||||
version = 0; */
|
||||
|
||||
table = props.getProperty (version == 0 ? "_tablename" : "_table");
|
||||
table = props.getProperty ("_table");
|
||||
idgen = props.getProperty ("_idgen");
|
||||
// see if there is a field which specifies the prototype of objects, if different prototypes
|
||||
// can be stored in this table
|
||||
|
@ -149,7 +149,7 @@ public class DbMapping implements Updatable {
|
|||
// see if this prototype extends (inherits from) any other prototype
|
||||
extendsProto = props.getProperty ("_extends");
|
||||
|
||||
sourceName = props.getProperty (version == 0 ? "_datasource" : "_db");
|
||||
sourceName = props.getProperty ("_db");
|
||||
if (sourceName != null) {
|
||||
source = app.getDbSource (sourceName);
|
||||
if (source == null) {
|
||||
|
@ -207,7 +207,7 @@ public class DbMapping implements Updatable {
|
|||
Relation rel = propertyToRelation (propName);
|
||||
if (rel == null)
|
||||
rel = new Relation (dbField, propName, this, props);
|
||||
rel.update (dbField, props, version);
|
||||
rel.update (dbField, props);
|
||||
p2d.put (propName, rel);
|
||||
if (rel.columnName != null &&
|
||||
(rel.reftype == Relation.PRIMITIVE ||
|
||||
|
@ -223,60 +223,21 @@ public class DbMapping implements Updatable {
|
|||
prop2db = p2d;
|
||||
db2prop = d2p;
|
||||
|
||||
if (version == 1) {
|
||||
String subnodeMapping = props.getProperty ("_children");
|
||||
if (subnodeMapping != null) {
|
||||
try {
|
||||
// check if subnode relation already exists. If so, reuse it
|
||||
if (subnodesRel == null)
|
||||
subnodesRel = new Relation (subnodeMapping, "_children", this, props);
|
||||
subnodesRel.update (subnodeMapping, props, version);
|
||||
subnodesRel.update (subnodeMapping, props);
|
||||
if (subnodesRel.accessor != null)
|
||||
propertiesRel = subnodesRel;
|
||||
|
||||
} catch (Exception x) {
|
||||
app.logEvent ("Error reading _subnodes relation for "+typename+": "+x.getMessage ());
|
||||
// subnodesRel = null;
|
||||
}
|
||||
} else
|
||||
subnodesRel = null;
|
||||
} else {
|
||||
String subnodeMapping = props.getProperty ("_subnodes");
|
||||
if (subnodeMapping != null) {
|
||||
try {
|
||||
// check if subnode relation already exists. If so, reuse it
|
||||
if (subnodesRel == null)
|
||||
subnodesRel = new Relation (subnodeMapping, "_subnodes", this, props);
|
||||
subnodesRel.update (subnodeMapping, props, version);
|
||||
|
||||
} catch (Exception x) {
|
||||
app.logEvent ("Error reading _subnodes relation for "+typename+": "+x.getMessage ());
|
||||
// subnodesRel = null;
|
||||
}
|
||||
} else
|
||||
subnodesRel = null;
|
||||
|
||||
String propertiesMapping = props.getProperty ("_properties");
|
||||
if (propertiesMapping != null) {
|
||||
try {
|
||||
// check if property relation already exists. If so, reuse it
|
||||
if (propertiesRel == null)
|
||||
propertiesRel = new Relation (propertiesMapping, "_properties", this, props);
|
||||
propertiesRel.update (propertiesMapping, props, version);
|
||||
|
||||
// take over groupby flag from subnodes, if properties are subnodes
|
||||
if (propertiesRel.subnodesAreProperties && subnodesRel != null) {
|
||||
propertiesRel.groupby = subnodesRel.groupby;
|
||||
propertiesRel.constraints = subnodesRel.constraints;
|
||||
propertiesRel.filter = subnodesRel.filter;
|
||||
}
|
||||
|
||||
} catch (Exception x) {
|
||||
app.logEvent ("Error reading _properties relation for "+typename+": "+x.getMessage ());
|
||||
// propertiesRel = null;
|
||||
}
|
||||
} else
|
||||
propertiesRel = null;
|
||||
subnodesRel = propertiesRel = null;
|
||||
}
|
||||
|
||||
if (groupbyMapping != null) {
|
||||
|
|
|
@ -89,213 +89,12 @@ public class Relation {
|
|||
otherType = null;
|
||||
}
|
||||
|
||||
public void update (String desc, Properties props, int version) {
|
||||
if (version == 0)
|
||||
update_v0 (desc, props);
|
||||
else if (version == 1)
|
||||
update_v1 (desc, props);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// parse methods for file format v0
|
||||
// parse methods for new file format
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void update_v0 (String desc, Properties props) {
|
||||
boolean mountpoint = false;
|
||||
Vector cnst = null;
|
||||
|
||||
if (desc == null || "".equals (desc.trim ())) {
|
||||
if (propName != null) {
|
||||
reftype = PRIMITIVE;
|
||||
columnName = propName;
|
||||
} else {
|
||||
reftype = INVALID;
|
||||
columnName = propName;
|
||||
}
|
||||
} else {
|
||||
desc = desc.trim ();
|
||||
String descLower = desc.toLowerCase ();
|
||||
if (descLower.startsWith ("[virtual]")) {
|
||||
desc = desc.substring (9).trim ();
|
||||
virtual = true;
|
||||
} else if (descLower.startsWith ("[collection]")) {
|
||||
desc = desc.substring (12).trim ();
|
||||
virtual = true;
|
||||
} else if (descLower.startsWith ("[mountpoint]")) {
|
||||
desc = desc.substring (12).trim ();
|
||||
virtual = true;
|
||||
mountpoint = true;
|
||||
} else {
|
||||
virtual = false;
|
||||
}
|
||||
if (descLower.startsWith ("[readonly]")) {
|
||||
desc = desc.substring (10).trim ();
|
||||
readonly = true;
|
||||
} else {
|
||||
readonly = false;
|
||||
}
|
||||
}
|
||||
|
||||
// parse the basic properties of this mapping
|
||||
parseMapping_v0 (desc, mountpoint);
|
||||
|
||||
// the following options only apply to object relations
|
||||
if (reftype != PRIMITIVE && reftype != INVALID) {
|
||||
|
||||
cnst = new Vector ();
|
||||
|
||||
Constraint c = parseConstraint_v0 (desc);
|
||||
|
||||
if (c != null)
|
||||
cnst.add (c);
|
||||
|
||||
parseOptions_v0 (cnst, props);
|
||||
|
||||
constraints = new Constraint[cnst.size()];
|
||||
cnst.copyInto (constraints);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a line describing a mapping of a property field. If the mapping is a
|
||||
* object reference of a collection of objects, put any constraints in the Vector.
|
||||
*/
|
||||
protected void parseMapping_v0 (String desc, boolean mountpoint) {
|
||||
|
||||
Application app = ownType.getApplication ();
|
||||
|
||||
if (desc.indexOf ("<") > -1) {
|
||||
reftype = COLLECTION;
|
||||
int lt = desc.indexOf ("<");
|
||||
int dot = desc.indexOf (".");
|
||||
String other = dot < 0 ? desc.substring (lt+1).trim () : desc.substring (lt+1, dot).trim ();
|
||||
otherType = app.getDbMapping (other);
|
||||
if (otherType == null)
|
||||
throw new RuntimeException ("DbMapping for "+other+" not found from "+ownType.typename);
|
||||
columnName = null;
|
||||
if (mountpoint)
|
||||
prototype = other;
|
||||
} else if (desc.indexOf (">") > -1) {
|
||||
reftype = REFERENCE;
|
||||
int bt = desc.indexOf (">");
|
||||
int dot = desc.indexOf (".");
|
||||
String other = dot > -1 ? desc.substring (bt+1, dot).trim () : desc.substring (bt+1).trim ();
|
||||
otherType = app.getDbMapping (other);
|
||||
if (otherType == null)
|
||||
throw new RuntimeException ("DbMapping for "+other+" not found from "+ownType.typename);
|
||||
columnName = desc.substring (0, bt).trim ();
|
||||
if (mountpoint)
|
||||
prototype = other;
|
||||
} else if (desc.indexOf (".") > -1) {
|
||||
reftype = COLLECTION;
|
||||
int dot = desc.indexOf (".");
|
||||
String other = desc.substring (0, dot).trim ();
|
||||
otherType = app.getDbMapping (other);
|
||||
if (otherType == null)
|
||||
throw new RuntimeException ("DbMapping for "+other+" not found from "+ownType.typename);
|
||||
columnName = null;
|
||||
// set accessor
|
||||
accessor = desc.substring (dot+1).trim ();
|
||||
if (mountpoint)
|
||||
prototype = other;
|
||||
} else {
|
||||
if (virtual) {
|
||||
reftype = COLLECTION;
|
||||
otherType = app.getDbMapping (desc);
|
||||
if (otherType == null)
|
||||
throw new RuntimeException ("DbMapping for "+desc+" not found from "+ownType.typename);
|
||||
if (mountpoint)
|
||||
prototype = desc;
|
||||
} else {
|
||||
reftype = PRIMITIVE;
|
||||
columnName = desc.trim ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse a line describing a mapping of a property field. If the mapping is a
|
||||
* object reference of a collection of objects, put any constraints in the Vector.
|
||||
*/
|
||||
protected Constraint parseConstraint_v0 (String desc) {
|
||||
if (desc.indexOf ("<") > -1) {
|
||||
int lt = desc.indexOf ("<");
|
||||
int dot = desc.indexOf (".");
|
||||
String remoteField = dot < 0 ? null : desc.substring (dot+1).trim ();
|
||||
String localField = lt <= 0 ? null : desc.substring (0, lt).trim ();
|
||||
return new Constraint (localField, otherType.getTableName (), remoteField, false);
|
||||
} else if (desc.indexOf (">") > -1) {
|
||||
int bt = desc.indexOf (">");
|
||||
int dot = desc.indexOf (".");
|
||||
String localField = desc.substring (0, bt).trim ();
|
||||
String remoteField = dot < 0 ? null : desc.substring (dot+1).trim ();
|
||||
return new Constraint (localField, otherType.getTableName (), remoteField, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void parseOptions_v0 (Vector cnst, Properties props) {
|
||||
String loading = props.getProperty (propName+".loadmode");
|
||||
aggressiveLoading = loading != null && "aggressive".equalsIgnoreCase (loading.trim());
|
||||
String caching = props.getProperty (propName+".cachemode");
|
||||
aggressiveCaching = caching != null && "aggressive".equalsIgnoreCase (caching.trim());
|
||||
// get order property
|
||||
order = props.getProperty (propName+".order");
|
||||
if (order != null && order.trim().length() == 0)
|
||||
order = null;
|
||||
// get additional filter property
|
||||
filter = props.getProperty (propName+".filter");
|
||||
if (filter != null && filter.trim().length() == 0)
|
||||
filter = null;
|
||||
// get max size of collection
|
||||
String max = props.getProperty (propName+".maxSize");
|
||||
if (max != null) try {
|
||||
maxSize = Integer.parseInt (max);
|
||||
} catch (NumberFormatException nfe) {
|
||||
maxSize = 0;
|
||||
}
|
||||
// get group by property
|
||||
groupby = props.getProperty (propName+".groupby");
|
||||
if (groupby != null && groupby.trim().length() == 0)
|
||||
groupby = null;
|
||||
if (groupby != null) {
|
||||
groupbyorder = props.getProperty (propName+".groupby.order");
|
||||
if (groupbyorder != null && groupbyorder.trim().length() == 0)
|
||||
groupbyorder = null;
|
||||
groupbyprototype = props.getProperty (propName+".groupby.prototype");
|
||||
if (groupbyprototype != null && groupbyprototype.trim().length() == 0)
|
||||
groupbyprototype = null;
|
||||
// aggressive loading and caching is not supported for groupby-nodes
|
||||
aggressiveLoading = aggressiveCaching = false;
|
||||
}
|
||||
// check if subnode condition should be applied for property relations
|
||||
if ("_properties".equalsIgnoreCase (propName) || virtual) {
|
||||
String subnodes2props = props.getProperty (propName+".aresubnodes");
|
||||
subnodesAreProperties = "true".equalsIgnoreCase (subnodes2props);
|
||||
if (virtual) {
|
||||
String subnodefilter = props.getProperty (propName+".subnoderelation");
|
||||
if (subnodefilter != null) {
|
||||
Constraint c = parseConstraint_v0 (subnodefilter);
|
||||
if (c != null) {
|
||||
cnst.add (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
// update virtual mapping, if it already exists
|
||||
if (virtualMapping != null) {
|
||||
virtualMapping.subnodesRel = getVirtualSubnodeRelation ();
|
||||
virtualMapping.propertiesRel = getVirtualPropertyRelation ();
|
||||
virtualMapping.lastTypeChange = ownType.lastTypeChange;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// parse methods for file format v1
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void update_v1 (String desc, Properties props) {
|
||||
public void update (String desc, Properties props) {
|
||||
Application app = ownType.getApplication ();
|
||||
if (desc == null || "".equals (desc.trim ())) {
|
||||
if (propName != null) {
|
||||
|
@ -344,7 +143,7 @@ public class Relation {
|
|||
if (reftype != PRIMITIVE && reftype != INVALID) {
|
||||
|
||||
Vector newConstraints = new Vector ();
|
||||
parseOptions_v1 (newConstraints, props);
|
||||
parseOptions (newConstraints, props);
|
||||
|
||||
constraints = new Constraint[newConstraints.size()];
|
||||
newConstraints.copyInto (constraints);
|
||||
|
@ -352,7 +151,7 @@ public class Relation {
|
|||
}
|
||||
|
||||
|
||||
protected void parseOptions_v1 (Vector cnst, Properties props) {
|
||||
protected void parseOptions (Vector cnst, Properties props) {
|
||||
String loading = props.getProperty (propName+".loadmode");
|
||||
aggressiveLoading = loading != null && "aggressive".equalsIgnoreCase (loading.trim());
|
||||
String caching = props.getProperty (propName+".cachemode");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue