* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ 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'; // Other constants const INVALID_IP_PORT = 'invalid:invalid'; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Creates an instance of this database wrapper by a provided user class * * @return $wrapperInstance An instance of the created wrapper class */ public static final function createNodeListDatabaseWrapper () { // Get a new instance $wrapperInstance = new NodeListDatabaseWrapper(); // Set (primary!) table name $wrapperInstance->setTableName(self::DB_TABLE_NODE_LIST); // Return the instance return $wrapperInstance; } /** * 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 = self::INVALID_IP_PORT; // Now get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for the node session id $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, $sessionId); $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; } /** * Resolves a ip:port combination into a session id * * @param $ipPort Ip:port combination * @return $sessionId A valid session id */ public function resolveSessionIdByIpPort ($ipPort) { // Set invalid session id as default $sessionId = 'invalid'; // Now get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for the node session id $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT, $ipPort); $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 session from result $sessionId = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID); } // END - if // Return result return $sessionId; } } // [EOF] ?>