Package | mx.data |
Class | public class DataService |
Inheritance | DataService DataManager Object |
Subclasses | DataService |
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
A DataService is constructed specifying the desired destination. These destinations are generally configured from the services-config.xml file.
There are two different sets of methods that retrieve data from the specified remote destination. The first are for collection managed objects. The second are for Single Managed Objects (SMOs).
For the collection managed objects the DataService.fill()
method
is used.
This method populates an ArrayCollection with objects that this services
will manage.
To get SMOs the DataService.getItem()
and
DataService.createItem()
methods are used.
When a previously filled ArrayCollection is no longer needed,
or the items within that collection should no longer receive or create
updates, the DataService.releaseCollection()
method is called.
When an item previously retrieved using DataService.getItem()
or DataService.createItem()
is no longer needed or should not
receive or create updates, the DataService.releaseItem()
method
should be called.
The DataService.createItem()
and
DataService.getItem()
methods return an
ItemReference.
This object can be used to release a specific instance of a single managed
object.
Unlike the DataService.releaseItem()
method, calling
ItemReference.releaseItem()
will release a specific instance of
an SMO.
DataService.releaseItem()
will release the first SMO that it
finds with a matching identity to that specified.
This is normally okay as long as the number of calls to
DataService.getItem()
and DataService.createItem()
matches the number of calls to DataService.releaseItem()
.
A connection to the remote destination is created automatically the first
time any methods that require a connection are called.
For example, calling the DataService.fill()
method or
DataService.commit()
operation when there are uncommitted
updates will attempt to establish a connection to the remote destination.
To force a DataService to become disconnected use the
DataService.disconnect()
method.
This method can be used to clean up remote destination resources when no
longer needed.
Because other services may be using the same physical connection calling
DataService.disconnect()
may terminate the connection.
The bindable property connected
indicates the current state
of the associated DataService connection.
If a remote destination has declared any security constraints for an
operation, credentials must be provided.
Credentials are set via the DataService.setCredentials()
call.
This turns into a login command at the remote destination.
To change credentials or invalidate the current session
DataService.logout()
can be called.
When called the DataService.logout()
method will release all
local managed data.
It is equivalent to calling DataService.release()
.
Each DataService has a dataStore
property that
returns an object of type mx.data.DataStore
.
This object stores the uncommitted changes for one or more
DataService objects.
By default, a DataService shares the same
DataStore with other data services if they have managed
association properties and share the same set of channels.
When sharing DataStores, a commit()
method
call on one DataService commits changes for all
DataService using the shared data store.
This preserves the order of operations in the event there are dependencies
between the changes in the associated DataService objects.
DataService and DataStore dispatch result and fault events for all operations that require a remote call.
NOTE: if you create two DataService instances that point to the same destination both of those instances will share the same collection of managed objects, and will dispatch the same set of events. For example, if you add an event listener to one DataService instance for a destination, and you use a different instance to initiate an operation, the first DataService instance will still receive those events. Each operation you initiate on a DataService returns an AsyncToken. You can add an event responder to that token to receive a result event specific for that operation. This approach often produces cleaner code than adding a result or fault event handler globally for a given destination.
Data binding can be used on properties of any managed instances for a
DataService.
DataService will also dispatch a "message" event when a remote
operation occurs for any managed object.
For example when a locally managed item is updated by a remote process a
message will be pushed to all DataService instances that are
still managing that item.
This message is dispatched as a MessageEvent.MESSAGE
event.
When a conflict is detected either at the remote destination in response to
a change committed by the DataService, or due to a pushed
change which conflicts with a local uncommitted change, a conflict
event is dispatched.
These events can be handled by listening for the
DataConflictEvent.CONFLICT
.
Data binding can be employed to update UI controls by binding to the
DataService.conflicts.resolved
property.
DataService supports the following data synchronization configuration modes:
-
autoCommit
- when true each change is immediately sent to the remote destination once detected. When this isfalse
, an explicit call to commit must be made. The bindableDataService.commitRequired
property can be used to determine whether or not there are uncommitted changes. -
autoSyncEnabled
- This affects any fill, getItem or createItem calls made and determines whether managed instances listen for changes made to these objects by other clients or using the server push api at the remote destination. -
autoMerge
property controls whether or not changes received from a remote destination are applied immediately or queued up until a call toDataService.merge()
is made.
The DataService.revertChanges()
method is used to revert
changes for a specific item or for all items.
When an error occurs for a remote destination operation, the committed
changes are put back into the uncommitted queue so the data stays in sync
with the remote destination data.
If the changes are in error, typically a call to
DataService.revertChanges()
is made to undo the changes as part
of a fault handler.
The mx.data.mxml.DataService class is an MXML-specific subclass of mx.data.DataService that allows binding to the properties of a DataService.
MXML SyntaxHide MXML SyntaxThe <mx:DataService> tag accepts the following tag attributes:
<mx:DataService Properties autoCommit="true" autoMerge="true" autoSaveCache="false" autoSyncEnabled="true" conflictDetector="No default." dataStore="No default." destination="No default." pageSize="No default." id="No default." Events conflict="No default." fault="No default." message="No default." propertyChange="No default." result="No default." />
See also
mx.data.Conflicts
mx.data.Conflict
mx.data.ItemReference
mx.data.IManaged
mx.data.utils.Managed
mx.data.IChangeObject
Creating a DataService component
Property | Defined By | ||
---|---|---|---|
adapter : DataServiceAdapter = null
An instance of a class which controls interaction with the server. | DataManager | ||
autoCommit : Boolean
Indicates if changes to the local cache are automatically committed. | DataManager | ||
autoConnect : Boolean
Indicates if this service should attempt to connect for any operations
that require a connection. | DataManager | ||
autoMerge : Boolean
If set to false, when changes are pushed from the remote
destination to the client they are not immediately applied. | DataManager | ||
autoSaveCache : Boolean
The local cache of data and changes can be stored to disk. | DataManager | ||
autoSyncEnabled : Boolean
When true, fill(), createItem() and
getItem() requests return items which listen for updates
made to these items from the remote destination. | DataManager | ||
cacheID : String
Provides access to the cache identifier for this service. | DataManager | ||
channelSet : ChannelSet
Provides access to the ChannelSet used by the service. | DataService | ||
commitRequired : Boolean [read-only]
Indicates if there are changes that have not been committed and
the commit() method should be called. | DataManager | ||
conflictDetector : ConflictDetector
Provides access to the current implementation being used to
detect conflicts for remote operations pushed to this
DataService. | DataManager | ||
conflicts : Conflicts [read-only]
Contains a Conflicts object, an ArrayList of
Conflict instances. | DataManager | ||
connected : Boolean [read-only]
Indicates if the DataService is connected to the remote destination. | DataManager | ||
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
dataStore : DataStore
Contains an object of type mx.data.DataStore. | DataManager | ||
deleteItemOnRemoveFromFill : Boolean
By default when you call the removeItemAt() method on a managed filled collection, it
issues a delete item call to the server to physically remove the item. | DataManager | ||
destination : String [read-only]
Indicates which remote destination this service is associated with. | DataService | ||
hierarchicalEventsDefault : Boolean
Associations optionally list for property change events on properties of
the associated instances. | DataManager | ||
indexReferences : Boolean
To tune the speed of your application, set this property to false
if you have a small number of fills or references to items managed by this
data service from association properties of other items. | DataManager | ||
isInitialized : Boolean [read-only]
Indicates if the metadata associated with this service is initialized. | DataManager | ||
manualSync : ManualSyncConfiguration
The manualSync property provides access to the ManualSyncConfiguration
instance for each data service. | DataManager | ||
maxFrequency : uint
Determines the maximum number of messages per second the DataManager wants
to receive. | DataManager | ||
mergeRequired : Boolean [read-only]
Indicates if there are any pending changes that must be
merged. | DataManager | ||
pageSize : int
Provides access to the current page size setting for all collections. | DataManager | ||
pagingEnabled : Boolean [read-only]
Indicates if the remote destination is configured to allow paged
requests. | DataManager | ||
priority : int
The default message priority for the messages sent by the data service. | DataManager | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | ||
requestTimeout : int
Provides access to the request timeout in seconds for an operation. | DataManager | ||
resetCollectionOnFill : Boolean
When true, after the fill operation completes, a RESET event is
sent. | DataManager | ||
resubscribeAttempts : int
Controls the number of times a disconnected data service will attempt to
resubscribe. | DataManager | ||
resubscribeInterval : int
Controls the delay, in milliseconds, between resubscribe attempts. | DataManager | ||
subscribed : Boolean [read-only]
Indicates if the DataService is subscribed to the remote destination. | DataManager | ||
throwItemPendingErrors : Boolean
Set this property to false if you want to suppress the throwing of item pending
errors when lazily fetched or unpaged data is accessed. | DataManager |
Method | Defined By | ||
---|---|---|---|
DataService(destination:String)
Constructs an instance of the DataService with the specified
destination. | DataService | ||
Clears any data stored to disk with a previous call to
saveCache() or when autoSaveCache was set to
true
| DataManager | ||
Clears the data specified by the passed descriptor from the local store. | DataManager | ||
Commits pending changes for all collections currently managed by
the DataStore associated with this data service. | DataManager | ||
Forces a connection attempt by this service to the remote destination. | DataManager | ||
Calls a count method on the remote destination. | DataManager | ||
Requests that the specified item be created in the remote store. | DataManager | ||
Requests that the specified item be deleted from the remote store. | DataManager | ||
Disconnects the DataService's network connection. | DataManager | ||
Executes a query with the provided name and arguments. | DataManager | ||
Fills the specified ListCollectionView based
on the associated fill method of the destination. | DataManager | ||
Fills the specified ListCollectionView based
on the associated fill method of the destination. | DataManager | ||
Executes a query which returns a single item. | DataManager | ||
Returns an ArrayCollection or a single managed object (SMO) from the
the local store. | DataManager | ||
getCacheDescriptors(view:ListCollectionView, options:uint = 0, item:Object = null):mx.rpc:AsyncToken
This method will fill the specified ListCollectionView with
CacheDataDescriptor(s). | DataManager | ||
This method will fill the specified ListCollectionView
with all cache identifiers previously used in the application. | DataManager | ||
Makes an asynchronous request for an item matching the
specified identity. | DataManager | ||
Looks up the supplied item with the given identity. | DataManager | ||
Returns page information for the specified collection. | DataManager | ||
Returns the pending operation in the message cache for the specified
item. | DataManager | ||
Indicates whether an object has a specified property defined. | Object | ||
Forces initialization of the DataStore. | DataManager | ||
Returns true if the passed collection is managed by this service. | DataManager | ||
Returns true if the passed collection is using paging features. | DataManager | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Returns true if the supplied range of items is all paged in. | DataManager | ||
Logs the user out of the destination for the DataService. | DataService | ||
Merges any pending updates into the managed set of objects. | DataManager | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Refreshes all data managed by this data service. | DataManager | ||
Refreshes an array collection previously filled with the fill method or managed as
a managed association. | DataManager | ||
Releases all managed collections and items for the DataService. | DataManager | ||
releaseCollection(view:ListCollectionView, clear:Boolean = false, copyStillManagedItems:Boolean = true):void
Releases any item within the specified collection from management by
this service. | DataManager | ||
releaseItem(item:IManaged, copyStillManagedItems:Boolean = true, enableStillManagedCheck:Boolean = true):IManaged
Releases the specified item from management by this service. | DataManager | ||
Releases a range of items in the collection. | DataManager | ||
Releases the value for a single-valued association. | DataManager | ||
Reverts any uncommitted changes to the specified item. | DataManager | ||
Reverts the changes for any item contained in the specified collection which should
be managed by this data service. | DataManager | ||
This method will save the current state of the DataService cache. | DataManager | ||
Sets the credentials for this DataService destination. | DataService | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Sets the credentials for the third party of this DataService destination. | DataService | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Triggers an update for the specified item. | DataManager | ||
Returns the primitive value of the specified object. | Object |
Event | Summary | Defined By | ||
---|---|---|---|---|
The DataConflictEvent.CONFLICT event is dispatched when a conflict is detected between either pending local changes and changes submitted by another client, or when changes submitted by this client are conflicting with those in the remote destination. | DataService | |||
The DataServiceFaultEvent.FAULT event is dispatched when a service call fails due to an error. | DataService | |||
The MessageEvent.MESSAGE event is dispatched when the remote destination pushes a notification of a data operation. | DataService | |||
The PropertyChangeEvent.PROPERTY_CHANGE event is dispatched when a property of this service changes. | DataService | |||
The ResultEvent.RESULT event is dispatched when a service call successfully returns. | DataService |
channelSet | property |
channelSet:ChannelSet
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Provides access to the ChannelSet used by the service.
The ChannelSet can be manually constructed and assigned, or it will be
dynamically created to use the configured Channels for the
destination
for this service.
Implementation
public function get channelSet():ChannelSet
public function set channelSet(value:ChannelSet):void
destination | property |
destination:String
[read-only] Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Indicates which remote destination this service is associated with.
Implementation
public function get destination():String
DataService | () | Constructor |
public function DataService(destination:String)
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Constructs an instance of the DataService with the specified destination. The destination must be a reference to a destination configured in the services-config.xml file.
Parametersdestination:String — that contains the name of the desired destination.
|
logout | () | method |
public function logout():void
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Logs the user out of the destination for the DataService. Logging out of a destination applies to everything connected using the same ChannelSet as specified in the server configuration. For example, if you are connected over the my-rtmp channel and you log out using one of your DataService instances, anything that was connected over the same ChannelSet is logged out.
Note: Adobe recommends that you use the mx.messaging.ChannelSet.logout() method rather than this method.
See also
setCredentials | () | method |
public function setCredentials(username:String, password:String):void
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Sets the credentials for this DataService destination. The credentials are applied to all services connected over the same ChannelSet.
Parameters
username:String — The username for the destination.
| |
password:String — The password for the destination
|
setRemoteCredentials | () | method |
public function setRemoteCredentials(username:String, password:String):void
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
Sets the credentials for the third party of this DataService destination.
Parameters
username:String — The username for the destination.
| |
password:String — The password for the destination.
|
conflict | Event |
mx.data.events.DataConflictEvent
property DataConflictEvent.type =
mx.data.events.DataConflictEvent.CONFLICT
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
The DataConflictEvent.CONFLICT
event is dispatched when a
conflict is detected between either pending local changes and changes
submitted by another client, or when changes submitted by this
client are conflicting with those in the remote destination.
Each DataService sends conflict events only for items of this
particular destination.
Use the conflict event on the DataService if you need to handle
conflicts for a set of related destinations at the same time.
CONFLICT
constant defines the value of the type
property
of the event object for a conflict
event.
The properties of the event object have the following values:
Property | Value |
---|---|
bubbles | false |
cancelable | false |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
conflict | The Conflict object that holds the conflict that occurred. |
message | The Message associated with this event. |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
fault | Event |
mx.data.events.DataServiceFaultEvent
property DataServiceFaultEvent.type =
mx.data.events.DataServiceFaultEvent.FAULT
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
The DataServiceFaultEvent.FAULT
event is dispatched when a
service call fails due to an error.
For example, a call to the fill()
method dispatches this event
if the call fails.
You'll also get this event for each item which generates an error as part of
a commit result.
In this case, the DataServiceFaultEvent will contain
the token returned by the commit, but the item and error message strings in
the fault are specific to the item which caused the error.
FAULT
constant defines the value of the type
property
of the event object for a fault
event.
The properties of the event object have the following values:
Property | Value |
---|---|
bubbles | false |
cancelable | true, calling preventDefault() from the associated token's responder.fault method will prevent the service or operation from dispatching this event |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
fault | The Fault object that holds the conflict that occurred. |
item | The item that generated the fault. |
identity | The identity of of the item that generated the fault. |
message | The Message associated with this event. |
token | The token that represents the call to the method. Used in the asynchronous completion token pattern. |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
message | Event |
mx.messaging.events.MessageEvent
property MessageEvent.type =
mx.messaging.events.MessageEvent.MESSAGE
The MessageEvent.MESSAGE
event is dispatched when the remote
destination pushes a notification of a data operation.
For example, when data is updated in the remote destination an update
operation is sent to all clients listening, this operation is converted to
a message event on this DataService.
The value of this constant is "message"
.
The properties of the event object have the following values:
Property | Value |
---|---|
bubbles | false |
cancelable | false |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
message | The message associated with this event. |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
propertyChange | Event |
mx.events.PropertyChangeEvent
property PropertyChangeEvent.type =
mx.events.PropertyChangeEvent.PROPERTY_CHANGE
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
The PropertyChangeEvent.PROPERTY_CHANGE
event is dispatched
when a property of this service changes.
This happens for the following properties:
commitRequired
mergeRequired
connected
PropertyChangeEvent.PROPERTY_CHANGE
constant defines the value of the
type
property of the event object for a PropertyChange
event.
The properties of the event object have the following values:
Property | Value |
---|---|
bubbles | Determined by the constructor; defaults to false. |
cancelable | Determined by the constructor; defaults to false. |
kind | The kind of change; PropertyChangeEventKind.UPDATE or PropertyChangeEventKind.DELETE. |
oldValue | The original property value. |
newValue | The new property value, if any. |
property | The property that changed. |
source | The object that contains the property that changed. |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
result | Event |
mx.rpc.events.ResultEvent
property ResultEvent.type =
mx.rpc.events.ResultEvent.RESULT
Language Version: | ActionScript 3.0 |
Product Version: | LiveCycle Data Services 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
The ResultEvent.RESULT
event is dispatched when a service call
successfully returns.
For example a call to fill()
will dispatch this event if the
call is successful.
The properties of the event object have the following values:
Property | Value |
---|---|
bubbles | false |
cancelable | true, preventDefault() from the associated token's responder.result method will prevent the service or operation from dispatching this event |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
message | The Message associated with this event. |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
result | Result that the RPC call returns. |
token | The token that represents the indiviudal call to the method. Used in the asynchronous completion token pattern. |
Fri Mar 19 2010, 02:45 AM -07:00