Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
c6a13278
Commit
c6a13278
authored
Mar 31, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed lockVersion to optimisticLock
parent
7de94d7f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
ActiveRecord.php
framework/db/ActiveRecord.php
+12
-12
No files found.
framework/db/ActiveRecord.php
View file @
c6a13278
...
@@ -277,19 +277,19 @@ class ActiveRecord extends Model
...
@@ -277,19 +277,19 @@ class ActiveRecord extends Model
}
}
/**
/**
* Returns the
column name that stores the lock version of a table row
.
* Returns the
name of the column that stores the lock version for implementing optimistic locking
.
*
*
*
This is used to implement optimistic locking. Optimistic locking allows multiple users
*
Optimistic locking allows multiple users to access the same record for edits. In case
*
to access the same record for edits. In case when a user attempts to save the record upon
*
when a user attempts to save the record upon some staled data (because another user
*
some staled data (because another user has modified the data), a [[StaleObjectException]]
*
has modified the data), a [[StaleObjectException]] exception will be thrown, and
*
will be thrown, and the update
is ignored.
*
the update or deletion
is ignored.
*
*
* Optimized locking is only supported by [[update()]] and [[delete()]].
* Optimized locking is only supported by [[update()]] and [[delete()]].
*
*
* To use optimized locking:
* To use optimized locking:
*
*
* 1. create a column to store the lock version. The column type should be
integer (or bigint)
* 1. create a column to store the lock version. The column type should be
`BIGINT DEFAULT 0`.
*
and default to 0.
Override this method to return the name of this column.
* Override this method to return the name of this column.
* 2. In the Web form that collects the user input, add a hidden field that stores
* 2. In the Web form that collects the user input, add a hidden field that stores
* the lock version of the recording being updated.
* the lock version of the recording being updated.
* 3. In the controller action that does the data updating, try to catch the [[StaleObjectException]]
* 3. In the controller action that does the data updating, try to catch the [[StaleObjectException]]
...
@@ -299,7 +299,7 @@ class ActiveRecord extends Model
...
@@ -299,7 +299,7 @@ class ActiveRecord extends Model
* @return string the column name that stores the lock version of a table row.
* @return string the column name that stores the lock version of a table row.
* If null is returned (default implemented), optimistic locking will not be supported.
* If null is returned (default implemented), optimistic locking will not be supported.
*/
*/
public
static
function
lockVersion
()
public
function
optimisticLock
()
{
{
return
null
;
return
null
;
}
}
...
@@ -739,7 +739,7 @@ class ActiveRecord extends Model
...
@@ -739,7 +739,7 @@ class ActiveRecord extends Model
* meaning all attributes that are loaded from DB will be saved.
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
* or [[beforeSave()]] stops the updating process.
* @throws StaleObjectException if [[
lockVersion
|optimistic locking]] is enabled and the data
* @throws StaleObjectException if [[
optimisticLock
|optimistic locking]] is enabled and the data
* being updated is outdated.
* being updated is outdated.
*/
*/
public
function
update
(
$runValidation
=
true
,
$attributes
=
null
)
public
function
update
(
$runValidation
=
true
,
$attributes
=
null
)
...
@@ -751,7 +751,7 @@ class ActiveRecord extends Model
...
@@ -751,7 +751,7 @@ class ActiveRecord extends Model
$values
=
$this
->
getDirtyAttributes
(
$attributes
);
$values
=
$this
->
getDirtyAttributes
(
$attributes
);
if
(
$values
!==
array
())
{
if
(
$values
!==
array
())
{
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
lockVersion
();
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
if
(
$lock
!==
null
)
{
$values
[
$lock
]
=
$this
->
$lock
+
1
;
$values
[
$lock
]
=
$this
->
$lock
+
1
;
$condition
[
$lock
]
=
new
Expression
(
"[[
$lock
]]+1"
);
$condition
[
$lock
]
=
new
Expression
(
"[[
$lock
]]+1"
);
...
@@ -823,7 +823,7 @@ class ActiveRecord extends Model
...
@@ -823,7 +823,7 @@ class ActiveRecord extends Model
*
*
* @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
* @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
* Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
* Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
* @throws StaleObjectException if [[
lockVersion
|optimistic locking]] is enabled and the data
* @throws StaleObjectException if [[
optimisticLock
|optimistic locking]] is enabled and the data
* being deleted is outdated.
* being deleted is outdated.
*/
*/
public
function
delete
()
public
function
delete
()
...
@@ -832,7 +832,7 @@ class ActiveRecord extends Model
...
@@ -832,7 +832,7 @@ class ActiveRecord extends Model
// we do not check the return value of deleteAll() because it's possible
// we do not check the return value of deleteAll() because it's possible
// the record is already deleted in the database and thus the method will return 0
// the record is already deleted in the database and thus the method will return 0
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$condition
=
$this
->
getOldPrimaryKey
(
true
);
$lock
=
$this
->
lockVersion
();
$lock
=
$this
->
optimisticLock
();
if
(
$lock
!==
null
)
{
if
(
$lock
!==
null
)
{
$condition
[
$lock
]
=
$this
->
$lock
;
$condition
[
$lock
]
=
$this
->
$lock
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment