1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Document transactions in docs

Summary:
Also add some formatting and links.

Also fix test broken by D2393.

Test Plan:
  diviner .

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2461
This commit is contained in:
vrana 2012-05-11 15:05:15 -07:00
parent f22d9131c6
commit b20ae2a07f
3 changed files with 34 additions and 25 deletions

View file

@ -111,6 +111,12 @@ us to construct short, human-readable object names (like D2258) and URIs. Global
PHIDs allow us to represent relationships between different types of objects in PHIDs allow us to represent relationships between different types of objects in
a homogenous way. a homogenous way.
= Transactions =
Transactional code should be written using transactions. Example of such code is
inserting multiple records where one doesn't make sense without the other or
selecting data later used for update. See chapter in @{class:LiskDAO}.
= Advanced Features = = Advanced Features =
We don't use MySQL advanced features such as triggers, stored procedures or We don't use MySQL advanced features such as triggers, stored procedures or

View file

@ -43,7 +43,8 @@
* *
* To create new Lisk objects, extend @{class:LiskDAO} and implement * To create new Lisk objects, extend @{class:LiskDAO} and implement
* @{method:establishLiveConnection}. It should return an * @{method:establishLiveConnection}. It should return an
* AphrontDatabaseConnection; this will tell Lisk where to save your objects. * @{class:AphrontDatabaseConnection}; this will tell Lisk where to save your
* objects.
* *
* class Dog extends LiskDAO { * class Dog extends LiskDAO {
* *
@ -57,6 +58,7 @@
* *
* Now, you should create your table: * Now, you should create your table:
* *
* lang=sql
* CREATE TABLE dog ( * CREATE TABLE dog (
* id int unsigned not null auto_increment primary key, * id int unsigned not null auto_increment primary key,
* name varchar(32) not null, * name varchar(32) not null,
@ -65,17 +67,17 @@
* dateModified int unsigned not null * dateModified int unsigned not null
* ); * );
* *
* For each property in your class, add a column with the same name to the * For each property in your class, add a column with the same name to the table
* table (see getConfiguration() for information about changing this mapping). * (see @{method:getConfiguration} for information about changing this mapping).
* Additionally, you should create the three columns `id`, `dateCreated` and * Additionally, you should create the three columns `id`, `dateCreated` and
* `dateModified`. Lisk will automatically manage these, using them to implement * `dateModified`. Lisk will automatically manage these, using them to implement
* autoincrement IDs and timestamps. If you do not want to use these features, * autoincrement IDs and timestamps. If you do not want to use these features,
* see getConfiguration() for information on disabling them. At a bare minimum, * see @{method:getConfiguration} for information on disabling them. At a bare
* you must normally have an `id` column which is a primary or unique key with a * minimum, you must normally have an `id` column which is a primary or unique
* numeric type, although you can change its name by overriding getIDKey() or * key with a numeric type, although you can change its name by overriding
* disable it entirely by overriding getIDKey() to return null. Note that many * @{method:getIDKey} or disable it entirely by overriding @{method:getIDKey} to
* methods rely on a single-part primary key and will no longer work (they will * return null. Note that many methods rely on a single-part primary key and
* throw) if you disable it. * will no longer work (they will throw) if you disable it.
* *
* As you add more properties to your class in the future, remember to add them * As you add more properties to your class in the future, remember to add them
* to the database table as well. * to the database table as well.
@ -88,7 +90,7 @@
* *
* = Creating, Retrieving, Updating, and Deleting = * = Creating, Retrieving, Updating, and Deleting =
* *
* To create and persist a Lisk object, use save(): * To create and persist a Lisk object, use @{method:save}:
* *
* $dog = id(new Dog()) * $dog = id(new Dog())
* ->setName('Sawyer') * ->setName('Sawyer')
@ -96,26 +98,27 @@
* ->save(); * ->save();
* *
* Note that **Lisk automatically builds getters and setters for all of your * Note that **Lisk automatically builds getters and setters for all of your
* object's properties** via __call(). If you want to add custom behavior to * object's protected properties** via @{method:__call}. If you want to add
* your getters or setters, you can do so by overriding the readField and * custom behavior to your getters or setters, you can do so by overriding the
* writeField methods. * @{method:readField} and @{method:writeField} methods.
* *
* Calling save() will persist the object to the database. After calling * Calling @{method:save} will persist the object to the database. After calling
* save(), you can call getID() to retrieve the object's ID. * @{method:save}, you can call @{method:getID} to retrieve the object's ID.
* *
* To load objects by ID, use the load() method: * To load objects by ID, use the @{method:load} method:
* *
* $dog = id(new Dog())->load($id); * $dog = id(new Dog())->load($id);
* *
* This will load the Dog record with ID $id into $dog, or ##null## if no such * This will load the Dog record with ID $id into $dog, or ##null## if no such
* record exists (load() is an instance method rather than a static method * record exists (@{method:load} is an instance method rather than a static
* because PHP does not support late static binding, at least until PHP 5.3). * method because PHP does not support late static binding, at least until PHP
* 5.3).
* *
* To update an object, change its properties and save it: * To update an object, change its properties and save it:
* *
* $dog->setBreed('Lab')->save(); * $dog->setBreed('Lab')->save();
* *
* To delete an object, call delete(): * To delete an object, call @{method:delete}:
* *
* $dog->delete(); * $dog->delete();
* *
@ -124,7 +127,7 @@
* = Queries = * = Queries =
* *
* Often, you want to load a bunch of objects, or execute a more specialized * Often, you want to load a bunch of objects, or execute a more specialized
* query. Use loadAllWhere() or loadOneWhere() to do this: * query. Use @{method:loadAllWhere} or @{method:loadOneWhere} to do this:
* *
* $pugs = $dog->loadAllWhere('breed = %s', 'Pug'); * $pugs = $dog->loadAllWhere('breed = %s', 'Pug');
* $sawyer = $dog->loadOneWhere('name = %s', 'Sawyer'); * $sawyer = $dog->loadOneWhere('name = %s', 'Sawyer');
@ -132,8 +135,8 @@
* These methods work like @{function:queryfx}, but only take half of a query * These methods work like @{function:queryfx}, but only take half of a query
* (the part after the WHERE keyword). Lisk will handle the connection, columns, * (the part after the WHERE keyword). Lisk will handle the connection, columns,
* and object construction; you are responsible for the rest of it. * and object construction; you are responsible for the rest of it.
* loadAllWhere() returns a list of objects, while loadOneWhere() returns a * @{method:loadAllWhere} returns a list of objects, while
* single object (or null). * @{method:loadOneWhere} returns a single object (or `null`).
* *
* = Managing Transactions = * = Managing Transactions =
* *
@ -159,6 +162,9 @@
* Assuming ##$obj##, ##$other## and ##$another## live on the same database, * Assuming ##$obj##, ##$other## and ##$another## live on the same database,
* this code will work correctly by establishing savepoints. * this code will work correctly by establishing savepoints.
* *
* Selects whose data are used later in the transaction should be included in
* @{method:beginReadLocking} or @{method:beginWriteLocking} block.
*
* @task conn Managing Connections * @task conn Managing Connections
* @task config Configuring Lisk * @task config Configuring Lisk
* @task load Loading Objects * @task load Loading Objects

View file

@ -34,7 +34,6 @@ final class LiskFixtureTestCase extends PhabricatorTestCase {
id(new PhabricatorUser()) id(new PhabricatorUser())
->setUserName('alincoln') ->setUserName('alincoln')
->setRealName('Abraham Lincoln') ->setRealName('Abraham Lincoln')
->setEmail('alincoln@example.com')
->save(); ->save();
} }
@ -46,7 +45,6 @@ final class LiskFixtureTestCase extends PhabricatorTestCase {
id(new PhabricatorUser()) id(new PhabricatorUser())
->setUserName('ugrant') ->setUserName('ugrant')
->setRealName('Ulysses S. Grant') ->setRealName('Ulysses S. Grant')
->setEmail('ugrant@example.com')
->save(); ->save();
} }
@ -58,7 +56,6 @@ final class LiskFixtureTestCase extends PhabricatorTestCase {
id(new PhabricatorUser()) id(new PhabricatorUser())
->setUserName('gwashington') ->setUserName('gwashington')
->setRealName('George Washington') ->setRealName('George Washington')
->setEmail('gwashington@example.com')
->save(); ->save();
$this->assertEqual( $this->assertEqual(