made localField and remoteField protected

This commit is contained in:
hns 2001-01-25 20:56:47 +00:00
parent 46a17c3028
commit d807e4a340

View file

@ -23,7 +23,7 @@ public class Relation {
public DbMapping home; public DbMapping home;
public DbMapping other; public DbMapping other;
public String propname; public String propname;
public String localField, remoteField; protected String localField, remoteField;
public int direction; public int direction;
public boolean virtual; public boolean virtual;
@ -164,8 +164,11 @@ public class Relation {
} }
public boolean usesPrimaryKey () { public boolean usesPrimaryKey () {
if (remoteField == null || other == null) if (other == null)
return false; return false;
if (remoteField == null)
// if remote field is null, it is assumed that it points to the primary key
return true;
return remoteField.equalsIgnoreCase (other.getIDField()); return remoteField.equalsIgnoreCase (other.getIDField());
} }
@ -192,19 +195,30 @@ public class Relation {
} }
/** /**
* Get the local column name for this relation. Uses the home node's id as fallback if local field is not specified. * Get the local column name for this relation to use in where clauses of select statements.
* This uses the home node's id as fallback if local field is not specified.
*/ */
public String getLocalField () { public String getLocalField () {
if (localField == null) // only assume local field is primary key if other objects "point" to this object
if (localField == null && direction == BACKWARD)
return home.getIDField (); return home.getIDField ();
return localField; return localField;
} }
/**
* Return the local field name for updates. This is the same as getLocalField, but does not return the
* primary key name as a fallback.
*/
public String getDbField () {
return localField;
}
/** /**
* Get the "remote" column name for this relation. Uses the remote node's id as fallback if the remote field is not specified. * Get the "remote" column name for this relation. Uses the remote node's id as fallback if the remote field is not specified.
*/ */
public String getRemoteField () { public String getRemoteField () {
if (remoteField == null) // only assume remote field is primary key if this relation "points" to an object
if (remoteField == null && direction == FORWARD)
return other.getIDField (); return other.getIDField ();
return remoteField; return remoteField;
} }