]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
Added exceptions + some code:
[hub.git] / application / hub / main / database / wrapper / node / class_NodeDistributedHashTableDatabaseWrapper.php
index 967941664345a40c6450d2c6f2bb449fbcbee2be..0beb31c0d3f02e1f81520bb205ab4824279a1b51 100644 (file)
@@ -34,6 +34,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
        const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
        const DB_COLUMN_NODE_MODE        = 'node_mode';
        const DB_COLUMN_ACCEPTED_OBJECTS = 'accepted_object_types';
+       const DB_COLUMN_NODE_LIST        = 'node_list';
+
+       // Exception codes
+       const EXCEPTION_NODE_ALREADY_REGISTERED = 0x800;
+       const EXCEPTION_NODE_NOT_REGISTERED     = 0x801;
 
        /**
         * Protected constructor
@@ -230,7 +235,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
                $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
 
                // Remove 'node_list'
-               $dataSetInstance->unsetCriteria('node_list');
+               $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
 
                // Run the "INSERT" query
                $this->queryInsertDataSet($dataSetInstance);
@@ -258,7 +263,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
                $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
 
                // Remove 'node_list'
-               $dataSetInstance->unsetCriteria('node_list');
+               $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
 
                // Run the "UPDATE" query
                $this->queryUpdateDataSet($dataSetInstance);
@@ -297,6 +302,13 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * @throws      NodeAlreadyRegisteredException  If the node is already registered
         */
        public function registerNode (array $nodeData) {
+               // Is the node registered?
+               if ($this->isNodeRegistered($nodeData)) {
+                       // Throw an exception
+                       throw new NodeAlreadyRegisteredException(array($this, $nodeData), self::EXCEPTION_NODE_ALREADY_REGISTERED);
+               } // END - if
+
+               // @TODO Unimplemented part
                $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
        }
 
@@ -310,6 +322,13 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
         * @throws      NodeDataMissingException        If the node's data is missing
         */
        public function updateNode (array $nodeData) {
+               // 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));
        }
 }