LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.data
Class LyDataSource

java.lang.Object
  extended by leon.data.LyDataSource
Direct Known Subclasses:
LyObjectSource, LyPeerDataSource

public abstract class LyDataSource
extends java.lang.Object

This class implements a collection of data of the same class. It provides methods for accessing, creating, deleting, modifying and counting datas.

Both physical class and logical class are managed by data sources. The only difference is that physical classes use direct instances of this class, and logical classes are handled by instances of an inherited class, LyObjectSource.

Each data source is connected to a data provider which is responsible to manage real objects : encoding requests and decoding results.

Data sources are valid within an application.

Objects returned via data sources are kept in caches.

See Also:
LyClass, LyObjectSource, LyCache

Field Summary
static java.lang.String __VERSION
          File version
 
Constructor Summary
LyDataSource(LyDataProvider provider, LyClass dataClass)
          Constructs a data source within the given application that manages the specified class.
 
Method Summary
 void addListener(LyDataSourceListener listener)
          Registers a listener to receive all events on objects contained within this data source.
abstract  void addListener(LyDataSourceListener listener, short type)
          Registers a listener to receive events of the given type on objects contained within this data source.
abstract  void addListener(LyDataSourceListener listener, java.util.Vector<LyField> fields)
          Registers a listener to receive modification events concerning given fields on objects contained within this data source.
 boolean checkObject(LyObjectId objectId)
          Tests if an object corresponding to a given object id is found in the cache of this data source.
 boolean checkObject(java.lang.Object object)
          Internal method to check validy of an object given as parameter.
 LyResponse createObject(java.lang.Object object, LyResponseListener listener, LyClassBinding classBinding)
          Create a new object on the associated data provider.
 LyResponse deleteObject(java.lang.Object object, LyResponseListener listener, LyClassBinding classBinding)
          Delete an object on the associated data provider.
 LyResponse deleteObjects(java.util.Vector<? extends java.lang.Object> objects, LyResponseListener listener, LyClassBinding classBinding)
          Delete a list of objects on the associated data provider.
 LyApplication getApplication()
          Gets the application of this data source.
 LyCache getCache()
          Gets the cache associated to this data source.
 LyClass getDataClass()
          Retrieves the class of data handled by this data source.
 LyDataProvider getDataProvider()
          Gets the provider of the data in this data source.
 long getLastModified()
          Returns the last time a modification occured within this data source.
abstract  java.lang.Object getObject(LyObjectId id)
          Gets an object from this data source by the specified identifier.
 java.lang.Object getObject(LyObjectId id, java.util.Vector<LyField> fields, LyClassBinding classBinding)
          Gets an object from this data source by the specified identifier.
 int getSize()
          Return the number of objects within this data source.
 int getSize(LyFilter filter)
          Return the number of objects within this data source matching the given filter.
 int getSize(LyFilter filter, LyClassBinding classBinding)
          Return the number of objects within this data source matching the given filter.
 boolean isReadOnly()
          Checks if the data source is read only or not.
 boolean isRollBack()
          The rollBack status of this datasource.
 boolean isSynchronous()
          Checks if the data source is synchronous or not.
 LyResponse loadObject(LyObjectId id, java.util.Vector<? extends LyField> fields, LyResponseListener listener, LyClassBinding classBinding)
          Method to load an object from its id on the associated data provider.
 LyResponse loadObjects(java.util.Vector<? extends LyField> fields, LySort sort, LyFilter filter, int n, LyResponseListener listener, LyClassBinding classBinding)
          Method for loading objects on the associated data provider.
 boolean receiveEvent(java.lang.String groupId, LyEventNotifier.EventType type, java.lang.Object object, LyValueSet values)
          This method is used by the event notifier to notify the data source for data changes made by other applications using the same datas.
 void receiveResponse(LyResponse response, LyResponse.Status status, java.lang.Object object, LyValueSet oldValues)
          Method used to receive a new response from data provider to a request sent by this data source.
 LyResponse reloadObject(LyObjectId id, java.util.Vector<? extends LyField> fields, LyResponseListener listener, LyClassBinding classBinding)
          Method to reload an object from its id on the associated data provider.
abstract  void removeListener(LyDataSourceListener listener)
          Unregisters a listener for notifications from this data source.
