Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/lisk/LiskDAO.php
| Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
| * @task load Loading Objects | * @task load Loading Objects | ||||
| * @task info Examining Objects | * @task info Examining Objects | ||||
| * @task save Writing Objects | * @task save Writing Objects | ||||
| * @task hook Hooks and Callbacks | * @task hook Hooks and Callbacks | ||||
| * @task util Utilities | * @task util Utilities | ||||
| * @task xaction Managing Transactions | * @task xaction Managing Transactions | ||||
| * @task isolate Isolation for Unit Testing | * @task isolate Isolation for Unit Testing | ||||
| */ | */ | ||||
| abstract class LiskDAO extends Phobject { | abstract class LiskDAO extends Phobject | ||||
| implements AphrontDatabaseTableRefInterface { | |||||
| const CONFIG_IDS = 'id-mechanism'; | const CONFIG_IDS = 'id-mechanism'; | ||||
| const CONFIG_TIMESTAMPS = 'timestamps'; | const CONFIG_TIMESTAMPS = 'timestamps'; | ||||
| const CONFIG_AUX_PHID = 'auxiliary-phid'; | const CONFIG_AUX_PHID = 'auxiliary-phid'; | ||||
| const CONFIG_SERIALIZATION = 'col-serialization'; | const CONFIG_SERIALIZATION = 'col-serialization'; | ||||
| const CONFIG_BINARY = 'binary'; | const CONFIG_BINARY = 'binary'; | ||||
| const CONFIG_COLUMN_SCHEMA = 'col-schema'; | const CONFIG_COLUMN_SCHEMA = 'col-schema'; | ||||
| const CONFIG_KEY_SCHEMA = 'key-schema'; | const CONFIG_KEY_SCHEMA = 'key-schema'; | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | /* -( Managing Connections )----------------------------------------------- */ | ||||
| /** | /** | ||||
| * Return a namespace for this object's connections in the connection cache. | * Return a namespace for this object's connections in the connection cache. | ||||
| * Generally, the database name is appropriate. Two connections are considered | * Generally, the database name is appropriate. Two connections are considered | ||||
| * equivalent if they have the same connection namespace and mode. | * equivalent if they have the same connection namespace and mode. | ||||
| * | * | ||||
| * @return string Connection namespace for cache | * @return string Connection namespace for cache | ||||
| * @task conn | * @task conn | ||||
| */ | */ | ||||
| abstract protected function getConnectionNamespace(); | protected function getConnectionNamespace() { | ||||
| return $this->getDatabaseName(); | |||||
| } | |||||
| abstract protected function getDatabaseName(); | |||||
| /** | /** | ||||
| * Get an existing, cached connection for this object. | * Get an existing, cached connection for this object. | ||||
| * | * | ||||
| * @param mode Connection mode. | * @param mode Connection mode. | ||||
| * @return AphrontDatabaseConnection|null Connection, if it exists in cache. | * @return AphrontDatabaseConnection|null Connection, if it exists in cache. | ||||
| * @task conn | * @task conn | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | if ($connection->isReadLocking()) { | ||||
| $lock_clause = 'FOR UPDATE'; | $lock_clause = 'FOR UPDATE'; | ||||
| } else if ($connection->isWriteLocking()) { | } else if ($connection->isWriteLocking()) { | ||||
| $lock_clause = 'LOCK IN SHARE MODE'; | $lock_clause = 'LOCK IN SHARE MODE'; | ||||
| } | } | ||||
| $args = func_get_args(); | $args = func_get_args(); | ||||
| $args = array_slice($args, 1); | $args = array_slice($args, 1); | ||||
| $pattern = 'SELECT * FROM %T WHERE '.$pattern.' %Q'; | $pattern = 'SELECT * FROM %R WHERE '.$pattern.' %Q'; | ||||
| array_unshift($args, $this->getTableName()); | array_unshift($args, $this); | ||||
| array_push($args, $lock_clause); | array_push($args, $lock_clause); | ||||
| array_unshift($args, $pattern); | array_unshift($args, $pattern); | ||||
| return call_user_func_array( | return call_user_func_array( | ||||
| array($connection, 'queryData'), | array($connection, 'queryData'), | ||||
| $args); | $args); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 607 Lines • ▼ Show 20 Lines | foreach ($map as $key => $value) { | ||||
| } else { | } else { | ||||
| $map[$key] = qsprintf($conn, '%C = %ns', $key, $value); | $map[$key] = qsprintf($conn, '%C = %ns', $key, $value); | ||||
| } | } | ||||
| } | } | ||||
| $map = implode(', ', $map); | $map = implode(', ', $map); | ||||
| $id = $this->getID(); | $id = $this->getID(); | ||||
| $conn->query( | $conn->query( | ||||
| 'UPDATE %T SET %Q WHERE %C = '.(is_int($id) ? '%d' : '%s'), | 'UPDATE %R SET %Q WHERE %C = '.(is_int($id) ? '%d' : '%s'), | ||||
| $this->getTableName(), | $this, | ||||
| $map, | $map, | ||||
| $this->getIDKeyForUse(), | $this->getIDKeyForUse(), | ||||
| $id); | $id); | ||||
| // We can't detect a missing object because updating an object without | // We can't detect a missing object because updating an object without | ||||
| // changing any values doesn't affect rows. We could jiggle timestamps | // changing any values doesn't affect rows. We could jiggle timestamps | ||||
| // to catch this for objects which track them if we wanted. | // to catch this for objects which track them if we wanted. | ||||
| $this->didWriteData(); | $this->didWriteData(); | ||||
| Show All 10 Lines | /* -( Writing Objects )---------------------------------------------------- */ | ||||
| * @task save | * @task save | ||||
| */ | */ | ||||
| public function delete() { | public function delete() { | ||||
| $this->isEphemeralCheck(); | $this->isEphemeralCheck(); | ||||
| $this->willDelete(); | $this->willDelete(); | ||||
| $conn = $this->establishConnection('w'); | $conn = $this->establishConnection('w'); | ||||
| $conn->query( | $conn->query( | ||||
| 'DELETE FROM %T WHERE %C = %d', | 'DELETE FROM %R WHERE %C = %d', | ||||
| $this->getTableName(), | $this, | ||||
| $this->getIDKeyForUse(), | $this->getIDKeyForUse(), | ||||
| $this->getID()); | $this->getID()); | ||||
| $this->didDelete(); | $this->didDelete(); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | foreach ($data as $key => $value) { | ||||
| get_class($this), | get_class($this), | ||||
| $key), | $key), | ||||
| $parameter_exception); | $parameter_exception); | ||||
| } | } | ||||
| } | } | ||||
| $data = implode(', ', $data); | $data = implode(', ', $data); | ||||
| $conn->query( | $conn->query( | ||||
| '%Q INTO %T (%LC) VALUES (%Q)', | '%Q INTO %R (%LC) VALUES (%Q)', | ||||
| $mode, | $mode, | ||||
| $this->getTableName(), | $this, | ||||
| $columns, | $columns, | ||||
| $data); | $data); | ||||
| // Only use the insert id if this table is using auto-increment ids | // Only use the insert id if this table is using auto-increment ids | ||||
| if ($id_mechanism === self::IDS_AUTOINCREMENT) { | if ($id_mechanism === self::IDS_AUTOINCREMENT) { | ||||
| $this->setID($conn->getInsertID()); | $this->setID($conn->getInsertID()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 745 Lines • ▼ Show 20 Lines | public function getColumnMaximumByteLength($column) { | ||||
| } | } | ||||
| $data_type = $map[$column]; | $data_type = $map[$column]; | ||||
| return id(new PhabricatorStorageSchemaSpec()) | return id(new PhabricatorStorageSchemaSpec()) | ||||
| ->getMaximumByteLengthForDataType($data_type); | ->getMaximumByteLengthForDataType($data_type); | ||||
| } | } | ||||
| /* -( AphrontDatabaseTableRefInterface )----------------------------------- */ | |||||
| public function getAphrontRefDatabaseName() { | |||||
| return $this->getDatabaseName(); | |||||
| } | |||||
| public function getAphrontRefTableName() { | |||||
| return $this->getTableName(); | |||||
| } | |||||
| } | } | ||||