public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $start = 0, $limit = -1)
 {
     //parent::query($select, $condition, $start, $limit);
     stubRODSConn::$params = array($select, $condition, $start, $limit);
     $name_array = array("/myZone");
     $owner_array = array("me");
     $zone_array = array("myZone");
     $create_array = array("01298479459");
     $modify_array = array("01298479459");
     $comment_array = array("foo");
     $names = $select->getNames();
     if (array_search("COL_D_DATA_ID", $names)) {
         //this is a file stats request - 2 files
         $id_array = array("2");
         $dname_array = array("first_file.txt");
         $dtype_array = array("generic");
         $dresc_array = array("testResc");
         $dsize_array = array("1020157");
         $result_array = array("COL_DATA_NAME" => $dname_array, "COL_COLL_NAME" => $name_array, "COL_D_DATA_ID" => $id_array, "COL_DATA_TYPE_NAME" => $dtype_array, "COL_D_RESC_NAME" => $dresc_array, "COL_DATA_SIZE" => $dsize_array, "COL_D_OWNER_NAME" => $owner_array, "COL_D_OWNER_ZONE" => $zone_array, "COL_D_CREATE_TIME" => $create_array, "COL_D_MODIFY_TIME" => $modify_array, "COL_D_COMMENTS" => $comment_array);
     } else {
         // this is a dirs stats request - 1 directory
         $name_array = array("/myZone");
         $id_array = array("1");
         $owner_array = array("me");
         $zone_array = array("myZone");
         $create_array = array("01298479459");
         $modify_array = array("01298479459");
         $comment_array = array("foo");
         $result_array = array("COL_COLL_NAME" => $name_array, "COL_COLL_ID" => $id_array, "COL_COLL_OWNER_NAME", $owner_array, "COL_COLL_OWNER_ZONE" => $zone_array, "COL_COLL_CREATE_TIME" => $create_array, "COL_COLL_MODIFY_TIME" => $modify_array, "COL_COLL_COMMENTS" => $comment_array);
     }
     if ($limit == -1) {
         $total = 1;
     } else {
         $total = $limit;
     }
     $results = new RODSGenQueResults($total, $result_array);
     return $results;
 }
 /**
  * update a single select field's attr/value. Note that if the value already exists,
  * it will OR the bits. This is used when you want more than one type of operation
  * for a select field, such as select_max and sort.
  */
 public function update($name, $attr)
 {
     require_once "RodsGenQueryNum.inc.php";
     //load magic numbers
     if (!isset($GLOBALS['PRODS_GENQUE_NUMS']["{$name}"])) {
         throw new RODSException("General Query select field name '{$name}' is not valid", 'PERR_USER_INPUT_ERROR');
     }
     $newattr = RODSGenQueSelFlds::attr2GenQueNumber($attr);
     for ($i = 0; $i < count($this->names); $i++) {
         if ($this->names[$i] == $name) {
             if ($this->attrs[$i] == 1) {
                 $this->attrs[$i] = $newattr;
             } else {
                 $this->attrs[$i] = $newattr | $this->attrs[$i];
             }
             return;
         }
     }
     $this->add($name, $attr);
 }
 /**
  * Makes a general query to RODS server. Think it as an SQL. "select foo from sometab where bar = '3'". In this example, foo is specified by "$select", bar and "= '3'" are speficed by condition.
  * @param RODSGenQueSelFlds $select the fields (names) to be returned/interested. There can not be more than 50 input fields. For example:"COL_COLL_NAME" means collection-name.
  * @param RODSGenQueConds $condition  All fields are defined in RodsGenQueryNum.inc.php and RodsGenQueryKeyWd.inc.php
  * @param integer $start result start from which row.
  * @param integer $limit up to how many rows should the result contain. If -1 is passed, all available rows will be returned
  * @return RODSGenQueResults
  * Note: This function is very low level. It's not recommended for beginners.
  */
 public function query(RODSGenQueSelFlds $select, RODSGenQueConds $condition, $start = 0, $limit = -1)
 {
     if ($select->getCount() < 1 || $select->getCount() > 50) {
         throw new RODSException("Only 1-50 fields are supported", 'PERR_USER_INPUT_ERROR');
     }
     // contruct select packet (RP_InxIvalPair $selectInp), and condition packets
     $select_pk = $select->packetize();
     $cond_pk = $condition->packetize();
     $condkw_pk = $condition->packetizeKW();
     // determin max number of results per query
     if ($limit > 0 && $limit < 500) {
         $max_result_per_query = $limit;
     } else {
         $max_result_per_query = 500;
     }
     $num_fetched_rows = 0;
     $continueInx = 0;
     $results = new RODSGenQueResults();
     do {
         // construct RP_GenQueryInp packet
         $options = 1 | $GLOBALS['PRODS_GENQUE_NUMS']['RETURN_TOTAL_ROW_COUNT'];
         $genque_input_pk = new RP_GenQueryInp($max_result_per_query, $continueInx, $condkw_pk, $select_pk, $cond_pk, $options, $start);
         // contruce a new API request message, with type GEN_QUERY_AN
         $msg = new RODSMessage("RODS_API_REQ_T", $genque_input_pk, $GLOBALS['PRODS_API_NUMS']['GEN_QUERY_AN']);
         fwrite($this->conn, $msg->pack());
         // send it
         // get value back
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             if (RODSException::rodsErrCodeToAbbr($intInfo) == 'CAT_NO_ROWS_FOUND') {
                 break;
             }
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
         $genque_result_pk = $msg_resv->getBody();
         $num_row_added = $results->addResults($genque_result_pk);
         $continueInx = $genque_result_pk->continueInx;
         $start = $start + $results->getNumRow();
     } while ($continueInx > 0 && ($results->getNumRow() < $limit || $limit < 0));
     // Make sure and close the query if there are any results left.
     if ($continueInx > 0) {
         $msg->getBody()->continueInx = $continueInx;
         $msg->getBody()->maxRows = -1;
         // tells the server to close the query
         fwrite($this->conn, $msg->pack());
         $msg_resv = new RODSMessage();
         $intInfo = $msg_resv->unpack($this->conn);
         if ($intInfo < 0) {
             throw new RODSException("RODSConn::query has got an error from the server", $GLOBALS['PRODS_ERR_CODES_REV']["{$intInfo}"]);
         }
     }
     return $results;
 }
