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(Collection<WikittyExtension> exts)
          Add multiples extensions.
 void addExtension(WikittyExtension ext)
          Add new extension.
 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 addPreloaded(Wikitty w)
          Ajoute un wikitty comme preloaded dans la liste des wikitties prechargee.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add property change listener.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add property change listener on property.
 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 faite sur le type d'objet, mais seulement sur le contenu des donnees.
 Set<String> fieldNames()
          Return only used fieldNames
 Set<String> getAllFieldNames()
          Return all fieldName available in all extension.
 Set<String> getAllPreloadPattern()
          Retourne tous les patterns de preload, celui demande lors du restore et tout ceux defini par le tag value 'preload' sur les extensions.
 Date getDeleteDate()
          Return deletion date.
 Set<String> getDirty()
          get the field modified after wikitty was restored
 WikittyExtension getExtension(String ext)
           
 Collection<WikittyExtension> getExtensionDependencies(String ext, boolean recursively)
          Recherche toutes les extensions de ce wikitty qui dependent d'une extension particuliere
 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)
          Get field value. if fieldName doesn't exists on this extension an exception is throw
<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
 Wikitty getFieldAsWikitty(String extName, String fieldName, boolean exceptionIfNotLoaded)
          return Wikitty for field only if this wikitty is preloaded, null or exception otherwize.
 List<Wikitty> getFieldAsWikittyList(String ext, String fieldName, boolean exceptionIfNotLoaded)
           
 Set<Wikitty> getFieldAsWikittySet(String ext, String fieldName, boolean exceptionIfNotLoaded)
           
 FieldType getFieldType(String fqfieldName)
          Return field type for the given fieldName.
 FieldType getFieldType(String extName, String fieldName)
          Return field type for the given fieldName.
 Map<String,Object> getFieldValue()
          All field value in unmodifiable map
 Object getFqField(String fqFieldName)
          get the value of and field given its fqn, if this field doesn't exists null is returned
 String getId()
          Get wikkity id.
 Map<String,Wikitty> getPreloaded()
          Retourne la map des wikitties precharges, si aucun objet n'est precharge alors retourne une map vide.
 String getPreloadPattern()
          Retourne le pattern de preload demande lors du restore ou null si aucun preload n'a ete demande.
 Wikitty getTarget()
           
 String getVersion()
           
 boolean hasExtension(String extName)
          Check if current wikitty has extension.
 boolean hasField(String fqfieldName)
          Check if current wikitty has requested fully qualified field.
 boolean hasField(String extName, String fieldName)
          Check if current wikitty has requested field.
 int hashCode()
           
 boolean hasMetaExtension(String metaExtensionName, String extensionName)
          Check that the wikitty has a metaExtension about a given extension.
 boolean isDeleted()
          Return true is wikitty is deleted.
 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)
          Remove property change listener.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove property change listener on property.
 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)
          Set deletion date.
 void setField(String ext, String fieldName, Object value)
          Set field value.
 void setFqField(String fieldName, Object value)
          set the value of a field given is fqn.
 void setPreloaded(Map<String,Wikitty> preloaded)
          Modifie la liste des wikitties prechargee
 void setPreloadPattern(String preloadPattern)
          Modifie le pattern de preload
 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()
           
 String toString(String extName)
          Return String representation of this wikitty with toString specific format of extension passed in argument.
 String toStringAllField()
          Print all field of all extension
 
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

getPreloadPattern

public String getPreloadPattern()
Description copied from interface: Wikitty
Retourne le pattern de preload demande lors du restore ou null si aucun preload n'a ete demande.

Specified by:
getPreloadPattern in interface Wikitty
Returns:

setPreloadPattern

public void setPreloadPattern(String preloadPattern)
Description copied from interface: Wikitty
Modifie le pattern de preload

Specified by:
setPreloadPattern in interface Wikitty
Parameters:
preloadPattern - un nouveau pattern ou null

getAllPreloadPattern

public Set<String> getAllPreloadPattern()
Description copied from interface: Wikitty
Retourne tous les patterns de preload, celui demande lors du restore et tout ceux defini par le tag value 'preload' sur les extensions. La Collection contient une liste de chaine qui n'ont comme separateur que des ','. Car chaque separateur ';' donne une entre differente dans la collection.

Specified by:
getAllPreloadPattern in interface Wikitty
Returns:
Collection with pattern or empty collection if no pattern

getPreloaded

public Map<String,Wikitty> getPreloaded()
Description copied from interface: Wikitty
Retourne la map des wikitties precharges, si aucun objet n'est precharge alors retourne une map vide. La collection retournee est non modifiable.

Specified by:
getPreloaded in interface Wikitty
Returns:
Retourne toujours une map au pire elle est vide

setPreloaded

public void setPreloaded(Map<String,Wikitty> preloaded)
Description copied from interface: Wikitty
Modifie la liste des wikitties prechargee

Specified by:
setPreloaded in interface Wikitty

addPreloaded

public void addPreloaded(Wikitty w)
Description copied from interface: Wikitty
Ajoute un wikitty comme preloaded dans la liste des wikitties prechargee.

Specified by:
addPreloaded in interface Wikitty
Parameters:
w - le wikitty a ajouter

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 faite 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:

toString

public String toString(String extName)
Description copied from interface: Wikitty
Return String representation of this wikitty with toString specific format of extension passed in argument. If this extension doesn't have specifique toString, normal toString is called #toString()

Specified by:
toString in interface Wikitty

toStringAllField

public String toStringAllField()
Description copied from interface: Wikitty
Print all field of all extension

Specified by:
toStringAllField in interface Wikitty

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)
Description copied from interface: Wikitty
Add property change listener.

