public interface Transaction
A client's request to the server to add, remove or modify an entity in its own Data Base.
query()
method.
The TransactionID of a sent transaction may be saved, i.e. the 5
int
values that represents the TransactionID may be properly
saved (see TransactionID
for details). From these saved values it's
possibile to
recreate the original TransactionID and
then create a Transaction object, that represents this past transaction,
using the following two values:
Context.makeTransaction()
in which the
transaction parameters are described by TransactionParam
and the
event listeners are described by
TransactionListener
.
Once locally created a transaction may be
sent to the server, and/or its status may be
queried to the server.
It is also possibile to query the status of a
past pending transaction
if the programmer created a new Transaction with a saved
TransactionID of a sent transaction.
Context.makeTransaction()
,
TransactionParam
,
TransactionListener
Field Summary | |
---|---|
static int |
STATUS_ABORTED
Lifecycle and Transaction status: Transaction completed unsuccessfully and ready to be released. |
static int |
STATUS_COMMITTED
Lifecycle and Transaction status: Transaction completed successfully and ready to be released. |
static int |
STATUS_FLYING
Lifecycle and Transaction status: Transaction is flying waiting to become STATUS_COMMITTED or
STATUS_ABORTED . |
Fields inherited from interface ActivityLifeCycle |
---|
RESULT_INVALID_CONNECTION_STATUS |
Fields inherited from interface LifeCycle |
---|
RESULT_GENERIC_ERROR, RESULT_INVALID_STATUS, RESULT_OK, STATUS_INIT, STATUS_RELEASED |
Method Summary | |
---|---|
TransactionID |
getTransactionID()
Returns the TransactionID of this (new or past) transaction. |
int |
query()
Try to query the server for the status of this (new or past) transaction. |
int |
send()
Try to send this new transaction to the server. |
Methods inherited from interface ActivityLifeCycle |
---|
getConnection |
Methods inherited from interface CommunicationLifeCycle |
---|
getContext, getListener, getParam |
Methods inherited from interface LifeCycle |
---|
enumChilds, getStatus, release |
Field Detail |
---|
static final int STATUS_FLYING
STATUS_COMMITTED
or
STATUS_ABORTED
. LifeCycle.getStatus()
.
STATUS_INIT
→ send()
ok →
STATUS_FLYING
. STATUS_INIT
→ query()
ok →
STATUS_FLYING
.
query()
, onTransactionSend()
call, onTransactionQuery()
call.
STATUS_FLYING
→
onTransactionSend()
bad → STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_COMMITTED
→ STATUS_COMMITTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_INVALID_TRANSACTION_ID
→ STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_GENERIC_ERROR
→ STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_ABORTED
→ STATUS_ABORTED
.
static final int STATUS_COMMITTED
LifeCycle.getStatus()
.
It's always a good practice to release a Transaction in this status.
STATUS_FLYING
→
onTransactionQuery()
RESULT_COMMITTED
→ STATUS_COMMITTED
.
LifeCycle.release()
.
STATUS_COMMITTED
→ LifeCycle.release()
→
STATUS_RELEASED
.
static final int STATUS_ABORTED
LifeCycle.getStatus()
.
It's always a good practice to release a Transaction in this status.
STATUS_FLYING
→
onTransactionSend()
bad → STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_INVALID_TRANSACTION_ID
→ STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_GENERIC_ERROR
→ STATUS_ABORTED
. STATUS_FLYING
→
onTransactionQuery()
RESULT_ABORTED
→ STATUS_ABORTED
.
LifeCycle.release()
.
STATUS_ABORTED
→ LifeCycle.release()
→
STATUS_RELEASED
.
Method Detail |
---|
int send()
This method must be called only when
STATUS_INIT
,
Connection.STATUS_CONNECTED
,
past TransactionID
is
null
).
If this method invocation completed successfully,
then
STATUS_FLYING
,
TransactionListener.onTransactionSend()
will be automatically called to handle it.
otherwise
TransactionListener.onTransactionSend()
will not be made,
In the latter case it is a good practice to release this Transaction.
RESULT_OK
if the operation completed
successfully,
RESULT_INVALID_STATUS
if the
current status is not
STATUS_INIT
,
ActivityLifeCycle.RESULT_INVALID_CONNECTION_STATUS
if the
associated Connection
current status is not
Connection.STATUS_CONNECTED
,
RESULT_GENERIC_ERROR
otherwise Entity
is null
).
int query()
This method must be called only when
STATUS_INIT
or STATUS_FLYING
,
Connection.STATUS_CONNECTED
,
getTransactionID()
is not null
).
If this method invocation completed successfully,
then
STATUS_FLYING
,
TransactionListener.onTransactionQuery()
will be automatically called to handle it.
otherwise
TransactionListener.onTransactionQuery()
will not be made,
In the latter case it is a good practice to release this Transaction.
RESULT_OK
if the operation completed
successfully,
RESULT_INVALID_STATUS
if the
current status is not
STATUS_INIT
nor STATUS_FLYING
,
ActivityLifeCycle.RESULT_INVALID_CONNECTION_STATUS
if the
associated Connection
current status is not
Connection.STATUS_CONNECTED
,
RESULT_GENERIC_ERROR
otherwise getTransactionID()
is null
).
TransactionID getTransactionID()
If there is a valid
past TransactionID
then
this method returns it, otherwise it returns the new TransactionID that
will be used by the send()
method.
null
is returned when the
past TransactionID
exists but it does not belongs to
the associated connection.