abstract  void setCache(LyInfoCache cachePolicy)
          Sets the cache for this data source.
 void setIgnoreErrorOnLoad(boolean ignoreErrorOnLoad)
          Sets the ignore error on load for this datasource.
 LyResponse setObject(java.lang.Object object, LyResponseListener listener, LyClassBinding classBinding)
          Set an object on the associated data provider.
 LyResponse setObjects(java.util.Vector<? extends java.lang.Object> objects, LyResponseListener listener, LyClassBinding classBinding)
          Set a list of objects on the associated data provider.
 void setReadOnly(boolean readOnly)
          Sets the write mode of this data source.
 void setRollBack(boolean rollBack)
          Set the rollBack status of this datasource.
 void setSynchronous(boolean synchronous)
          Sets the synchronous mode of this data source.
 void unload()
          Unloads completely the data of this datasource.
 void unload(boolean notify)
          Unloads completely the data of this datasource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

public static final java.lang.String __VERSION
File version

See Also:
Constant Field Values
Constructor Detail

LyDataSource

public LyDataSource(LyDataProvider provider,
                    LyClass dataClass)
Constructs a data source within the given application that manages the specified class.

Parameters:
provider - Provider on which this data source is connected.
dataClass - Class of data handled by this new data source.
Method Detail

setCache

public abstract void setCache(LyInfoCache cachePolicy)
Sets the cache for this data source.

Parameters:
cachePolicy - Informations for the cache to associate to this object source.
Throws:
java.lang.IllegalArgumentException - If the given cache policy is null.
java.lang.IllegalStateException - If the data source is already associated to a cache that contains objects.

getDataProvider

public final LyDataProvider getDataProvider()
Gets the provider of the data in this data source.

Returns:
Provider of the data managed in this data source.

getDataClass

public final LyClass getDataClass()
Retrieves the class of data handled by this data source.

Returns:
Class of the data managed in this data source.

getCache

public final LyCache getCache()
Gets the cache associated to this data source. Depends on the cache policy chosen for the data class.

Returns:
Cache instance associated to this data source.

getApplication

public final LyApplication getApplication()
Gets the application of this data source.

Returns:
Application of this data source.

getLastModified

public long getLastModified()
Returns the last time a modification occured within this data source.

Returns:
Last modification date of this data source.

isReadOnly

public final boolean isReadOnly()
Checks if the data source is read only or not.

Returns:
True if the data source is read only, false if it is writable.

isSynchronous

public final boolean isSynchronous()
Checks if the data source is synchronous or not.

Returns:
True if the data source sends request in synchronous mode, false if they are sent asynchronously.

setReadOnly

public void setReadOnly(boolean readOnly)
Sets the write mode of this data source. When turned to read only, modification requests are not accepted anymore.

Parameters:
readOnly - True if read only, false if writable.

setIgnoreErrorOnLoad

public void setIgnoreErrorOnLoad(boolean ignoreErrorOnLoad)
Sets the ignore error on load for this datasource. If an error occured during the load of an object by its id, the object is not registered in the unknown object list if this parameter is set to true. - INTERNAL USE ONLY -

Parameters:
ignoreErrorOnLoad - True to enable the mode, false if writable.

setSynchronous

public void setSynchronous(boolean synchronous)
Sets the synchronous mode of this data source.

Parameters:
synchronous - True if the data source sends request in synchronous mode, false if they are sent asynchronously.

addListener

public void addListener(LyDataSourceListener listener)
Registers a listener to receive all events on objects contained within this data source.

Parameters:
listener - New listener. To receive these events, the listener have to implement the LyDataSourceListener interface.

addListener

public abstract void addListener(LyDataSourceListener listener,
                                 short type)
Registers a listener to receive events of the given type on objects contained within this data source.

Parameters:
listener - New listener. To receive these events, the listener have to implement the LyDataSourceListener interface.
type - Indicates which type of event the listener wants to receive. Types are defined as constant in LyDataSourceEvent class : TYPE_CREATE, TYPE_SET, TYPE_DELETE
Throws:
java.lang.IllegalArgumentException - If the listener is null or if the given type is unknown.

addListener

public abstract void addListener(LyDataSourceListener listener,
                                 java.util.Vector<LyField> fields)
Registers a listener to receive modification events concerning given fields on objects contained within this data source. Warning ! This method only registers the listener for modification events.

