com.sri.emo.dbobj
Class Relation

java.lang.Object
  extended by com.jcorporate.expresso.core.dataobjects.BaseDataObject
      extended by com.jcorporate.expresso.core.dataobjects.jdbc.JDBCDataObject
          extended by com.jcorporate.expresso.core.dbobj.DBObject
              extended by com.jcorporate.expresso.core.dbobj.SecuredDBObject
                  extended by com.sri.emo.dbobj.Relation
All Implemented Interfaces:
Cacheable, ContextNested, DataObject, Securable, LookupInterface, IViewable, ModelVisitable, Serializable, Comparable

public class Relation
extends SecuredDBObject
implements Comparable, ModelVisitable, IViewable

Encapsulate a linkage between two nodes.

Relation should NOT be subclassed from RowSecuredDBObject because a relationship can be established in either direction, by either owning party, and if the source or destination node is removed, the relationship should be removed. In other words, the relationship should not be owned by anyone, so that it may be removed by either "owning" party.

Author:
larry hamel
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jcorporate.expresso.core.dbobj.DBObject
DBObject.FieldError, DBObject.FieldUpdate
 
Field Summary
static String RELATION_ANNOTATION
           
static String RELATION_CREATED
           
static String RELATION_DEST
           
static String RELATION_MODIFIED
           
static String RELATION_ORDER
           
static String RELATION_OWNER
           
static String RELATION_SRC
           
static String RELATION_TYPE
           
 
Fields inherited from class com.jcorporate.expresso.core.dbobj.SecuredDBObject
ADD, ALL_FUNCTIONS, CACHE_NAME, CACHE_TTY, DELETE, SEARCH, SYSTEM_ACCOUNT_NAME, UPDATE
 
Fields inherited from class com.jcorporate.expresso.core.dbobj.DBObject
ATTRIBUTE_ERROR, ATTRIBUTE_ERROR_MESSAGE, ATTRIBUTE_PAGE_LIMIT, BIG_DECIMAL_ZERO, CACHE_LIMIT_PERCENT, CACHE_LIMIT_TTL, EMAIL_MASK, EVENT_ADD, EVENT_DELETE, EVENT_UPDATE, FLOAT_MASK, INT_MASK, IS_CHECK_RELATIONAL_INTEGRITY, IS_MUTABLE, sCacheStats, UPDATE_CHANGED_ONLY, WHERE_KEYWORD
 
Fields inherited from class com.jcorporate.expresso.core.dataobjects.jdbc.JDBCDataObject
anyFieldsDistinct, anyFieldsToInput, anyFieldsToRetrieve, appendCustomWhere, caseSensitiveQuery, customWhereClause, dbKey, distinctFields, inputFields, localConnection, LONGBINARY_READ_DEFAULT_SIZE, maxRecords, myClassName, myUpdates, offsetRecord, recordSet, retrieveFields, sMetadataMap, sortKeys
 
Fields inherited from class com.jcorporate.expresso.core.dataobjects.BaseDataObject
currentStatus, globalMask
 
Fields inherited from interface com.jcorporate.expresso.core.dataobjects.Securable
SYSTEM_ACCOUNT
 
Fields inherited from interface com.jcorporate.expresso.core.dataobjects.DataObject
STATUS_CURRENT, STATUS_DELETED, STATUS_NEW, STATUS_UPDATED
 
Constructor Summary
Relation()
          Default constructor for Relation creates a new object of this type with no connection yet allocated.
Relation(ControllerRequest request)
          Deprecated. Use RequestRegistry to propage these parameters instead.
Relation(DBConnection theConnection)
          Constructor
Relation(DBConnection theConnection, int theUser)
          Constructor
Relation(ReadOnlyUser userSecurity)
          Constructor for security setup.
