return $wrapperInstance;
}
+ /**
+ * Static getter for an array of all DHT database entries
+ *
+ * @return $elements All elements for the DHT dabase
+ */
+ public static final function getAllElements () {
+ // Create array and ...
+ $elements = array(
+ self::DB_COLUMN_NODE_ID,
+ self::DB_COLUMN_SESSION_ID,
+ self::DB_COLUMN_EXTERNAL_IP,
+ self::DB_COLUMN_LISTEN_PORT,
+ self::DB_COLUMN_PRIVATE_KEY_HASH,
+ self::DB_COLUMN_NODE_MODE,
+ self::DB_COLUMN_ACCEPTED_OBJECTS,
+ self::DB_COLUMN_NODE_LIST
+ );
+
+ // ... return it
+ return $elements;
+ }
+
+ /**
+ * Prepares a search instance for given node data
+ *
+ * @param $nodeData An array with valid node data
+ * @return $searchInstance An instance of a SearchCriteria class
+ */
+ private function prepareSearchInstance (array $nodeData) {
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
+ // Get instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for node id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
+ $searchInstance->setLimit(1);
+
+ // Return it
+ return $searchInstance;
+ }
+
/**
* Prepares a "local" instance of a StoreableCriteria class with all node
* data for insert/update queries. This data set contains data from *this*
* Registeres a node by given message data.
*
* @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableMessage class
+ * @param $handlerInstance An instance of a Handleable class
* @return void
*/
public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance) {
* Updates an existing entry in node list
*
* @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableMessage class
+ * @param $handlerInstance An instance of a Handleable class
* @param $searchInstance An instance of LocalSearchCriteria class
* @return void
*/
assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
// Get search criteria
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for node id and limit it to one entry
- $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
- $searchInstance->setLimit(1);
+ $searchInstance = $this->prepareSearchInstance($nodeData);
// Query database and get a result instance back
$resultInstance = $this->doSelectByCriteria(
* @throws NodeAlreadyRegisteredException If the node is already registered
*/
public function registerNode (array $nodeData) {
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
// Is the node registered?
if ($this->isNodeRegistered($nodeData)) {
// Throw an exception
* @throws NodeDataMissingException If the node's data is missing
*/
public function updateNode (array $nodeData) {
+ // Assert on array elements
+ assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
+
// Is the node registered?
if (!$this->isNodeRegistered($nodeData)) {
// No, then throw an exception
throw new NodeDataMissingException(array($this, $nodeData), self::EXCEPTION_NODE_NOT_REGISTERED);
} // END - if
- // @TODO Unimplemented part
- $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
+ // Get a search instance
+ $searchInstance = $this->prepareSearchInstance($nodeData);
+
+ // Get a data set instance
+ $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
+
+ // Add search instance
+ $dataSetInstance->setSearchInstance($searchInstance);
+
+ // Set primary key (session id)
+ $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
+
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Add all array elements
+ $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
+
+ // Remove 'node_list'
+ $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
+
+ // Run the "UPDATE" query
+ $this->queryUpdateDataSet($dataSetInstance);
}
}