org.nuiton.wikitty.entities
Class WikittyCopyOnWrite

java.lang.Object
  extended by org.nuiton.wikitty.entities.WikittyCopyOnWrite
All Implemented Interfaces:
Serializable, Cloneable, Wikitty

public class WikittyCopyOnWrite
extends Object
implements Wikitty

this class wrap a wikitty in a proxy that copy the wikitty before applying any change It is used for caching purpose. This class own a reference to an actual wikitty, multiple instance of this class can own some references to a same actual wikitty. To prevent the target to be modified, a copy is created to prevent side-effect. So, when a wikitty restored from cache is modified, a copy is modified, so if change are cancelled, next restore will restore the original and not the modified version (until the modified version is stored). used in WikittyServiceCached

See Also:
Serialized Form

Field Summary
protected  Wikitty target
           
protected  boolean targetIsACopy
           
 
Constructor Summary
WikittyCopyOnWrite(Wikitty target)
          only WikittyService with cache should create instances
 
Method Summary
 void addExtension(List<WikittyExtension> exts)
           
 void addExtension(WikittyExtension ext)
           
 void addMetaExtension(WikittyExtension metaExtension, String extensionFqn)
          add a meta-extension on the given extension to this wikitty.
 void addMetaExtension(WikittyExtension metaExtension, WikittyExtension extension)
          add a meta-extension about the given extension to this wikitty.
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void addToField(String fqFieldName, Object value)
          Add an element in a field
 void addToField(String ext, String fieldName, Object value)
           
 void clearDirty()
          clear the lists of modified field since last restore.
 void clearField(String fqFieldName)
          Clear a field
 void clearField(String ext, String fieldName)
           
 Wikitty clone()
           
 boolean equals(Object obj)
          ATTENTION, la condition d'egalite n'est pas faire sur le type d'objet, mais seulement sur le contenu des donnees.
 Set<String> fieldNames()
           
 Date getDeleteDate()
           
 Set<String> getDirty()
          get the field modified after wikitty was restored
 WikittyExtension getExtension(String ext)
           
 Collection<WikittyExtension> getExtensionDependencies(String ext, boolean recursively)
           
 Collection<String> getExtensionNames()
           
 Collection<WikittyExtension> getExtensions()
           
 BigDecimal getFieldAsBigDecimal(String ext, String fieldName)
           
 boolean getFieldAsBoolean(String ext, String fieldName)
           
 byte[] getFieldAsBytes(String ext, String fieldName)
           
 Date getFieldAsDate(String ext, String fieldName)
           
 double getFieldAsDouble(String ext, String fieldName)
           
 float getFieldAsFloat(String ext, String fieldName)
           
 int getFieldAsInt(String ext, String fieldName)
           
<E> List<E>
getFieldAsList(String ext, String fieldName, Class<E> clazz)
          If object is a set, it is automatically transform to list.
 long getFieldAsLong(String ext, String fieldName)
           
 Object getFieldAsObject(String ext, String fieldName)
           
<E> Set<E>
getFieldAsSet(String ext, String fieldName, Class<E> clazz)
           
 String getFieldAsString(String ext, String fieldName)
           
 String getFieldAsWikitty(String ext, String fieldName)
          return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller
 FieldType getFieldType(String fqfieldName)
          return field type for the given fieldName.
 Object getFqField(String fqFieldName)
          get the value of and field given its fqn
 String getId()
           
 Wikitty getTarget()
           
 String getVersion()
           
 boolean hasExtension(String extName)
           
 boolean hasField(String extName, String fieldName)
           
 int hashCode()
           
 boolean hasMetaExtension(String metaExtensionName, String extensionName)
          check that the wikitty has a metaExtension about a given extension.
 boolean isDeleted()
           
 boolean isEmpty()
           
 void removeFromField(String fqFieldName, Object value)
          Remove an element from a field
 void removeFromField(String ext, String fieldName, Object value)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void replaceWith(Wikitty w)
          Replace all field of current wikitty with field found in w.
 void replaceWith(Wikitty w, boolean force)
          Replace all field of current wikitty with field found in w.
 void setDeleteDate(Date delete)
          Server only used
 void setField(String ext, String fieldName, Object value)
           
 void setFqField(String fieldName, Object value)
          set the value of a field given is fqn.
 void setVersion(String version)
          Server only used
protected  void substituteTargetWithCopy()
          replaceWith target with a clone this method must be called to prevent any modification on target
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

target

protected Wikitty target

targetIsACopy

protected boolean targetIsACopy
Constructor Detail

WikittyCopyOnWrite

public WikittyCopyOnWrite(Wikitty target)
only WikittyService with cache should create instances

Method Detail

replaceWith

