\triagens\ArangoDbTransaction

Transaction object

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->setWriteCollections($array or $string if single collection)
$this->setReadCollections($array or $string if single collection)


Summary

Methods
Properties
Constants
__construct()
execute()
setCollections()
getCollections()
setAction()
getAction()
setWaitForSync()
getWaitForSync()
setLockTimeout()
getLockTimeout()
setParams()
getParams()
setWriteCollections()
getWriteCollections()
setReadCollections()
getReadCollections()
set()
__set()
get()
__get()
__toString()
buildTransactionAttributesFromArray()
$collection
$readCollection
$writeCollection
$action
$waitForSync
$lockTimeout
ENTRY_COLLECTIONS
ENTRY_ACTION
ENTRY_WAIT_FOR_SYNC
ENTRY_LOCK_TIMEOUT
ENTRY_PARAMS
ENTRY_READ
ENTRY_WRITE
getConnection()
$attributes
N/A
No private methods found
$_connection
N/A

Constants

ENTRY_COLLECTIONS

ENTRY_COLLECTIONS

Collections index

ENTRY_ACTION

ENTRY_ACTION

Action index

ENTRY_WAIT_FOR_SYNC

ENTRY_WAIT_FOR_SYNC

WaitForSync index

ENTRY_LOCK_TIMEOUT

ENTRY_LOCK_TIMEOUT

Lock timeout index

ENTRY_PARAMS

ENTRY_PARAMS

Params index

ENTRY_READ

ENTRY_READ

Read index

ENTRY_WRITE

ENTRY_WRITE

WRITE index

Properties

$collection

$collection : array

  • The collections array that includes both read and write collection definitions

Type

array

$readCollection

$readCollection : mixed

  • The read-collections array or string (if only one)

Type

mixed

$writeCollection

$writeCollection : mixed

  • The write-collections array or string (if only one)

Type

mixed

$action

$action : string

  • The action to pass to the server

Type

string

$waitForSync

$waitForSync : boolean

  • WaitForSync on the transaction

Type

boolean

$lockTimeout

$lockTimeout : integer

  • LockTimeout on the transaction

Type

integer

$attributes

$attributes : array

The transaction's attributes.

Type

array

Methods

__construct()

__construct(\triagens\ArangoDb\Connection $connection, array $transactionArray) : \triagens\ArangoDb\Transaction

Initialise the transaction object

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 )

Parameters

\triagens\ArangoDb\Connection $connection
  • the connection to be used
array $transactionArray
  • transaction initialization data

Returns

\triagens\ArangoDb\Transaction

execute()

execute() : mixed

Execute the transaction

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.

Throws

\triagens\ArangoDb\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

setCollections()

setCollections(array $value)

Set the collections array.

The array should have 2 sub-arrays, namely 'read' and 'write' which should hold the respective collections for the transaction

Parameters

array $value

getCollections()

getCollections() : array

Get collections array

This holds the read and write collections of the transaction

Returns

array —

$value

setAction()

setAction(string $value)

set action value

Parameters

string $value

getAction()

getAction() : string

get action value

Returns

string —

action

setWaitForSync()

setWaitForSync(boolean $value)

set waitForSync value

Parameters

boolean $value

getWaitForSync()

getWaitForSync() : boolean

get waitForSync value

Returns

boolean —

waitForSync

setLockTimeout()

setLockTimeout(integer $value)

Set lockTimeout value

Parameters

integer $value

getLockTimeout()

getLockTimeout() : integer

Get lockTimeout value

Returns

integer —

lockTimeout

setParams()

setParams(array $value)

Set params value

Parameters

array $value

getParams()

getParams() : array

Get params value

Returns

array —

params

setWriteCollections()

setWriteCollections(array $value)

Convenience function to directly set write-collections without having to access them from the collections attribute.

Parameters

array $value

getWriteCollections()

getWriteCollections() : array

Convenience function to directly get write-collections without having to access them from the collections attribute.

Returns

array —

params

setReadCollections()

setReadCollections(array $value)

Convenience function to directly set read-collections without having to access them from the collections attribute.

Parameters

array $value

getReadCollections()

getReadCollections() : array

Convenience function to directly get read-collections without having to access them from the collections attribute.

Returns

array —

params

set()

set( $key,  $value)

Sets an attribute

Parameters

$key
$value

Throws

\triagens\ArangoDb\ClientException

__set()

__set(string $key, mixed $value) : void

Set an attribute, magic method

This is a magic method that allows the object to be used without declaring all document attributes first.

Parameters

string $key
  • attribute name
mixed $value
  • value for attribute

Throws

\triagens\ArangoDb\ClientException

get()

get(string $key) : mixed

Get an attribute

Parameters

string $key
  • name of attribute

Returns

mixed —
  • value of attribute, NULL if attribute is not set

__get()

__get(string $key) : mixed

Get an attribute, magic method

This function is mapped to get() internally.

Parameters

string $key
  • name of attribute

Returns

mixed —
  • value of attribute, NULL if attribute is not set

__toString()

__toString() : string

Returns the action string

Returns

string —
  • the current action string

buildTransactionAttributesFromArray()

buildTransactionAttributesFromArray( $options)

Build the object's attributes from a given array

Parameters

$options

getConnection()

getConnection() : \triagens\ArangoDb\Connection

Return the connection object

Returns

\triagens\ArangoDb\Connection
  • the connection object