private function applyDQLCalls(IcingaDoctrine_Query $query, array $sequence, $targetValues = null, $nr = 0)
 {
     if ($targetValues !== null && empty($targetValues)) {
         return;
     }
     AppKitLogger::verbose("Applying dql sequence %s", $sequence);
     foreach ($sequence as $call) {
         $call["arg"] = str_replace("{ID}", $nr, $call["arg"]);
         if (in_array($call["arg"] . $call["type"], $this->dqlHistory)) {
             continue;
         }
         if ($targetValues !== null) {
             $arg = $this->replaceCredentialTokens($call["arg"], $targetValues);
         } else {
             $arg = $this->replaceTokens($call["arg"]);
         }
         AppKitLogger::verbose("Applying call query->%s(%s)", $call["type"], $arg);
         $this->dqlHistory[] = $call["arg"] . $call["type"];
         switch ($call["type"]) {
             case 'select':
                 $query->addSelect($arg);
                 break;
             case 'innerjoin':
             case 'join':
                 $query->innerJoin($arg, null);
                 break;
             case 'leftjoin':
                 $query->leftJoin($arg, null);
                 break;
             case 'where':
             case 'andwhere':
                 $query->andWhere($arg);
                 break;
             case 'orwhere':
                 $query->orWhere($arg);
                 break;
             case 'limit':
                 $query->limit($arg);
                 break;
             case 'offset':
                 $query->offset($arg);
                 break;
             case 'groupby':
                 $query->addGroupBy($arg);
                 break;
         }
         AppKitLogger::verbose("After call query->%s(%s): %s ", $call["type"], $arg, $query->getSqlQuery());
     }
 }