Class Item
- java.lang.Object
-
- com.exedio.cope.Item
-
- All Implemented Interfaces:
Serializable
,Comparable<Item>
- Direct Known Subclasses:
Dispatcher.Run
,DynamicModel.Enum
,DynamicModel.Field
,DynamicModel.Type
,History.Event
,History.Feature
,PasswordLimiter.Refusal
,PasswordRecovery.Token
,Schedule.Run
,TextUrlFilter.Paste
public abstract class Item extends Object implements Serializable, Comparable<Item>
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
Fields Modifier and Type Field Description static ItemField.DeletePolicy
CASCADE
Deprecated.UseItemField.cascade()
insteadstatic ItemField.DeletePolicy
FORBID
Deprecated.Is default delete policy anyway.static ItemField.DeletePolicy
NULLIFY
Deprecated.UseItemField.nullify()
instead
-
Constructor Summary
Constructors Modifier Constructor Description protected
Item(ActivationParameters ap)
Activation constructor.protected
Item(SetValue<?>... setValues)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Item
activeCopeItem()
Returns the active item object representing the same item as this item object.protected void
afterNewCopeItem()
Is called after every item creation.void
appendCopeID(StringBuilder bf)
Is equivalent tobf.{@link StringBuilder#append(String) append}({@link #getCopeID()});
protected void
beforeDeleteCopeItem()
Is called before every item deletion.protected SetValue<?>[]
beforeSetCopeItem(SetValue<?>[] setValues)
Is called before every item modification.int
compareTo(Item o)
Defines an order consistent to the query result order when usingQuery.setOrderBy
methods with anyItemFunction
.void
deleteCopeItem()
boolean
equals(Object o)
Returns true, ifo
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<?>
getCopeType()
Returns the type of this item.int
hashCode()
Returns a hash code, that is consistent withequals(Object)
.boolean
isActiveCopeItem()
Returns, whether this item is active.static <E extends Enum<E>>
EnumField<E>newEnumAttribute(Class<E> valueClass)
Deprecated.Renamed tonewEnumField(Class)
.static <E extends Enum<E>>
EnumField<E>newEnumField(Class<E> valueClass)
Deprecated.UseEnumField.create(Class)
insteadstatic <E extends Item>
ItemField<E>newItemAttribute(Class<E> valueClass)
Deprecated.Renamed tonewItemField(Class)
.static <E extends Item>
ItemField<E>newItemAttribute(Class<E> valueClass, ItemField.DeletePolicy policy)
Deprecated.static <E extends Item>
ItemField<E>newItemField(Class<E> valueClass)
Deprecated.UseItemField.create(Class)
insteadstatic <E extends Item>
ItemField<E>newItemField(Class<E> valueClass, ItemField.DeletePolicy policy)
Deprecated.UseItemField.create(Class, DeletePolicy)
insteadprotected static <C extends Item>
Type<C>newType(Class<C> javaClass)
Deprecated.UseTypesBound.newType(Class)
instead.<E> void
set(FunctionField<E> field, E value)
void
set(SetValue<?>... setValues)
String
toString()
ReturnsgetCopeID()
as a default implementation for all persistent classes.protected Object
writeReplace()
-
-
-
Field Detail
-
FORBID
@Deprecated public static final ItemField.DeletePolicy FORBID
Deprecated.Is default delete policy anyway.
-
NULLIFY
@Deprecated public static final ItemField.DeletePolicy NULLIFY
Deprecated.UseItemField.nullify()
instead
-
CASCADE
@Deprecated public static final ItemField.DeletePolicy CASCADE
Deprecated.UseItemField.cascade()
instead
-
-
Constructor Detail
-
Item
protected Item(SetValue<?>... setValues)
-
Item
protected Item(ActivationParameters ap)
Activation constructor. Is used for internal purposes only. Does not actually create a new item, but a passive item object for an already existing item.
-
-
Method Detail
-
getCopeID
public final String getCopeID()
Returns a string unique for this item in all other items of the model. For any itema</tt> in its model <tt>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)
-
appendCopeID
public final void appendCopeID(StringBuilder bf)
Is equivalent tobf.{@link StringBuilder#append(String) append}({@link #getCopeID()});
-
getCopeType
public final Type<?> getCopeType()
Returns the type of this item. Never returns null.
-
equals
public final boolean equals(Object o)
Returns true, ifo
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.
-
hashCode
public final int hashCode()
Returns a hash code, that is consistent withequals(Object)
. Note, that this is not necessarily equivalent togetCopeID().hashCode()
. Does not activate this item, if it's not already active.
-
compareTo
public int compareTo(Item o)
Defines an order consistent to the query result order when usingQuery.setOrderBy
methods with anyItemFunction
.- Specified by:
compareTo
in interfaceComparable<Item>
-
toString
public String toString()
ReturnsgetCopeID()
as a default implementation for all persistent classes.
-
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 objectsa</tt>, <tt>b
the following holds true:If and only if
a.equals(b)</tt> then <tt>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 returnsthis
. Never returns null.
-
afterNewCopeItem
protected void afterNewCopeItem()
Is called after every item creation. Is called only, ifDefaultChangeHook
has beeninstalled
. Override this method when needed. The default implementation does nothing.If you want to affect field values before creating the item write a method:
static SetValue[] beforeNewCopeItem(SetValue[])
If you want to postpone your action until the current transaction commits, use either
pre
- orpost
-commit hooks.- See Also:
ChangeHook.afterNew(Item)
-
beforeSetCopeItem
protected SetValue<?>[] beforeSetCopeItem(SetValue<?>[] setValues)
Is called before every item modification. Is called only, ifDefaultChangeHook
has beeninstalled
. Override this method when needed. The default implementation does nothing.If you want to affect field values before creating the item write a method:
static SetValue[] beforeNewCopeItem(SetValue[])
If you want to postpone your action until the current transaction commits, use either
pre
- orpost
-commit hooks.- Parameters:
setValues
- is never null and never empty- Returns:
- must not return null
- See Also:
set(SetValue[])
,set(FunctionField, Object)
,ChangeHook.beforeSet(Item, SetValue[])
-
get
public final <E> E get(Function<E> function)
-
set
public final <E> void set(FunctionField<E> field, E value)
- Throws:
MandatoryViolationException
- ifvalue</tt> is null and <tt>field
ismandatory
.FinalViolationException
- iffield
isfinal
.ClassCastException
- ifvalue</tt> is not compatible to <tt>field
.
-
set
public final void set(SetValue<?>... setValues)
- Throws:
MandatoryViolationException
- ifvalue</tt> is null and <tt>field
ismandatory
.FinalViolationException
- iffield
isfinal
.ClassCastException
- ifvalue</tt> is not compatible to <tt>field
.
-
deleteCopeItem
public final void deleteCopeItem()
- Throws:
IntegrityViolationException
- if this item cannot be deleted due areference
withItemField.DeletePolicy.FORBID
pointing to this item.
-
beforeDeleteCopeItem
protected void beforeDeleteCopeItem()
Is called before every item deletion. Is called only, ifDefaultChangeHook
has beeninstalled
. Override this method when needed. The default implementation does nothing.If you want to postpone your action until the current transaction commits, use either
pre
- orpost
-commit hooks.- See Also:
ChangeHook.beforeDelete(Item)
-
existsCopeItem
public final boolean existsCopeItem()
Returns, whether the item does exist. There are two possibilities, why an item could not exist:- the item has been deleted by
deleteCopeItem()
. - the item has been created in a transaction,
that was subsequently rolled back by
Model.rollback()
.
- the item has been deleted by
-
writeReplace
protected final Object writeReplace()
-
newEnumField
@Deprecated public static final <E extends Enum<E>> EnumField<E> newEnumField(Class<E> valueClass)
Deprecated.UseEnumField.create(Class)
instead
-
newItemField
@Deprecated public static final <E extends Item> ItemField<E> newItemField(Class<E> valueClass)
Deprecated.UseItemField.create(Class)
instead
-
newItemField
@Deprecated public static final <E extends Item> ItemField<E> newItemField(Class<E> valueClass, ItemField.DeletePolicy policy)
Deprecated.UseItemField.create(Class, DeletePolicy)
instead
-
newEnumAttribute
@Deprecated public static final <E extends Enum<E>> EnumField<E> newEnumAttribute(Class<E> valueClass)
Deprecated.Renamed tonewEnumField(Class)
.
-
newItemAttribute
@Deprecated public static final <E extends Item> ItemField<E> newItemAttribute(Class<E> valueClass)
Deprecated.Renamed tonewItemField(Class)
.
-
newItemAttribute
@Deprecated public static final <E extends Item> ItemField<E> newItemAttribute(Class<E> valueClass, ItemField.DeletePolicy policy)
Deprecated.
-
newType
@Deprecated protected static final <C extends Item> Type<C> newType(Class<C> javaClass)
Deprecated.UseTypesBound.newType(Class)
instead.
-
-