Fixed case of misspelled datasource. This should now throw

an error when trying to get a connection instead of using the
internal db instead.
This commit is contained in:
hns 2001-08-01 00:10:19 +00:00
parent 7ef38c647c
commit 94e086dfd8

View file

@ -30,6 +30,8 @@ public class DbMapping implements Updatable {
// name of data source to which this mapping writes // name of data source to which this mapping writes
DbSource source; DbSource source;
// name of datasource
String sourceName;
// name of db table // name of db table
String table; String table;
@ -136,12 +138,12 @@ public class DbMapping implements Updatable {
// see if this prototype extends (inherits from) any other prototype // see if this prototype extends (inherits from) any other prototype
extendsProto = props.getProperty ("_extends"); extendsProto = props.getProperty ("_extends");
String sourceName = props.getProperty ("_datasource"); sourceName = props.getProperty ("_datasource");
if (sourceName != null) { if (sourceName != null) {
source = app.getDbSource (sourceName); source = app.getDbSource (sourceName);
if (source == null) { if (source == null) {
// what we really want to do here is mark the DbMapping as invalid, so no data can be saved to it. app.logEvent ("*** Data Source for prototype "+typename+" does not exist: "+sourceName);
throw new RuntimeException ("DbSource \""+sourceName+"\" not found for prototype "+typename); app.logEvent ("*** accessing or storing a "+typename+" object will cause an error.");
} }
} }
@ -244,8 +246,12 @@ public class DbMapping implements Updatable {
public Connection getConnection () throws ClassNotFoundException, SQLException { public Connection getConnection () throws ClassNotFoundException, SQLException {
if (source == null && parentMapping != null) if (source == null && parentMapping != null)
return parentMapping.getConnection (); return parentMapping.getConnection ();
if (source == null) if (source == null) {
throw new SQLException ("Tried to get Connection from non-relational embedded data source."); if (sourceName == null)
throw new SQLException ("Tried to get Connection from non-relational embedded data source.");
else
throw new SQLException ("Datasource is not defined: "+sourceName+".");
}
return source.getConnection (); return source.getConnection ();
} }
@ -425,10 +431,18 @@ public class DbMapping implements Updatable {
return app.getWrappedNodeManager (); return app.getWrappedNodeManager ();
} }
/**
* Tell whether this data mapping maps to a relational database table. This returns true
* if a datasource is specified, even if it is not a valid one. Otherwise, objects with invalid
* mappings would be stored in the embedded db instead of an error being thrown, which is
* not what we want.
*/
public boolean isRelational () { public boolean isRelational () {
if (source == null && parentMapping != null) if (sourceName != null)
return true;
if (parentMapping != null)
return parentMapping.isRelational (); return parentMapping.isRelational ();
return source != null; return false;
} }
/** /**