put all the Relation constructors in try{}catch blocks.

This commit is contained in:
hns 2001-02-08 20:58:28 +00:00
parent cfad0969b9
commit 9c91767abc

View file

@ -79,6 +79,8 @@ public class DbMapping {
/** /**
* Read the mapping from the Properties. Return true if the properties were changed. * Read the mapping from the Properties. Return true if the properties were changed.
* The read is split in two, this method and the rewire method. The reason is that in order
* for rewire to work, all other db mappings must have been initialized and registered.
*/ */
public synchronized boolean read () { public synchronized boolean read () {
@ -91,6 +93,14 @@ public class DbMapping {
String sourceName = props.getProperty ("_datasource"); String sourceName = props.getProperty ("_datasource");
if (sourceName != null) if (sourceName != null)
source = (DbSource) IServer.dbSources.get (sourceName.toLowerCase ()); source = (DbSource) IServer.dbSources.get (sourceName.toLowerCase ());
idField = props.getProperty ("_id");
// id field must not be null
if (idField == null)
idField = "id";
nameField = props.getProperty ("_name");
lastTypeChange = lastmod; lastTypeChange = lastmod;
// set the cached schema & keydef to null so it's rebuilt the next time around // set the cached schema & keydef to null so it's rebuilt the next time around
schema = null; schema = null;
@ -98,6 +108,10 @@ public class DbMapping {
return true; return true;
} }
/**
* This is the second part of the property reading process, called after the first part has been
* completed on all other mappings in this application
*/
public synchronized void rewire () { public synchronized void rewire () {
// if (table != null && source != null) { // if (table != null && source != null) {
@ -108,6 +122,7 @@ public class DbMapping {
for (Enumeration e=props.keys(); e.hasMoreElements(); ) { for (Enumeration e=props.keys(); e.hasMoreElements(); ) {
String propName = (String) e.nextElement (); String propName = (String) e.nextElement ();
try {
if (!propName.startsWith ("_") && propName.indexOf (".") < 0) { if (!propName.startsWith ("_") && propName.indexOf (".") < 0) {
String dbField = props.getProperty (propName); String dbField = props.getProperty (propName);
Relation rel = new Relation (dbField, propName, this, props); Relation rel = new Relation (dbField, propName, this, props);
@ -115,16 +130,15 @@ public class DbMapping {
if (rel.localField != null) if (rel.localField != null)
d2p.put (rel.localField, rel); d2p.put (rel.localField, rel);
// IServer.getLogger().log ("Mapping "+propName+" -> "+dbField); // IServer.getLogger().log ("Mapping "+propName+" -> "+dbField);
}
} catch (Exception x) {
IServer.getLogger ().log ("Error in type.properties: "+x.getMessage ());
}
}
}
}
prop2db = p2d; prop2db = p2d;
db2prop = d2p; db2prop = d2p;
idField = props.getProperty ("_id");
nameField = props.getProperty ("_name");
String ano = props.getProperty ("_anonymous"); String ano = props.getProperty ("_anonymous");
if (ano != null) { if (ano != null) {
// comma-separated list of true/false values // comma-separated list of true/false values
@ -147,16 +161,22 @@ public class DbMapping {
String subnodeMapping = props.getProperty ("_subnodes"); String subnodeMapping = props.getProperty ("_subnodes");
if (subnodeMapping != null) { if (subnodeMapping != null) {
try {
subnodesRel = new Relation (subnodeMapping, "_subnodes", this, props); subnodesRel = new Relation (subnodeMapping, "_subnodes", this, props);
if (subnodesRel.isReference ()) if (subnodesRel.isReference ())
subnodes = subnodesRel.other; subnodes = subnodesRel.other;
else else
subnodes = (DbMapping) app.getDbMapping (subnodeMapping); subnodes = (DbMapping) app.getDbMapping (subnodeMapping);
} catch (Exception x) {
IServer.getLogger ().log ("Error in type.properties: "+x.getMessage ());
subnodesRel = null;
}
} else } else
subnodesRel = null; subnodesRel = null;
String propertiesMapping = props.getProperty ("_properties"); String propertiesMapping = props.getProperty ("_properties");
if (propertiesMapping != null) { if (propertiesMapping != null) {
try {
propertiesRel = new Relation (propertiesMapping, "_properties", this, props); propertiesRel = new Relation (propertiesMapping, "_properties", this, props);
if (propertiesRel.isReference ()) if (propertiesRel.isReference ())
properties = propertiesRel.other; properties = propertiesRel.other;
@ -165,10 +185,14 @@ public class DbMapping {
// take over groupby flag from subnodes, if properties are subnodes // take over groupby flag from subnodes, if properties are subnodes
if (propertiesRel.subnodesAreProperties && subnodesRel != null) if (propertiesRel.subnodesAreProperties && subnodesRel != null)
propertiesRel.groupby = subnodesRel.groupby; propertiesRel.groupby = subnodesRel.groupby;
} catch (Exception x) {
IServer.getLogger ().log ("Error in type.properties: "+x.getMessage ());
propertiesRel = null;
}
} else } else
propertiesRel = null; propertiesRel = null;
IServer.getLogger().log ("rewiring: "+parent+" -> "+this+" -> "+subnodes); IServer.getLogger().log ("rewiring: "+this);
} }