A transaction is an object that is used to prepare and send a transaction
to the server.
The object encapsulates:
- the collections definitions for locking
- the actual javascript function
- additional options like waitForSync, lockTimeout and params
The transaction object requires the connection object and can be initialized
with or without initial transaction configuration.
Any configuration can be set and retrieved by the object's methods like this:
$this->setAction('function (){your code};');
$this->setCollections(array('read' => 'my_read_collection, 'write' => array('col_1', 'col2')));
or like this:
$this->action('function (){your code};');
$this->collections(array('read' => 'my_read_collection, 'write' => array('col_1', 'col2')));
There are also helper functions to set collections directly, based on their locking:
$this->setReadCollections($array or $string if single collection)
$this->setWriteCollections($array or $string if single collection)
$this->setExclusiveCollections($array or $string if single collection)
package |
ArangoDBClient |
since |
1.3 |
inherited_from |
\ArangoDBClient\TransactionBase |
Methods
Initialise the transaction object
__construct(\ArangoDBClient\Connection $connection, array $transactionArray = null
)
The $transaction array can be used to specify the collections, action and further
options for the transaction in form of an array.
Example:
array(
'collections' => array(
'write' => array(
'my_collection'
)
),
'action' => 'function (){}',
'waitForSync' => true
)
inherited_from |
\ArangoDBClient\TransactionBase::__construct() |
Parameters
$connection
\ArangoDBClient\Connection
- the connection to be used
$transactionArray
array
- transaction initialization data
Exceptions
\ArangoDBClient\ClientException |
|
Initialise the transaction object
__construct(\ArangoDBClient\Connection $connection)
Inherited
Parameters
$connection
\ArangoDBClient\Connection
- the connection to be used
Exceptions
\ArangoDBClient\ClientException |
|
Get an attribute, magic method
__get(string $key) : mixed
This function is mapped to get() internally.
magic |
|
inherited_from |
\ArangoDBClient\TransactionBase::__get() |
Parameters
Returns
mixed
- value of attribute, NULL if attribute is not set
Get an attribute, magic method
__get(string $key) : mixed
Inherited
This function is mapped to get() internally.
Parameters
Returns
mixed
- value of attribute, NULL if attribute is not set
Is triggered by calling isset() or empty() on inaccessible properties.
__isset(string $key) : boolean
inherited_from |
\ArangoDBClient\TransactionBase::__isset() |
Parameters
Returns
boolean
returns true or false (set or not set)
Is triggered by calling isset() or empty() on inaccessible properties.
__isset(string $key) : boolean
Inherited
Parameters
Returns
boolean
returns true or false (set or not set)
Set an attribute, magic method
__set(string $key, mixed $value) : void
This is a magic method that allows the object to be used without
declaring all document attributes first.
magic |
|
inherited_from |
\ArangoDBClient\TransactionBase::__set() |
Parameters
Exceptions
\ArangoDBClient\ClientException |
|
Set an attribute, magic method
__set(string $key, mixed $value) : void
Inherited
This is a magic method that allows the object to be used without
declaring all document attributes first.
Parameters
Exceptions
\ArangoDBClient\ClientException |
|
Returns the action string
__toString() : string
Returns
string
- the current action string
Build the object's attributes from a given array
buildTransactionAttributesFromArray($options)
inherited_from |
\ArangoDBClient\TransactionBase::buildTransactionAttributesFromArray() |
Parameters
$options
Exceptions
\ArangoDBClient\ClientException |
|
Execute the transaction
execute() : mixed
This will post the query to the server and return the results as
a Cursor. The cursor can then be used to iterate the results.
Exceptions
\ArangoDBClient\Exception |
throw exception if transaction failed |
Returns
mixed
true if successful without a return value or the return value if one was set in the action
Get an attribute
get(string $key) : mixed
Inherited
Parameters
Returns
mixed
- value of attribute, NULL if attribute is not set
get action value
getAction() : string
Get collections array
getCollections() : array
Inherited
This holds the read and write collections of the transaction
Returns
array
$value
Convenience function to directly get exclusive-collections without having to access
them from the collections attribute.
getExclusiveCollections() : array
Inherited
Get lockTimeout value
getLockTimeout() : integer
Inherited
Returns
integer
lockTimeout
Get params value
getParams() : array
Convenience function to directly get read-collections without having to access
them from the collections attribute.
getReadCollections() : array
Inherited
get waitForSync value
getWaitForSync() : boolean
Inherited
Returns
boolean
waitForSync
Convenience function to directly get write-collections without having to access
them from the collections attribute.
getWriteCollections() : array
Inherited
Sets an attribute
set($key, $value)
inherited_from |
\ArangoDBClient\TransactionBase::set() |
Parameters
$key
$value
Exceptions
\ArangoDBClient\ClientException |
|
Sets an attribute
set($key, $value)
Inherited
Parameters
$key
$value
Exceptions
\ArangoDBClient\ClientException |
|
set action value
setAction(string $value)
Parameters
$value
string
Exceptions
\ArangoDBClient\ClientException |
|
Set the collections array.
setCollections(array $value)
Inherited
The array should have 2 sub-arrays, namely 'read' and 'write' which should hold the respective collections
for the transaction
Parameters
$value
array
Convenience function to directly set exclusive-collections without having to access
them from the collections attribute.
setExclusiveCollections(array $value)
Inherited
Set lockTimeout value
setLockTimeout(integer $value)
Inherited
Parameters
$value
integer
Exceptions
\ArangoDBClient\ClientException |
|
Set params value
setParams(array $value)
Parameters
$value
array
Exceptions
\ArangoDBClient\ClientException |
|
Convenience function to directly set read-collections without having to access
them from the collections attribute.
setReadCollections(array $value)
Inherited
set waitForSync value
setWaitForSync(boolean $value)
Inherited
Parameters
$value
boolean
Exceptions
\ArangoDBClient\ClientException |
|
Convenience function to directly set write-collections without having to access
them from the collections attribute.
setWriteCollections(array $value)
Inherited
Build the object's attributes from a given array
buildTransactionAttributesFromArray($options)
Inherited
Parameters
$options
Exceptions
\ArangoDBClient\ClientException |
|
Return the connection object
getConnection() : \ArangoDBClient\Connection
Inherited
Returns
\ArangoDBClient\Connection
- the connection object
Properties
- The action to pass to the server
$action : string
magic |
|
property |
- The action to pass to the server |
The transaction's attributes.
$attributes : array
- The collections array that includes both read and write collection definitions
$collection : array
magic |
|
property |
- The collections array that includes both read and write collection definitions |
- LockTimeout on the transaction
$lockTimeout : integer
magic |
|
property |
- LockTimeout on the transaction |
- The read-collections array or string (if only one)
$readCollection : mixed
magic |
|
property |
- The read-collections array or string (if only one) |
- WaitForSync on the transaction
$waitForSync : boolean
magic |
|
property |
- WaitForSync on the transaction |
- The write-collections array or string (if only one)
$writeCollection : mixed
magic |
|
property |
- The write-collections array or string (if only one) |
string The action property of the transaction.
$_action :
The connection object
$_connection : \ArangoDBClient\Connection
Constants
Action index
ENTRY_ACTION = 'action'
Collections index
ENTRY_COLLECTIONS = 'collections'
EXCLUSIVE index
ENTRY_EXCLUSIVE = 'exclusive'
Lock timeout index
ENTRY_LOCK_TIMEOUT = 'lockTimeout'
Params index
ENTRY_PARAMS = 'params'
Read index
ENTRY_READ = 'read'
WaitForSync index
ENTRY_WAIT_FOR_SYNC = 'waitForSync'
WRITE index
ENTRY_WRITE = 'write'