exedio cope

com.exedio.cope
Class Item

java.lang.Object
  extended by com.exedio.cope.Item
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Dispatcher.Failure, Draft, DraftItem, History.Event, History.Feature, PasswordRecovery.Token, Schedule.Run

public abstract class Item
extends Object
implements Serializable

This is the super class for all classes, that want to store their data persistently with COPE.

Serialization of instances of Item is guaranteed to be light-weight - there are no non-static, non-transient object reference fields in this class or its superclasses.

Author:
Ralf Wiebicke
See Also:
Serialized Form

Field Summary
static ItemField.DeletePolicy CASCADE
           
static ItemField.DeletePolicy FORBID
           
static ItemField.DeletePolicy NULLIFY
           
 
Constructor Summary
protected Item(ReactivationConstructorDummy reactivationDummy, int pk)
          Reactivation constructor.
protected Item(ReactivationConstructorDummy reactivationDummy, int pk, Type<? extends Item> typeWithoutJavaClass)
           
protected Item(SetValue... setValues)
           
  Item(SetValue[] setValues, Type<? extends Item> typeWithoutJavaClass)
           
 
Method Summary
 Item activeCopeItem()
          Returns the active item object representing the same item as this item object.
 void deleteCopeItem()
           
 boolean equals(Object o)
          Returns true, if o represents the same item as this item.
 boolean existsCopeItem()
          Returns, whether the item does exist.
<E> E
get(Function<E> function)
           
 String getCopeID()
          Returns a string unique for this item in all other items of the model.
 Type<? extends Item> getCopeType()
          Returns the type of this item.
 int hashCode()
          Returns a hash code, that is consistent with equals(Object).
 boolean isActiveCopeItem()
          Returns, whether this item is active.
static
<E extends Enum<E>>
EnumField<E>
newEnumAttribute(Class<E> valueClass)
          Deprecated. Renamed to newEnumField(Class).
static
<E extends Enum<E>>
EnumField<E>
newEnumField(Class<E> valueClass)
           
static
<E extends Item>
ItemField<E>
newItemAttribute(Class<E> valueClass)
          Deprecated. Renamed to newItemField(Class).
static
<E extends Item>
ItemField<E>
newItemAttribute(Class<E> valueClass, ItemField.DeletePolicy policy)
          Deprecated. Renamed to newItemField(Class, com.exedio.cope.ItemField.DeletePolicy).
static
<E extends Item>
ItemField<E>
newItemField(Class<E> valueClass)
           
static
<E extends Item>
ItemField<E>
newItemField(Class<E> valueClass, ItemField.DeletePolicy policy)
           
protected static
<C extends Item>
Type<C>
newType(Class<C> javaClass)
           
protected  void postCreate()
          Is called after every item creation.
<E> void
set(FunctionField<E> field, E value)
           
 void set(SetValue... setValues)
           
 String toString()
          Returns getCopeID() as a default implementation for all persistent classes.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FORBID

public static final ItemField.DeletePolicy FORBID

NULLIFY

public static final ItemField.DeletePolicy NULLIFY

CASCADE

public static final ItemField.DeletePolicy CASCADE
Constructor Detail

Item

protected Item(SetValue... setValues)
Throws:
MandatoryViolationException - if value is null and field is mandatory.
ClassCastException - if value is not compatible to field.

Item

public Item(SetValue[] setValues,
            Type<? extends Item> typeWithoutJavaClass)

Item

protected Item(ReactivationConstructorDummy reactivationDummy,
               int pk)
Reactivation constructor. Is used for internal purposes only. Does not actually create a new item, but a passive item object for an already existing item.


Item

protected Item(ReactivationConstructorDummy reactivationDummy,
               int pk,
               Type<? extends Item> typeWithoutJavaClass)
Method Detail

getCopeID

