[Beeframework-svn] SF.net SVN: beeframework:[34] trunk
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2013-05-07 13:23:29
|
Revision: 34
http://sourceforge.net/p/beeframework/code/34
Author: m_plomer
Date: 2013-05-07 13:23:23 +0000 (Tue, 07 May 2013)
Log Message:
-----------
- intermediate commit: basic feature detection framework for PDO
Modified Paths:
--------------
trunk/examples/conf/log4php.xml
trunk/framework/Bee/Persistence/Pdo/Behaviors/DelegateBase.php
trunk/framework/Bee/Persistence/Pdo/Behaviors/GenericOrderedDelegate.php
Added Paths:
-----------
trunk/framework/Bee/Persistence/Pdo/FeatureDetector.php
Modified: trunk/examples/conf/log4php.xml
===================================================================
--- trunk/examples/conf/log4php.xml 2013-05-07 11:44:44 UTC (rev 33)
+++ trunk/examples/conf/log4php.xml 2013-05-07 13:23:23 UTC (rev 34)
@@ -18,7 +18,7 @@
<appender_ref ref="default" />
</root>
<logger name="Bee" additivity="false">
- <level value="warn" />
+ <level value="info" />
<appender_ref ref="framework" />
</logger>
</configuration>
\ No newline at end of file
Modified: trunk/framework/Bee/Persistence/Pdo/Behaviors/DelegateBase.php
===================================================================
--- trunk/framework/Bee/Persistence/Pdo/Behaviors/DelegateBase.php 2013-05-07 11:44:44 UTC (rev 33)
+++ trunk/framework/Bee/Persistence/Pdo/Behaviors/DelegateBase.php 2013-05-07 13:23:23 UTC (rev 34)
@@ -1,5 +1,8 @@
<?php
namespace Bee\Persistence\Pdo\Behaviors;
+
+use Bee\Persistence\Pdo\FeatureDetector;
+
/*
* Copyright 2008-2010 the original author or authors.
*
@@ -23,7 +26,7 @@
* Date: 05.05.13
* Time: 23:52
*/
-abstract class DelegateBase {
+abstract class DelegateBase extends FeatureDetector {
/**
* @var \PDO
@@ -69,4 +72,12 @@
$res = $qry->fetch(\PDO::FETCH_NUM);
return $res [0];
}
+
+ /**
+ * @param string $feature
+ * @return bool
+ */
+ protected function pdoSupportsFeature($feature) {
+ return self::supports($feature, $this->getPdo());
+ }
}
Modified: trunk/framework/Bee/Persistence/Pdo/Behaviors/GenericOrderedDelegate.php
===================================================================
--- trunk/framework/Bee/Persistence/Pdo/Behaviors/GenericOrderedDelegate.php 2013-05-07 11:44:44 UTC (rev 33)
+++ trunk/framework/Bee/Persistence/Pdo/Behaviors/GenericOrderedDelegate.php 2013-05-07 13:23:23 UTC (rev 34)
@@ -166,11 +166,12 @@
$qryDomain = $this->getQueryDomain();
$qryString = sprintf($newPos < $oldPos ? self::SHIFT_UP_QUERY_TEMPLATE : self::SHIFT_DOWN_QUERY_TEMPLATE,
$this->getPosExpression(), $qryDomain, $this->getDomainRestrictionString($orderedEntity, $params, $restriction));
- // if this is a single table update, add ORDER clause to avoid unique constraint violation
-// if (stripos($qryDomain, ' JOIN ') === false) {
-// $qryString .= ' ORDER BY ' . $this->getPosExpression() . ($newPos < $oldPos ? ' DESC' : ' ASC');
-// }
-// var_dump($qryString);
+
+ // if this is a single table update, add ORDER clause to avoid unique constraint violation (if driver supports it)
+ if ($this->pdoSupportsFeature(self::FEATURE_ORDERED_UPDATE) && stripos($qryDomain, ' JOIN ') === false) {
+ $qryString .= ' ORDER BY ' . $this->getPosExpression() . ($newPos < $oldPos ? ' DESC' : ' ASC');
+ }
+
$this->getPdo()->prepare($qryString)->execute($params);
}
Added: trunk/framework/Bee/Persistence/Pdo/FeatureDetector.php
===================================================================
--- trunk/framework/Bee/Persistence/Pdo/FeatureDetector.php (rev 0)
+++ trunk/framework/Bee/Persistence/Pdo/FeatureDetector.php 2013-05-07 13:23:23 UTC (rev 34)
@@ -0,0 +1,82 @@
+<?php
+namespace Bee\Persistence\Pdo;
+ /*
+ * Copyright 2008-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * User: mp
+ * Date: 07.05.13
+ * Time: 14:42
+ */
+
+class FeatureDetector {
+
+ const FEATURE_ORDERED_UPDATE = 'ORDERED_UPDATE';
+
+ private static $FEATURE_CACHE = array();
+
+ private static $DETECTORS;
+
+ /**
+ * @var \Logger
+ */
+ private static $log;
+
+ /**
+ * @return \Logger
+ */
+ protected static function getLog() {
+ if (!self::$log) {
+ self::$log = \Bee_Framework::getLoggerForClass(__CLASS__);
+ }
+ return self::$log;
+ }
+
+ /**
+ * @param string $feature
+ * @param \PDO $pdoConnection
+ * @return bool
+ */
+ public static function supports($feature, \PDO $pdoConnection) {
+ self::init();
+ $connKey = spl_object_hash($pdoConnection);
+ if (!array_key_exists($connKey, self::$FEATURE_CACHE)) {
+ self::$FEATURE_CACHE[$connKey] = array();
+ }
+ if (!array_key_exists($feature, self::$FEATURE_CACHE[$connKey])) {
+ $detector = self::$DETECTORS[$feature];
+ $result = $detector($pdoConnection);
+ self::$FEATURE_CACHE[$connKey][$feature] = $result;
+ self::getLog()->info("PDO connection $connKey supports feature $feature : " . ($result ? "YES" : "NO"));
+ }
+ return self::$FEATURE_CACHE[$connKey][$feature];
+ }
+
+ private static function init() {
+ if (!self::$DETECTORS) {
+ self::$DETECTORS = array(
+ self::FEATURE_ORDERED_UPDATE => function (\PDO $pdoConnection) {
+ switch ($pdoConnection->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
+ case 'mysql':
+ return true;
+ }
+ return false;
+ }
+ );
+ }
+ }
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|