Relation(SecuredDBObject obj)
           
 
Method Summary
 void acceptVisitor(ModelVisitor visitor)
          Accepts the visitor and redirects the visitor to the appropriate type we're dealing with.
 void add()
          handle inverse too
 Relation clone(String cloneNodeId, String fieldname)
          Deep copy fields.
 Relation clone(String cloneNodeId, String fieldname, String relType)
          Deep copy fields.
 int compareTo(Object o)
          Compares this object with the specified object for order.
 void delete(boolean deleteDetails)
          Handle inverse too.
 String getDestId()
           
 Node getDestNode()
           
 String getOrder()
           
 int getOrderInt()
           
 String getRelationTypeName()
           
 String getSrcId()
           
 Node getSrcNode()
           
 RelationType getType()
           
 Transition getViewTrans()
          This version assumes that we're looking at the node that is the source node since we don't have enough information to choose otherwise.
 boolean isReflexive()
           
 boolean isStrong()
           
 boolean isUpstreamLink(String srcOrDest)
           
 void setDestId(String id)
           
 void setOrder(int order)
           
 void setOrder(String order)
           
 void setRelationTypeName(String relationType)
           
 void setSrcId(String id)
           
protected  void setupFields()
          Defines the database table name and fields for this DB object
 void update()
          we override to handle case where relation type is manipulated.
 void updateOrder()
          normal update is disallowed, but update JUST for order is ok since we are not updating primary key that way
 
Methods inherited from class com.jcorporate.expresso.core.dbobj.SecuredDBObject
canRequesterAdd, canRequesterDelete, canRequesterRead, canRequesterUpdate, checkAllowed, copyAttributes, count, createSecurityCache, delete, deleteAll, find, getRequestingUid, getRequestingUser, getString, getString, getString, getString, getString, getString, getSystemUid, instantiate, isAllowed, retrieve, search, searchAndRetrieveList, searchAndRetrieveList, setRequestingUid, setRequestingUser
 
Methods inherited from class com.jcorporate.expresso.core.dbobj.DBObject
addDetail, addField, addField, addFieldError, addFoundKeys, addIfNeeded, addIndex, addKey, addMaster, addOrUpdate, addSortKey, addTransition, addVirtualField, addVirtualField, addVirtualField, addVirtualField, average, basicAdd, cacheIsChangedComparison, canUseRetrieve, checkAllReferredToBy, checkAllRefs, checkAllRefsPublic, checkDeleteDetailPerm, checkField, checkMutable, checkRef, checkRef, clear, clearDistinctFields, clearError, clearFieldsToInput, clearFieldsToRetrieve, clearSortKeys, clone, containsWildCards, copyAllFields, deleteAll, deleteDetails, denotesRange, equals, fetchImmut, fetchImmutable, forKey, formatDateTime, get, getAllAttributes, getAttribute, getAttributesIterator, getBooleanFieldValue, getCacheSize, getCacheStatsMap, getCacheUtil, getCheckZeroUpdate, getCustomWhereClause, getDataContext, getDataField, getDataTransferObject, getDBName, getDetails, getDistinctFieldCount, getDistinctFields, getField, getFieldAttributesIterator, getFieldBigDecimal, getFieldBoolean, getFieldByte, getFieldByteArray, getFieldData, getFieldDate, getFieldDecimalFormatted, getFieldDouble, getFieldErrorMessage, getFieldFloat, getFieldInt, getFieldLong, getFieldMetaData, getFieldShort, getFieldsToInputCount, getFieldsToRetrieveCount, getFilterClass, getFoundCount, getFoundKeysArray, getIndexArray, getISOValuesDefault, getISOValuesDefault, getISOValuesDefault, getKey, getKeyFieldListIterator, getLength, getLengthInt, getLocale, getLogger, getLookupObject, getMax, getMax, getMaxRecords, getMyKeys, getMyUpdatesArray, getOffsetRecord, getPatternMatcher, getPrecision, getSerializedForm, getSizeEstimate, getStringFilter, getThisDBbj, getThisDBObj, getValidValueDescrip, getValidValues, getValidValuesList, getValues, getValuesDefault, getValuesDefault, getValuesDefault, hasError, hasErrors, haveAllKeys, initialize, isCached, isChanged, isDistinct, isEmpty, isFieldDistinct, isFieldNull, isFieldsToInput, isFieldsToRetrieve, isFieldToRetrieve, isMultiValued, isMutable, isMutable, isReadOnly, isSecret, isVirtual, loadFromConnection, logChange, max, min, newInstance, noNewLine, noQuotes, notifyListeners, populateDefaultValues, referredToBy, removeAttribute, removeFromCache, retrieveFromCache, saveBinaryField, search, set, setAttribute, setCacheLimit, setCacheLimit, setCacheLimitAsPercent, setCacheSize, setCharset, setCheckZeroUpdate, setConnection, setConnection, setCustomWhereClause, setCustomWhereClause, setDataContext, setDataField, setDataTransferObject, setDefaultValue, setDescription, setField, setField, setField, setField, setField, setField, setField, setField, setField, setField, setFieldData, setFieldData, setFieldDistinct, setFieldsToInput, setFieldsToRetrieve, setFilterClass, setFilterClass, setKey, setKeys, setLocale, setLookupField, setLookupObject, setMask, setMaxRecords, setMultiValued, setName, setOffsetRecord, setReadOnly, setSchema, setSecret, setSortKey, setStringFilter, setStringFiltersOnAll, setTargetDbSchema, setTargetTable, sqlAggrFunction, sum, toDebugString, update, updateAll, updateAll, updateIsChanged, verify
 