Exemple #4
0
 public function findFiles(array $terms, &$total_count, $start = 0, $limit = -1, array $sort_flds = array(), $get_cb = array('RODSConnManager', 'getConn'), $rel_cb = array('RODSConnManager', 'releaseConn'))
 {
     $flds = array("COL_DATA_NAME" => NULL, "COL_D_DATA_ID" => NULL, "COL_DATA_TYPE_NAME" => NULL, "COL_D_RESC_NAME" => NULL, "COL_DATA_SIZE" => NULL, "COL_D_OWNER_NAME" => NULL, "COL_D_OWNER_ZONE" => NULL, "COL_D_CREATE_TIME" => NULL, "COL_D_MODIFY_TIME" => NULL, "COL_COLL_NAME" => NULL, "COL_D_COMMENTS" => NULL);
     foreach ($sort_flds as $sort_fld_key => $sort_fld_val) {
         switch ($sort_fld_key) {
             case 'name':
                 if ($sort_fld_val === false) {
                     $flds['COL_DATA_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'size':
                 if ($sort_fld_val === false) {
                     $flds['COL_DATA_SIZE'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_SIZE'] = 'order_by_asc';
                 }
                 break;
             case 'mtime':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_MODIFY_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_MODIFY_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'ctime':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_CREATE_TIME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_CREATE_TIME'] = 'order_by_asc';
                 }
                 break;
             case 'typename':
                 if ($sort_fld_val === false) {
                     $flds['COL_DATA_TYPE_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_DATA_TYPE_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'owner':
                 if ($sort_fld_val === false) {
                     $flds['COL_D_OWNER_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_D_OWNER_NAME'] = 'order_by_asc';
                 }
                 break;
             case 'dirname':
                 if ($sort_fld_val === false) {
                     $flds['COL_COLL_NAME'] = 'order_by_desc';
                 } else {
                     $flds['COL_COLL_NAME'] = 'order_by_asc';
                 }
                 break;
             default:
                 /*
                 throw new RODSException("Sort field name '$sort_fld_key' is not valid",
                   'PERR_USER_INPUT_ERROR');
                 break;
                 */
         }
     }
     $select = new RODSGenQueSelFlds(array_keys($flds), array_values($flds));
     $descendantOnly = false;
     $recursive = false;
     $logicalFile = false;
     $condition = new RODSGenQueConds();
     foreach ($terms as $term_key => $term_val) {
         switch ($term_key) {
             case 'name':
                 //$condition->add('COL_DATA_NAME', 'like', '%'.$term_val.'%');
                 $condition->add('COL_DATA_NAME', 'like', $term_val);
                 break;
             case 'smtime':
                 $condition->add('COL_D_MODIFY_TIME', '>=', $term_val);
                 break;
             case 'emtime':
                 $condition->add('COL_D_MODIFY_TIME', '<', $term_val);
                 break;
             case 'owner':
                 $condition->add('COL_D_OWNER_NAME', '=', $term_val);
                 break;
             case 'ownerzone':
                 $condition->add('COL_D_OWNER_ZONE', '=', $term_val);
                 break;
             case 'rescname':
                 $condition->add('COL_D_RESC_NAME', '=', $term_val);
                 break;
             case 'metadata':
                 $meta_array = $term_val;
                 foreach ($meta_array as $meta) {
                     if (isset($meta->name)) {
                         if ($meta->nameop === 'like') {
                             $condition->add('COL_META_DATA_ATTR_NAME', 'like', '%' . $meta->name . '%');
                         } else {
                             if (isset($meta->nameop)) {
                                 $condition->add('COL_META_DATA_ATTR_NAME', $meta->nameop, $meta->name);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_NAME', '=', $meta->name);
                             }
                         }
                     }
                     if (isset($meta->value)) {
                         if ($meta->op === 'like') {
                             $condition->add('COL_META_DATA_ATTR_VALUE', 'like', '%' . $meta->value . '%');
                         } else {
                             if (isset($meta->op)) {
                                 $condition->add('COL_META_DATA_ATTR_VALUE', $meta->op, $meta->value);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_VALUE', '=', $meta->value);
                             }
                         }
                     }
                     if (isset($meta->unit)) {
                         if ($meta->unitop === 'like') {
                             $condition->add('COL_META_DATA_ATTR_UNIT', 'like', '%' . $meta->unit . '%');
                         } else {
                             if (isset($meta->unitop)) {
                                 $condition->add('COL_META_DATA_ATTR_UNIT', $meta->unitop, $meta->unit);
                             } else {
                                 $condition->add('COL_META_DATA_ATTR_UNIT', '=', $meta->unit);
                             }
                         }
                     }
                 }
                 break;
             case 'descendantOnly':
                 if (true === $term_val) {
                     $descendantOnly = true;
                 }
                 break;
             case 'recursive':
                 if (true === $term_val) {
                     $recursive = true;
                 }
                 break;
             case 'logicalFile':
                 if (true === $term_val) {
                     $logicalFile = true;
                 }
                 break;
             default:
                 throw new RODSException("Term field name '{$term_key}' is not valid", 'PERR_USER_INPUT_ERROR');
                 break;
         }
     }
     if ($descendantOnly === true) {
         if ($recursive === true) {
             $condition->add('COL_COLL_NAME', 'like', $this->path_str . '/%', array(array('op' => '=', 'val' => $this->path_str)));
         } else {
             $condition->add('COL_COLL_NAME', '=', $this->path_str);
         }
     }
     if ($logicalFile === true) {
         $select->update('COL_D_RESC_NAME', 'count');
         $select->update('COL_DATA_SIZE', 'max');
         $select->update('COL_D_CREATE_TIME', 'min');
         $select->update('COL_D_MODIFY_TIME', 'max');
     }
     //$conn = RODSConnManager::getConn($this->account);
     $conn = call_user_func_array($get_cb, array(&$this->account));
     $results = $conn->query($select, $condition, $start, $limit);
     //RODSConnManager::releaseConn($conn);
     call_user_func($rel_cb, $conn);
     $total_count = $results->getTotalCount();
     $result_values = $results->getValues();
     $found = array();
     for ($i = 0; $i < $results->getNumRow(); $i++) {
         $resc_name = $logicalFile === true ? NULL : $result_values['COL_D_RESC_NAME'][$i];
         $num_replica = $logicalFile === true ? intval($result_values['COL_D_RESC_NAME'][$i]) : NULL;
         $stats = new RODSFileStats($result_values['COL_DATA_NAME'][$i], $result_values['COL_DATA_SIZE'][$i], $result_values['COL_D_OWNER_NAME'][$i], $result_values['COL_D_OWNER_ZONE'][$i], $result_values['COL_D_MODIFY_TIME'][$i], $result_values['COL_D_CREATE_TIME'][$i], $result_values['COL_D_DATA_ID'][$i], $result_values['COL_DATA_TYPE_NAME'][$i], $resc_name, $result_values['COL_D_COMMENTS'][$i], $num_replica);
         if ($result_values['COL_COLL_NAME'][$i] == '/') {
             $full_path = '/' . $result_values['COL_DATA_NAME'][$i];
         } else {
             $full_path = $result_values['COL_COLL_NAME'][$i] . '/' . $result_values['COL_DATA_NAME'][$i];
         }
         $found[] = new ProdsFile($this->account, $full_path, false, $stats);
     }
     return $found;
 }