Branch 'oracle' - lib/kolab_sync_db.php lib/kolab_sync.php lib/kolab_sync_transaction_manager.php
Aleksander Machniak
machniak at kolabsys.com
Thu Sep 18 11:31:33 CEST 2014
lib/kolab_sync.php | 2 -
lib/kolab_sync_db.php | 64 ---------------------------------
lib/kolab_sync_transaction_manager.php | 31 ++++-----------
3 files changed, 9 insertions(+), 88 deletions(-)
New commits:
commit c4bc1954b0d17155ed2bce9591f4e4d256f10452
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Thu Sep 18 11:30:12 2014 +0200
Handle database transactions with rcube_db class
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index ab9c27c..515076e 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -141,7 +141,7 @@ class kolab_sync extends rcube
// Register Syncroton backends
Syncroton_Registry::set('loggerBackend', $this->logger);
- Syncroton_Registry::set(Syncroton_Registry::DATABASE, new kolab_sync_db);
+ Syncroton_Registry::set(Syncroton_Registry::DATABASE, $this->get_dbh());
Syncroton_Registry::set(Syncroton_Registry::TRANSACTIONMANAGER, kolab_sync_transaction_manager::getInstance());
Syncroton_Registry::set(Syncroton_Registry::DEVICEBACKEND, new kolab_sync_backend_device);
Syncroton_Registry::set(Syncroton_Registry::FOLDERBACKEND, new kolab_sync_backend_folder);
diff --git a/lib/kolab_sync_db.php b/lib/kolab_sync_db.php
deleted file mode 100644
index b56ce52..0000000
--- a/lib/kolab_sync_db.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-/**
- +--------------------------------------------------------------------------+
- | Kolab Sync (ActiveSync for Kolab) |
- | |
- | Copyright (C) 2011-2012, Kolab Systems AG <contact at kolabsys.com> |
- | |
- | This program is free software: you can redistribute it and/or modify |
- | it under the terms of the GNU Affero General Public License as published |
- | by the Free Software Foundation, either version 3 of the License, or |
- | (at your option) any later version. |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public License |
- | along with this program. If not, see <http://www.gnu.org/licenses/> |
- +--------------------------------------------------------------------------+
- | Author: Aleksander Machniak <machniak at kolabsys.com> |
- +--------------------------------------------------------------------------+
-*/
-
-/**
- * Database layer wrapper with transaction support
- */
-class kolab_sync_db
-{
- /**
- * the database adapter
- *
- * @var rcube_db
- */
- protected $db;
-
-
- public function __construct()
- {
- $this->db = rcube::get_instance()->get_dbh();
- }
-
- public function beginTransaction()
- {
- $query = 'BEGIN';
-
- $this->db->query($query);
- }
-
- public function commit()
- {
- $query = 'COMMIT';
-
- $this->db->query($query);
- }
-
- public function rollBack()
- {
- $query = 'ROLLBACK';
-
- $this->db->query($query);
- }
-}
diff --git a/lib/kolab_sync_transaction_manager.php b/lib/kolab_sync_transaction_manager.php
index e097378..2121d89 100644
--- a/lib/kolab_sync_transaction_manager.php
+++ b/lib/kolab_sync_transaction_manager.php
@@ -103,13 +103,8 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
}
if (! in_array($_transactionable, $this->_openTransactionables)) {
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " new transactionable. Starting transaction on this resource");
- }
-
- if ($_transactionable instanceof kolab_sync_db) {
- //setAutocommit($_transactionable,false);
- $_transactionable->beginTransaction();
+ if ($_transactionable instanceof rcube_db) {
+ $_transactionable->startTransaction();
}
else {
$this->rollBack();
@@ -122,10 +117,6 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
$transactionId = sha1(mt_rand(). microtime());
array_push($this->_openTransactions, $transactionId);
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " queued transaction with id $transactionId");
- }
-
return $transactionId;
}
@@ -149,19 +140,14 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
$numOpenTransactions = count($this->_openTransactions);
if ($numOpenTransactions === 0) {
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " no more open transactions in queue commiting all transactionables");
- }
-
foreach ($this->_openTransactionables as $transactionableIdx => $transactionable) {
- if ($transactionable instanceof kolab_sync_db) {
- $transactionable->commit();
- //setAutocommit($transactionable,true);
+ if ($transactionable instanceof rcube_db) {
+ $transactionable->endTransaction();
}
}
$this->_openTransactionables = array();
- $this->_openTransactions = array();
+ $this->_openTransactions = array();
}
else {
if ($this->_logger instanceof Zend_Log) {
@@ -182,13 +168,12 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
}
foreach ($this->_openTransactionables as $transactionable) {
- if ($transactionable instanceof kolab_sync_db) {
- $transactionable->rollBack();
- //setAutocommit($transactionable,true);
+ if ($transactionable instanceof rcube_db) {
+ $transactionable->rollbackTransaction();
}
}
$this->_openTransactionables = array();
- $this->_openTransactions = array();
+ $this->_openTransactions = array();
}
}
More information about the commits
mailing list