Package | mx.data |
Class | public class DataService |
Inheritance | DataService ![]() ![]() |
Subclasses | DataService |
Language Version: | ActionScript 3.0 |
Product Version: | Adobe Digital Enterprise Platform Data Services for Java EE 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
A DataService instance is constructed specifying the desired destination. Destinations are generally configured from the services-config.xml file, but can also be configured dynamically with runtime configuration, as in the case of model-driven development.
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.
For collection managed objects, you use the DataService.fill()
method.
This method populates an ArrayCollection with objects that this service
manages.
To get single manged objects, use the DataService.getItem()
and
DataService.createItem()
methods.
When a previously filled ArrayCollection is no longer needed
or the items within that collection should no longer receive or create
updates, call the DataService.releaseCollection()
method.
When an item previously retrieved using DataService.getItem()
or DataService.createItem()
is no longer needed or should not
receive or create updates, call the DataService.releaseItem()
method
The DataService.createItem()
and
DataService.getItem()
methods return an
ItemReference instance that you can use to release a specific instance of a single managed
object.
Unlike the DataService.releaseItem()
method, calling the
ItemReference.releaseItem()
method releases a specific instance of
a single managed object.
The DataService.releaseItem()
method releases the first single managed object that it
finds with an identity that matches a specified identity.
This is fine as long as the number of calls to the
DataService.getItem()
and DataService.createItem()
methods matches the number of calls to the DataService.releaseItem()
method.
A connection to the remote destination is created automatically the first
time you call any methods that require a connection.
For example, when you call the DataService.fill()
method or
the DataService.commit()
method when there are uncommitted
updates, the DataService instance attempts to establish a connection to the remote destination.
To force a DataService instance to disconnect, call the
DataService.disconnect()
method.
You can use the DataService.disconnect()
method to clean up remote destination resources
that are no longer needed.
Because other services may be using the same physical connection, calling the
DataService.disconnect()
method may terminate the connection.
The bindable connected
property indicates the current state
of the associated DataService connection.
If a remote destination has declared any security constraints for an
operation, you must provide credentials by calling the DataService.setCredentials()
method.
A call to the DataService.setCredentials()
method turns into a login command at the remote destination.
To change credentials or invalidate the current session, call
the DataService.logout()
method, which releases all
local managed data.
Calling the DataService.logout()
method is equivalent to calling the
DataService.release()
method.
Each DataService instance has a dataStore
property that
returns an object of type mx.data.DataStore
.
This object stores the uncommitted changes for one or more
DataService instances.
By default, a DataService instance shares the same
DataStore instance with other DataService instances if they have managed
association properties and share the same set of channels.
When sharing a DataStore instance, a call to the commit()
method
on one DataService instance commits changes for all
DataService instances using the shared DataStore instance.
This preserves the order of operations in the event that there are dependencies
between the changes in the associated DataService instances.
DataService and DataStore instances 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 instances share the same collection of managed objects and 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 still receives those events. Each operation you initiate on a DataService instance returns an AsyncToken instance. You can add an event responder to that AsyncToken instance to receive a result event specific to that operation. This approach often produces cleaner code than adding a result or fault event handler globally for a given destination.
You can use data binding on properties of any managed object for a
DataService instance.
A DataService instance also dispatches a "message" event when a remote
operation occurs for any managed object.
For example, when a remote process updates a locally managed item, a
message is pushed to all DataService instances that are
still managing that item.
This message is dispatched as a MessageEvent.MESSAGE
event.
A conflict event is dispatched when a conflict is detected either at the remote destination in response to
a change the DataService instance commits or due to a pushed
change that conflicts with a local uncommitted change.
You can handle conflict events by listening for
DataConflictEvent.CONFLICT
.
Use data binding to update user interface controls by binding to the
DataService.conflicts.resolved
property.
The DataService class supports the following data synchronization configuration modes:
-
autoCommit
- when true each change is immediately sent to the remote destination when detected. When this isfalse
, you must make an explicit call to thecommit()
method. Use the bindableDataService.commitRequired
property determine if there are uncommitted changes. -
autoSyncEnabled
- This affects anyfill()
,getItem()
orcreateItem()
method calls and determines whether managed instances listen for changes made to these objects by other clients or by the DataServiceTransaction server push API at the remote destination. -
autoMerge
- Controls whether changes received from a remote destination are applied immediately or queued up until a call to theDataService.merge()
method is made.
Use the DataService.revertChanges()
method 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 data at the remote destination.
If the changes are in error, you typically make a call to the
DataService.revertChanges()
method to undo the changes as part
of a fault handler.
The mx.data.mxml.DataService class is an MXML-specific subclass of the mx.data.DataService class that allows binding to the properties of a DataService instance.
MXML Syntax
The <mx:DataService> element accepts the following 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." />
More examples
Related API Elements
mx.data.Conflicts
mx.data.Conflict
mx.data.ItemReference
mx.data.IManaged
mx.data.utils.Managed
mx.data.IChangeObject
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object |
Method | Defined By | ||
---|---|---|---|
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object |
Thu Dec 6 2018, 01:12 PM -08:00