public final String getCopeID()
Returns a string unique for this item in all other items of the model. For any item a in its model m the following holds true: a.equals(m.getItem(a.getCopeID()). Does not activate this item, if it's not already active. Never returns null.

See Also:
Model.getItem(String)

getCopeType

public final Type<? extends Item> getCopeType()
Returns the type of this item. Never returns null.


equals

public final boolean equals(Object o)
Returns true, if o represents the same item as this item. Is equivalent to
(o != null) && (o instanceof Item) && getCopeID().equals(((Item)o).getCopeID())
Does not activate this item, if it's not already active.

Overrides:
equals in class Object

hashCode

public final int hashCode()
Returns a hash code, that is consistent with equals(Object). Note, that this is not neccessarily equivalent to getCopeID().hashCode(). Does not activate this item, if it's not already active.

Overrides:
hashCode in class Object

toString

public String toString()
Returns getCopeID() as a default implementation for all persistent classes.

Overrides:
toString in class Object

isActiveCopeItem

public final boolean isActiveCopeItem()
Returns, whether this item is active.


activeCopeItem

public final Item activeCopeItem()
Returns the active item object representing the same item as this item object. For any two item objects a, b the following holds true:

If and only if a.equals(b) then a.activeCopeItem() == b.activeCopeItem().

So it does for items, what String.intern() does for strings. Does activate this item, if it's not already active. Is guaranteed to be very cheap, if this item object is already active, which means this method returns this. Never returns null.


postCreate

protected void postCreate()
Is called after every item creation. Override this method when needed. The default implementation does nothing.


get

public final <E> E get(Function<E> function)

set

public final <E> void set(FunctionField<E> field,
                          E value)
               throws UniqueViolationException,
                      MandatoryViolationException,
                      StringLengthViolationException,
                      FinalViolationException,
                      ClassCastException
Throws:
MandatoryViolationException - if value is null and field is mandatory.
FinalViolationException - if field is final.
ClassCastException - if value is not compatible to field.
UniqueViolationException
StringLengthViolationException

set

public final void set(SetValue... setValues)
               throws UniqueViolationException,
                      MandatoryViolationException,
                      StringLengthViolationException,
                      FinalViolationException,
                      ClassCastException
Throws:
MandatoryViolationException - if value is null and field is mandatory.
FinalViolationException - if field is final.
ClassCastException - if value is not compatible to field.
UniqueViolationException
StringLengthViolationException

deleteCopeItem

public final void deleteCopeItem()
                          throws IntegrityViolationException
Throws:
IntegrityViolationException

existsCopeItem

public final boolean existsCopeItem()
Returns, whether the item does exist. There are two possibilities, why an item could not exist:
  1. the item has been deleted by deleteCopeItem().
  2. the item has been created in a transaction, that was subsequently rolled back by Model.rollback().


newType

protected static final <C extends Item> Type<C> newType(Class<C> javaClass)

newEnumField

public static final <E extends Enum<E>> EnumField<E> newEnumField(Class<E> valueClass)

newItemField

public static final <E extends Item> ItemField<E> newItemField(Class<E> valueClass)

newItemField

public static final <E extends Item> ItemField<E> newItemField(Class<E> valueClass,
                                                               ItemField.DeletePolicy policy)

newEnumAttribute

@Deprecated
public static final <E extends Enum<E>> EnumField<E> newEnumAttribute(Class<E> valueClass)
Deprecated. Renamed to newEnumField(Class).


newItemAttribute

@Deprecated
public static final <E extends Item> ItemField<E> newItemAttribute(Class<E> valueClass)
Deprecated. Renamed to newItemField(Class).


newItemAttribute

@Deprecated
public static final <E extends Item> ItemField<E> newItemAttribute(Class<E> valueClass,
                                                                              ItemField.DeletePolicy policy)
Deprecated. Renamed to newItemField(Class, com.exedio.cope.ItemField.DeletePolicy).


Cope with
Object
Persistence

SourceForge.net LogoCopyright © 2004-2008 exedio Gesellschaft für Softwareentwicklung mbH. All rights reserved.
svn.12752 build.5319 20090312135114