public void replaceWith(Wikitty w)
Description copied from interface: Wikitty
Replace all field of current wikitty with field found in w. This two wikitty must have same id

Specified by:
replaceWith in interface Wikitty
Parameters:
w - wikitty where we take information

replaceWith

public void replaceWith(Wikitty w,
                        boolean force)
Description copied from interface: Wikitty
Replace all field of current wikitty with field found in w. This two wikitty must have same id if force is false

Specified by:
replaceWith in interface Wikitty
Parameters:
w - wikitty where we take information

getTarget

public Wikitty getTarget()

substituteTargetWithCopy

protected void substituteTargetWithCopy()
replaceWith target with a clone this method must be called to prevent any modification on target


equals

public boolean equals(Object obj)
ATTENTION, la condition d'egalite n'est pas faire sur le type d'objet, mais seulement sur le contenu des donnees. Le equals repond a la question "Est-ce qu'on represente le meme wikitty ?".

Overrides:
equals in class Object
Parameters:
obj -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

clone

public Wikitty clone()
              throws CloneNotSupportedException
Specified by:
clone in interface Wikitty
Overrides:
clone in class Object
Throws:
CloneNotSupportedException
See Also:
Object.clone()

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface Wikitty

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface Wikitty

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface Wikitty

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface Wikitty

getId

public String getId()
Specified by:
getId in interface Wikitty

isDeleted

public boolean isDeleted()
Specified by:
isDeleted in interface Wikitty

getDeleteDate

public Date getDeleteDate()
Specified by:
getDeleteDate in interface Wikitty

setDeleteDate

public void setDeleteDate(Date delete)
Description copied from interface: Wikitty
Server only used

Specified by:
setDeleteDate in interface Wikitty

addExtension

public void addExtension(WikittyExtension ext)
Specified by:
addExtension in interface Wikitty

addExtension

public void addExtension(List<WikittyExtension> exts)
Specified by:
addExtension in interface Wikitty

hasExtension

public boolean hasExtension(String extName)
Specified by:
hasExtension in interface Wikitty

hasField

public boolean hasField(String extName,
                        String fieldName)
Specified by:
hasField in interface Wikitty

getExtension

public WikittyExtension getExtension(String ext)
Specified by:
getExtension in interface Wikitty

getExtensionNames

public Collection<String> getExtensionNames()
Specified by:
getExtensionNames in interface Wikitty

getExtensions

public Collection<WikittyExtension> getExtensions()
Specified by:
getExtensions in interface Wikitty

getExtensionDependencies

public Collection<WikittyExtension> getExtensionDependencies(String ext,
                                                             boolean recursively)
Specified by:
getExtensionDependencies in interface Wikitty

getFieldType

public FieldType getFieldType(String fqfieldName)
Description copied from interface: Wikitty
return field type for the given fieldName.

Specified by:
getFieldType in interface Wikitty
Parameters:
fqfieldName - fully qualified fieldName extension.fieldname
Returns:
field type

setField

public void setField(String ext,
                     String fieldName,
                     Object value)
Specified by:
setField in interface Wikitty

getFieldAsObject

public Object getFieldAsObject(String ext,
                               String fieldName)
Specified by:
getFieldAsObject in interface Wikitty

getFieldAsBytes

public byte[] getFieldAsBytes(String ext,
                              String fieldName)
Specified by:
getFieldAsBytes in interface Wikitty

getFieldAsBoolean

public boolean getFieldAsBoolean(String ext,
                                 String fieldName)
Specified by:
getFieldAsBoolean in interface Wikitty

getFieldAsBigDecimal

public BigDecimal getFieldAsBigDecimal(String ext,
                                       String fieldName)
Specified by:
getFieldAsBigDecimal in interface Wikitty

getFieldAsInt

public int getFieldAsInt(String ext,
                         String fieldName)
Specified by:
getFieldAsInt in interface Wikitty

getFieldAsLong

public long getFieldAsLong(String ext,
                           String fieldName)
Specified by:
getFieldAsLong in interface Wikitty

getFieldAsFloat

public float getFieldAsFloat(String ext,
                             String fieldName)
Specified by:
getFieldAsFloat in interface Wikitty

getFieldAsDouble

public double getFieldAsDouble(String ext,
                               String fieldName)
Specified by:
getFieldAsDouble in interface Wikitty

getFieldAsString

public String getFieldAsString(String ext,
                               String fieldName)
Specified by:
getFieldAsString in interface Wikitty

getFieldAsDate

public Date getFieldAsDate(String ext,
                           String fieldName)
Specified by:
getFieldAsDate in interface Wikitty

getFieldAsWikitty

public String getFieldAsWikitty(String ext,
                                String fieldName)
Description copied from interface: Wikitty
return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller

