Package net.sf.basedb.core.data
Class BasicData
- java.lang.Object
-
- net.sf.basedb.core.data.BasicData
-
- All Implemented Interfaces:
IdentifiableData
- Direct Known Subclasses:
AnnotationData
,AnnotationSetData
,AnyToAnyData
,ArrayDesignBlockData
,ArrayDesignPlateData
,BioAssayData
,BioAssaySetData
,BioMaterialEventData
,BioMaterialEventSourceData
,BioPlateEventParticipantData
,BioPlateEventTypeData
,BioPlateTypeData
,BioWellData
,ChangeHistoryData
,ChangeHistoryDetailData
,ContextData
,DataCubeColumnData
,DataCubeData
,DataCubeExtraValueData
,DataCubeFilterData
,DataCubeLayerData
,DataFileTypeData
,DiskUsageData
,ExtraValueData
,ExtraValueTypeData
,FeatureData
,FileSetData
,FileSetMemberData
,GroupData
,HelpData
,ItemListSyncFilterData
,ItemSubtypeData
,ItemSubtypeFileTypeData
,JobAgentSettingsData
,KeyData
,MessageData
,MimeTypeData
,NewsData
,OwnedData
,ParameterValueData
,PasswordData
,PlateEventData
,PlateEventTypeData
,PlateGeometryData
,PlatformData
,PlatformFileTypeData
,PlatformVariantData
,PluginTypeData
,QuantityData
,QuotaData
,QuotaTypeData
,RawData
,ReporterData
,ReporterTypeData
,RoleData
,RootRawBioAssayData
,SchemaVersionData
,SessionData
,SettingData
,TransformationData
,UnitData
,UnitSymbolData
,UserData
,UserDeviceData
,VirtualDbData
,WellData
public abstract class BasicData extends Object implements IdentifiableData
This is the root superclass of all data classes. Each class must inherit from this class or one of the subclasses. The main purpose of this class is to handle object identity. It contains a Hibernate mapping for thegetId()
property and overrides the default implementations of theequals(Object)
andhashCode()
methods.For all practical purposes object identity is the same as database identity, ie. two objects are considered equal if they reference the same row in the database. Objects that has not yet been saved to the database should be handled carefully and not be put into
Set
:s orMap
:s since that may break the contract for theequals()
andhashCode()
methods.We recommend that the
equals()
andhashCode()
methods not are overridden in subclasses, unless you really know what you are doing. Actually, we would have liked to make the methodsfinal
but that would disable the proxy feature of Hibernate.- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Developer documentation: Basic classes and interfaces
-
-
Constructor Summary
Constructors Constructor Description BasicData()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
Check if this item is equal to another item.int
getId()
Get the id of the item.int
getVersion()
Get the version of the item.int
hashCode()
For new items (getId() returns 0) the hash code is the same as returned by theSystem.identityHashCode()
method.(package private) void
setId(int id)
Set the id of the item.(package private) void
setVersion(int version)
Set the version of the item.String
toString()
The string will look likeClassName[id=55]
orClassName[new]
.
-
-
-
Field Detail
-
hashCode
private int hashCode
Stores the hash code of the item. This value is initialised the first time it is asked for by an application.- See Also:
hashCode()
-
id
private int id
-
version
private int version
-
-
Method Detail
-
toString
public String toString()
The string will look likeClassName[id=55]
orClassName[new]
.
-
equals
public boolean equals(Object other)
Check if this item is equal to another item. They are considered to be equal if they are of the same class and have the same ID. Items that has not yet been assigned an ID (id == 0) are equal only if they refer to the same object instance. We must also handle the fact that theother
object can be a Hibernate proxy, which is a dynamically generated subclass of the actual class. Do not override this method in a subclass!
-
hashCode
public int hashCode()
For new items (getId() returns 0) the hash code is the same as returned by theSystem.identityHashCode()
method. Items loaded from the database uses theid
as the hash code. We must also consider the case were a new object is saved to the database. Our recommendation is to not place the object inSet
(or other structure) that calls thehashCode
method before the object is saved to the database. If you do that the contract for theequals()/hashCode()
method is broken andequals()
may return true even ifhashCode()
returns different values. Do not override this method in a subclass!
-
getId
public int getId()
Get the id of the item. The id is automatically generated by the database the first time the item is saved to the database. A new item has the value 0.- Specified by:
getId
in interfaceIdentifiableData
- Returns:
- The id of the item or 0
- Hibernate: id
- column="`id`" type="int" generator-class="native" unsaved-value="0"
-
setId
void setId(int id)
Set the id of the item. Only used by Hibernate.- Parameters:
id
- The id of the item
-
getVersion
@NotLoggable public int getVersion()
Get the version of the item. This value is used by Hibernate to check if another process or thread has modified the corresponding row in the databse since this item was loaded from the. If that is the case, this item can't be saved and an exception will be thrown.- Specified by:
getVersion
in interfaceIdentifiableData
- Hibernate: version
- column="`version`" type="int"
-
setVersion
void setVersion(int version)
Set the version of the item. Only used by Hibernate.- Parameters:
version
- The version of the item
-
-