jackalope/jackalope-doctrine-dbal — pull request #71 by lsmith77 (2012-11-05 17:13:51+00:00)
Title: updated to match changes in the WritingInterface

again lots of changes due to white space changes (``git diff -w master | pbcopy``)
```
diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php
index 0ac1faa..4373a31 100644
--- a/src/Jackalope/Transport/DoctrineDBAL/Client.php
+++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php
@@ -406,9 +406,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
// 4. if a reference is in the properties, either update the uuid based on the map if its inside the copied graph or keep it.
// 5. "May drop mixin types"

- try {
- $this->conn->beginTransaction();
-
$query = 'SELECT * FROM phpcr_nodes WHERE path LIKE ? AND workspace_name = ?';
$stmt = $this->conn->executeQuery($query, array($srcAbsPath . '%', $workspaceName));

@@ -426,12 +423,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
' SELECT ?, b.property_name, ?, b.idx, b.data FROM phpcr_binarydata b WHERE b.node_id = ?';
$this->conn->executeUpdate($query, array($newNodeId, $this->workspaceName, $srcNodeId));
}
-
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollBack();
- throw $e;
- }
}

/**
@@ -474,9 +465,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
// TODO: Not sure if there are always ALL props in $props, should we grab the online data here?
// TODO: Binary data is handled very inefficiently here, UPSERT will really be necessary here as well as lazy handling

- $this->conn->beginTransaction();
-
- try {
if (!$propsData) {
$propsData = $this->propsToXML($props);
}
@@ -531,33 +519,11 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
$this->syncBinaryData($nodeId, $propsData['binaryData']);
}

- // update foreign keys (references)
$this->syncForeignKeys($nodeId, $path, $props);

- // Update internal indexes
- $this->syncInternalIndexes();
- // Update user indexes
- $this->syncUserIndexes();
-
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollback();
- throw $e;
- }
-
return $nodeId;
}

- private function syncInternalIndexes()
- {
- // TODO implement syncInternalIndexes()
- }
-
- private function syncUserIndexes()
- {
- // TODO implement syncUserIndexes()
- }
-
private function syncBinaryData($nodeId, $binaryData)
{
foreach ($binaryData as $propertyName => $binaryValues) {
@@ -987,18 +953,7 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
WHERE (path = ? OR path LIKE ?)
AND workspace_name = ?';

- $this->conn->beginTransaction();
-
- try {
$this->conn->executeUpdate($query, $params);
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollBack();
-
- return false;
- }
-
- return true;
}

/**
@@ -1028,8 +983,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->loadXml($xml);

- $this->conn->beginTransaction();
-
$found = false;
foreach ($dom->getElementsByTagNameNS('http://www.jcp.org/jcr/sv/1.0', 'property') as $propertyNode) {
if ($propertyName == $propertyNode->getAttribute('sv:name')) {
@@ -1046,12 +999,7 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
'DELETE FROM phpcr_nodes_foreignkeys
WHERE source_id = ?
AND source_property_name = ?';
- try {
$this->conn->executeUpdate($query, array($nodeId, $propertyName));
- } catch (\Exception $e) {
- $this->conn->rollBack();
-
- return false;
}
}
$propertyNode->parentNode->removeChild($propertyNode);
@@ -1059,7 +1007,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
}
}
if (! $found) {
- $this->conn->rollBack();
throw new ItemNotFoundException("Node $nodePath has no property $propertyName");
}
$xml = $dom->saveXML();
@@ -1067,16 +1014,7 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
$query = 'UPDATE phpcr_nodes SET props = ? WHERE id = ?';
$params = array($xml, $nodeId);

- try {
$this->conn->executeUpdate($query, $params);
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollBack();
-
- return false;
- }
-
- return true;
}

/**
@@ -1101,9 +1039,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
throw new PathNotFoundException("Parent of the destination path '" . $this->getParentPath($dstAbsPath) . "' has to exist.");
}

- try {
- $this->conn->beginTransaction();
-
$query = 'SELECT path, id FROM phpcr_nodes WHERE path LIKE ? OR path = ? AND workspace_name = ? ' . $this->conn->getDatabasePlatform()->getForUpdateSQL();
$stmt = $this->conn->executeQuery($query, array($srcAbsPath . '/%', $srcAbsPath, $this->workspaceName));

@@ -1157,11 +1092,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
$query .= "WHERE id IN (" . $ids . ")";

$this->conn->executeUpdate($query, $values);
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollBack();
- throw $e;
- }
}

/**
@@ -1180,7 +1110,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
*/

// Retrieve an array of siblings names in the original order.
- $this->conn->beginTransaction();
$qb = $this->conn->createQueryBuilder();

$qb->select("CONCAT(n.namespace,(CASE namespace WHEN '' THEN '' ELSE ':' END), n.local_name)")
@@ -1225,7 +1154,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
}
}

- try {
$values[':absPath'] = $absPath;
$sql = "UPDATE phpcr_nodes SET sort_order = CASE CONCAT(
namespace,
@@ -1245,12 +1173,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
$sql .= " ELSE sort_order END WHERE parent = :absPath";

$this->conn->executeUpdate($sql, $values);
- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollBack();
- throw $e;
- }
-
}

/**
@@ -1834,9 +1756,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
return;
}

- $this->conn->beginTransaction();
-
- try {
$this->conn->delete('phpcr_namespaces', array('prefix' => $prefix));
$this->conn->delete('phpcr_namespaces', array('uri' => $uri));

@@ -1845,13 +1764,6 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
'uri' => $uri,
));

- $this->conn->commit();
- } catch (\Exception $e) {
- $this->conn->rollback();
-
- throw $e;
- }
-
if (!empty($this->namespaces)) {
$this->namespaces[$prefix] = $uri;
}
@@ -1987,7 +1899,24 @@ class Client extends BaseTransport implements QueryTransport, WritingInterface,
/**
* {@inheritDoc}
*/
+ public function prepareSave()
+ {
+ $this->conn->beginTransaction();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function finishSave()
{
+ $this->conn->commit();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function rollbackSave()
+ {
+ $this->conn->rollback();
}
}
```