From c9b927af09572b7429b6de4ffe8b2ade178b7a53 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 6 Mar 2002 15:01:15 +0000 Subject: [PATCH] Work on type.properties v. 1.2 support. --- src/helma/objectmodel/db/Relation.java | 165 ++++++++++++++++++++++--- 1 file changed, 149 insertions(+), 16 deletions(-) diff --git a/src/helma/objectmodel/db/Relation.java b/src/helma/objectmodel/db/Relation.java index 94d3a541..c916ae95 100644 --- a/src/helma/objectmodel/db/Relation.java +++ b/src/helma/objectmodel/db/Relation.java @@ -137,19 +137,19 @@ public class Relation { } // parse the basic properties of this mapping - parseMapping (desc, mountpoint); + parseMapping_v0 (desc, mountpoint); // the following options only apply to object relations if (reftype != PRIMITIVE && reftype != INVALID) { cnst = new Vector (); - Constraint c = parseConstraint (desc); + Constraint c = parseConstraint_v0 (desc); if (c != null) cnst.add (c); - parseOptions (cnst, props); + parseOptions_v0 (cnst, props); constraints = new Constraint[cnst.size()]; 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 * 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 (); @@ -222,7 +222,7 @@ 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 Constraint parseConstraint (String desc) { + protected Constraint parseConstraint_v0 (String desc) { if (desc.indexOf ("<") > -1) { int lt = desc.indexOf ("<"); int dot = desc.indexOf ("."); @@ -239,7 +239,7 @@ public class Relation { return null; } - protected void parseOptions (Vector cnst, Properties props) { + 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"); @@ -280,7 +280,7 @@ public class Relation { if (virtual) { String subnodefilter = props.getProperty (propName+".subnoderelation"); if (subnodefilter != null) { - Constraint c = parseConstraint (subnodefilter); + Constraint c = parseConstraint_v0 (subnodefilter); if (c != null) { 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) { @@ -314,11 +314,8 @@ public class Relation { } 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 (); + if (descLower.startsWith ("collection")) { + desc = desc.substring (10).trim (); virtual = true; } else if (descLower.startsWith ("[mountpoint]")) { desc = desc.substring (12).trim (); @@ -336,19 +333,19 @@ public class Relation { } // parse the basic properties of this mapping - parseMapping (desc, mountpoint); + parseMapping_v1 (desc, mountpoint); // the following options only apply to object relations if (reftype != PRIMITIVE && reftype != INVALID) { cnst = new Vector (); - Constraint c = parseConstraint (desc); + Constraint c = parseConstraint_v1 (desc); if (c != null) cnst.add (c); - parseOptions (cnst, props); + parseOptions_v1 (cnst, props); constraints = new Constraint[cnst.size()]; 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; + } + } + } + + /////////////////////////////////////////////////////////////////////////////////////////// /**