Parameters:
listener - New listener. To receive these events, the listener have to implement the LyDataSourceListener interface.
fields - List of fields on which the listener wants to be notified when they are modified.
Throws:
java.lang.IllegalArgumentException - If the listener is null.

removeListener

public abstract void removeListener(LyDataSourceListener listener)
Unregisters a listener for notifications from this data source. The given listener is unregistered for all types of events he has been registered for.

Parameters:
listener - The listener which shall not receive further events.
Throws:
java.lang.IllegalArgumentException - If the listener is null or if it is not known as listener on this data source.

unload

public void unload()
Unloads completely the data of this datasource. Empties associated cache. This methods notifies virews for objects deletions.


unload

public void unload(boolean notify)
Unloads completely the data of this datasource. Empties associated cache.

Parameters:
notify - indicates wether the unload action should notify objects deletion. Notifying deletions makes sense when views are opened and when application is not exiting.

getObject

public java.lang.Object getObject(LyObjectId id,
                                  java.util.Vector<LyField> fields,
                                  LyClassBinding classBinding)
Gets an object from this data source by the specified identifier.

Parameters:
id - Object identifier of the searched object.
fields - A list of fields that need to be fetched. Null for all.
classBinding - Binding between logical class and physical class. This binding may contain extra information required for encoding the request.
Returns:
The requested object if it was found, or null if it could not be found.

getObject

public abstract java.lang.Object getObject(LyObjectId id)
Gets an object from this data source by the specified identifier.

Parameters:
id - Object identifier of the searched object.
Returns:
The requested object if it was found, or null if it could not be found.

getSize

public int getSize()
Return the number of objects within this data source.

Returns:
Number of objects found.

getSize

public int getSize(LyFilter filter)
Return the number of objects within this data source matching the given filter.

Parameters:
filter - Filter applied on objects for counting.
Returns:
Number of objects matching the given filter in this data source.

getSize

public int getSize(LyFilter filter,
                   LyClassBinding classBinding)
Return the number of objects within this data source matching the given filter.

Parameters:
filter - Filter applied on objects for counting.
classBinding - Binding between logical class and physical class. This binding may contain extra information required for encoding the request (such as extra filter).
Returns:
Number of objects matching the given filter in this data source.

checkObject

public boolean checkObject(LyObjectId objectId)
Tests if an object corresponding to a given object id is found in the cache of this data source.

Parameters:
objectId - Object id for which an object is searched.
Returns:
True if an object with the given object id is found in the cache, else false.

checkObject

public boolean checkObject(java.lang.Object object)
Internal method to check validy of an object given as parameter.

Parameters:
object - Checked object.
Returns:
True if the given object is found in the cache, else false.

createObject

public LyResponse createObject(java.lang.Object object,
                               LyResponseListener listener,
                               LyClassBinding classBinding)
Create a new object on the associated data provider. This method commits local creation by creating the object on the physical layer.

Parameters:
object - Object to create.
listener - Listener of the response.
classBinding - Binding between logical class and physical class. This binding may contain extra information required for encoding the request.
Returns:
Response to the creation.
Throws:
java.lang.IllegalStateException - If the data source is in read only mode.

setObject

public LyResponse setObject(java.lang.Object object,
                            LyResponseListener listener,
                            LyClassBinding classBinding)
Set an object on the associated data provider. This method commits local modification by setting the object on the physical layer.

Parameters:
object - Object to modify.
listener - Listener of the response.
classBinding - Binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the modification.
Throws:
java.lang.IllegalStateException - If the data source is in read only mode.
java.lang.IllegalArgumentException - If the given object is invalid.

setObjects

public LyResponse setObjects(java.util.Vector<? extends java.lang.Object> objects,
                             LyResponseListener listener,
                             LyClassBinding classBinding)
Set a list of objects on the associated data provider. This method commits local modifications by setting the objects on the physical layer.

Parameters:
objects - List of objects to modify.
listener - Listener of the response.
classBinding - Binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the modification.
Throws:
java.lang.IllegalStateException - If the data source is in read only mode.
java.lang.IllegalArgumentException - If given objects list is null or if one of these objects is invalid.

deleteObject

public LyResponse deleteObject(java.lang.Object object,
                               LyResponseListener listener,
                               LyClassBinding classBinding)
