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,23 +122,23 @@ 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 ();
if (!propName.startsWith ("_") && propName.indexOf (".") < 0) { try {
String dbField = props.getProperty (propName); if (!propName.startsWith ("_") && propName.indexOf (".") < 0) {
Relation rel = new Relation (dbField, propName, this, props); String dbField = props.getProperty (propName);
p2d.put (propName, rel); Relation rel = new Relation (dbField, propName, this, props);
if (rel.localField != null) p2d.put (propName, rel);
d2p.put (rel.localField, rel); if (rel.localField != null)
// IServer.getLogger().log ("Mapping "+propName+" -> "+dbField); d2p.put (rel.localField, rel);
// 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,28 +161,38 @@ public class DbMapping {
String subnodeMapping = props.getProperty ("_subnodes"); String subnodeMapping = props.getProperty ("_subnodes");
if (subnodeMapping != null) { if (subnodeMapping != null) {
subnodesRel = new Relation (subnodeMapping, "_subnodes", this, props); try {
if (subnodesRel.isReference ()) subnodesRel = new Relation (subnodeMapping, "_subnodes", this, props);
subnodes = subnodesRel.other; if (subnodesRel.isReference ())
else subnodes = subnodesRel.other;
subnodes = (DbMapping) app.getDbMapping (subnodeMapping); else
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) {
propertiesRel = new Relation (propertiesMapping, "_properties", this, props); try {
if (propertiesRel.isReference ()) propertiesRel = new Relation (propertiesMapping, "_properties", this, props);
properties = propertiesRel.other; if (propertiesRel.isReference ())
else properties = propertiesRel.other;
properties = (DbMapping) app.getDbMapping (propertiesMapping); else
// take over groupby flag from subnodes, if properties are subnodes properties = (DbMapping) app.getDbMapping (propertiesMapping);
if (propertiesRel.subnodesAreProperties && subnodesRel != null) // take over groupby flag from subnodes, if properties are subnodes
propertiesRel.groupby = subnodesRel.groupby; if (propertiesRel.subnodesAreProperties && subnodesRel != null)
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);
} }