Null out tableName and dbSource if they are inherited from parent mapping.

Make sure we always use parent mapping in get/setLastDataChange() and
getNewID() if table and dbsource are inherited.
This commit is contained in:
hns 2004-06-09 15:42:34 +00:00
parent 1b223aef93
commit b201bf8f35

View file

@ -218,8 +218,21 @@ public final class DbMapping implements Updatable {
if (extendsProto != null) { if (extendsProto != null) {
parentMapping = app.getDbMapping(extendsProto); parentMapping = app.getDbMapping(extendsProto);
if (parentMapping != null && parentMapping.needsUpdate()) { if (parentMapping != null) {
parentMapping.update(); if (parentMapping.needsUpdate()) {
parentMapping.update();
}
// if tableName or DbSource are inherited from the parent mapping
// set them to null so we are aware of the fact.
if (tableName != null &&
tableName.equals(parentMapping.getTableName())) {
tableName = null;
}
if (dbSourceName != null &&
dbSourceName.equals(parentMapping.getDbSourceName())) {
dbSourceName = null;
dbSource = null;
}
} }
} else { } else {
parentMapping = null; parentMapping = null;
@ -392,6 +405,17 @@ public final class DbMapping implements Updatable {
return dbSource; return dbSource;
} }
/**
* Get the dbsource name used for this type mapping.
*/
public String getDbSourceName() {
if ((dbSourceName == null) && (parentMapping != null)) {
return parentMapping.getDbSourceName();
}
return dbSourceName;
}
/** /**
* Get the table name used for this type mapping. * Get the table name used for this type mapping.
*/ */
@ -1150,18 +1174,23 @@ public final class DbMapping implements Updatable {
* @return ... * @return ...
*/ */
public long getLastDataChange() { public long getLastDataChange() {
return lastDataChange; // refer to parent mapping if it uses the same db/table
if (inheritsStorage()) {
return parentMapping.getLastDataChange();
} else {
return lastDataChange;
}
} }
/** /**
* *
*/ */
public void setLastDataChange(long t) { public void setLastDataChange(long t) {
lastDataChange = t; // propagate data change timestamp to storage-compatible parent mapping
if (inheritsStorage()) {
// propagate data change timestamp to parent mapping
if ((parentMapping != null) && (dbSource == null)) {
parentMapping.setLastDataChange(t); parentMapping.setLastDataChange(t);
} else {
lastDataChange = t;
} }
} }
@ -1173,13 +1202,13 @@ public final class DbMapping implements Updatable {
* @return ... * @return ...
*/ */
public synchronized long getNewID(long dbmax) { public synchronized long getNewID(long dbmax) {
if ((parentMapping != null) && (dbSource == null)) { // refer to parent mapping if it uses the same db/table
if (inheritsStorage()) {
return parentMapping.getNewID(dbmax); return parentMapping.getNewID(dbmax);
} else {
lastID = Math.max(dbmax + 1, lastID + 1);
return lastID;
} }
lastID = Math.max(dbmax + 1, lastID + 1);
return lastID;
} }
/** /**
@ -1229,6 +1258,24 @@ public final class DbMapping implements Updatable {
return (dbSourceName == null) ? null : typename; return (dbSourceName == null) ? null : typename;
} }
/**
* Check whether this DbMapping inherits its storage location from its
* parent mapping. The raison d'etre for this is that we need to detect
* inherited storage even if the dbsource and table are explicitly set
* in the extended mapping.
*
* @return true if this mapping shares its parent mapping storage
*/
private boolean inheritsStorage() {
// note: tableName and dbSourceName are nulled out in update() if they
// are inherited from the parent mapping. This way we know that
// storage is not inherited if either of them is not null.
if (parentMapping == null || tableName != null || dbSourceName != null) {
return false;
}
return true;
}
/** /**
* Tell if another DbMapping is storage-compatible to this one, i.e. it is stored in the same table or * Tell if another DbMapping is storage-compatible to this one, i.e. it is stored in the same table or
* embedded database. * embedded database.