Permalink
Browse files

Many changes, still unstable

--HG--
rename : DocumentMetaData.php => MetaData.php
  • Loading branch information...
1 parent 0ee3bf5 commit 2df2f397a1169232f450339b5c909cd7cc448d31 intel352 committed Jul 6, 2011
Showing with 1,172 additions and 808 deletions.
  1. +1 −1 .hgsubstate
  2. +116 −41 Adapter.php
  3. +113 −0 CommandBuilder.php
  4. +34 −88 Connection.php
  5. +80 −0 Container.php
  6. +46 −491 Document.php
  7. +0 −53 DocumentMetaData.php
  8. +1 −1 Exception.php
  9. +72 −0 MetaData.php
  10. +476 −0 Model.php
  11. +84 −0 Object.php
  12. +0 −68 Schema.php
  13. +22 −55 drivers/riak/Adapter.php
  14. +73 −0 drivers/riak/Container.php
  15. +54 −0 drivers/riak/Object.php
  16. +0 −10 drivers/riak/Schema.php
View
@@ -1 +1 @@
-95a9ccac60335767c33e84f20b64b9a59d8791ba vendors/riiak
+34dc8eddddb66224e6b9be9f306f74fc57d10dd8 vendors/riiak
View
@@ -1,76 +1,151 @@
<?php
namespace ext\activedocument;
-use CComponent;
+
+use \Yii,
+ \CComponent;
abstract class Adapter extends CComponent {
- protected $_drivers;
+
+ /**
+ * @var \ext\activedocument\Connection
+ */
+ protected $_connection;
+ protected $_storageInstance;
+ protected $_containers = array();
+ protected $_cacheExclude = array();
protected $_errorCode;
protected $_errorInfo;
- protected $_runningTransaction=false;
-
- abstract public function createContainer($name);
- abstract public function loadContainer($name);
- abstract public function loadContainers($containers=array());
- abstract public function saveContainer($name, $data);
- abstract public function saveContainers($name, $containers=array());
- abstract public function deleteContainer($name);
- abstract public function deleteContainers($containers=array());
- abstract public function createDataObject($container, $key, $data);
- abstract public function loadDataObject($container, $key);
- abstract public function saveDataObject($container, $key, $data);
- abstract public function saveDataObjects($container, $dataObjects=array());
- abstract public function deleteDataObject($container, $key);
- abstract public function deleteDataObjects($container, $keys=array());
- abstract public function lastInsertId();
-
- public function __construct() {
- }
-
+ protected $_runningTransaction = false;
+
+ abstract protected function loadStorageInstance(array $attributes=null);
+
+ abstract protected function loadContainer($name);
+
+ public function __construct(Connection $conn, array $attributes=null) {
+ $this->_connection = $conn;
+ foreach ($conn->schemaCachingExclude as $name)
+ $this->_cacheExclude[$name] = true;
+ $this->_storageInstance = $this->loadStorageInstance($attributes);
+ }
+
+ public function __get($name) {
+ if (property_exists($this->_storageInstance, $name) || $this->_storageInstance->canGetProperty($name))
+ return $this->_storageInstance->$name;
+ return parent::__get($name);
+ }
+
+ public function __set($name, $value) {
+ if (property_exists($this->_storageInstance, $name) || $this->_storageInstance->canSetProperty($name))
+ $this->_storageInstance->$name = $value;
+ else
+ return parent::__set($name, $value);
+ }
+
+ public function __isset($name) {
+ if (property_exists($this->_storageInstance, $name) || $this->_storageInstance->canGetProperty($name))
+ return $this->_storageInstance->$name !== null;
+ return parent::__isset($name);
+ }
+
+ public function __unset($name) {
+ if (property_exists($this->_storageInstance, $name) || $this->_storageInstance->canSetProperty($name))
+ return $this->_storageInstance->$name = null;
+ return parent::__unset($name);
+ }
+
+ public function getStorageInstance() {
+ return $this->_storageInstance;
+ }
+
+ /**
+ * @return Connection storage connection. The connection is active.
+ */
+ public function getConnection() {
+ return $this->_connection;
+ }
+
+ public function getConfig() {
+ return $this->_connection->attributes;
+ }
+
+ /**
+ * @param string $name
+ * @return \ext\activedocument\Container
+ */
+ public function getContainer($name) {
+ if (isset($this->_containers[$name]))
+ return $this->_containers[$name];
+ else {
+ if ($this->_connection->containerPrefix !== null && strpos($name, '{{') !== false)
+ $realName = preg_replace('/\{\{(.*?)\}\}/', $this->_connection->containerPrefix . '$1', $name);
+ else
+ $realName=$name;
+
+ // temporarily disable query caching
+ /* if($this->_connection->queryCachingDuration>0)
+ {
+ $qcDuration=$this->_connection->queryCachingDuration;
+ $this->_connection->queryCachingDuration=0;
+ } */
+
+ if (!isset($this->_cacheExclude[$name]) && ($duration = $this->_connection->schemaCachingDuration) > 0 && $this->_connection->schemaCacheID !== false && ($cache = Yii::app()->getComponent($this->_connection->schemaCacheID)) !== null) {
+ $key = 'activedocument.storageschema.' . $this->_connection->driver . '.' . $this->_connection->containerPrefix . '.' . $name;
+ if (($container = $cache->get($key)) === false) {
+ $container = $this->loadContainer($realName);
+ if ($container !== null)
+ $cache->set($key, $container, $duration);
+ }
+ $this->_containers[$name] = $container;
+ }
+ else
+ $this->_containers[$name] = $container = $this->loadContainer($realName);
+
+ /* if(isset($qcDuration)) // re-enable query caching
+ $this->_connection->queryCachingDuration=$qcDuration; */
+
+ return $container;
+ }
+ }
+
public function beginTransaction() {
- $this->_runningTransaction=true;
+ $this->_runningTransaction = true;
}
-
+
public function commit() {
- $this->_runningTransaction=false;
+ $this->_runningTransaction = false;
}
-
+
public function getErrorCode() {
return $this->_errorCode;
}
-
+
public function getErrorInfo() {
return $this->_errorInfo;
}
-
+
public function exec() {
+
}
-
- public function getAvailableDrivers() {
- if(is_array($this->_drivers))
- return $this->_drivers;
- $this->_drivers=scandir(realpath(__DIR__.'/drivers/'));
- $this->_drivers=array_filter($this->_drivers, function($f){if(preg_match('/^\.|\.\.$/', $f)) return false; return true;});
- return $this->_drivers;
- }
-
+
public function getInTransaction() {
return $this->_runningTransaction;
}
-
+
public function prepare() {
;
}
-
+
public function query() {
;
}
-
+
public function quote() {
;
}
-
+
public function rollBack() {
;
}
+
}
View
@@ -0,0 +1,113 @@
+<?php
+
+namespace ext\activedocument;
+use \CComponent;
+
+class CommandBuilder extends CComponent {
+ const PARAM_PREFIX=':ap';
+
+ /**
+ * @var \ext\activedocument\Adapter
+ */
+ protected $_adapter;
+ /**
+ * @var \ext\activedocument\Connection
+ */
+ protected $_connection;
+
+ public function __construct(Adapter $adapter) {
+ $this->_adapter = $adapter;
+ $this->_connection = $adapter->getConnection();
+ }
+
+ /**
+ * @return \ext\activedocument\Connection
+ */
+ public function getConnection() {
+ return $this->_connection;
+ }
+
+ /**
+ * @return \ext\activedocument\Adapter
+ */
+ public function getAdapter() {
+ return $this->_adapter;
+ }
+
+ public function getLastInsertID() {
+ /*$this->ensureContainer($container);
+ if ($container->sequenceName !== null)
+ return $this->_connection->getLastInsertID($container->sequenceName);
+ else
+ return null;*/
+ }
+
+ public function createFindCommand($container, $criteria, $alias='t') {
+ }
+
+ public function createCountCommand($container, $criteria, $alias='t') {
+ }
+
+ public function createDeleteCommand($container, $criteria) {
+ }
+
+ public function createInsertCommand($container, $data) {
+ }
+
+ public function createUpdateCommand($container, $data, $criteria) {
+ }
+
+ public function createUpdateCounterCommand($container, $counters, $criteria) {
+ }
+
+ public function createSqlCommand($sql, $params=array()) {
+ }
+
+ public function applyJoin($sql, $join) {
+ }
+
+ public function applyCondition($sql, $condition) {
+ }
+
+ public function applyOrder($sql, $orderBy) {
+ }
+
+ public function applyLimit($sql, $limit, $offset) {
+ }
+
+ public function applyGroup($sql, $group) {
+ }
+
+ public function applyHaving($sql, $having) {
+ }
+
+ public function bindValues($command, $values) {
+ }
+
+ public function createCriteria($condition='', $params=array()) {
+ }
+
+ public function createPkCriteria($container, $pk, $condition='', $params=array(), $prefix=null) {
+ }
+
+ public function createPkCondition($container, $values, $prefix=null) {
+ }
+
+ public function createColumnCriteria($container, $columns, $condition='', $params=array(), $prefix=null) {
+ }
+
+ public function createSearchCondition($container, $columns, $keywords, $prefix=null, $caseSensitive=true) {
+ }
+
+ public function createInCondition($container, $columnName, $values, $prefix=null) {
+ }
+
+ protected function createCompositeInCondition($container, $values, $prefix) {
+ }
+
+ protected function ensureContainer(&$container) {
+ if (is_string($container) && ($container = $this->_adapter->getContainer($containerName = $container)) === null)
+ throw new Exception(Yii::t('yii', 'Container "{container}" does not exist.', array('{container}' => $containerName)));
+ }
+
+}
Oops, something went wrong.

0 comments on commit 2df2f39

Please sign in to comment.