Specified by:
getFieldAsWikitty in interface Wikitty
Parameters:
ext - extension name where this field must to be
fieldName - the field name
Returns:
id of wikitty object or null

getFieldAsList

public <E> List<E> getFieldAsList(String ext,
                                  String fieldName,
                                  Class<E> clazz)
Description copied from interface: Wikitty
If object is a set, it is automatically transform to list.

Specified by:
getFieldAsList in interface Wikitty
Returns:
unmodifiable list

getFieldAsSet

public <E> Set<E> getFieldAsSet(String ext,
                                String fieldName,
                                Class<E> clazz)
Specified by:
getFieldAsSet in interface Wikitty
Returns:
unmodifiable list

addToField

public void addToField(String ext,
                       String fieldName,
                       Object value)
Specified by:
addToField in interface Wikitty

removeFromField

public void removeFromField(String ext,
                            String fieldName,
                            Object value)
Specified by:
removeFromField in interface Wikitty

clearField

public void clearField(String ext,
                       String fieldName)
Specified by:
clearField in interface Wikitty

addToField

public void addToField(String fqFieldName,
                       Object value)
Description copied from interface: Wikitty
Add an element in a field

Specified by:
addToField in interface Wikitty
Parameters:
fqFieldName - the fully qualified name of a collection field
value - the value to be added to the collection
See Also:
org.nuiton.wikitty.Wikitty#addToField(String, Object)

removeFromField

public void removeFromField(String fqFieldName,
                            Object value)
Description copied from interface: Wikitty
Remove an element from a field

Specified by:
removeFromField in interface Wikitty
Parameters:
fqFieldName - the fully qualified name of a collection field
value - the value to be removed to the collection
See Also:
org.nuiton.wikitty.Wikitty#removeFromField(String, Object)

clearField

public void clearField(String fqFieldName)
Description copied from interface: Wikitty
Clear a field

Specified by:
clearField in interface Wikitty
Parameters:
fqFieldName - the fully qualified name of a collection field
See Also:
org.nuiton.wikitty.Wikitty#clearField(String)

fieldNames

public Set<String> fieldNames()
Specified by:
fieldNames in interface Wikitty

getFqField

public Object getFqField(String fqFieldName)
Description copied from interface: Wikitty
get the value of and field given its fqn

Specified by:
getFqField in interface Wikitty

getVersion

public String getVersion()
Specified by:
getVersion in interface Wikitty

setVersion

public void setVersion(String version)
Description copied from interface: Wikitty
Server only used

Specified by:
setVersion in interface Wikitty

getDirty

public Set<String> getDirty()
Description copied from interface: Wikitty
get the field modified after wikitty was restored

Specified by:
getDirty in interface Wikitty
Returns:
a set of fully qualified field names
See Also:
org.nuiton.wikitty.Wikitty#getDirty()

clearDirty

public void clearDirty()
Description copied from interface: Wikitty
clear the lists of modified field since last restore.

Specified by:
clearDirty in interface Wikitty
See Also:
org.nuiton.wikitty.Wikitty#clearDirty()

setFqField

public void setFqField(String fieldName,
                       Object value)
Description copied from interface: Wikitty
set the value of a field given is fqn.

Specified by:
setFqField in interface Wikitty
Parameters:
fieldName - fqn (ex: extensionName.fieldName)
value - new value
See Also:
org.nuiton.wikitty.Wikitty#setFqField(String, Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Wikitty

hasMetaExtension

public boolean hasMetaExtension(String metaExtensionName,
                                String extensionName)
Description copied from interface: Wikitty
check that the wikitty has a metaExtension about a given extension.

Specified by:
hasMetaExtension in interface Wikitty
Parameters:
metaExtensionName - the metaExtension to be checked
extensionName - an extension already added to the wikitty
See Also:
org.nuiton.wikitty.Wikitty#hasMetaExtension(String, String)

addMetaExtension

public void addMetaExtension(WikittyExtension metaExtension,
                             WikittyExtension extension)
Description copied from interface: Wikitty
add a meta-extension about the given extension to this wikitty.

Specified by:
addMetaExtension in interface Wikitty
Parameters:
metaExtension - the metaExtension to add
extension - an extension already added to the wikitty
See Also:
org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, WikittyExtension)

addMetaExtension

public void addMetaExtension(WikittyExtension metaExtension,
                             String extensionFqn)
Description copied from interface: Wikitty
add a meta-extension on the given extension to this wikitty.

Specified by:
addMetaExtension in interface Wikitty
Parameters:
metaExtension - the metaExtension to add
extensionFqn - the name of the extension already added to the wikitty
See Also:
org.nuiton.wikitty.Wikitty#addMetaExtension(WikittyExtension, String)


Copyright © 2009-2011 CodeLutin. All Rights Reserved.