Specified by:
addPropertyChangeListener in interface Wikitty
Parameters:
listener - listener to add

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Description copied from interface: Wikitty
Remove property change listener.

Specified by:
removePropertyChangeListener in interface Wikitty
Parameters:
listener - listener to remove

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Description copied from interface: Wikitty
Add property change listener on property.

Specified by:
addPropertyChangeListener in interface Wikitty
Parameters:
propertyName - property to listen
listener - listener to add

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Description copied from interface: Wikitty
Remove property change listener on property.

Specified by:
removePropertyChangeListener in interface Wikitty
Parameters:
propertyName - property to listen
listener - listener to remove

getId

public String getId()
Description copied from interface: Wikitty
Get wikkity id.

Specified by:
getId in interface Wikitty
Returns:
wikytty id

isDeleted

public boolean isDeleted()
Description copied from interface: Wikitty
Return true is wikitty is deleted.

Specified by:
isDeleted in interface Wikitty
Returns:
true is wikitty is deleted

getDeleteDate

public Date getDeleteDate()
Description copied from interface: Wikitty
Return deletion date.

Specified by:
getDeleteDate in interface Wikitty
Returns:
deletion date or null if not deleted

setDeleteDate

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

Specified by:
setDeleteDate in interface Wikitty
Parameters:
delete - deletion date

addExtension

public void addExtension(WikittyExtension ext)
Description copied from interface: Wikitty
Add new extension.

Specified by:
addExtension in interface Wikitty
Parameters:
ext - extension to add

addExtension

public void addExtension(Collection<WikittyExtension> exts)
Description copied from interface: Wikitty
Add multiples extensions.

Specified by:
addExtension in interface Wikitty
Parameters:
exts - extensions to add

hasExtension

public boolean hasExtension(String extName)
Description copied from interface: Wikitty
Check if current wikitty has extension.

Specified by:
hasExtension in interface Wikitty
Parameters:
extName - extension name to check
Returns:
true if current wikitty has extension.

hasField

public boolean hasField(String extName,
                        String fieldName)
Description copied from interface: Wikitty
Check if current wikitty has requested field.

Specified by:
hasField in interface Wikitty
Parameters:
extName - extension name
fieldName - field name on extension
Returns:
true if wikitty has field

hasField

public boolean hasField(String fqfieldName)
Description copied from interface: Wikitty
Check if current wikitty has requested fully qualified field.

Specified by:
hasField in interface Wikitty
Parameters:
fqfieldName - fully qualified field name
Returns:
true if wikitty has field

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)
Description copied from interface: Wikitty
Recherche toutes les extensions de ce wikitty qui dependent d'une extension particuliere

Specified by:
getExtensionDependencies in interface Wikitty
Parameters:
ext - le nom d'une extension
recursively - si la dependance doit aussi etre recherche recursivement
Returns:
la liste des extensions de ce Wikitty qui depande de l'extension dont le nom est passé en parametre (de facon direct ou indirect)

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

getFieldType

public FieldType getFieldType(String extName,
                              String fieldName)
Description copied from interface: Wikitty
Return field type for the given fieldName.

Specified by:
getFieldType in interface Wikitty
Parameters:
extName - extension name
fieldName - field name
Returns:
field type

setField

public void setField(String ext,
                     String fieldName,
                     Object value)
Description copied from interface: Wikitty
Set field value.

Specified by:
setField in interface Wikitty
Parameters:
ext - extension
fieldName - field name

getFieldAsObject

public Object getFieldAsObject(String ext,
                               String fieldName)
Description copied from interface: Wikitty
Get field value. if fieldName doesn't exists on this extension an exception is throw

Specified by:
getFieldAsObject in interface Wikitty
Parameters:
ext - extension name
fieldName - field name
Returns:

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

getFieldAsWikitty

public Wikitty getFieldAsWikitty(String extName,
                                 String fieldName,
                                 boolean exceptionIfNotLoaded)
Description copied from interface: Wikitty
return Wikitty for field only if this wikitty is preloaded, null or exception otherwize.

Specified by:
getFieldAsWikitty in interface Wikitty
Parameters:
extName - extension name where this field must to be
fieldName - the field name
exceptionIfNotLoaded - if true and this field is not preloaded an exception is throw, otherwize null is returned. But if field is null (never set or set to null) and exceptionIfNotLoaded is true. This method must return null and not throw exception.
Returns:
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

getFieldAsWikittyList

public List<Wikitty> getFieldAsWikittyList(String ext,
                                           String fieldName,
                                           boolean exceptionIfNotLoaded)
Specified by:
getFieldAsWikittyList in interface Wikitty

getFieldAsSet

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

getFieldAsWikittySet

public Set<Wikitty> getFieldAsWikittySet(String ext,
                                         String fieldName,
                                         boolean exceptionIfNotLoaded)
Specified by:
getFieldAsWikittySet in interface Wikitty

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()
Description copied from interface: Wikitty
Return only used fieldNames

Specified by:
fieldNames in interface Wikitty
Returns:

getFieldValue

public Map<String,Object> getFieldValue()
Description copied from interface: Wikitty
All field value in unmodifiable map

Specified by:
getFieldValue in interface Wikitty
Returns:

getAllFieldNames

public Set<String> getAllFieldNames()
Description copied from interface: Wikitty
Return all fieldName available in all extension. Field is fq.

Specified by:
getAllFieldNames in interface Wikitty
Returns:

getFqField

public Object getFqField(String fqFieldName)
Description copied from interface: Wikitty
get the value of and field given its fqn, if this field doesn't exists null is returned

Specified by:
getFqField in interface Wikitty
Returns:

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
Returns:
true if current wikitty has meta extension
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-2012 CodeLutin. All Rights Reserved.