Work on type.properties v. 1.2 support.

This commit is contained in:
hns 2002-03-06 15:01:15 +00:00
parent 5cf87fab38
commit c9b927af09

View file

@ -137,19 +137,19 @@ public class Relation {
} }
// parse the basic properties of this mapping // parse the basic properties of this mapping
parseMapping (desc, mountpoint); parseMapping_v0 (desc, mountpoint);
// the following options only apply to object relations // the following options only apply to object relations
if (reftype != PRIMITIVE && reftype != INVALID) { if (reftype != PRIMITIVE && reftype != INVALID) {
cnst = new Vector (); cnst = new Vector ();
Constraint c = parseConstraint (desc); Constraint c = parseConstraint_v0 (desc);
if (c != null) if (c != null)
cnst.add (c); cnst.add (c);
parseOptions (cnst, props); parseOptions_v0 (cnst, props);
constraints = new Constraint[cnst.size()]; constraints = new Constraint[cnst.size()];
cnst.copyInto (constraints); cnst.copyInto (constraints);
@ -164,7 +164,7 @@ public class Relation {
* Parse a line describing a mapping of a property field. If the mapping is a * 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. * object reference of a collection of objects, put any constraints in the Vector.
*/ */
protected void parseMapping (String desc, boolean mountpoint) { protected void parseMapping_v0 (String desc, boolean mountpoint) {
Application app = ownType.getApplication (); Application app = ownType.getApplication ();
@ -222,7 +222,7 @@ public class Relation {
* Parse a line describing a mapping of a property field. If the mapping is a * 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. * object reference of a collection of objects, put any constraints in the Vector.
*/ */
protected Constraint parseConstraint (String desc) { protected Constraint parseConstraint_v0 (String desc) {
if (desc.indexOf ("<") > -1) { if (desc.indexOf ("<") > -1) {
int lt = desc.indexOf ("<"); int lt = desc.indexOf ("<");
int dot = desc.indexOf ("."); int dot = desc.indexOf (".");
@ -239,7 +239,7 @@ public class Relation {
return null; return null;
} }
protected void parseOptions (Vector cnst, Properties props) { protected void parseOptions_v0 (Vector cnst, Properties props) {
String loading = props.getProperty (propName+".loadmode"); String loading = props.getProperty (propName+".loadmode");
aggressiveLoading = loading != null && "aggressive".equalsIgnoreCase (loading.trim()); aggressiveLoading = loading != null && "aggressive".equalsIgnoreCase (loading.trim());
String caching = props.getProperty (propName+".cachemode"); String caching = props.getProperty (propName+".cachemode");
@ -280,7 +280,7 @@ public class Relation {
if (virtual) { if (virtual) {
String subnodefilter = props.getProperty (propName+".subnoderelation"); String subnodefilter = props.getProperty (propName+".subnoderelation");
if (subnodefilter != null) { if (subnodefilter != null) {
Constraint c = parseConstraint (subnodefilter); Constraint c = parseConstraint_v0 (subnodefilter);
if (c != null) { if (c != null) {
cnst.add (c); cnst.add (c);
} }
@ -296,7 +296,7 @@ public class Relation {
} }
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
// parse methods for file format v0 // parse methods for file format v1
//////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////
private void update_v1 (String desc, Properties props) { private void update_v1 (String desc, Properties props) {
@ -314,11 +314,8 @@ public class Relation {
} else { } else {
desc = desc.trim (); desc = desc.trim ();
String descLower = desc.toLowerCase (); String descLower = desc.toLowerCase ();
if (descLower.startsWith ("[virtual]")) { if (descLower.startsWith ("collection")) {
desc = desc.substring (9).trim (); desc = desc.substring (10).trim ();
virtual = true;
} else if (descLower.startsWith ("[collection]")) {
desc = desc.substring (12).trim ();
virtual = true; virtual = true;
} else if (descLower.startsWith ("[mountpoint]")) { } else if (descLower.startsWith ("[mountpoint]")) {
desc = desc.substring (12).trim (); desc = desc.substring (12).trim ();
@ -336,19 +333,19 @@ public class Relation {
} }
// parse the basic properties of this mapping // parse the basic properties of this mapping
parseMapping (desc, mountpoint); parseMapping_v1 (desc, mountpoint);
// the following options only apply to object relations // the following options only apply to object relations
if (reftype != PRIMITIVE && reftype != INVALID) { if (reftype != PRIMITIVE && reftype != INVALID) {
cnst = new Vector (); cnst = new Vector ();
Constraint c = parseConstraint (desc); Constraint c = parseConstraint_v1 (desc);
if (c != null) if (c != null)
cnst.add (c); cnst.add (c);
parseOptions (cnst, props); parseOptions_v1 (cnst, props);
constraints = new Constraint[cnst.size()]; constraints = new Constraint[cnst.size()];
cnst.copyInto (constraints); cnst.copyInto (constraints);
@ -359,6 +356,142 @@ public class Relation {
} }
} }
/**
* 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_v1 (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_v1 (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_v1 (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_v1 (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;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
/** /**