]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php
New exception and interface added, continued development:
[hub.git] / application / hub / main / database / wrapper / class_NodeListDatabaseWrapper.php
index d2ce594b73a0709598d9c833a378d7f01a32771e..cf29bb8d51813ddba7357c252c6ed36684452594 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class NodeListDatabaseWrapper extends BaseDatabaseWrapper {
+class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable {
        // Table names
        const DB_TABLE_NODE_LIST = 'node_list';
 
+       // Constants for column name
+       const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
+       const DB_COLUMN_NODE_IP_PORT    = 'node_ipport';
+
        /**
         * Protected constructor
         *
@@ -59,6 +63,39 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper {
        public final function getIndexKey () {
                return $this->getDatabaseInstance()->getIndexKey();
        }
+
+       /**
+        * Resolves a session id into an ip:port combination
+        *
+        * @param       $sessionId      A valid session id
+        * @return      $recipient      Recipient as ip:port combination
+        */
+       public function resolveIpPortBySessionId ($sessionId) {
+               // Set invalid ip:port combination
+               $recipient = 'invalid:invalid';
+
+               // Now get a search criteria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Search for the node number zero which is hard-coded the default
+               $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, 1);
+               $searchInstance->setLimit(1);
+
+               // Get a result back
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+               // Is it valid?
+               if ($resultInstance->next()) {
+                       // Save the result instance in this class
+                       $this->setResultInstance($resultInstance);
+
+                       // Get the node id from result and set it
+                       $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT);
+               } // END - if
+
+               // Return result
+               return $recipient;
+       }
 }
 
 // [EOF]