mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
#17893298 : added DB based lock (using unique key)
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6000 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
fb18db9528
commit
ea7c87ec0d
5 changed files with 60 additions and 0 deletions
|
|
@ -646,5 +646,33 @@
|
|||
$args->module_filebox_srl = $vars->module_filebox_srl;
|
||||
return executeQuery('module.deleteModuleFileBox', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function of locking (timeout is in seconds)
|
||||
*/
|
||||
function lock($lock_name, $timeout, $member_srl = null) {
|
||||
$this->unlockTimeoutPassed();
|
||||
$args->lock_name = $lock_name;
|
||||
if(!$timeout) $timeout = 60;
|
||||
$args->deadline = date("YmdHis", time() + $timeout);
|
||||
if($member_srl) $args->member_srl = $member_srl;
|
||||
$output = executeQuery('module.insertLock', $args);
|
||||
if($output->toBool()) {
|
||||
$output->add('lock_name', $lock_name);
|
||||
$output->add('deadline', $args->deadline);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function unlockTimeoutPassed() {
|
||||
executeQuery('module.deleteLocksTimeoutPassed');
|
||||
}
|
||||
|
||||
function unlock($lock_name, $deadline) {
|
||||
$args->lock_name = $lock_name;
|
||||
$args->deadline = $deadline;
|
||||
$output = executeQuery('module.deleteLock', $args);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
9
modules/module/queries/deleteLock.xml
Normal file
9
modules/module/queries/deleteLock.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<query id="deleteLock" action="delete">
|
||||
<tables>
|
||||
<table name="module_locks" />
|
||||
</tables>
|
||||
<conditions>
|
||||
<condition operation="equal" column="lock_name" var="lock_name" notnull="notnull" />
|
||||
<condition operation="equal" column="deadline" var="deadline" notnull="notnull" pipe="and" />
|
||||
</conditions>
|
||||
</query>
|
||||
8
modules/module/queries/deleteLocksTimeoutPassed.xml
Normal file
8
modules/module/queries/deleteLocksTimeoutPassed.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<query id="deleteLocksTimeoutPassed" action="delete">
|
||||
<tables>
|
||||
<table name="module_locks" />
|
||||
</tables>
|
||||
<conditions>
|
||||
<condition operation="below" column="deadline" var="deadline" default="curdate()" notnull="notnull" />
|
||||
</conditions>
|
||||
</query>
|
||||
10
modules/module/queries/insertLock.xml
Normal file
10
modules/module/queries/insertLock.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<query id="insertLock" action="insert">
|
||||
<tables>
|
||||
<table name="module_locks" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="lock_name" var="lock_name" notnull="notnull" />
|
||||
<column name="deadline" var="deadline" notnull="notnull" />
|
||||
<column name="member_srl" var="member_srl" />
|
||||
</columns>
|
||||
</query>
|
||||
5
modules/module/schemas/module_locks.xml
Normal file
5
modules/module/schemas/module_locks.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<table name="module_locks">
|
||||
<column name="lock_name" type="varchar" size="40" notnull="notnull" unique="unique_lock_name" />
|
||||
<column name="deadline" type="date" index="idx_deadline" />
|
||||
<column name="member_srl" type="number" size="11" />
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue