net.datacrow.core.objects
Class DcObject

java.lang.Object
  extended by net.datacrow.core.objects.DcObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<DcObject>
Direct Known Subclasses:
ContactPerson, Container, DcAssociate, DcMapping, DcMediaObject, DcProperty, DcTemplate, ExternalReference, Item, Loan, Permission, Picture, User

public class DcObject
extends java.lang.Object
implements java.lang.Comparable<DcObject>, java.io.Serializable

This class is what it is all about. Each DcObject represents an item within Data Crow. DcObjects are very generic by nature. There are no direct getters and setters for their values. Instead the values are stored in a Map object and the values are retrieved by using the field indices.
It's recommended before starting new development of plugins to create so called helper classes for your new module. Examples of helper classes are Software and Movie.
DcObjects are managed and maintained by the Data Manager class (DataManager. Each DcObject belongs to a (@link DcModule).

Author:
Robert Jan van der Waals
See Also:
Serialized Form

Field Summary
static int _ID
           
static int _SYS_AVAILABLE
           
static int _SYS_CONTAINER
           
static int _SYS_CREATED
           
static int _SYS_DISPLAYVALUE
           
static int _SYS_EXTERNAL_REFERENCES
           
static int _SYS_FILEHASH
           
static int _SYS_FILEHASHTYPE
           
static int _SYS_FILENAME
           
static int _SYS_FILESIZE
           
static int _SYS_LENDBY
           
static int _SYS_LOANDAYSTILLOVERDUE
           
static int _SYS_LOANDUEDATE
           
static int _SYS_LOANDURATION
           
static int _SYS_MODIFIED
           
static int _SYS_MODULE
           
static int _SYS_SERVICE
           
static int _SYS_SERVICEURL
           
static int _VALUE
           
protected  java.util.Collection<DcObject> children
           
 
Constructor Summary
DcObject(int module)
          Creates a new instance.
 
Method Summary
 void addChild(DcObject child)
           
 void addExternalReference(java.lang.String type, java.lang.String key)
          Adds or updates the existing external key of the specified type.
 void addRequest(IRequest request)
          Add a request.
 void applyEnhancers(boolean update)
          Applies the enhancers on this item.
 void applyTemplate()
           
 void applyTemplate(DcTemplate template)
           
protected  void beforeDelete()
           
protected  void beforeSave()
          Actions to be performed before saving the object.
 void checkIntegrity()
          Checks the integrity of the item.
 void clearValues()
          Resets this item.
 DcObject clone()
          Clones this objects.
 int compareTo(DcObject o)
           
 void copy(DcObject dco, boolean overwrite, boolean allowDeletes)
          Copies all values from the specified Data Crow object.
 void copyImage(Picture picture, int field)
          Copy an existing picture and set it on this item.
 DcImageIcon createIcon()
          The icon used to represent this item.
 void delete(boolean validate)
          Permanently deletes the item.
 void destroy()
           
 boolean equals(java.lang.Object o)
           
protected  void executeRequests(boolean saveSuccessful)
           
protected  void finalize()
           
 void flushImages()
          Frees the resources hold by this items pictures.
 java.util.List<DcObject> getChildren()
          Retrieves the child objects belonging to this item.
 java.util.List<DcObject> getCurrentChildren()
          Gets the children as they have been currently set (without reloading them).
 int getDatabaseFieldCount()
          Retrieves the database column count.
 java.lang.String getDatabaseFieldName(int index)
          Retrieves the database column name.
 int getDefaultSortFieldIdx()
          The default sort field index.
 int getDisplayFieldIdx()
          Educated guess..
 java.lang.String getDisplayString(int index)
          Gets the display value for the specified field.
 java.lang.String getExternalReference(java.lang.String type)
           
 DcField getField(int index)
          Retrieves the field
 int[] getFieldIndices()
          Retrieves all field indices.
 java.util.Collection<DcField> getFields()
          Retrieves all fields belonging to this object .
 int getFieldType(int index)
          Retrieves the field type.
 DcField getFileField()
           
 java.lang.String getFilename()
          Retrieves the filename value.
 DcImageIcon getIcon()
           
 java.lang.String getID()
          The internal ID
 java.lang.String getLabel(int index)
           
 int getMaxFieldLength(int index)
          Retrieves the maximum field / value length.
 DcModule getModule()
          Retrieves the module to which this object belongs.
 java.lang.String getName()
          Returns the name of this object based on the field settings.
 java.lang.String getNormalizedString(int index)
           
 java.util.Collection<DcField> getNotSearchableFields()
          Retrieves all fields on which cannot be searched.
 java.lang.String getParentID()
          Retrieves the ID of the parent of this object.
 int getParentReferenceFieldIndex()
          Retrieves the index of the field which is used to hold the link to the parent.
 Requests getRequests()
          Retrieves all the requests.
 int getSystemDisplayFieldIdx()
           
 java.lang.String getTableName()
          The database table name.
 java.lang.String getTableShortName()
           
 java.lang.Object getValue(int index)
          Retrieves the value for the specified field.
protected  DcValue getValueDef(int index)
           
 java.util.Map<java.lang.Integer,DcValue> getValues()
          Retrieves the value objects.
 int hashCode()
           
 boolean hasPrimaryKey()
          Is this object capable of storing IDs? In most cases the answer should be yes.
 void initializeImages()
          Loads the actual image / picture information.
 void initializeReferences()
          Loads the actual reference information.
 void initializeReferences(int index, boolean full)
           
 boolean isChanged()
          Checks whether the object holds unchanged values.
 boolean isChanged(int index)
          Checks whether the specified field holds a changed value.
 boolean isDestroyed()
           
 boolean isEnabled(int index)
          Indicates whether the field is enabled.
 boolean isFilled(int index)
          Does this field contains a value?
 boolean isLastInLine()
          Indicates the item is last in line of a save or delete action.
 boolean isLoaded()
           
 boolean isNew()
           
 boolean isRequired(int index)
          Checks whether the field is marked as required.
 boolean isSearchable(int index)
          Indicates whether the specified field can be searched on.
 void isUnique()
          Checks if the item is unique.
 boolean isUpdateGUI()
          Indicates whether ANY interface updates should be performed.
 void load(int[] fields)
           
 void load(int[] fields, boolean overruleLoadCheck)
          Loads the item from the database.
 void loadChildren(int[] fields)
          Load all children.
 void markAsChanged()
          Marks the object as changed.
 void markAsUnchanged()
          Mark all fields as unchanged.
 void merge(DcObject dco)
          Merges the values of this and the source item.
 void release()
          Unloads this items.
 void reload()
           
 void removeChildren()
          Remove all children from this object
 void removeRequests()
          Clears the requests.
 void saveNew(boolean queued)
          Inserts the item into the database.
 void saveUpdate(boolean queued)
          Save the changed item to the database.
 void saveUpdate(boolean queued, boolean validate)
          Save the changed item to the database.
 void setChanged(int index, boolean b)
          Manually mark a field as changed
 void setChildren(java.util.Collection<DcObject> children)
           
 void setIDs()
           
 void setLastInLine(boolean lastInLine)
          Indicates the item is last in line of a save or delete action.
 void setLoanInformation()
          Update the loan information.
 void setLoanInformation(Loan loan)
          Update the loan information based on the supplied loan object.
 void setNew(boolean b)
           
 void setUpdateGUI(boolean updateGUI)
          Indicate whether ANY interface updates should be performed.
 void setValidate(boolean validate)
          Indicates if validation should take place when the item is saved.
 void setValue(int index, java.lang.Object o)
          Sets a value on this object.
 void setValueForColumn(java.lang.String column, java.lang.Object value)
          Set the value using the database field name as key.
 void setValueForName(java.lang.String sysName, java.lang.Object value)
          Set the value using the system name of the field.
 void setValueLowLevel(int index, java.lang.Object o)
          Applies the value directly on this item.
 java.lang.String toString()
           
protected  void validateRequiredFields()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

children

protected java.util.Collection<DcObject> children

_ID

public static final int _ID
See Also:
Constant Field Values

_SYS_MODULE

public static final int _SYS_MODULE
See Also:
Constant Field Values

_SYS_AVAILABLE

public static final int _SYS_AVAILABLE
See Also:
Constant Field Values

_SYS_LENDBY

public static final int _SYS_LENDBY
See Also:
Constant Field Values

_SYS_LOANDURATION

public static final int _SYS_LOANDURATION
See Also:
Constant Field Values

_SYS_CREATED

public static final int _SYS_CREATED
See Also:
Constant Field Values

_SYS_MODIFIED

public static final int _SYS_MODIFIED
See Also:
Constant Field Values

_SYS_SERVICE

public static final int _SYS_SERVICE
See Also:
Constant Field Values

_SYS_SERVICEURL

public static final int _SYS_SERVICEURL
See Also:
Constant Field Values

_SYS_FILEHASH

public static final int _SYS_FILEHASH
See Also:
Constant Field Values

_SYS_FILESIZE

public static final int _SYS_FILESIZE
See Also:
Constant Field Values

_SYS_FILENAME

public static final int _SYS_FILENAME
See Also:
Constant Field Values

_SYS_FILEHASHTYPE

public static final int _SYS_FILEHASHTYPE
See Also:
Constant Field Values

_SYS_CONTAINER

public static final int _SYS_CONTAINER
See Also:
Constant Field Values

_SYS_DISPLAYVALUE

public static final int _SYS_DISPLAYVALUE
See Also:
Constant Field Values

_SYS_LOANDUEDATE

public static final int _SYS_LOANDUEDATE
See Also:
Constant Field Values

_SYS_LOANDAYSTILLOVERDUE

public static final int _SYS_LOANDAYSTILLOVERDUE
See Also:
Constant Field Values

_VALUE

public static final int _VALUE
See Also:
Constant Field Values

_SYS_EXTERNAL_REFERENCES

public static final int _SYS_EXTERNAL_REFERENCES
See Also:
Constant Field Values
Constructor Detail

DcObject

public DcObject(int module)
Creates a new instance.

Parameters:
module -
Method Detail

isLastInLine

public boolean isLastInLine()
Indicates the item is last in line of a save or delete action. Items last in line (of a batch) will cause additional GUI updates to be performed.


setLastInLine

public void setLastInLine(boolean lastInLine)
Indicates the item is last in line of a save or delete action. Items last in line (of a batch) will cause additional GUI updates to be performed.


isUpdateGUI

public boolean isUpdateGUI()
Indicates whether ANY interface updates should be performed.


setUpdateGUI

public void setUpdateGUI(boolean updateGUI)
Indicate whether ANY interface updates should be performed. Setting this to false will only cause the database to be updated but will no push the update to the GUI. By default this value is set to true.


isLoaded

public boolean isLoaded()

reload

public void reload()

load

public void load(int[] fields)

load

public void load(int[] fields,
                 boolean overruleLoadCheck)
Loads the item from the database. Initializes images, references and loan information.


getSystemDisplayFieldIdx

public int getSystemDisplayFieldIdx()

isDestroyed

public boolean isDestroyed()

getDisplayFieldIdx

public int getDisplayFieldIdx()
Educated guess..


getDefaultSortFieldIdx

public int getDefaultSortFieldIdx()
The default sort field index. In case the user has not specified the field to sort on this value will be used.


getName

public java.lang.String getName()
Returns the name of this object based on the field settings. If the field settings do no specify any descriptive fields the default name field index is used as defined in the module definition.


hasPrimaryKey

public boolean hasPrimaryKey()
Is this object capable of storing IDs? In most cases the answer should be yes.


removeRequests

public void removeRequests()
Clears the requests.


getValues

public java.util.Map<java.lang.Integer,DcValue> getValues()
Retrieves the value objects.


setValueForColumn

public void setValueForColumn(java.lang.String column,
                              java.lang.Object value)
Set the value using the database field name as key.

Parameters:
column -
value -

setValueForName

public void setValueForName(java.lang.String sysName,
                            java.lang.Object value)
Set the value using the system name of the field.

Parameters:
sysName -
value -

getExternalReference

public java.lang.String getExternalReference(java.lang.String type)

addExternalReference

public void addExternalReference(java.lang.String type,
                                 java.lang.String key)
Adds or updates the existing external key of the specified type.

Parameters:
type - The type of the key
key - The external key / ID

getRequests

public Requests getRequests()
Retrieves all the requests. These requests will be executed after a save or a delete.

Returns:

getTableName

public java.lang.String getTableName()
The database table name.


getTableShortName

public java.lang.String getTableShortName()

getDatabaseFieldCount

public int getDatabaseFieldCount()
Retrieves the database column count. This count will differ from the field count as some fields are calculated and not stored in the database.

Returns:

getLabel

public java.lang.String getLabel(int index)

initializeImages

public void initializeImages()
Loads the actual image / picture information. Changes are overwritten. Useful when reloading an object.


initializeReferences

public void initializeReferences(int index,
                                 boolean full)

initializeReferences

public void initializeReferences()
Loads the actual reference information. Uses the Data Manager to retrieve the references and stores them in this object.


addRequest

public void addRequest(IRequest request)
Add a request. This request will be executed after saving or deleting the object.

Parameters:
request -

isFilled

public boolean isFilled(int index)
Does this field contains a value?

Parameters:
index -

removeChildren

public void removeChildren()
Remove all children from this object


setNew

public void setNew(boolean b)

isNew

public boolean isNew()

loadChildren

public void loadChildren(int[] fields)
Load all children. Children will only be loaded when no child information is present yet. Will not overwrite existing values.


setChildren

public void setChildren(java.util.Collection<DcObject> children)

addChild

public void addChild(DcObject child)

getChildren

public java.util.List<DcObject> getChildren()
Retrieves the child objects belonging to this item.

Returns:
The children or null of none.

getCurrentChildren

public java.util.List<DcObject> getCurrentChildren()
Gets the children as they have been currently set (without reloading them).


getParentID

public java.lang.String getParentID()
Retrieves the ID of the parent of this object.

Returns:
The parent ID or null.

getParentReferenceFieldIndex

public int getParentReferenceFieldIndex()
Retrieves the index of the field which is used to hold the link to the parent.


getIcon

public DcImageIcon getIcon()

createIcon

public DcImageIcon createIcon()
The icon used to represent this item.


getFileField

public DcField getFileField()

getFilename

public java.lang.String getFilename()
Retrieves the filename value. This will only generate a result if the object has a file field.

Returns:
The file name or null.

getModule

public DcModule getModule()
Retrieves the module to which this object belongs.


getFields

public java.util.Collection<DcField> getFields()
Retrieves all fields belonging to this object .


markAsUnchanged

public void markAsUnchanged()
Mark all fields as unchanged. This does not reset the values to their original values! (use #load())


setLoanInformation

public void setLoanInformation()
Update the loan information.


setLoanInformation

public void setLoanInformation(Loan loan)
Update the loan information based on the supplied loan object.


beforeSave

protected void beforeSave()
                   throws ValidationException
Actions to be performed before saving the object.

Throws:
ValidationException

flushImages

public void flushImages()
Frees the resources hold by this items pictures.


setValue

public void setValue(int index,
                     java.lang.Object o)
Sets a value on this object.

Parameters:
index - The field index.
o - The value to be set.

setValueLowLevel

public void setValueLowLevel(int index,
                             java.lang.Object o)
Applies the value directly on this item. All checks are bypasses.

Parameters:
index - The field index.
o - The value to be set.

markAsChanged

public void markAsChanged()
Marks the object as changed.


isChanged

public boolean isChanged()
Checks whether the object holds unchanged values.

See Also:
DcValue.isChanged()

isChanged

public boolean isChanged(int index)
Checks whether the specified field holds a changed value.

Parameters:
index - The field index
See Also:
DcValue.isChanged()

setChanged

public void setChanged(int index,
                       boolean b)
Manually mark a field as changed

Parameters:
index - The field index
b - Changed true / false
See Also:
DcValue.isChanged()

isEnabled

public boolean isEnabled(int index)
Indicates whether the field is enabled. This depends on the field settings which can be altered by the user.

Parameters:
index -
See Also:
DcFieldDefinitions, DcField.isEnabled()

isRequired

public boolean isRequired(int index)
Checks whether the field is marked as required. This depends on the field settings which can be altered by the user.

Parameters:
index - The field index
See Also:
DcFieldDefinitions

isSearchable

public boolean isSearchable(int index)
Indicates whether the specified field can be searched on.

Parameters:
index - The field index

getID

public java.lang.String getID()
The internal ID


getNotSearchableFields

public java.util.Collection<DcField> getNotSearchableFields()
Retrieves all fields on which cannot be searched.


release

public void release()
Unloads this items. Its resources are freed and its pictures are unloaded. The item is unusable after this operation (!).


destroy

public void destroy()

clearValues

public void clearValues()
Resets this item. All values are set to empty.

Parameters:
nochecks - Just do it, do not check whether we are dealing with an edited item

getMaxFieldLength

public int getMaxFieldLength(int index)
Retrieves the maximum field / value length.

Parameters:
index - The field index

getValue

public java.lang.Object getValue(int index)
Retrieves the value for the specified field.

Parameters:
index - The field index.

getNormalizedString

public java.lang.String getNormalizedString(int index)

getDisplayString

public java.lang.String getDisplayString(int index)
Gets the display value for the specified field.

Parameters:
index - The field index
See Also:
_SYS_DISPLAYVALUE

getFieldType

public int getFieldType(int index)
Retrieves the field type.

Parameters:
index - The field index.
See Also:
ComponentFactory

getDatabaseFieldName

public java.lang.String getDatabaseFieldName(int index)
Retrieves the database column name.

Parameters:
index - The field index.
Returns:
The database field name or null for UI only fields.

applyEnhancers

public void applyEnhancers(boolean update)
Applies the enhancers on this item.

Parameters:
update - Indicates if the item is new or existing.
See Also:
ValueEnhancers

saveNew

public void saveNew(boolean queued)
             throws ValidationException
Inserts the item into the database.

Parameters:
queued - Indicates if the item should be saved using the query queue.
Throws:
ValidationException
See Also:
Query, DatabaseManager, QueryQueue

saveUpdate

public void saveUpdate(boolean queued)
                throws ValidationException
Save the changed item to the database.

Parameters:
queued - Indicates if the item should be saved using the query queue.
Throws:
ValidationException
See Also:
Query, DatabaseManager, QueryQueue

saveUpdate

public void saveUpdate(boolean queued,
                       boolean validate)
                throws ValidationException
Save the changed item to the database.

Parameters:
queued - Indicates if the item should be saved using the query queue.
validate - Indicates if the item should be validated before saving.
Throws:
ValidationException
See Also:
Query, DatabaseManager, QueryQueue

delete

public void delete(boolean validate)
            throws ValidationException
Permanently deletes the item.

Throws:
ValidationException

beforeDelete

protected void beforeDelete()
                     throws ValidationException
Throws:
ValidationException

setValidate

public void setValidate(boolean validate)
Indicates if validation should take place when the item is saved.


getField

public DcField getField(int index)
Retrieves the field

Parameters:
index - Field index

checkIntegrity

public void checkIntegrity()
                    throws ValidationException
Checks the integrity of the item.

Parameters:
update - Indicates if the item is new or not.
Throws:
ValidationException

isUnique

public void isUnique()
              throws ValidationException
Checks if the item is unique.

Parameters:
o - The item to be checked.
update - Indicates if the item is new or not.
Throws:
ValidationException

getFieldIndices

public int[] getFieldIndices()
Retrieves all field indices.


setIDs

public void setIDs()

getValueDef

protected DcValue getValueDef(int index)

executeRequests

protected void executeRequests(boolean saveSuccessful)

validateRequiredFields

protected void validateRequiredFields()
                               throws ValidationException
Throws:
ValidationException

merge

public void merge(DcObject dco)
Merges the values of this and the source item. Only empty values are updated with the values of the source item.

Parameters:
dco - The source item.

copy

public void copy(DcObject dco,
                 boolean overwrite,
                 boolean allowDeletes)
Copies all values from the specified Data Crow object.

Parameters:
overwrite - Indicates whether existing values should be overwritten.
allowDeletes - Allows existing values to be cleared.
dco - Source item.

applyTemplate

public void applyTemplate()

applyTemplate

public void applyTemplate(DcTemplate template)

copyImage

public void copyImage(Picture picture,
                      int field)
Copy an existing picture and set it on this item. This is the safest way to copy an picture of another item to this item.


clone

public DcObject clone()
Clones this objects. All values are copies as well as its children. The clone operates on copies of the pictures and the children and can be used entirely in parallel with its clone(s). Note; this is not a shallow copy and costs just as much resources as its original. After using the clone it is best to discard it by calling the destroy method.

Overrides:
clone in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(DcObject o)
Specified by:
compareTo in interface java.lang.Comparable<DcObject>