Methods inherited from class com.jcorporate.expresso.core.dataobjects.jdbc.JDBCDataObject
addInParam, addOutParam, buildWhereClause, buildWhereClauseBuffer, checkZeroUpdate, constructNewMetaData, createAndExecuteSearch, createAndRunStoreProcedure, createSQLSelectStatement, createSQLSelectStatement, getConnectionPool, getCustomStringFieldValue, getDef, getDistinctFieldArrayList, getExecutor, getFieldsToInputIterator, getFieldsToRetrieveIterator, getJDBCMetaData, getJDBCUtil, getLocalConnection, getMappedDataContext, getMetaData, getQueryInterface, getSerialForm, loadFromConnection, makeLimitationStub, quoteIfNeeded, runStoredProcedure, runStoredProcedureAndRetrieveList, selectFieldString, setCaseSensitiveQuery, setDBConnectionPool, setDBName, setMappedDataContext, setOriginalDBName, setTargetStoreProcedure
 
Methods inherited from class com.jcorporate.expresso.core.dataobjects.BaseDataObject
getGlobalMask, getStatus, isGlobalMasked, setFieldsWithDefaults, setGlobalMask, setStatus
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RELATION_SRC

public static final String RELATION_SRC
See Also:
Constant Field Values

RELATION_DEST

public static final String RELATION_DEST
See Also:
Constant Field Values

RELATION_TYPE

public static final String RELATION_TYPE
See Also:
Constant Field Values

RELATION_ANNOTATION

public static final String RELATION_ANNOTATION
See Also:
Constant Field Values

RELATION_OWNER

public static final String RELATION_OWNER
See Also:
Constant Field Values

RELATION_CREATED

public static final String RELATION_CREATED
See Also:
Constant Field Values

RELATION_MODIFIED

public static final String RELATION_MODIFIED
See Also:
Constant Field Values

RELATION_ORDER

public static final String RELATION_ORDER
See Also:
Constant Field Values
Constructor Detail

Relation

public Relation()
         throws DBException
Default constructor for Relation creates a new object of this type with no connection yet allocated.

Throws:
DBException - If the new object cannot be created

Relation

public Relation(DBConnection theConnection)
         throws DBException
Constructor

Parameters:
theConnection - Database connection to communicate with the database
Throws:
DBException - If the new object cannot be created

Relation

public Relation(DBConnection theConnection,
                int theUser)
         throws DBException
Constructor

Parameters:
theConnection - DBConnection to be used to communicate with the database
theUser - User name attempting to access the object
Throws:
DBException - If the user cannot access this object or the object cannot be initialized

Relation

public Relation(ControllerRequest request)
         throws DBException
Deprecated. Use RequestRegistry to propage these parameters instead.

Constructor.

Parameters:
request - ControllerRequest
Throws:
DBException

Relation

public Relation(ReadOnlyUser userSecurity)
         throws DBException
Constructor for security setup.

Parameters:
userSecurity - ReadOnlyUser security context.
Throws:
DBException - upon construction error.

Relation

public Relation(SecuredDBObject obj)
         throws DBException
Throws:
DBException
Method Detail

setupFields

protected void setupFields()
                    throws DBException
Defines the database table name and fields for this DB object

Overrides:
setupFields in class DBObject
Throws:
DBException - if the operation cannot be performed

