dbw = $dbw; $this->logger = $logger; $this->id = $id; $this->didbegin = false; /* If we are not in a transaction, we need to be for savepoint trickery */ if ( !$dbw->trxLevel() ) { $dbw->begin( __CLASS__, DatabasePostgres::TRANSACTION_INTERNAL ); $this->didbegin = true; } } public function __destruct() { if ( $this->didbegin ) { $this->dbw->rollback(); $this->didbegin = false; } } public function commit() { if ( $this->didbegin ) { $this->dbw->commit( __CLASS__, DatabasePostgres::FLUSHING_INTERNAL ); $this->didbegin = false; } } protected function query( $keyword, $msg_ok, $msg_failed ) { if ( $this->dbw->doQuery( $keyword . " " . $this->id ) !== false ) { $this->logger->debug( sprintf( $msg_ok, $this->id ) ); } else { $this->logger->debug( sprintf( $msg_failed, $this->id ) ); } } public function savepoint() { $this->query( "SAVEPOINT", "Transaction state: savepoint \"%s\" established.\n", "Transaction state: establishment of savepoint \"%s\" FAILED.\n" ); } public function release() { $this->query( "RELEASE", "Transaction state: savepoint \"%s\" released.\n", "Transaction state: release of savepoint \"%s\" FAILED.\n" ); } public function rollback() { $this->query( "ROLLBACK TO", "Transaction state: savepoint \"%s\" rolled back.\n", "Transaction state: rollback of savepoint \"%s\" FAILED.\n" ); } public function __toString() { return (string)$this->id; } }