예제 #1
0
 public function testSelectGlobal()
 {
     $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer')));
     $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false));
     $conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET'));
     $sm = new SQLAzureShardManager($conn);
     $sm->selectGlobal();
 }
 /**
  * Work on the Global/Federation based on currently existing shards and
  * perform the given operation on the underyling schema synchronizer given
  * the different partioned schema instances.
  *
  * @param Schema $schema
  * @param Closure $operation
  * @return array
  */
 private function work(Schema $schema, \Closure $operation)
 {
     list($global, $federation) = $this->partitionSchema($schema);
     $sql = array();
     $this->shardManager->selectGlobal();
     $globalSql = $operation($this->synchronizer, $global);
     if ($globalSql) {
         $sql[] = "-- Work on Root Federation\nUSE FEDERATION ROOT WITH RESET;";
         $sql = array_merge($sql, $globalSql);
     }
     $shards = $this->shardManager->getShards();
     foreach ($shards as $shard) {
         $this->shardManager->selectShard($shard['rangeLow']);
         $federationSql = $operation($this->synchronizer, $federation);
         if ($federationSql) {
             $sql[] = "-- Work on Federation ID " . $shard['id'] . "\n" . "USE FEDERATION " . $this->shardManager->getFederationName() . " (" . $this->shardManager->getDistributionKey() . " = " . $shard['rangeLow'] . ") WITH RESET, FILTERING = OFF;";
             $sql = array_merge($sql, $federationSql);
         }
     }
     return $sql;
 }