Delete an object on the associated data provider. This method commits local deletion by deleting the object on the physical layer.

Parameters:
object - Object to delete.
listener - Listener of the response.
classBinding - Binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the deletion.
Throws:
java.lang.IllegalStateException - If the data source is in read only mode.
java.lang.IllegalArgumentException - If the given object is invalid.

deleteObjects

public LyResponse deleteObjects(java.util.Vector<? extends java.lang.Object> objects,
                                LyResponseListener listener,
                                LyClassBinding classBinding)
Delete a list of objects on the associated data provider. This method commits local deletions by deleting the objects on the physical layer.

Parameters:
objects - List of objects to delete.
listener - Listener of the response.
classBinding - Binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the deletion.
Throws:
java.lang.IllegalStateException - If the data source is in read only mode.
java.lang.IllegalArgumentException - If given objects list is null or if one of these objects is invalid.

reloadObject

public LyResponse reloadObject(LyObjectId id,
                               java.util.Vector<? extends LyField> fields,
                               LyResponseListener listener,
                               LyClassBinding classBinding)
Method to reload an object from its id on the associated data provider. Load fields of an object from a given object id.

Parameters:
id - Object identifier corresponding to the object to reload.
fields - Fields to load (null means all fields).
listener - Listener of the response.
classBinding - binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the loading.

loadObject

public LyResponse loadObject(LyObjectId id,
                             java.util.Vector<? extends LyField> fields,
                             LyResponseListener listener,
                             LyClassBinding classBinding)
Method to load an object from its id on the associated data provider. Load fields of an object from a given object id.

Parameters:
id - Object identifier corresponding to the object to load.
fields - Fields to load (null means all fields).
listener - Listener of the response.
classBinding - binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the loading.

loadObjects

public LyResponse loadObjects(java.util.Vector<? extends LyField> fields,
                              LySort sort,
                              LyFilter filter,
                              int n,
                              LyResponseListener listener,
                              LyClassBinding classBinding)
Method for loading objects on the associated data provider. Load fields of a specified number of objects sorted by a given sort and that match a given filter.

Parameters:
fields - Fields to load (null means all fields).
sort - Gives sort criteria, or null if there is no sort (the order is the one of the physical layer).
filter - Gives filter criteria, or null if there is no filter (all objects).
n - Indicates the number of objects to load (-1 means no limit).
listener - Listener of the response.
classBinding - binding between logical class and physical class This binding may contain extra information required for encoding the request.
Returns:
Response to the loading.

receiveResponse

public void receiveResponse(LyResponse response,
                            LyResponse.Status status,
                            java.lang.Object object,
                            LyValueSet oldValues)
Method used to receive a new response from data provider to a request sent by this data source. This method may be called several times if several objects are concerned.

Parameters:
response - Response where there is a new object concerned.
status - Status of the new response. Valid status are defined in LyResponse.
object - Object concerned by this response.
oldValues - Values that have changed for the object with this response (null when the operation is not a load or a modifcation).
Throws:
java.lang.IllegalArgumentException - If response parameter is null.
See Also:
LyResponse, createObject(java.lang.Object, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), setObject(java.lang.Object, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), setObjects(java.util.Vector, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), deleteObject(java.lang.Object, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), deleteObjects(java.util.Vector, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), loadObject(leon.data.LyObjectId, java.util.Vector, leon.data.LyResponseListener, leon.info.binding.LyClassBinding), loadObjects(java.util.Vector, leon.info.LySort, leon.info.LyFilter, int, leon.data.LyResponseListener, leon.info.binding.LyClassBinding)

receiveEvent

public boolean receiveEvent(java.lang.String groupId,
                            LyEventNotifier.EventType type,
                            java.lang.Object object,
                            LyValueSet values)
This method is used by the event notifier to notify the data source for data changes made by other applications using the same datas.

Parameters:
groupId - Id of the group of events. May be null for non grouped events.
type - Type of the event. Valid types are defined in LyEventNotifier.
object - Object concerned by the event
values - New values.
Returns:
True if the event was treated with success, false otherwise.

setRollBack

public void setRollBack(boolean rollBack)
Set the rollBack status of this datasource.

Parameters:
rollBack - true indicates that a rollback is on the way

isRollBack

public boolean isRollBack()
The rollBack status of this datasource.

Returns:
true during a rollback

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com