clone

public Relation clone(String cloneNodeId,
                      String fieldname)
               throws DBException
Deep copy fields.

Parameters:
cloneNodeId - the id of the node being cloned
fieldname - within this Relation object, the name of the Relation field (RELATION_SRC or RELATION_DEST) which the cloned node occupies; in other words, clone the other field, replace this field
Returns:
a cloned relation.
Throws:
DBException - upon database error.

clone

public Relation clone(String cloneNodeId,
                      String fieldname,
                      String relType)
               throws DBException
Deep copy fields.

Parameters:
cloneNodeId - the id of the node being cloned
fieldname - within this Relation object, the name of the Relation field (RELATION_SRC or RELATION_DEST) which the cloned node occupies; in other words, clone the other field, replace this field
relType - The relationship type.
Returns:
a cloned relation.
Throws:
DBException - upon database error.

setSrcId

public void setSrcId(String id)
              throws DBException
Throws:
DBException

setDestId

public void setDestId(String id)
               throws DBException
Throws:
DBException

getRelationTypeName

public String getRelationTypeName()
                           throws DBException
Throws:
DBException

setRelationTypeName

public void setRelationTypeName(String relationType)
                         throws DBException
Throws:
DBException

getDestId

public String getDestId()
                 throws DBException
Throws:
DBException

getSrcId

public String getSrcId()
                throws DBException
Throws:
DBException

getSrcNode

public Node getSrcNode()
                throws DBException
Throws:
DBException

add

public void add()
         throws DBException
handle inverse too

Specified by:
add in interface DataObject
Overrides:
add in class SecuredDBObject
Throws:
DBException - If the user is not permitted to add or if the add fails

updateOrder

public void updateOrder()
                 throws DBException
normal update is disallowed, but update JUST for order is ok since we are not updating primary key that way

Throws:
DBException - if the update to the database fails due to a database error

isReflexive

public boolean isReflexive()
                    throws DBException
Throws:
DBException

getType

public RelationType getType()
                     throws DBException
Throws:
DBException

delete

public void delete(boolean deleteDetails)
            throws DBException
Handle inverse too.

Overrides:
delete in class DBObject
Parameters:
deleteDetails - true if detail fields should be deteled as well.
Throws:
DBException - if delete is not allowed for the current user

update

public void update()
            throws DBException
we override to handle case where relation type is manipulated. easier to delete and add;

Specified by:
update in interface DataObject
Overrides:
update in class SecuredDBObject
Throws:
DBException - because this operation disallowed, in favor of delete() + add()

getDestNode

public Node getDestNode()
                 throws DBException
Throws:
DBException

isUpstreamLink

public boolean isUpstreamLink(String srcOrDest)
                       throws DBException
Parameters:
srcOrDest - use either Relation.RELATION_DEST or Relation.RELATION_SRC to indicate what kind of containment relation (there are 2 relations that are inverses)
Returns:
true if this relation is a 'containership' type relation, and our node is contained by this relation;
Throws:
DBException - upon database error.

compareTo

public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

In the foregoing description, the notation sgn(expression) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this Object.

getOrderInt

public int getOrderInt()
                throws DBException
Throws:
DBException

setOrder

public void setOrder(String order)
              throws DBException
Throws:
DBException

setOrder

public void setOrder(int order)
              throws DBException
Throws:
DBException

getOrder

public String getOrder()
                throws DBException
Throws:
DBException

getViewTrans

public Transition getViewTrans()
                        throws DBException
This version assumes that we're looking at the node that is the source node since we don't have enough information to choose otherwise.

Specified by:
getViewTrans in interface IViewable
Returns:
transtion for viewing, including label for name of object; never null
Throws:
DBException - if src or dest IDs not found
To Do:
Test me

acceptVisitor

public void acceptVisitor(ModelVisitor visitor)
Description copied from interface: ModelVisitable
Accepts the visitor and redirects the visitor to the appropriate type we're dealing with.

Specified by:
acceptVisitor in interface ModelVisitable
Parameters:
visitor - ViewVisitor

isStrong

public boolean isStrong()
                 throws DBException
Throws:
DBException


Copyright © 2004-2006 Codeguild, Inc.. All Rights Reserved.