3 * A database wrapper for node informations
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper, Registerable {
25 // Constants for database table names
26 const DB_TABLE_NODE_INFORMATION = 'node_data';
28 // Constants for database column names
29 const DB_COLUMN_NODE_NR = 'node_nr';
30 const DB_COLUMN_NODE_ID = 'node_id';
31 const DB_COLUMN_SESSION_ID = 'session_id';
32 const DB_COLUMN_PRIVATE_KEY = 'private_key';
33 const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
34 const DB_COLUMN_NODE_TYPE = 'node_type';
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Creates an instance of this database wrapper by a provided user class
49 * @return $wrapperInstance An instance of the created wrapper class
51 public static final function createNodeInformationDatabaseWrapper () {
53 $wrapperInstance = new NodeInformationDatabaseWrapper();
55 // Set (primary!) table name
56 $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
58 // Return the instance
59 return $wrapperInstance;
63 * 'Registers' a new node id along with data provided in the node instance.
64 * This may sound confusing but avoids double code very nicely...
66 * @param $nodeInstance A node instance
67 * @param $requestInstance An instance of a Requestable class
70 public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
71 // Get a dataset instance
72 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
74 // Set the primary key
75 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
77 // Add registration elements to the dataset
78 $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
80 // "Insert" this dataset instance completely into the database
81 $this->queryInsertDataSet($dataSetInstance);
85 * 'Registers' a new session id along with data provided in the node instance.
86 * This may sound confusing but avoids double code very nicely...
88 * @param $nodeInstance An instance of a BaseHubNode class
89 * @param $requestInstance An instance of a Requestable class
90 * @param $searchInstance An instance of a LocalSearchCriteria class
93 public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
94 // Get a dataset instance
95 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
97 // Set search instance
98 $dataSetInstance->setSearchInstance($searchInstance);
100 // Set the primary key
101 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
103 // Add registration elements to the dataset
104 $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
106 // "Insert" this dataset instance completely into the database
107 $this->queryUpdateDataSet($dataSetInstance);
111 * 'Registers' a private key along with data provided in the node instance.
112 * This may sound confusing but avoids double code very nicely...
114 * @param $nodeInstance An instance of a BaseHubNode class
115 * @param $requestInstance An instance of a Requestable class
116 * @param $searchInstance An instance of a LocalSearchCriteria class
119 public function registerPrivateKey (BaseHubNode $nodeInstance, Requestable $requestInstance, LocalSearchCriteria $searchInstance) {
120 // Get a dataset instance
121 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
123 // Set the primary key
124 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
126 // Set search instance
127 $dataSetInstance->setSearchInstance($searchInstance);
129 // Add registration elements to the dataset
130 $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
132 // "Insert" this dataset instance completely into the database
133 $this->queryUpdateDataSet($dataSetInstance);