├── .gitignore ├── LICENSE ├── OrientDB ├── Commands │ ├── OrientDBCommandAbstract.php │ ├── OrientDBCommandCommand.php │ ├── OrientDBCommandCommit.php │ ├── OrientDBCommandConfigGet.php │ ├── OrientDBCommandConfigList.php │ ├── OrientDBCommandConfigSet.php │ ├── OrientDBCommandConnect.php │ ├── OrientDBCommandCount.php │ ├── OrientDBCommandDBClose.php │ ├── OrientDBCommandDBCreate.php │ ├── OrientDBCommandDBDelete.php │ ├── OrientDBCommandDBExists.php │ ├── OrientDBCommandDBList.php │ ├── OrientDBCommandDBOpen.php │ ├── OrientDBCommandDataclusterAdd.php │ ├── OrientDBCommandDataclusterCount.php │ ├── OrientDBCommandDataclusterDatarange.php │ ├── OrientDBCommandDataclusterRemove.php │ ├── OrientDBCommandDatasegmentAdd.php │ ├── OrientDBCommandDatasegmentDelete.php │ ├── OrientDBCommandQuery.php │ ├── OrientDBCommandRecordCreate.php │ ├── OrientDBCommandRecordDelete.php │ ├── OrientDBCommandRecordLoad.php │ ├── OrientDBCommandRecordUpdate.php │ ├── OrientDBCommandSelect.php │ ├── OrientDBCommandSelectAsync.php │ ├── OrientDBCommandSelectGremlin.php │ └── OrientDBCommandShutdown.php ├── OrientDB.php ├── OrientDBDataTypes.php ├── OrientDBHelpers.php ├── OrientDBRecord.php ├── OrientDBRecordDecoder.php ├── OrientDBRecordEncoder.php └── OrientDBSocket.php ├── SpeedTest ├── OrientDBRecordSpeedBigTest.php ├── OrientDBRecordSpeedTest.php └── data │ └── CharterofFundamentalRightsoftheEuropeanUnion.txt ├── Tests ├── OrientDBClassBasicTest.php ├── OrientDBCommandCommandTest.php ├── OrientDBCommandCommitTest.php ├── OrientDBCommandConfigGetTest.php ├── OrientDBCommandConfigListTest.php ├── OrientDBCommandConfigSetTest.php ├── OrientDBCommandCountTest.php ├── OrientDBCommandDBCreateTest.php ├── OrientDBCommandDBDeleteTest.php ├── OrientDBCommandDBExistsTest.php ├── OrientDBCommandDBListTest.php ├── OrientDBCommandDBOpenTest.php ├── OrientDBCommandDataclusterAddTest.php ├── OrientDBCommandDataclusterCountTest.php ├── OrientDBCommandDataclusterDatarangeTest.php ├── OrientDBCommandDataclusterRemoveTest.php ├── OrientDBCommandDatasegmentAddTest.php ├── OrientDBCommandDatasegmentDeleteTest.php ├── OrientDBCommandQueryTest.php ├── OrientDBCommandRecordCreateTest.php ├── OrientDBCommandRecordDeleteTest.php ├── OrientDBCommandRecordLoadTest.php ├── OrientDBCommandRecordUpdateTest.php ├── OrientDBCommandSelectAsyncTest.php ├── OrientDBCommandSelectTest.php ├── OrientDBCommandShutdownTest.php ├── OrientDBCommandsBasicTest.php ├── OrientDBConnectTest.php ├── OrientDBConvertComplementTest.php ├── OrientDBDataTest.php ├── OrientDBI64Test.php ├── OrientDBRecordEncoderTest.php ├── OrientDBRecordTest.php ├── OrientDBTypeDateTest.php ├── OrientDBTypeLinkTest.php └── OrientDB_TestCase.php ├── composer.json ├── example.php ├── gremlin.php ├── phpunit.xml ├── readme.markdown └── speedtest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .project 3 | .settings/ 4 | PHPUnit/ 5 | report/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2013, Anton Terekhov 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of the Netmonsters LLC nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandCommand.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * command() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandCommand extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * Query text 23 | * @var string 24 | */ 25 | protected $query; 26 | 27 | /** 28 | * Command mode 29 | * @var string 30 | */ 31 | protected $mode; 32 | 33 | /** 34 | * Fetchplan 35 | * @var string 36 | */ 37 | protected $fetchPlan; 38 | 39 | const MODE_SYNC = 's'; 40 | 41 | const MODE_ASYNC = 'a'; 42 | 43 | public function __construct($parent) 44 | { 45 | parent::__construct($parent); 46 | $this->opType = OrientDBCommandAbstract::COMMAND; 47 | } 48 | 49 | public function prepare() 50 | { 51 | parent::prepare(); 52 | if (!empty($this->mode)) { 53 | // Populate $this->attribs with mode from child classes 54 | array_unshift($this->attribs, $this->mode); 55 | } 56 | if (count($this->attribs) > 3 || count($this->attribs) < 2) { 57 | throw new OrientDBWrongParamsException('This command requires query and, optionally, fetchplan'); 58 | } 59 | if (empty($this->mode)) { 60 | if ($this->attribs[0] == OrientDB::COMMAND_SELECT_SYNC || $this->attribs[0] == OrientDB::COMMAND_SELECT_ASYNC || $this->attribs[0] == OrientDB::COMMAND_QUERY) { 61 | $this->mode = $this->attribs[0]; 62 | } else { 63 | throw new OrientDBWrongParamsException('Wrong command mode'); 64 | } 65 | } 66 | if (($this->mode == OrientDB::COMMAND_QUERY || $this->mode == OrientDB::COMMAND_SELECT_SYNC) && count($this->attribs) == 3) { 67 | throw new OrientDBWrongParamsException('Fetch is useless with COMMAND_QUERY'); 68 | } 69 | $this->query = trim($this->attribs[1]); 70 | $this->fetchPlan = '*:0'; 71 | if (count($this->attribs) == 3) { 72 | $this->fetchPlan = $this->attribs[2]; 73 | } 74 | 75 | // Add mode 76 | if ($this->mode == OrientDB::COMMAND_QUERY || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) { 77 | $this->addByte(self::MODE_SYNC); 78 | } else { 79 | $this->addByte(self::MODE_ASYNC); 80 | } 81 | if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC) { 82 | $objName = 'com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery'; 83 | } elseif ($this->mode == OrientDB::COMMAND_SELECT_SYNC) { 84 | $objName = 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'; 85 | } elseif ($this->mode == OrientDB::COMMAND_SELECT_GREMLIN) { 86 | $objName = 'com.orientechnologies.orient.graph.gremlin.OCommandGremlin'; 87 | } else { 88 | $objName = 'com.orientechnologies.orient.core.sql.OCommandSQL'; 89 | } 90 | // Java query object serialization 91 | $buff = ''; 92 | // Java query object name serialization 93 | $buff .= pack('N', strlen($objName)); 94 | $buff .= $objName; 95 | // Query text serialization in TEXT mode 96 | $buff .= pack('N', strlen($this->query)); 97 | $buff .= $this->query; 98 | if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC || $this->mode == OrientDB::COMMAND_SELECT_SYNC || $this->mode == OrientDB::COMMAND_SELECT_GREMLIN) { 99 | // Limit set to -1 to ignore and use TEXT MODE 100 | $buff .= pack('N', -1); 101 | // Add a fetchplan 102 | $buff .= pack('N', strlen($this->fetchPlan)); 103 | $buff .= $this->fetchPlan; 104 | } 105 | // Params serialization, we have 0 params 106 | $buff .= pack('N', 0); 107 | // Now query object serialization complete, add it to command bytes 108 | $this->addString($buff); 109 | } 110 | 111 | /** 112 | * (non-PHPdoc) 113 | * @see OrientDBCommandAbstract::parseResponse() 114 | * @return bool|OrientDBTypeLink|OrientDBRecord|string|array 115 | */ 116 | protected function parseResponse() 117 | { 118 | $this->debugCommand('status'); 119 | $status = $this->readByte(); 120 | if ($this->mode == OrientDB::COMMAND_SELECT_ASYNC) { 121 | if ($status != chr(0)) { 122 | $records = array(); 123 | while ($status == chr(1)) { 124 | 125 | $record = $this->readRecord(); 126 | $records[] = $record; 127 | 128 | $this->debugCommand('record_status_next'); 129 | $status = $this->readByte(); 130 | } 131 | // Cache records 132 | $cachedRecords = array(); 133 | while ($status == chr(2)) { 134 | $this->debugCommand('record_content'); 135 | $record = $this->readRecord(); 136 | $cachedRecords[$record->recordID] = $record; 137 | $this->debugCommand('record_status_cache'); 138 | $status = $this->readByte(); 139 | } 140 | // Invalidate cache 141 | $this->parent->cachedRecords = $cachedRecords; 142 | return $records; 143 | } 144 | return false; 145 | } else { 146 | if ($status == 'l') { 147 | // List of records 148 | $this->debugCommand('records_count'); 149 | $recordsCount = $this->readInt(); 150 | if ($recordsCount == 0) { 151 | return false; 152 | } 153 | $records = array(); 154 | for ($i = 0; $i < $recordsCount; $i++) { 155 | $records[] = $this->readRecord(); 156 | } 157 | return $records; 158 | } else if ($status == 'n') { 159 | // Null 160 | return null; 161 | } else if ($status == 'r') { 162 | // Single record 163 | return $this->readRecord(); 164 | } else if ($status == 'a') { 165 | // Something other 166 | return $this->readString(); 167 | } 168 | } 169 | return null; 170 | } 171 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandCommit.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * commit() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandCommit extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::TX_COMMIT; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | throw new OrientDBException('Not implemented'); 31 | } 32 | 33 | protected function parseResponse() 34 | { 35 | 36 | } 37 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandConfigGet.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * configGet() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandConfigGet extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::CONFIG_GET; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 1) { 31 | throw new OrientDBWrongParamsException('This command requires config name'); 32 | } 33 | // Add option name 34 | $this->addString($this->attribs[0]); 35 | } 36 | 37 | /** 38 | * (non-PHPdoc) 39 | * @see OrientDBCommandAbstract::parseResponse() 40 | * @return string 41 | */ 42 | protected function parseResponse() 43 | { 44 | $this->debugCommand('config_value'); 45 | $value = $this->readString(); 46 | 47 | return $value; 48 | } 49 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandConfigList.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * configList() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandConfigList extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::CONFIG_LIST; 25 | } 26 | 27 | /** 28 | * (non-PHPdoc) 29 | * @see OrientDBCommandAbstract::parseResponse() 30 | * @return array 31 | */ 32 | protected function parseResponse() 33 | { 34 | $this->debugCommand('options_count'); 35 | $numOptions = $this->readShort(); 36 | 37 | $options = array(); 38 | for ($i = 0; $i < $numOptions; $i++) { 39 | $this->debugCommand('option_name'); 40 | $optionName = $this->readString(); 41 | $this->debugCommand('option_value'); 42 | $options[$optionName] = $this->readString(); 43 | } 44 | 45 | return $options; 46 | } 47 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandConfigSet.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * configSet() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandConfigSet extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::CONFIG_SET; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 2) { 31 | throw new OrientDBWrongParamsException('This command requires config name and value'); 32 | } 33 | // Add option name 34 | $this->addString($this->attribs[0]); 35 | // Add option value 36 | $this->addString($this->attribs[1]); 37 | } 38 | 39 | /** 40 | * (non-PHPdoc) 41 | * @see OrientDBCommandAbstract::parseResponse() 42 | * @return bool 43 | */ 44 | protected function parseResponse() 45 | { 46 | return true; 47 | } 48 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandConnect.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * connect() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandConnect extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * SessionID of current connection 23 | * @var int 24 | */ 25 | public $sessionID; 26 | 27 | public function __construct($parent) 28 | { 29 | parent::__construct($parent); 30 | $this->opType = OrientDBCommandAbstract::CONNECT; 31 | } 32 | 33 | public function prepare() 34 | { 35 | parent::prepare(); 36 | if (count($this->attribs) != 2) { 37 | throw new OrientDBWrongParamsException('This command requires login and password'); 38 | } 39 | // Add Driver name 40 | $this->addString(OrientDB::DRIVER_NAME); 41 | // Add Driver version 42 | $this->addString(OrientDB::DRIVER_VERSION); 43 | // Add protocol version 44 | $this->addShort($this->parent->getProtocolVersionClient()); 45 | // Add client ID 46 | $this->addString(''); 47 | // Add login 48 | $this->addString($this->attribs[0]); 49 | // Add password 50 | $this->addString($this->attribs[1]); 51 | } 52 | 53 | /** 54 | * (non-PHPdoc) 55 | * @see OrientDBCommandAbstract::parseResponse() 56 | * @return bool 57 | */ 58 | protected function parseResponse() 59 | { 60 | $this->debugCommand('sessionID'); 61 | $this->sessionID = $this->readInt(); 62 | return true; 63 | } 64 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandCount.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * count() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandCount extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::COUNT; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 1) { 31 | throw new OrientDBWrongParamsException('This command requires cluster name'); 32 | } 33 | // Add cluster name 34 | $this->addString($this->attribs[0]); 35 | } 36 | 37 | /** 38 | * (non-PHPdoc) 39 | * @see OrientDBCommandAbstract::parseResponse() 40 | * @return int 41 | */ 42 | protected function parseResponse() 43 | { 44 | $this->debugCommand('count'); 45 | $count = $this->readLong(); 46 | return $count; 47 | } 48 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBClose.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBClose() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBClose extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DB_CLOSE; 25 | } 26 | 27 | /** 28 | * (non-PHPdoc) 29 | * @see OrientDBCommandAbstract::parseResponse() 30 | * @return void 31 | */ 32 | protected function parseResponse() 33 | { 34 | } 35 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBCreate.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBCreate() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBCreate extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DB_CREATE; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 2) { 31 | throw new OrientDBWrongParamsException('This command requires DB name and type'); 32 | } 33 | // Add DB name 34 | $this->addString($this->attribs[0]); 35 | // Add DB type. Since rc9. Right now only document is supported 36 | $this->addString('document'); 37 | // Add DB storage type 38 | $db_types = array( 39 | OrientDB::DB_TYPE_MEMORY, 40 | OrientDB::DB_TYPE_LOCAL); 41 | if (!in_array($this->attribs[1], $db_types)) { 42 | throw new OrientDBWrongParamsException('Not supported DB type. Supported types is: ' . implode(', ', $db_types)); 43 | } 44 | $this->addString($this->attribs[1]); 45 | } 46 | 47 | /** 48 | * (non-PHPdoc) 49 | * @see OrientDBCommandAbstract::parseResponse() 50 | * @return bool 51 | */ 52 | protected function parseResponse() 53 | { 54 | return true; 55 | } 56 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBDelete.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBDelete() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBDelete extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DB_DELETE; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 1) { 31 | throw new OrientDBWrongParamsException('This command requires DB name'); 32 | } 33 | // Add DB name 34 | $this->addString($this->attribs[0]); 35 | } 36 | 37 | /** 38 | * (non-PHPdoc) 39 | * @see OrientDBCommandAbstract::parseResponse() 40 | * @return bool 41 | */ 42 | protected function parseResponse() 43 | { 44 | // Orient DB returns nothing here 45 | return true; 46 | } 47 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBExists.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBExists() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBExists extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DB_EXIST; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 1) { 31 | throw new OrientDBWrongParamsException('This command requires DB name'); 32 | } 33 | // Add DB name 34 | $this->addString($this->attribs[0]); 35 | } 36 | 37 | /** 38 | * (non-PHPdoc) 39 | * @see OrientDBCommandAbstract::parseResponse() 40 | * @return bool 41 | */ 42 | protected function parseResponse() 43 | { 44 | $this->debugCommand('exist_result'); 45 | $result = $this->readByte(); 46 | if ($result == chr(1)) { 47 | return true; 48 | } 49 | return false; 50 | } 51 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBList.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBList() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBList extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DB_LIST; 25 | } 26 | 27 | /** 28 | * (non-PHPdoc) 29 | * @see OrientDBCommandAbstract::parseResponse() 30 | * @return array 31 | */ 32 | protected function parseResponse() 33 | { 34 | $this->debugCommand('database_list'); 35 | $decoder = new OrientDBRecordDecoder($this->readString()); 36 | return $decoder->data->databases; 37 | } 38 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDBOpen.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * DBOpen() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDBOpen extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * SessionID of current connection 23 | * @var int 24 | */ 25 | public $sessionID; 26 | 27 | public function __construct($parent) 28 | { 29 | parent::__construct($parent); 30 | $this->opType = OrientDBCommandAbstract::DB_OPEN; 31 | } 32 | 33 | public function prepare() 34 | { 35 | parent::prepare(); 36 | if (count($this->attribs) != 3) { 37 | throw new OrientDBWrongParamsException('This command requires DB name, login and password'); 38 | } 39 | // Add Driver name 40 | $this->addString(OrientDB::DRIVER_NAME); 41 | // Add Driver version 42 | $this->addString(OrientDB::DRIVER_VERSION); 43 | // Add protocol version 44 | $this->addShort($this->parent->getProtocolVersionClient()); 45 | // Add client ID 46 | $this->addString(''); 47 | // Add DB name 48 | $this->addString($this->attribs[0]); 49 | // Add DB type. Since rc9. Right now only document is supported 50 | $this->addString('document'); 51 | // Add login 52 | $this->addString($this->attribs[1]); 53 | // Add password 54 | $this->addString($this->attribs[2]); 55 | } 56 | 57 | /** 58 | * (non-PHPdoc) 59 | * @see OrientDBCommandAbstract::parseResponse() 60 | * @return array 61 | */ 62 | protected function parseResponse() 63 | { 64 | $this->debugCommand('sessionID'); 65 | $this->sessionID = $this->readInt(); 66 | 67 | $this->debugCommand('clusters'); 68 | $numClusters = $this->readShort(); 69 | 70 | $clusters = array(); 71 | for ($i = 0; $i < $numClusters; $i++) { 72 | $cluster = new stdClass(); 73 | $this->debugCommand('cluster_name'); 74 | $cluster->name = $this->readString(); 75 | $this->debugCommand('clusterID'); 76 | $cluster->id = $this->readShort(); 77 | $this->debugCommand('cluster_type'); 78 | $cluster->type = $this->readString(); 79 | $this->debugCommand('cluster_datasegment_id'); 80 | $cluster->datasegmentid = $this->readShort(); 81 | $clusters[] = $cluster; 82 | } 83 | $this->debugCommand('config_bytes'); 84 | $config = $this->readBytes(); 85 | $this->debugCommand('orientdb-release-string'); 86 | $this->readString(); 87 | 88 | return array( 89 | 'clusters' => $clusters, 90 | 'config' => $config); 91 | } 92 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDataclusterAdd.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * dataclusterAdd() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDataclusterAdd extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * Name of new cluster 23 | * @var string 24 | */ 25 | protected $clusterName; 26 | 27 | /** 28 | * Cluster type 29 | * @var string 30 | * @see OrientDB::$clusterTypes 31 | */ 32 | protected $clusterType; 33 | 34 | /** 35 | * Cluster location 36 | * @var string 37 | */ 38 | protected $clusterLocation = 'default'; 39 | 40 | /** 41 | * Cluster location 42 | * @var string 43 | */ 44 | protected $datasegmentName = 'default'; 45 | 46 | public function __construct($parent) 47 | { 48 | parent::__construct($parent); 49 | $this->opType = OrientDBCommandAbstract::DATACLUSTER_ADD; 50 | } 51 | 52 | public function prepare() 53 | { 54 | parent::prepare(); 55 | if (count($this->attribs) != 2) { 56 | throw new OrientDBWrongParamsException('This command requires cluster name and cluster type'); 57 | } 58 | $this->clusterName = $this->attribs[0]; 59 | if (in_array($this->attribs[1], OrientDB::$clusterTypes)) { 60 | $this->clusterType = $this->attribs[1]; 61 | } else { 62 | throw new OrientDBWrongParamsException('Incorrect cluster Type: ' . $this->attribs[1] . '. Available types is: ' . implode(', ', OrientDB::$clusterTypes)); 63 | } 64 | // Add clusterType 65 | $this->addString($this->clusterType); 66 | // Add clusterName 67 | $this->addString($this->clusterName); 68 | // Add clusterLocation 69 | $this->addString($this->clusterLocation); 70 | // Add datasegment name 71 | $this->addString($this->datasegmentName); 72 | } 73 | 74 | /** 75 | * (non-PHPdoc) 76 | * @see OrientDBCommandAbstract::parseResponse() 77 | * @return int 78 | */ 79 | protected function parseResponse() 80 | { 81 | $this->debugCommand('clusterID'); 82 | $clusterID = $this->readShort(); 83 | return $clusterID; 84 | } 85 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDataclusterCount.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * dataclusterCount() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDataclusterCount extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DATACLUSTER_COUNT; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 1) { 31 | throw new OrientDBWrongParamsException('This command requires cluster IDs in array'); 32 | } 33 | if (!is_array($this->attribs[0])) { 34 | throw new OrientDBWrongParamsException('Array expected'); 35 | } 36 | // Add count 37 | $this->addShort(count($this->attribs[0])); 38 | // Add clusterIDs 39 | for ($i = 0; $i < count($this->attribs[0]); $i++) { 40 | $this->addShort($this->attribs[0][$i]); 41 | } 42 | // Flag - Tombstone 43 | if ($this->parent->protocolVersion >= 13) { 44 | $this->addByte(0); 45 | } 46 | } 47 | 48 | /** 49 | * (non-PHPdoc) 50 | * @see OrientDBCommandAbstract::parseResponse() 51 | * @return int 52 | */ 53 | protected function parseResponse() 54 | { 55 | $this->debugCommand('count'); 56 | $count = $this->readLong(); 57 | return $count; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDataclusterDatarange.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * dataclusterDatarange() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDataclusterDatarange extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID used in command 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | public function __construct($parent) 28 | { 29 | parent::__construct($parent); 30 | $this->opType = OrientDBCommandAbstract::DATACLUSTER_DATARANGE; 31 | } 32 | 33 | public function prepare() 34 | { 35 | parent::prepare(); 36 | if (count($this->attribs) != 1) { 37 | throw new OrientDBWrongParamsException('This command requires cluster ID'); 38 | } 39 | $this->clusterID = $this->attribs[0]; 40 | if (!is_int($this->clusterID)) { 41 | throw new OrientDBWrongParamsException('Integer expected'); 42 | } 43 | // Add clusterID 44 | $this->addShort($this->clusterID); 45 | } 46 | 47 | /** 48 | * (non-PHPdoc) 49 | * @see OrientDBCommandAbstract::parseResponse() 50 | * @return array 51 | */ 52 | protected function parseResponse() 53 | { 54 | $this->debugCommand('start_pos'); 55 | $startPos = $this->readLong(); 56 | $this->debugCommand('end_pos'); 57 | $endPos = $this->readLong(); 58 | return array( 59 | 'start' => $startPos, 60 | 'end' => $endPos); 61 | } 62 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDataclusterRemove.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * dataclusterRemove() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDataclusterRemove extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID used in command 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | public function __construct($parent) 28 | { 29 | parent::__construct($parent); 30 | $this->opType = OrientDBCommandAbstract::DATACLUSTER_REMOVE; 31 | } 32 | 33 | public function prepare() 34 | { 35 | parent::prepare(); 36 | if (count($this->attribs) != 1) { 37 | throw new OrientDBWrongParamsException('This command requires cluster ID'); 38 | } 39 | if (is_int($this->attribs[0])) { 40 | $this->clusterID = $this->attribs[0]; 41 | } else { 42 | throw new OrientDBWrongParamsException('Integer expected'); 43 | } 44 | // Add clusterID 45 | $this->addShort($this->clusterID); 46 | } 47 | 48 | /** 49 | * (non-PHPdoc) 50 | * @see OrientDBCommandAbstract::parseResponse() 51 | * @return bool 52 | */ 53 | protected function parseResponse() 54 | { 55 | $this->debugCommand('remove_result'); 56 | $result = $this->readByte(); 57 | if ($result == chr(1)) { 58 | return true; 59 | } 60 | return false; 61 | } 62 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDatasegmentAdd.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * datasegmentAdd() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDatasegmentAdd extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DATASEGMENT_ADD; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | throw new OrientDBException('Not implemented'); 31 | } 32 | 33 | protected function parseResponse() 34 | { 35 | } 36 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandDatasegmentDelete.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * datasegmentAdd() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandDatasegmentDelete extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::DATASEGMENT_REMOVE; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | throw new OrientDBException('Not implemented'); 31 | } 32 | 33 | protected function parseResponse() 34 | { 35 | } 36 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandQuery.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * query() command for OrientDB-PHP 13 | * This is pseudo command, and its underlying is command() 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandQuery extends OrientDBCommandCommand 19 | { 20 | public function __construct($parent) 21 | { 22 | $this->mode = OrientDB::COMMAND_QUERY; 23 | parent::__construct($parent); 24 | } 25 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandRecordCreate.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * recordCreate() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandRecordCreate extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | /** 28 | * Record type 29 | * @var string 30 | * @see OrientDB::$recordTypes 31 | */ 32 | protected $recordType; 33 | 34 | /** 35 | * Record content 36 | * @var string|OrientDBRecord 37 | */ 38 | protected $recordContent; 39 | 40 | /** 41 | * Mode. 0 = synchronous (default mode waits for the answer) 1 = asynchronous (don't need an answer) 42 | * @var int 43 | */ 44 | protected $mode = 0x00; 45 | 46 | /** 47 | * @var int 48 | */ 49 | protected $datasegmentID = 0; 50 | 51 | public function __construct($parent) 52 | { 53 | parent::__construct($parent); 54 | $this->opType = OrientDBCommandAbstract::RECORD_CREATE; 55 | } 56 | 57 | public function prepare() 58 | { 59 | parent::prepare(); 60 | if (count($this->attribs) > 3 || count($this->attribs) < 2) { 61 | throw new OrientDBWrongParamsException('This command requires cluster ID, record content and, optionally, record Type'); 62 | } 63 | // Add datasegment ID 64 | $this->addInt($this->datasegmentID); 65 | // Process clusterID 66 | $this->clusterID = (int) $this->attribs[0]; 67 | // Add ClusterID 68 | $this->addShort($this->clusterID); 69 | // Process recordContent 70 | $this->recordContent = $this->attribs[1]; 71 | // Add RecordContent 72 | $this->addBytes($this->recordContent); 73 | // recordType 74 | $this->recordType = OrientDB::RECORD_TYPE_DOCUMENT; 75 | if (count($this->attribs) == 3) { 76 | if (in_array($this->attribs[2], OrientDB::$recordTypes)) { 77 | $this->recordType = $this->attribs[2]; 78 | } else { 79 | throw new OrientDBWrongParamsException('Incorrect record Type: ' . $this->attribs[2] . '. Available types is: ' . implode(', ', OrientDB::$recordTypes)); 80 | } 81 | } 82 | $this->addByte($this->recordType); 83 | // Synchronous mode 84 | $this->addByte(chr($this->mode)); 85 | } 86 | 87 | /** 88 | * (non-PHPdoc) 89 | * @see OrientDBCommandAbstract::parseResponse() 90 | * @return int 91 | */ 92 | protected function parseResponse() 93 | { 94 | $this->debugCommand('record_pos'); 95 | $position = $this->readLong(); 96 | $this->debugCommand('record_version'); 97 | $version = $this->readInt(); 98 | 99 | if ($this->recordContent instanceof OrientDBRecord) { 100 | $this->recordContent->recordPos = $position; 101 | $this->recordContent->clusterID = $this->clusterID; 102 | $this->recordContent->version = $version; 103 | } 104 | 105 | return $position; 106 | } 107 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandRecordDelete.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * recordDelete() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandRecordDelete extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | /** 28 | * Record position 29 | * @var int 30 | */ 31 | protected $recordPos; 32 | 33 | /** 34 | * Record type 35 | * @var string 36 | * @see OrientDB::$recordTypes 37 | */ 38 | protected $recordType; 39 | 40 | /** 41 | * Record version 42 | * @var int 43 | */ 44 | protected $version; 45 | 46 | /** 47 | * Mode. 0 = synchronous (default mode waits for the answer) 1 = asynchronous (don't need an answer) 48 | * @var int 49 | */ 50 | protected $mode = 0x00; 51 | 52 | public function __construct($parent) 53 | { 54 | parent::__construct($parent); 55 | $this->opType = OrientDBCommandAbstract::RECORD_DELETE; 56 | } 57 | 58 | public function prepare() 59 | { 60 | parent::prepare(); 61 | if (count($this->attribs) > 2 || count($this->attribs) < 1) { 62 | throw new OrientDBWrongParamsException('This command requires record ID and, optionally, record version'); 63 | } 64 | $arr = explode(':', $this->attribs[0]); 65 | if (count($arr) != 2) { 66 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 67 | } 68 | $this->clusterID = (int) $arr[0]; 69 | $this->recordPos = (int) $arr[1]; 70 | 71 | if ($this->clusterID === 0 || (string) $this->recordPos !== $arr[1]) { 72 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 73 | } 74 | if (count($this->attribs) == 2) { 75 | $this->version = (int) $this->attribs[1]; 76 | } else { 77 | // Pessimistic way 78 | $this->version = -1; 79 | } 80 | // Add ClusterID 81 | $this->addShort($this->clusterID); 82 | // Add RecordID 83 | $this->addLong($this->recordPos); 84 | // Add version 85 | $this->addInt($this->version); 86 | // Synchronous mode 87 | $this->addByte(chr($this->mode)); 88 | } 89 | 90 | /** 91 | * (non-PHPdoc) 92 | * @see OrientDBCommandAbstract::parseResponse() 93 | * @return bool 94 | */ 95 | protected function parseResponse() 96 | { 97 | $this->debugCommand('delete_result'); 98 | $result = $this->readByte(); 99 | if ($result == chr(1)) { 100 | return true; 101 | } else { 102 | return false; 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandRecordLoad.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * recordLoad() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandRecordLoad extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | /** 28 | * Record position 29 | * @var int 30 | */ 31 | protected $recordPos; 32 | 33 | /** 34 | * Fetchplan 35 | * @var string 36 | */ 37 | protected $fetchPlan; 38 | 39 | public function __construct($parent) 40 | { 41 | parent::__construct($parent); 42 | $this->opType = OrientDBCommandAbstract::RECORD_LOAD; 43 | } 44 | 45 | public function prepare() 46 | { 47 | parent::prepare(); 48 | if (count($this->attribs) > 2 || count($this->attribs) < 1) { 49 | throw new OrientDBWrongParamsException('This command requires record ID and, optionally, fetch plan'); 50 | } 51 | $arr = explode(':', $this->attribs[0]); 52 | if (count($arr) != 2) { 53 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 54 | } 55 | $this->clusterID = (int) $arr[0]; 56 | $this->recordPos = (int) $arr[1]; 57 | 58 | if ((string) $this->clusterID !== $arr[0] || (string) $this->recordPos !== $arr[1]) { 59 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 60 | } 61 | // Add ClusterID 62 | $this->addShort($this->clusterID); 63 | // Add RecordID 64 | $this->addLong($this->recordPos); 65 | // Fetchplan 66 | $this->fetchPlan = '*:0'; 67 | if (count($this->attribs) == 2) { 68 | $this->fetchPlan = $this->attribs[1]; 69 | } 70 | $this->addString($this->fetchPlan); 71 | // Cache ignore - use cache 72 | $this->addByte(0); 73 | // Flag - Tombstone 74 | if ($this->parent->protocolVersion >= 13) { 75 | $this->addByte(0); 76 | } 77 | } 78 | 79 | /** 80 | * (non-PHPdoc) 81 | * @see OrientDBCommandAbstract::parseResponse() 82 | * @return bool|OrientDBTypeLink|OrientDBRecord 83 | */ 84 | protected function parseResponse() 85 | { 86 | $this->debugCommand('record_status_first'); 87 | $status = $this->readByte(); 88 | if ($status != chr(0)) { 89 | $this->debugCommand('record_content'); 90 | $record_content = $this->readBytes(); 91 | $this->debugCommand('record_version'); 92 | $record_version = $this->readInt(); 93 | $this->debugCommand('record_type'); 94 | $record_type = $this->readByte(); 95 | $this->debugCommand('record_status_cache'); 96 | $status = $this->readByte(); 97 | 98 | $cachedRecords = array(); 99 | while ($status != chr(0)) { 100 | $this->debugCommand('record_content'); 101 | $record = $this->readRecord(); 102 | $cachedRecords[$record->recordID] = $record; 103 | $this->debugCommand('record_status_next'); 104 | $status = $this->readByte(); 105 | } 106 | // Invalidate cache 107 | $this->parent->cachedRecords = $cachedRecords; 108 | // Form a record 109 | $record = new OrientDBRecord(); 110 | $record->type = $record_type; 111 | $record->clusterID = $this->clusterID; 112 | $record->recordPos = $this->recordPos; 113 | $record->version = $record_version; 114 | $record->content = $record_content; 115 | 116 | return $record; 117 | } 118 | return false; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandRecordUpdate.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * recordUpdate() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandRecordUpdate extends OrientDBCommandAbstract 19 | { 20 | 21 | /** 22 | * ClusterID 23 | * @var int 24 | */ 25 | protected $clusterID; 26 | 27 | /** 28 | * Record position 29 | * @var int 30 | */ 31 | protected $recordPos; 32 | 33 | /** 34 | * Record type 35 | * @var string 36 | * @see OrientDB::$recordTypes 37 | */ 38 | protected $recordType; 39 | 40 | /** 41 | * record version 42 | * @var int 43 | */ 44 | protected $version; 45 | 46 | /** 47 | * Record content param 48 | * @var string|OrientDBRecord 49 | */ 50 | protected $recordContent; 51 | 52 | protected $mode = 0x00; 53 | 54 | public function __construct($parent) 55 | { 56 | parent::__construct($parent); 57 | $this->opType = OrientDBCommandAbstract::RECORD_UPDATE; 58 | } 59 | 60 | public function prepare() 61 | { 62 | parent::prepare(); 63 | if (count($this->attribs) > 4 || count($this->attribs) < 2) { 64 | throw new OrientDBWrongParamsException('This command requires record ID, record content and, optionally, record version and, optionally, record type'); 65 | } 66 | $arr = explode(':', $this->attribs[0]); 67 | if (count($arr) != 2) { 68 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 69 | } 70 | $this->clusterID = (int) $arr[0]; 71 | $this->recordPos = (int) $arr[1]; 72 | 73 | if ($this->clusterID === 0 || (string) $this->recordPos !== $arr[1]) { 74 | throw new OrientDBWrongParamsException('Wrong format for record ID'); 75 | } 76 | // Add ClusterID 77 | $this->addShort($this->clusterID); 78 | // Add Record pos 79 | $this->addLong($this->recordPos); 80 | // Prepare record content 81 | $this->recordContent = $this->attribs[1]; 82 | // Add record content 83 | $this->addBytes($this->recordContent); 84 | // Add version 85 | if (count($this->attribs) >= 3) { 86 | $this->version = (int) $this->attribs[2]; 87 | } else { 88 | // Pessimistic way 89 | $this->version = -1; 90 | } 91 | $this->addInt($this->version); 92 | if (count($this->attribs) == 4) { 93 | if (in_array($this->attribs[3], OrientDB::$recordTypes)) { 94 | $this->recordType = $this->attribs[3]; 95 | } else { 96 | throw new OrientDBWrongParamsException('Incorrect record Type: ' . $this->attribs[2] . '. Available types is: ' . implode(', ', OrientDB::$recordTypes)); 97 | } 98 | } else { 99 | $this->recordType = OrientDB::RECORD_TYPE_DOCUMENT; 100 | } 101 | // Add recordType 102 | $this->addByte($this->recordType); 103 | $this->addByte(chr($this->mode)); 104 | } 105 | 106 | /** 107 | * (non-PHPdoc) 108 | * @see OrientDBCommandAbstract::parseResponse() 109 | * @return int 110 | */ 111 | protected function parseResponse() 112 | { 113 | $this->debugCommand('record_version'); 114 | $version = $this->readInt(); 115 | 116 | if ($this->recordContent instanceof OrientDBRecord) { 117 | $this->recordContent->recordPos = $this->recordPos; 118 | $this->recordContent->clusterID = $this->clusterID; 119 | $this->recordContent->version = $version; 120 | } 121 | return $version; 122 | } 123 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandSelect.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * select() command for OrientDB-PHP 13 | * This is pseudo command, and its underlying is command() 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandSelect extends OrientDBCommandCommand 19 | { 20 | public function __construct($parent) 21 | { 22 | $this->mode = OrientDB::COMMAND_SELECT_SYNC; 23 | parent::__construct($parent); 24 | } 25 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandSelectAsync.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * selectAsync() command for OrientDB-PHP 13 | * This is pseudo command, and its underlying is command() 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandSelectAsync extends OrientDBCommandCommand 19 | { 20 | public function __construct($parent) 21 | { 22 | $this->mode = OrientDB::COMMAND_SELECT_ASYNC; 23 | parent::__construct($parent); 24 | } 25 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandSelectGremlin.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * selectGremlin() command for OrientDB-PHP 13 | * This is pseudo command, and its underlying is command() 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandSelectGremlin extends OrientDBCommandCommand 19 | { 20 | public function __construct($parent) 21 | { 22 | $this->mode = OrientDB::COMMAND_SELECT_GREMLIN; 23 | parent::__construct($parent); 24 | } 25 | } -------------------------------------------------------------------------------- /OrientDB/Commands/OrientDBCommandShutdown.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * shutdown() command for OrientDB-PHP 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Command 17 | */ 18 | class OrientDBCommandShutdown extends OrientDBCommandAbstract 19 | { 20 | 21 | public function __construct($parent) 22 | { 23 | parent::__construct($parent); 24 | $this->opType = OrientDBCommandAbstract::SHUTDOWN; 25 | } 26 | 27 | public function prepare() 28 | { 29 | parent::prepare(); 30 | if (count($this->attribs) != 2) { 31 | throw new OrientDBWrongParamsException('This command requires name and password'); 32 | } 33 | // Add name 34 | $this->addString($this->attribs[0]); 35 | // Add name 36 | $this->addString($this->attribs[1]); 37 | } 38 | 39 | /** 40 | * (non-PHPdoc) 41 | * @see OrientDBCommandAbstract::parseResponse() 42 | * @return void 43 | */ 44 | protected function parseResponse() 45 | { 46 | } 47 | } -------------------------------------------------------------------------------- /OrientDB/OrientDBDataTypes.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * Class represent OrientDB link to another document 13 | * @author Anton Terekhov 14 | * @package OrientDB-PHP 15 | * @subpackage Datatypes 16 | */ 17 | class OrientDBTypeLink 18 | { 19 | 20 | /** 21 | * Link text without hash sign 22 | * @var string 23 | */ 24 | private $link; 25 | 26 | /** 27 | * Cluster ID in link 28 | * @var int 29 | */ 30 | public $clusterID; 31 | 32 | /** 33 | * Record Position in link 34 | * @var int 35 | */ 36 | public $recordPos; 37 | 38 | /** 39 | * 40 | * Create object from string or two integers. Using a kind of overloading 41 | * @example #10:1 42 | * @example 10:1 43 | * @example 10, 1 44 | * @param string|int $link 45 | * @param null|int|string $recordPos 46 | */ 47 | public function __construct($link, $recordPos = null) 48 | { 49 | if (is_null($recordPos)) { 50 | // Construct from one string #10:1 51 | if (substr($link, 0, 1) === '#') { 52 | $link = substr($link, 1); 53 | } 54 | if (preg_match('/^([0-9]+):([0-9]+)$/', $link, $matches)) { 55 | $this->link = $link; 56 | $this->clusterID = (int) $matches[1]; 57 | $this->recordPos = (int) $matches[2]; 58 | } 59 | } else { 60 | // Construct from two integers 61 | $this->clusterID = (int) $link; 62 | $this->recordPos = $recordPos; 63 | if (((string) $this->clusterID !== (string) $link) || (!is_numeric($this->recordPos))) { 64 | $this->clusterID = null; 65 | $this->recordPos = null; 66 | } 67 | if (!is_null($this->clusterID) && !is_null($this->recordPos)) { 68 | $this->link = $this->clusterID . ':' . $this->recordPos; 69 | } 70 | } 71 | } 72 | 73 | /** 74 | * Magic method overloading 75 | * @return string 76 | */ 77 | public function __toString() 78 | { 79 | if ($this->link) { 80 | return '#' . $this->link; 81 | } 82 | return ''; 83 | } 84 | 85 | /** 86 | * Return link without hash sign 87 | * @return string 88 | * @example 10:1 89 | */ 90 | public function get() 91 | { 92 | return $this->link; 93 | } 94 | 95 | /** 96 | * 97 | * Return link with hash sign 98 | * @return string 99 | * @example #10:1 100 | */ 101 | public function getHash() 102 | { 103 | return '#' . $this->link; 104 | } 105 | } 106 | 107 | /** 108 | * Class represent OrientDB date 109 | * @author Anton Terekhov 110 | * @package OrientDB-PHP 111 | * @subpackage Datatypes 112 | */ 113 | class OrientDBTypeDate 114 | { 115 | 116 | /** 117 | * Timestamp 118 | * @var int 119 | */ 120 | private $timestamp; 121 | 122 | /** 123 | * Create object from string or int 124 | * @param string|int $time 125 | */ 126 | public function __construct($time) 127 | { 128 | if (substr($time, -1, 1) === 't') { 129 | $time = substr($time, 0, -1); 130 | } 131 | if ((string) (int) $time === (string) $time) { 132 | $this->timestamp = (int) $time; 133 | } 134 | } 135 | 136 | /** 137 | * Magic method overloading 138 | * @return string 139 | */ 140 | public function __toString() 141 | { 142 | if ($this->timestamp) { 143 | return $this->timestamp . 't'; 144 | } 145 | return ''; 146 | } 147 | 148 | /** 149 | * Return time for timestamp 150 | * @return int 151 | */ 152 | public function getTime() 153 | { 154 | return $this->timestamp; 155 | } 156 | 157 | /** 158 | * Return timestamp in OrientDB format 159 | * @return string 160 | */ 161 | public function getValue() 162 | { 163 | if ($this->timestamp) { 164 | return $this->timestamp . 't'; 165 | } 166 | return null; 167 | } 168 | } -------------------------------------------------------------------------------- /OrientDB/OrientDBHelpers.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * OrientDBHelpers contains methods not needed in production use of this 13 | * library 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Debug 17 | */ 18 | class OrientDBHelpers 19 | { 20 | 21 | /** 22 | * Echoes bytes in $data to stdout 23 | * @param string $data 24 | * @param string $newline 25 | */ 26 | static public function hexDump($data, $newline = PHP_EOL) 27 | { 28 | /** 29 | * @var string 30 | */ 31 | static $from = ''; 32 | 33 | /** 34 | * @var string 35 | */ 36 | static $to = ''; 37 | 38 | /** 39 | * number of bytes per line 40 | * @var int 41 | */ 42 | static $width = 16; 43 | 44 | /** 45 | * padding for non-visible characters 46 | * @var string 47 | */ 48 | static $pad = '.'; 49 | 50 | if ($from === '') { 51 | for ($i = 0; $i <= 0xFF; $i++) { 52 | $from .= chr($i); 53 | $to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad; 54 | } 55 | } 56 | 57 | $hex = str_split(bin2hex($data), $width * 2); 58 | $chars = str_split(strtr($data, $from, $to), $width); 59 | 60 | $offset = 0; 61 | foreach ($hex as $i => $line) { 62 | echo sprintf('%6X', $offset) . ' : ' . implode(' ', str_split(str_pad($line, $width * 2, ' '), 2)) . ' [' . $chars[$i] . ']' . $newline; 63 | $offset += $width; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /OrientDB/OrientDBRecord.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * Class representing OrientDB Record 13 | * @author Anton Terekhov 14 | * @package OrientDB-PHP 15 | * @subpackage Datatypes 16 | * @property int clusterID ClusterID of record 17 | * @property int|string recordPos Record position in cluster 18 | * @property string className Class name of record 19 | * @property string content Document source as delivered from OrientDB 20 | * @property-read string recordID Fully-qualified recordID 21 | * 22 | */ 23 | class OrientDBRecord 24 | { 25 | /** 26 | * Flag, if current $this->content was already decoded to $this->data 27 | * @var bool 28 | */ 29 | private $isParsed = false; 30 | 31 | /** 32 | * ClassName as parsed from document 33 | * @var string 34 | */ 35 | private $className; 36 | 37 | /** 38 | * Document type 39 | * @example OrientDB::RECORD_TYPE_DOCUMENT 40 | * @see OrientDB::$recordTypes 41 | * @var string 42 | */ 43 | public $type = OrientDB::RECORD_TYPE_DOCUMENT; 44 | 45 | /** 46 | * ClusterID 47 | * @var int 48 | */ 49 | private $clusterID; 50 | 51 | /** 52 | * Record position in cluster 53 | * @var int 54 | */ 55 | private $recordPos; 56 | 57 | /** 58 | * Full qualified record ID 59 | * @example 1:1 60 | * @var string 61 | */ 62 | private $recordID; 63 | 64 | /** 65 | * Document version 66 | * @var int 67 | */ 68 | public $version; 69 | 70 | /** 71 | * Document source as delivered from OrientDB 72 | * @var string 73 | */ 74 | private $content; 75 | 76 | /** 77 | * A placeholder for document data 78 | * @var OrientDBData|string 79 | */ 80 | public $data; 81 | 82 | /** 83 | * Construct new instance 84 | */ 85 | public function __construct() 86 | { 87 | $this->data = new OrientDBData($this); 88 | $this->isParsed = true; 89 | } 90 | 91 | /** 92 | * Parses $this->content and populates $this->data 93 | * @return void 94 | */ 95 | public function parse() 96 | { 97 | // Check, if we already decoded current $this->content 98 | if (!$this->isParsed) { 99 | // Parse record content 100 | if ($this->type == OrientDB::RECORD_TYPE_DOCUMENT) { 101 | $parser = new OrientDBRecordDecoder(rtrim($this->content)); 102 | 103 | $this->className = $parser->className; 104 | foreach ($parser->data as $key => $value) { 105 | $this->data->$key = $value; 106 | } 107 | } else { 108 | $this->data = $this->content; 109 | } 110 | $this->isParsed = true; 111 | } 112 | } 113 | 114 | /** 115 | * Forces that record was already parsed 116 | * @return void 117 | */ 118 | public function setParsed() 119 | { 120 | $this->isParsed = true; 121 | } 122 | 123 | /** 124 | * Fully resets class, equals to new() 125 | * @return void 126 | */ 127 | public function reset() 128 | { 129 | $this->data = new OrientDBData($this); 130 | $this->className = null; 131 | $this->content = null; 132 | $this->isParsed = true; 133 | $this->clusterID = null; 134 | $this->recordPos = null; 135 | $this->recordID = null; 136 | $this->version = null; 137 | } 138 | 139 | /** 140 | * Resets Record data, keeping className and clusterID intact 141 | * @return void 142 | */ 143 | public function resetData() 144 | { 145 | $this->data = new OrientDBData($this); 146 | $this->content = null; 147 | $this->isParsed = true; 148 | $this->recordPos = null; 149 | $this->recordID = null; 150 | $this->version = null; 151 | } 152 | 153 | /** 154 | * Magic method 155 | * @return string 156 | */ 157 | public function __toString() 158 | { 159 | $encoder = new OrientDBRecordEncoder($this->data, $this->className); 160 | return $encoder->buffer; 161 | } 162 | 163 | /** 164 | * Parses recordID from $this->clusterID and $this->recordPos. Populates $this->recordID 165 | * @return void 166 | */ 167 | private function parseRecordID() 168 | { 169 | if ((int) $this->clusterID !== $this->clusterID) { 170 | return; 171 | } 172 | if ($this->clusterID >= 0 && is_numeric($this->recordPos)) { 173 | if ($this->recordPos >= 0) { 174 | $this->recordID = $this->clusterID . ':' . $this->recordPos; 175 | } 176 | } 177 | } 178 | 179 | public function __get($name) 180 | { 181 | if ($name === 'className') { 182 | $this->parse(); 183 | } 184 | if ($name === 'recordPos' || $name === 'clusterID' || $name === 'recordID' || $name === 'className' || $name == 'content') { 185 | return $this->$name; 186 | } 187 | $trace = debug_backtrace(); 188 | trigger_error('Undefined property via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); 189 | return null; 190 | } 191 | 192 | public function __set($name, $value) 193 | { 194 | if ($name === 'recordPos' || $name === 'clusterID') { 195 | if (is_numeric($value) || is_null($value)) { 196 | $this->$name = $value; 197 | } 198 | $this->parseRecordID(); 199 | } elseif ($name === 'content') { 200 | $this->content = $value; 201 | $this->isParsed = false; 202 | $this->data = new OrientDBData($this); 203 | } elseif ($name === 'className') { 204 | $this->className = $value; 205 | } elseif ($name === 'recordID') { 206 | $trace = debug_backtrace(); 207 | trigger_error('Can\'t directly set property ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); 208 | } else { 209 | $trace = debug_backtrace(); 210 | trigger_error('Can\'t set property ' . $name . ' via __set() in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); 211 | } 212 | } 213 | } 214 | 215 | /** 216 | * Class representing OrientDB Record Data. Mainly used for parsing record "on demand" while any function for getting data is called 217 | * @author Anton Terekhov 218 | * @package OrientDB-PHP 219 | * @subpackage Datatypes 220 | * 221 | */ 222 | class OrientDBData implements Countable, Iterator 223 | { 224 | /** 225 | * Data holder 226 | * @var array 227 | */ 228 | private $data = array(); 229 | 230 | /** 231 | * Link to parent record, for calling it's ->parse() 232 | * @var OrientDBRecord|null 233 | */ 234 | private $record; 235 | 236 | 237 | /** 238 | * Link to parent record 239 | * @param $record OrientDBRecord|null 240 | * @throws OrientDBException 241 | */ 242 | public function __construct($record = null) 243 | { 244 | if (!is_null($record)) { 245 | if ($record instanceof OrientDBRecord) { 246 | $this->record = $record; 247 | } else { 248 | throw new OrientDBException('Only OrientDBRecord instance can be used in __construct()'); 249 | } 250 | } 251 | } 252 | 253 | public function &__get($name) 254 | { 255 | $this->isParsed(); 256 | if (array_key_exists($name, $this->data)) { 257 | return $this->data[$name]; 258 | } 259 | trigger_error('Undefined index: ' . $name, E_USER_NOTICE); 260 | } 261 | 262 | public function __set($name, $value) 263 | { 264 | $this->data[$name] = $value; 265 | } 266 | 267 | 268 | /** 269 | * Magic function for isset() call 270 | * @param $name 271 | * @return bool 272 | */ 273 | public function __isset($name) 274 | { 275 | $this->isParsed(); 276 | return isset($this->data[$name]); 277 | } 278 | 279 | /** 280 | * Magic function for unset() calls 281 | * @param $name 282 | * @return void 283 | */ 284 | public function __unset($name) 285 | { 286 | unset($this->data[$name]); 287 | } 288 | 289 | /** 290 | * Count elements of an object. The return value is cast to an integer. 291 | * @link http://php.net/manual/en/countable.count.php 292 | * @return int The custom count as an integer. 293 | */ 294 | public function count() 295 | { 296 | $this->isParsed(); 297 | return count($this->data); 298 | } 299 | 300 | /** 301 | * Return the current element 302 | * @link http://php.net/manual/en/iterator.current.php 303 | * @return mixed Can return any type. 304 | */ 305 | public function current() 306 | { 307 | $this->isParsed(); 308 | return current($this->data); 309 | } 310 | 311 | /** 312 | * Move forward to next element 313 | * @link http://php.net/manual/en/iterator.next.php 314 | * @return void Any returned value is ignored. 315 | */ 316 | public function next() 317 | { 318 | $this->isParsed(); 319 | next($this->data); 320 | } 321 | 322 | /** 323 | * Return the key of the current element 324 | * @link http://php.net/manual/en/iterator.key.php 325 | * @return int scalar on success 326 | * 0 on failure. 327 | */ 328 | public function key() 329 | { 330 | $this->isParsed(); 331 | return key($this->data); 332 | } 333 | 334 | /** 335 | * Checks if current position is valid 336 | * @link http://php.net/manual/en/iterator.valid.php 337 | * @return boolean The return value will be casted to boolean and then evaluated. 338 | * Returns true on success or false on failure. 339 | */ 340 | public function valid() 341 | { 342 | $this->isParsed(); 343 | return key($this->data) !== null; 344 | } 345 | 346 | /** 347 | * Rewind the Iterator to the first element 348 | * @link http://php.net/manual/en/iterator.rewind.php 349 | * @return void Any returned value is ignored. 350 | */ 351 | public function rewind() 352 | { 353 | $this->isParsed(); 354 | reset($this->data); 355 | } 356 | 357 | /** 358 | * Check, if current dataset was already de-serialized 359 | * @return void 360 | */ 361 | private function isParsed() 362 | { 363 | if (!is_null($this->record)) { 364 | // If we have link to parent record 365 | $this->record->parse(); 366 | } 367 | } 368 | 369 | /** 370 | * Get all keys for data 371 | * @return array 372 | */ 373 | public function getKeys() 374 | { 375 | return array_keys($this->data); 376 | } 377 | } -------------------------------------------------------------------------------- /OrientDB/OrientDBRecordEncoder.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * Class to encode OrientDB record 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Datatypes 17 | */ 18 | class OrientDBRecordEncoder 19 | { 20 | 21 | /** 22 | * ClassName as parsed from document 23 | * @var string 24 | */ 25 | protected $className; 26 | 27 | /** 28 | * A placeholder for document data 29 | * @var StdClass 30 | */ 31 | protected $data; 32 | 33 | /** 34 | * Serialized record 35 | * @var string 36 | */ 37 | public $buffer; 38 | 39 | /** 40 | * Construct new instance 41 | * @param OrientDBData $data Data from OrientDBRecord instance 42 | * @param string $className ClassName from OrientDBRecord instance 43 | * @return \OrientDBRecordEncoder 44 | */ 45 | public function __construct($data, $className = null) 46 | { 47 | $this->data = $data; 48 | $this->className = $className; 49 | $this->encode(); 50 | } 51 | 52 | /** 53 | * Parses $this->content and populates $this->data and $this->className 54 | * @return void 55 | */ 56 | protected function encode() 57 | { 58 | if (!is_null($this->className)) { 59 | $this->buffer .= $this->className . '@'; 60 | } 61 | $tokens = $this->process($this->data); 62 | 63 | $this->buffer .= implode(',', $tokens); 64 | } 65 | 66 | /** 67 | * Recursively encodes data to OrientDB representation 68 | * @param array|OrientDBData $data Data to be encoded 69 | * @param bool $isAssoc Is keys needs to be included 70 | * @param bool $isArray Is this array or class 71 | * @throws OrientDBException 72 | * @return array Array of tokens 73 | */ 74 | protected function process($data, $isAssoc = true, $isArray = false) 75 | { 76 | $tokens = array(); 77 | 78 | foreach ($data as $key => $value) { 79 | $buffer = ''; 80 | if ($isAssoc) { 81 | if ($isArray) { 82 | $buffer = self::encodeString($key) . ':'; 83 | } else { 84 | $buffer = $key . ':'; 85 | } 86 | } 87 | /** 88 | * 89 | * PHP manual says what gettype() is slow and we should use is_* functions instead. But tests says that its approx. 5-10% faster encoding using single gettype() call instead of separate calls to is_int(), is_string(), etc. 90 | * @var string 91 | */ 92 | $valueType = gettype($value); 93 | switch ($valueType) { 94 | case 'integer': 95 | $buffer .= $value; 96 | break; 97 | 98 | case 'double': 99 | $buffer .= $value . chr(OrientDBRecordDecoder::CCODE_NUM_FLOAT); 100 | break; 101 | 102 | case 'string': 103 | $buffer .= self::encodeString($value); 104 | break; 105 | 106 | case 'boolean': 107 | if ($value === true) { 108 | $buffer .= 'true'; 109 | } else { 110 | $buffer .= 'false'; 111 | } 112 | break; 113 | 114 | case 'array': 115 | $arrayAssoc = self::isAssoc($value); 116 | if ($arrayAssoc === true) { 117 | // This is assoc array, using map 118 | $boundStart = chr(OrientDBRecordDecoder::CCODE_OPEN_CURLY); 119 | $boundEnd = chr(OrientDBRecordDecoder::CCODE_CLOSE_CURLY); 120 | } else { 121 | // Array will always be encoded as a set, as 1) Orient itself converts set to list (and vice-versa too) 2) PHP lacks build-in set type 122 | $boundStart = chr(OrientDBRecordDecoder::CCODE_OPEN_SQUARE); 123 | $boundEnd = chr(OrientDBRecordDecoder::CCODE_CLOSE_SQUARE); 124 | } 125 | $buffer .= $boundStart; 126 | /** 127 | * @TODO Fix possible PHP fatal: Maximum function nesting level of '100' reached, aborting! 128 | */ 129 | $buffer .= implode(',', $this->process($value, $arrayAssoc, true)); 130 | $buffer .= $boundEnd; 131 | break; 132 | 133 | case 'NULL': 134 | 135 | break; 136 | 137 | case is_a($value, 'OrientDBTypeLink'): 138 | /** @var $value OrientDBTypeLink */ 139 | $buffer .= $value->getHash(); 140 | break; 141 | 142 | case is_a($value, 'OrientDBTypeDate'): 143 | $buffer .= (string) $value; 144 | break; 145 | 146 | case is_a($value, 'OrientDBRecord'): 147 | $buffer .= chr(OrientDBRecordDecoder::CCODE_OPEN_PARENTHESES); 148 | /** @var $value OrientDBRecord */ 149 | $buffer .= $value->__toString(); 150 | $buffer .= chr(OrientDBRecordDecoder::CCODE_CLOSE_PARENTHESES); 151 | break; 152 | 153 | default: 154 | throw new OrientDBException('Can\'t serialize: ' . $valueType); 155 | } 156 | $tokens[] = $buffer; 157 | } 158 | return $tokens; 159 | } 160 | 161 | /** 162 | * Returns escaped string, suitable for OrientDBRecord format 163 | * @param string $string 164 | * @return string 165 | */ 166 | public static function encodeString($string) 167 | { 168 | /** 169 | * @TODO Unit tests 170 | */ 171 | return '"' . addcslashes($string, '"\\') . '"'; 172 | } 173 | 174 | /** 175 | * Check is array is associative or sequential 176 | * @param array $array 177 | * @return bool 178 | */ 179 | protected static function isAssoc($array) 180 | { 181 | if (!is_array($array)) { 182 | return null; 183 | } 184 | return (bool) count(array_filter(array_keys($array), 'is_string')); 185 | } 186 | } -------------------------------------------------------------------------------- /OrientDB/OrientDBSocket.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | /** 12 | * Socket class in OrientDB-PHP library. 13 | * 14 | * @author Anton Terekhov 15 | * @package OrientDB-PHP 16 | * @subpackage Main 17 | */ 18 | class OrientDBSocket 19 | { 20 | /** 21 | * Socket object 22 | * @var resource 23 | */ 24 | private $socket; 25 | 26 | /** 27 | * Default buffer length 28 | * @var int 29 | */ 30 | private $bufferLen; 31 | 32 | /** 33 | * Control debug output 34 | * @var bool 35 | */ 36 | public $debug = false; 37 | 38 | /** 39 | * Create new instance 40 | * @param string $host 41 | * @param int $port 42 | * @param int $timeout 43 | * @param int $bufferLen 44 | * @throws OrientDBConnectException 45 | */ 46 | public function __construct($host, $port, $timeout = 30, $bufferLen = 16384) 47 | { 48 | $this->socket = @fsockopen($host, $port, $errno, $errstr, $timeout); 49 | 50 | if ($this->socket === false) { 51 | throw new OrientDBConnectException("Socket error #{$errno}: {$errstr}"); 52 | } 53 | 54 | stream_set_blocking($this->socket, 1); 55 | stream_set_timeout($this->socket, 1); 56 | 57 | $this->bufferLen = $bufferLen; 58 | } 59 | 60 | /** 61 | * Destructor 62 | */ 63 | public function __destruct() 64 | { 65 | fclose($this->socket); 66 | } 67 | 68 | /** 69 | * Read bytes from socket 70 | * @param int $length Bytes to read 71 | * @return string 72 | */ 73 | public function read($length = null) 74 | { 75 | $data = fread($this->socket, $length === null ? $this->bufferLen : $length); 76 | if ($this->debug) { 77 | OrientDBHelpers::hexDump($data); 78 | } 79 | return $data; 80 | } 81 | 82 | /** 83 | * Send data to socket 84 | * @param string $data 85 | */ 86 | public function send($data) 87 | { 88 | fwrite($this->socket, $data); 89 | if ($this->debug) { 90 | OrientDBHelpers::hexDump($data); 91 | } 92 | } 93 | 94 | /** 95 | * Check if socket still a valid resource 96 | * @return bool 97 | */ 98 | public function isValid() 99 | { 100 | return is_resource($this->socket); 101 | } 102 | } -------------------------------------------------------------------------------- /SpeedTest/OrientDBRecordSpeedBigTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBRecord() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBRecordSpeedBigTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testDecodeRecordBig() 24 | { 25 | $runs = 10; 26 | $fieldsCnt = 10; 27 | 28 | $pwd = dirname(realpath(__FILE__)); 29 | $text = file_get_contents($pwd . '/data/CharterofFundamentalRightsoftheEuropeanUnion.txt'); 30 | 31 | $content = array(); 32 | // Prepare some strings 33 | for ($i = 0; $i < $fieldsCnt; $i++) { 34 | $temp = $text; 35 | for ($j = 0; $j < 5; $j++) { 36 | $pos = rand(0, strlen($text)); 37 | $temp = substr($temp, 0, $pos) . '"' . substr($temp, $pos + 1); 38 | } 39 | $content[] = 'text_' . $i . ':' . OrientDBRecordEncoder::encodeString($temp); 40 | } 41 | // Prepare some booleans 42 | for ($i = 0; $i < $fieldsCnt; $i++) { 43 | $content[] = sprintf('bool_%1$s:%2$s', $i, (rand(0, 1) ? 'true' : 'false')); 44 | } 45 | // Prepare some links 46 | for ($i = 0; $i < $fieldsCnt; $i++) { 47 | $content[] = sprintf('link_%1$s:#%2$s:%3$s', $i, rand(1, 20), rand(0, 500000)); 48 | } 49 | // Prepare some numbers 50 | for ($i = 0; $i < $fieldsCnt; $i++) { 51 | $content[] = sprintf('num_%1$s:%2$ff', $i, rand(-2000000, 2000000)); 52 | } 53 | // Some map 54 | $map = array(); 55 | for ($i = 0; $i < $fieldsCnt; $i++) { 56 | $map[] = sprintf('"very.long.map_%1$05d":%2$d', $i, rand(-2000, 2000)); 57 | } 58 | $content[] = 'map:{' . implode(',', $map) . '}'; 59 | $content = implode(',', $content); 60 | var_dump(strlen($content)); 61 | $timeStart = microtime(true); 62 | for ($i = 0; $i < $runs; $i++) { 63 | $record = new OrientDBRecord(); 64 | $record->content = $content; 65 | $record->parse(); 66 | } 67 | $timeEnd = microtime(true); 68 | $this->assertNotEmpty($record->data); 69 | echo $timeEnd - $timeStart; 70 | } 71 | } -------------------------------------------------------------------------------- /SpeedTest/OrientDBRecordSpeedTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBRecord() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBRecordSpeedTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testDecodeRecordTextValue() 24 | { 25 | $runs = 10; 26 | $pwd = dirname(realpath(__FILE__)); 27 | $text = file_get_contents($pwd . '/data/CharterofFundamentalRightsoftheEuropeanUnion.txt'); 28 | $content = 'text:' . OrientDBRecordEncoder::encodeString($text); 29 | $timeStart = microtime(true); 30 | for ($i = 0; $i < $runs; $i++) { 31 | $record = new OrientDBRecord(); 32 | $record->content = $content; 33 | $record->parse(); 34 | } 35 | $timeEnd = microtime(true); 36 | $this->assertSame($text, $record->data->text); 37 | // echo $timeEnd - $timeStart; 38 | } 39 | 40 | public function testDecodeRecordFieldNames() 41 | { 42 | $runs = 10; 43 | $fieldsCnt = 100; 44 | // Prepare a document 45 | $document = array(); 46 | for ($i = 0; $i < $fieldsCnt; $i++) { 47 | $document[] = sprintf('%1$s_%2$s:"%2$s"', 'fieldname', $i); 48 | } 49 | $document = implode(',', $document); 50 | $timeStart = microtime(true); 51 | for ($i = 0; $i < $runs; $i++) { 52 | $record = new OrientDBRecord(); 53 | $record->content = $document; 54 | $record->parse(); 55 | } 56 | $timeEnd = microtime(true); 57 | $this->assertNotEmpty($record->data); 58 | // echo $timeEnd - $timeStart; 59 | } 60 | 61 | public function testDecodeRecordBooleanValue() 62 | { 63 | $runs = 10; 64 | $fieldCnt = 100; 65 | // Prepare a document 66 | $document = array(); 67 | for ($i = 0; $i < $fieldCnt; $i++) { 68 | $document[] = sprintf('%1$s:%2$s', $i, (rand(0, 1) ? 'true' : 'false')); 69 | } 70 | $document = implode(',', $document); 71 | $timeStart = microtime(true); 72 | for ($i = 0; $i < $runs; $i++) { 73 | $record = new OrientDBRecord(); 74 | $record->content = $document; 75 | $record->parse(); 76 | } 77 | $timeEnd = microtime(true); 78 | $this->assertNotEmpty($record->data); 79 | // echo $timeEnd - $timeStart; 80 | } 81 | 82 | public function testDecodeRecordLinkValue() 83 | { 84 | $runs = 10; 85 | $fieldCnt = 100; 86 | // Prepare a document 87 | $document = array(); 88 | $rid = 100; 89 | for ($i = 0; $i < $fieldCnt; $i++) { 90 | $document[] = sprintf('%1$s:#%1$s:%2$s', $i, $rid--); 91 | } 92 | $document = implode(',', $document); 93 | $timeStart = microtime(true); 94 | for ($i = 0; $i < $runs; $i++) { 95 | $record = new OrientDBRecord(); 96 | $record->content = $document; 97 | $record->parse(); 98 | } 99 | $timeEnd = microtime(true); 100 | $this->assertNotEmpty($record->data); 101 | // echo $timeEnd - $timeStart; 102 | } 103 | 104 | public function testDecodeRecordNumberValue() 105 | { 106 | $runs = 10; 107 | $fieldCnt = 100; 108 | // Prepare a document 109 | $document = array(); 110 | for ($i = 0; $i < $fieldCnt; $i++) { 111 | $document[] = sprintf('%1$s:%2$ff', $i, rand(-2000000, 2000000)); 112 | } 113 | $document = implode(',', $document); 114 | $timeStart = microtime(true); 115 | for ($i = 0; $i < $runs; $i++) { 116 | $record = new OrientDBRecord(); 117 | $record->content = $document; 118 | $record->parse(); 119 | } 120 | $timeEnd = microtime(true); 121 | $this->assertNotEmpty($record->data); 122 | // echo $timeEnd - $timeStart; 123 | } 124 | 125 | public function testDecodeRecordMapValue() 126 | { 127 | $runs = 10; 128 | $fieldCnt = 100; 129 | // Prepare a document 130 | $map = array(); 131 | for ($i = 0; $i < $fieldCnt; $i++) { 132 | $map[] = sprintf('"very.long.fieldname_%1$05d":%2$d', $i, rand(-2000, 2000)); 133 | } 134 | $map = implode(',', $map); 135 | $timeStart = microtime(true); 136 | for ($i = 0; $i < $runs; $i++) { 137 | $record = new OrientDBRecord(); 138 | $record->content = 'map:{' . $map . '}'; 139 | $record->parse(); 140 | } 141 | $timeEnd = microtime(true); 142 | $this->assertNotEmpty($record->data->map); 143 | // echo $timeEnd - $timeStart; 144 | } 145 | 146 | public function testFullResetSpeed() 147 | { 148 | $steps = 10000; 149 | 150 | $new_start = microtime(true); 151 | for ($i = 0; $i < $steps; $i++) { 152 | $record = new OrientDBRecord(); 153 | $record->className = 'TestClass'; 154 | $record->data->field1 = 'Data 1'; 155 | $record->data->field2 = 13121982; 156 | $record->data->field3 = true; 157 | } 158 | $new_end = microtime(true) - $new_start; 159 | 160 | $reset_start = microtime(true); 161 | $record = new OrientDBRecord(); 162 | for ($i = 0; $i < $steps; $i++) { 163 | $record->reset(); 164 | $record->className = 'TestClass'; 165 | $record->data->field1 = 'Data 1'; 166 | $record->data->field2 = 13121982; 167 | $record->data->field3 = true; 168 | } 169 | $reset_end = microtime(true) - $reset_start; 170 | $this->assertLessThanOrEqual($new_end, $reset_end, $new_end . ' !> ' . $reset_end); 171 | } 172 | 173 | public function testResetDataSpeed() 174 | { 175 | $steps = 10000; 176 | 177 | $new_start = microtime(true); 178 | for ($i = 0; $i < $steps; $i++) { 179 | $record = new OrientDBRecord(); 180 | $record->className = 'TestClass'; 181 | $record->data->field1 = 'Data 1'; 182 | $record->data->field2 = 13121982; 183 | $record->data->field3 = true; 184 | } 185 | $new_end = microtime(true) - $new_start; 186 | 187 | $reset_start = microtime(true); 188 | $record = new OrientDBRecord(); 189 | for ($i = 0; $i < $steps; $i++) { 190 | $record->resetData(); 191 | $record->data->field1 = 'Data 1'; 192 | $record->data->field2 = 13121982; 193 | $record->data->field3 = true; 194 | } 195 | $reset_end = microtime(true) - $reset_start; 196 | $this->assertLessThanOrEqual($new_end, $reset_end, $new_end . ' !> ' . $reset_end); 197 | } 198 | } -------------------------------------------------------------------------------- /Tests/OrientDBClassBasicTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * Base class tests in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBClassBasicTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost'); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | /** 35 | * @outputBuffering enabled 36 | * @medium 37 | */ 38 | public function testDebug() 39 | { 40 | $this->assertFalse($this->db->isDebug()); 41 | $this->db->setDebug(true); 42 | $this->db->DBOpen('demo', 'writer', 'writer'); 43 | $record = $this->db->recordLoad('1:1'); 44 | $this->assertTrue($this->db->isDebug()); 45 | $this->db->setDebug(false); 46 | $this->assertFalse($this->db->isDebug()); 47 | $this->expectOutputRegex('/protocol_version/'); 48 | } 49 | 50 | public function testMethodNotImplemented() 51 | { 52 | $this->setExpectedException('OrientDBWrongCommandException'); 53 | /** @noinspection PhpUndefinedMethodInspection */ 54 | $this->db->methodNotExist(); 55 | } 56 | 57 | public function testProtocolVersion() 58 | { 59 | $this->setExpectedException('OrientDBException'); 60 | $this->db->setProtocolVersion(1); 61 | } 62 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandCommitTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * commit() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBCommitTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testCommitOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->commit(); 38 | } 39 | 40 | public function testCommitOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->commit(); 45 | } 46 | 47 | public function testCommitOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->commit(); 51 | } 52 | 53 | public function testCommitOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBException', 'Not implemented'); 57 | $recordPos = $this->db->commit(); 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandConfigGetTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * configGet() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBConfigGetTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testConfigGetOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $value = $this->db->configGet('log.console.level'); 38 | } 39 | 40 | public function testConfigGetOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $value = $this->db->configGet('log.console.level'); 44 | $this->assertInternalType('string', $value); 45 | } 46 | 47 | public function testConfigGetOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $value = $this->db->configGet('log.console.level'); 51 | } 52 | 53 | public function testConfigGetOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBWrongCommandException'); 57 | $value = $this->db->configGet('log.console.level'); 58 | } 59 | 60 | public function testConfigGetWithWrongOption() 61 | { 62 | $this->db->connect('root', $this->root_password); 63 | $value = $this->db->configGet('NONEXISTENT'); 64 | $this->assertEmpty($value); 65 | } 66 | 67 | public function testConfigGetWithWrongOptionCount() 68 | { 69 | $this->db->connect('root', $this->root_password); 70 | $this->setExpectedException('OrientDBWrongParamsException'); 71 | /** @noinspection PhpParamsInspection */ 72 | $value = $this->db->configGet(); 73 | } 74 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandConfigListTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * configList() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBConfigListTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testConfigListOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->configList(); 38 | } 39 | 40 | /** 41 | * @large 42 | */ 43 | public function testConfigListOnConnectedDB() 44 | { 45 | $this->db->connect('root', $this->root_password); 46 | $list = $this->db->configList(); 47 | $this->assertInternalType('array', $list); 48 | } 49 | 50 | public function testConfigListOnNotOpenDB() 51 | { 52 | $this->setExpectedException('OrientDBWrongCommandException'); 53 | $list = $this->db->configList(); 54 | } 55 | 56 | public function testConfigListOnOpenDB() 57 | { 58 | $this->db->DBOpen('demo', 'writer', 'writer'); 59 | $this->setExpectedException('OrientDBWrongCommandException'); 60 | $list = $this->db->configList(); 61 | } 62 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandConfigSetTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * configSet() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBConfigSetTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testConfigSetOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $result = $this->db->configSet('log.console.level', 'info'); 38 | } 39 | 40 | public function testConfigSetOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $result = $this->db->configSet('log.console.level', 'info'); 44 | $this->assertTrue($result); 45 | } 46 | 47 | public function testConfigSetOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $result = $this->db->configSet('log.console.level', 'info'); 51 | } 52 | 53 | public function testConfigSetOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBWrongCommandException'); 57 | $result = $this->db->configSet('log.console.level', 'info'); 58 | } 59 | 60 | public function testConfigSetWithWrongOption() 61 | { 62 | $this->db->connect('root', $this->root_password); 63 | $result = $this->db->configSet('NONEXISTENT', 'info'); 64 | $this->assertTrue($result); 65 | } 66 | 67 | public function testConfigSetWithWrongOptionCount() 68 | { 69 | $this->db->connect('root', $this->root_password); 70 | $this->setExpectedException('OrientDBWrongParamsException'); 71 | /** @noinspection PhpParamsInspection */ 72 | $result = $this->db->configSet(); 73 | } 74 | 75 | public function testConfigSetWithNoValue() 76 | { 77 | $this->db->connect('root', $this->root_password); 78 | $this->setExpectedException('OrientDBWrongParamsException'); 79 | /** @noinspection PhpParamsInspection */ 80 | $result = $this->db->configSet('log.console.level'); 81 | } 82 | 83 | public function testConfigSetWithWrongValue() 84 | { 85 | $this->db->connect('root', $this->root_password); 86 | $this->setExpectedException('OrientDBException'); 87 | $result = $this->db->configSet('log.console.level', 'WRONGVALUE'); 88 | } 89 | 90 | public function testConfigSetWithCorrectValue() 91 | { 92 | $this->db->connect('root', $this->root_password); 93 | $option = 'log.console.level'; 94 | $startvalue = 'info'; 95 | $value = 'warning'; 96 | $result = $this->db->configSet($option, $value); 97 | $dbvalue = $this->db->configGet($option); 98 | $this->AssertSame($value, $dbvalue); 99 | // Return log level to info 100 | $result = $this->db->configSet($option, 'info'); 101 | $returnvalue = $this->db->configGet($option); 102 | $this->AssertSame($startvalue, $returnvalue); 103 | } 104 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandCountTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * count() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBCountTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clustername = 'default'; 25 | 26 | protected function setUp() 27 | { 28 | $this->db = new OrientDB('localhost', 2424); 29 | } 30 | 31 | protected function tearDown() 32 | { 33 | $this->db = null; 34 | } 35 | 36 | public function testCountOnNotConnectedDB() 37 | { 38 | $this->setExpectedException('OrientDBWrongCommandException'); 39 | $result = $this->db->count($this->clustername); 40 | } 41 | 42 | public function testCountOnConnectedDB() 43 | { 44 | $this->db->connect('root', $this->root_password); 45 | $this->setExpectedException('OrientDBWrongCommandException'); 46 | $result = $this->db->count($this->clustername); 47 | } 48 | 49 | public function testCountOnNotOpenDB() 50 | { 51 | $this->setExpectedException('OrientDBWrongCommandException'); 52 | $result = $this->db->count($this->clustername); 53 | } 54 | 55 | public function testCountOnOpenDB() 56 | { 57 | $this->db->DBOpen('demo', 'writer', 'writer'); 58 | $result = $this->db->count($this->clustername); 59 | $this->assertInternalType('integer', $result); 60 | } 61 | 62 | public function testCountWithWrongCluster() 63 | { 64 | $this->db->DBOpen('demo', 'writer', 'writer'); 65 | $this->setExpectedException('OrientDBException'); 66 | $result = $this->db->count('NONEXISTENT'); 67 | } 68 | 69 | public function testCountWithWrongOptionCount() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $this->setExpectedException('OrientDBWrongParamsException'); 73 | /** @noinspection PhpParamsInspection */ 74 | $result = $this->db->count(); 75 | } 76 | 77 | public function testCountWithCorrectValue() 78 | { 79 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 80 | $count = $this->db->count($this->clustername); 81 | // Find out clusterID 82 | $clusterID = 0; 83 | foreach ($clusters['clusters'] as $cluster) { 84 | if ($cluster->name == $this->clustername) { 85 | $clusterID = $cluster->id; 86 | break; 87 | } 88 | } 89 | if ($clusterID == 0) { 90 | $this->markTestSkipped('No cluster ' . $this->clustername . ' found'); 91 | } 92 | // Create temporary record 93 | $id = $this->db->recordCreate($clusterID, 'record'); 94 | $newcount = $this->db->count($this->clustername); 95 | $this->AssertSame($count + 1, $newcount); 96 | // Delete temporary record 97 | $this->db->recordDelete($clusterID . ':' . $id); 98 | $newcount = $this->db->count($this->clustername); 99 | $this->AssertSame($count, $newcount); 100 | } 101 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDBCreateTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * DBCreate() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDBCreateTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $dbName = 'unittest_'; 25 | 26 | protected static $dbSequence = 0; 27 | 28 | protected function setUp() 29 | { 30 | $this->db = new OrientDB('localhost', 2424); 31 | } 32 | 33 | protected function tearDown() 34 | { 35 | if ($this->db->isConnected()) { 36 | try { 37 | $result = $this->db->DBDelete($this->getDBName()); 38 | } 39 | catch (OrientDBException $e) { 40 | } 41 | } 42 | $this->db = null; 43 | } 44 | 45 | protected function sequenceInc() 46 | { 47 | self::$dbSequence++; 48 | // if (self::$dbSequence == 5) { 49 | // echo self::$dbSequence . PHP_EOL; 50 | // debug_print_backtrace(); 51 | // } 52 | } 53 | 54 | protected function getDBName() 55 | { 56 | return $this->dbName . self::$dbSequence; 57 | } 58 | 59 | public function testDBCreateOnNotConnectedDB() 60 | { 61 | $this->sequenceInc(); 62 | $this->setExpectedException('OrientDBWrongCommandException'); 63 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 64 | } 65 | 66 | public function testDBCreateOnConnectedDB() 67 | { 68 | $this->sequenceInc(); 69 | $this->db->connect('root', $this->root_password); 70 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 71 | $this->assertTrue($result); 72 | $result = $this->db->DBDelete($this->getDBName()); 73 | } 74 | 75 | public function testDBCreateOnNotOpenDB() 76 | { 77 | $this->sequenceInc(); 78 | $this->setExpectedException('OrientDBWrongCommandException'); 79 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 80 | } 81 | 82 | public function testDBCreateOnOpenDB() 83 | { 84 | $this->sequenceInc(); 85 | $this->db->DBOpen('demo', 'writer', 'writer'); 86 | $this->setExpectedException('OrientDBWrongCommandException'); 87 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 88 | } 89 | 90 | /** 91 | * In 0.9.2.4 till 1.0rc2-snapshot r3082 it was possible to create memory databases with same name 92 | */ 93 | public function testDBCreateWithExistNameAndSameTypeMemory() 94 | { 95 | $this->sequenceInc(); 96 | $this->db->connect('root', $this->root_password); 97 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 98 | $this->assertTrue($result); 99 | try { 100 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 101 | } 102 | catch (OrientDBException $e) { 103 | $this->db->DBDelete($this->getDBName()); 104 | return; 105 | } 106 | $this->db->DBDelete($this->getDBName()); 107 | $this->fail('Created new DB with existed name and same type: MEMORY'); 108 | } 109 | 110 | public function testDBCreateWithExistNameAndSameTypeLocal() 111 | { 112 | $this->sequenceInc(); 113 | $this->db->connect('root', $this->root_password); 114 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 115 | $this->assertTrue($result); 116 | try { 117 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 118 | } 119 | catch (OrientDBException $e) { 120 | $this->db->DBDelete($this->getDBName()); 121 | return; 122 | } 123 | $this->db->DBDelete($this->getDBName()); 124 | $this->fail('Created new DB with existed name and same type: LOCAL'); 125 | } 126 | 127 | /** 128 | * In 0.9.2.4 till 1.0rc2-snapshot r3110 it was possible to create different databases types with same name 129 | */ 130 | public function testDBCreateWithExistNameAndDifferentTypeOne() 131 | { 132 | $this->sequenceInc(); 133 | $this->db->connect('root', $this->root_password); 134 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 135 | $this->assertTrue($result); 136 | try { 137 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 138 | } 139 | catch (OrientDBException $e) { 140 | $this->db->DBDelete($this->getDBName()); 141 | return; 142 | } 143 | $this->db->DBDelete($this->getDBName()); 144 | $this->fail('Created new DB with existed name'); 145 | } 146 | 147 | /** 148 | * In 0.9.2.4 till 1.0rc2-snapshot r3082 it was possible to create different databases types with same name 149 | */ 150 | public function testDBCreateWithExistNameAndDifferentTypeTwo() 151 | { 152 | $this->sequenceInc(); 153 | $this->db->connect('root', $this->root_password); 154 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 155 | $this->assertTrue($result); 156 | try { 157 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 158 | } 159 | catch (OrientDBException $e) { 160 | $this->db->DBDelete($this->getDBName()); 161 | return; 162 | } 163 | $this->db->DBDelete($this->getDBName()); 164 | $this->fail('Created new DB with existed name'); 165 | } 166 | 167 | public function testDBCreateWithWrongOptionCount() 168 | { 169 | $this->sequenceInc(); 170 | $this->db->connect('root', $this->root_password); 171 | $this->setExpectedException('OrientDBWrongParamsException'); 172 | /** @noinspection PhpParamsInspection */ 173 | $result = $this->db->DBCreate($this->getDBName()); 174 | } 175 | 176 | public function testDBCreateWithTypeMemory() 177 | { 178 | $this->sequenceInc(); 179 | $this->db->connect('root', $this->root_password); 180 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 181 | $this->assertTrue($result); 182 | $this->db->DBDelete($this->getDBName()); 183 | } 184 | 185 | public function testDBCreateWithTypeLocal() 186 | { 187 | $this->sequenceInc(); 188 | $this->db->connect('root', $this->root_password); 189 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 190 | $this->assertTrue($result); 191 | $this->db->DBDelete($this->getDBName()); 192 | } 193 | 194 | public function testDBCreateWithTypeWrong() 195 | { 196 | $this->sequenceInc(); 197 | $this->db->connect('root', $this->root_password); 198 | $this->setExpectedException('OrientDBWrongParamsException'); 199 | $result = $this->db->DBCreate($this->getDBName(), 'INCORRECT'); 200 | } 201 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDBDeleteTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * DBDelete() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDBDeleteTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $dbName = 'unittest_'; 25 | 26 | protected static $dbSequence = 0; 27 | 28 | protected function setUp() 29 | { 30 | $this->db = new OrientDB('localhost', 2424); 31 | } 32 | 33 | protected function tearDown() 34 | { 35 | $this->db = null; 36 | } 37 | 38 | protected function sequenceInc() 39 | { 40 | self::$dbSequence++; 41 | } 42 | 43 | protected function getDBName() 44 | { 45 | return $this->dbName . self::$dbSequence; 46 | } 47 | 48 | public function testDBCreateOnNotConnectedDB() 49 | { 50 | $this->sequenceInc(); 51 | $this->setExpectedException('OrientDBWrongCommandException'); 52 | $result = $this->db->DBDelete($this->getDBName()); 53 | } 54 | 55 | public function testDBDeleteOnConnectedDB() 56 | { 57 | $this->sequenceInc(); 58 | $this->db->connect('root', $this->root_password); 59 | $result = $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 60 | $this->assertTrue($result); 61 | $result = $this->db->DBDelete($this->getDBName()); 62 | $this->assertTrue($result); 63 | } 64 | 65 | public function testDBDeleteOnNotOpenDB() 66 | { 67 | $this->sequenceInc(); 68 | $this->setExpectedException('OrientDBWrongCommandException'); 69 | $result = $this->db->DBDelete($this->getDBName()); 70 | } 71 | 72 | public function testDBDeleteOnOpenDB() 73 | { 74 | $this->sequenceInc(); 75 | $this->db->DBOpen('demo', 'writer', 'writer'); 76 | $this->setExpectedException('OrientDBWrongCommandException'); 77 | $result = $this->db->DBDelete($this->getDBName()); 78 | } 79 | 80 | public function testDBDeleteWithTypeMemory() 81 | { 82 | $this->sequenceInc(); 83 | $this->db->connect('root', $this->root_password); 84 | $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_MEMORY); 85 | $result = $this->db->DBDelete($this->getDBName()); 86 | $this->assertTrue($result); 87 | } 88 | 89 | public function testDBDeleteWithTypeLocal() 90 | { 91 | $this->sequenceInc(); 92 | $this->db->connect('root', $this->root_password); 93 | $this->db->DBCreate($this->getDBName(), OrientDB::DB_TYPE_LOCAL); 94 | $result = $this->db->DBDelete($this->getDBName()); 95 | $this->assertTrue($result); 96 | } 97 | 98 | public function testDBDeleteWithNonExistDB() 99 | { 100 | $this->db->connect('root', $this->root_password); 101 | $this->setExpectedException('OrientDBException', 'com.orientechnologies.orient.core.exception.OStorageException: Database with name \'INVALID\' doesn\'t exits.'); 102 | $result = $this->db->DBDelete('INVALID'); 103 | } 104 | 105 | public function testDBDeleteWithWrongOptionCount() 106 | { 107 | $this->sequenceInc(); 108 | $this->db->connect('root', $this->root_password); 109 | $this->setExpectedException('OrientDBWrongParamsException'); 110 | /** @noinspection PhpParamsInspection */ 111 | $result = $this->db->DBDelete(); 112 | } 113 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDBExistsTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * DBExists() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDBExistsTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDBExistsOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $result = $this->db->DBExists('demo'); 38 | } 39 | 40 | public function testDBExistsOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $result = $this->db->DBExists('demo'); 44 | 45 | $this->assertTrue($result); 46 | 47 | $result = $this->db->DBExists('INVALID'); 48 | $this->assertFalse($result); 49 | } 50 | 51 | public function testDBExistsOnNotOpenDB() 52 | { 53 | $this->setExpectedException('OrientDBWrongCommandException'); 54 | $result = $this->db->DBExists('demo'); 55 | } 56 | 57 | public function testDBExistsOnOpenDB() 58 | { 59 | $this->db->DBOpen('demo', 'writer', 'writer'); 60 | $this->setExpectedException('OrientDBWrongCommandException'); 61 | $result = $this->db->DBExists('demo'); 62 | } 63 | 64 | public function testDBExistsWithWrongOptionCount() 65 | { 66 | $this->db->connect('root', $this->root_password); 67 | $this->setExpectedException('OrientDBWrongParamsException'); 68 | /** @noinspection PhpParamsInspection */ 69 | $result = $this->db->DBExists(); 70 | } 71 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDBListTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * DBList() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDBListTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDBListOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $result = $this->db->DBList(); 38 | } 39 | 40 | public function testDBListOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $result = $this->db->DBList(); 44 | $this->assertInternalType('array', $result); 45 | $this->assertArrayHasKey('demo', $result); 46 | } 47 | 48 | public function testDBListOnNotOpenDB() 49 | { 50 | $this->setExpectedException('OrientDBWrongCommandException'); 51 | $result = $this->db->DBList(); 52 | } 53 | 54 | public function testDBListOnOpenDB() 55 | { 56 | $this->db->DBOpen('demo', 'writer', 'writer'); 57 | $this->setExpectedException('OrientDBWrongCommandException'); 58 | $result = $this->db->DBList(); 59 | } 60 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDBOpenTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * DBOpen() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDBOpenTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDBOpen() 35 | { 36 | $config = $this->db->DBOpen('demo', 'admin', 'admin'); 37 | $this->assertInternalType('array', $config); 38 | $this->assertArrayHasKey('clusters', $config); 39 | $this->assertInternalType('array', $config['clusters']); 40 | $this->assertArrayHasKey('config', $config); 41 | 42 | $cluster = $config['clusters'][0]; 43 | $this->assertInstanceOf('StdClass', $cluster); 44 | $this->assertAttributeInternalType('string', 'name', $cluster); 45 | $this->assertAttributeInternalType('integer', 'id', $cluster); 46 | $this->assertAttributeInternalType('string', 'type', $cluster); 47 | $this->assertAttributeInternalType('integer', 'datasegmentid', $cluster); 48 | } 49 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDataclusterAddTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * dataclusterAdd() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDataclusterAddTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clusterName; 25 | 26 | protected function setUp() 27 | { 28 | $this->db = new OrientDB('localhost', 2424); 29 | $this->clusterName = 'testdataclusteradd_' . rand(10, 99); 30 | } 31 | 32 | protected function tearDown() 33 | { 34 | $this->db = null; 35 | } 36 | 37 | public function testDataclusterAddOnNotConnectedDB() 38 | { 39 | $this->setExpectedException('OrientDBWrongCommandException'); 40 | $result = $this->db->dataclusterAdd('name', OrientDB::DATACLUSTER_TYPE_PHYSICAL); 41 | } 42 | 43 | public function testDataclusterAddOnConnectedDB() 44 | { 45 | $this->db->connect('root', $this->root_password); 46 | $this->setExpectedException('OrientDBWrongCommandException'); 47 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 48 | } 49 | 50 | public function testDataclusterAddOnNotOpenDB() 51 | { 52 | $this->setExpectedException('OrientDBWrongCommandException'); 53 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 54 | } 55 | 56 | public function testDataclusterAddOnOpenDBAdmin() 57 | { 58 | $clusters = $this->db->DBOpen('demo', 'admin', 'admin'); 59 | foreach ($clusters['clusters'] as $cluster) { 60 | if ($cluster->name === $this->clusterName) { 61 | $this->db->dataclusterRemove($cluster->id); 62 | } 63 | } 64 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 65 | $this->assertInternalType('integer', $result); 66 | $this->db->dataclusterRemove($result); 67 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_MEMORY); 68 | $this->assertInternalType('integer', $result); 69 | $this->db->dataclusterRemove($result); 70 | $this->assertInternalType('integer', $result); 71 | } 72 | 73 | public function testDataclusterAddOnOpenDBWriter() 74 | { 75 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 76 | $this->setExpectedException('OrientDBException'); 77 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 78 | } 79 | 80 | public function testDataclusterAddWithWrongParamCount() 81 | { 82 | $this->db->DBOpen('demo', 'writer', 'writer'); 83 | $this->setExpectedException('OrientDBWrongParamsException'); 84 | /** @noinspection PhpParamsInspection */ 85 | $result = $this->db->dataclusterAdd('name'); 86 | } 87 | 88 | public function testDataclusterAddWithWrongParamType() 89 | { 90 | $this->db->DBOpen('demo', 'writer', 'writer'); 91 | $this->setExpectedException('OrientDBWrongParamsException'); 92 | $result = $this->db->dataclusterAdd('name', 'INVALID'); 93 | } 94 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDataclusterCountTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * dataclusterCount() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDataclusterCountTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDataclusteCountOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $result = $this->db->dataclusterCount(array()); 38 | } 39 | 40 | public function testDataclusteCountOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $result = $this->db->dataclusterCount(array()); 45 | } 46 | 47 | public function testDataclusteCountOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $result = $this->db->dataclusterCount(array()); 51 | } 52 | 53 | public function testDataclusteCountOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $result = $this->db->dataclusterCount(array()); 57 | $this->assertInternalType('integer', $result); 58 | $this->AssertSame(0, $result); 59 | } 60 | 61 | public function testDataclusteCountWithWrongParamCount() 62 | { 63 | $this->db->DBOpen('demo', 'writer', 'writer'); 64 | $this->setExpectedException('OrientDBWrongParamsException'); 65 | /** @noinspection PhpParamsInspection */ 66 | $result = $this->db->dataclusterCount(); 67 | } 68 | 69 | public function testDataclusteCountWithWrongParamType() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $this->setExpectedException('OrientDBWrongParamsException'); 73 | $result = $this->db->dataclusterCount('string'); 74 | } 75 | 76 | public function testDataclusteCountOnClusterNotExist() 77 | { 78 | $this->db->DBOpen('demo', 'writer', 'writer'); 79 | $this->setExpectedException('OrientDBException'); 80 | $result = $this->db->dataclusterCount(array(10000)); 81 | } 82 | 83 | public function testDataclusteCountOnManyClusters() 84 | { 85 | $this->db->DBOpen('demo', 'writer', 'writer'); 86 | $result1 = $this->db->dataclusterCount(array(1)); 87 | $result2 = $this->db->dataclusterCount(array(2)); 88 | $result = $this->db->dataclusterCount(array(1, 2)); 89 | $this->AssertSame($result1 + $result2, $result); 90 | } 91 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDataclusterDatarangeTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * dataclusterDatarange() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDataclusterDatarangeTest extends OrientDB_TestCase 22 | { 23 | protected $clusterID = 2; 24 | 25 | protected function setUp() 26 | { 27 | $this->db = new OrientDB('localhost', 2424); 28 | } 29 | 30 | protected function tearDown() 31 | { 32 | $this->db = null; 33 | } 34 | 35 | public function testDataclusterDatarangeOnNotConnectedDB() 36 | { 37 | $this->setExpectedException('OrientDBWrongCommandException'); 38 | $result = $this->db->dataclusterDatarange($this->clusterID); 39 | } 40 | 41 | public function testDataclusterDatarangeOnConnectedDB() 42 | { 43 | $this->db->connect('root', $this->root_password); 44 | $this->setExpectedException('OrientDBWrongCommandException'); 45 | $result = $this->db->dataclusterDatarange($this->clusterID); 46 | } 47 | 48 | public function testDataclusterDatarangeOnNotOpenDB() 49 | { 50 | $this->setExpectedException('OrientDBWrongCommandException'); 51 | $result = $this->db->dataclusterDatarange($this->clusterID); 52 | } 53 | 54 | public function testDataclusterDatarangeOnOpenDB() 55 | { 56 | $this->db->DBOpen('demo', 'writer', 'writer'); 57 | $result = $this->db->dataclusterDatarange($this->clusterID); 58 | $this->assertInternalType('array', $result); 59 | } 60 | 61 | public function testDataclusterDatarangeWithWrongParamCount() 62 | { 63 | $this->db->DBOpen('demo', 'writer', 'writer'); 64 | $this->setExpectedException('OrientDBWrongParamsException'); 65 | /** @noinspection PhpParamsInspection */ 66 | $result = $this->db->dataclusterDatarange(); 67 | } 68 | 69 | public function testDataclusterDatarangeWithWrongParamType() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $this->setExpectedException('OrientDBWrongParamsException'); 73 | $result = $this->db->dataclusterDatarange('string'); 74 | } 75 | 76 | public function testDataclusterDatarangeOnClusterNotExist() 77 | { 78 | $this->db->DBOpen('demo', 'writer', 'writer'); 79 | $this->setExpectedException('OrientDBException'); 80 | $result = $this->db->dataclusterDatarange(10000); 81 | } 82 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDataclusterRemoveTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * dataclusterRemove() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDataclusterRemoveTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clusterName; 25 | 26 | protected function setUp() 27 | { 28 | $this->db = new OrientDB('localhost', 2424); 29 | $this->clusterName = 'testdataclusterremove_' . rand(10, 99); 30 | } 31 | 32 | protected function tearDown() 33 | { 34 | $this->db = null; 35 | } 36 | 37 | public function testDataclusterRemoveOnNotConnectedDB() 38 | { 39 | $this->setExpectedException('OrientDBWrongCommandException'); 40 | $result = $this->db->dataclusterRemove(10000); 41 | } 42 | 43 | public function testDataclusterRemoveOnConnectedDB() 44 | { 45 | $this->db->connect('root', $this->root_password); 46 | $this->setExpectedException('OrientDBWrongCommandException'); 47 | $result = $this->db->dataclusterRemove(10000); 48 | } 49 | 50 | public function testDataclusterRemoveOnNotOpenDB() 51 | { 52 | $this->setExpectedException('OrientDBWrongCommandException'); 53 | /** @noinspection PhpParamsInspection */ 54 | $result = $this->db->dataclusterRemove(); 55 | } 56 | 57 | public function testDataclusterRemoveOnOpenDBAdmin() 58 | { 59 | $clusters = $this->db->DBOpen('demo', 'admin', 'admin'); 60 | foreach ($clusters['clusters'] as $cluster) { 61 | if ($cluster->name === $this->clusterName) { 62 | $this->db->dataclusterRemove($cluster->id); 63 | } 64 | } 65 | $result = $this->db->dataclusterAdd($this->clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 66 | $this->assertInternalType('integer', $result); 67 | $result = $this->db->dataclusterRemove($result); 68 | $this->assertInternalType('boolean', $result); 69 | } 70 | 71 | // As of r3013 Its still possible to remove datacluster with user 'writer'. Fixer in r3030 72 | public function testDataclusterRemoveOnOpenDBWriter() 73 | { 74 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 75 | $this->setExpectedException('OrientDBException'); 76 | $result = $this->db->dataclusterRemove(1); 77 | } 78 | 79 | public function testDataclusterRemoveWithWrongParamCount() 80 | { 81 | $this->db->DBOpen('demo', 'writer', 'writer'); 82 | $this->setExpectedException('OrientDBWrongParamsException'); 83 | /** @noinspection PhpParamsInspection */ 84 | $result = $this->db->dataclusterRemove(); 85 | } 86 | 87 | public function testDataclusterRemoveWithWrongParamType() 88 | { 89 | $this->db->DBOpen('demo', 'writer', 'writer'); 90 | $this->setExpectedException('OrientDBWrongParamsException'); 91 | $result = $this->db->dataclusterRemove('INVALID'); 92 | } 93 | 94 | public function testDataclusterRemoveOnClusterNotExist() 95 | { 96 | $this->db->DBOpen('demo', 'writer', 'writer'); 97 | $this->setExpectedException('OrientDBException'); 98 | $result = $this->db->dataclusterRemove(10000); 99 | } 100 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDatasegmentAddTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * datasegmentAdd() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDatasegmentAddTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDatasegmentAddOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->datasegmentAdd('', ''); 38 | } 39 | 40 | public function testDatasegmentAddOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->datasegmentAdd('', ''); 45 | } 46 | 47 | public function testDatasegmentAddOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->datasegmentAdd('', ''); 51 | } 52 | 53 | public function testDatasegmentAddOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBException', 'Not implemented'); 57 | $recordPos = $this->db->datasegmentAdd('', ''); 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandDatasegmentDeleteTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2012 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * datasegmentDelete() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBDatagesmentDeleteTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testDatasegmentDeleteOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->datasegmentDelete(''); 38 | } 39 | 40 | public function testDatasegmentDeleteOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->datasegmentDelete(''); 45 | } 46 | 47 | public function testDatasegmentDeleteOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->datasegmentDelete(''); 51 | } 52 | 53 | public function testDatasegmentDeleteOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBException', 'Not implemented'); 57 | $recordPos = $this->db->datasegmentDelete(''); 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandQueryTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * query() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBQueryTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testQueryOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->query(''); 38 | } 39 | 40 | public function testQueryOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->query(''); 45 | } 46 | 47 | public function testQueryOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->query(''); 51 | } 52 | 53 | /** 54 | * @medium 55 | */ 56 | public function testQueryOnOpenDB() 57 | { 58 | $this->db->DBOpen('demo', 'writer', 'writer'); 59 | $links = $this->db->query('find references 14:1'); 60 | $this->assertInternalType('array', $links); 61 | $this->assertInstanceOf('OrientDBRecord', array_pop($links)); 62 | } 63 | 64 | public function testQueryWithModeQueryAndFetchPlan() 65 | { 66 | $this->db->DBOpen('demo', 'writer', 'writer'); 67 | $this->setExpectedException('OrientDBWrongParamsException'); 68 | $records = $this->db->query('', '*:-1'); 69 | } 70 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandRecordCreateTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * recordCreate() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBRecordCreateTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clusterID = 2; 25 | 26 | protected $recordContent = 'testrecord:0'; 27 | 28 | protected function setUp() 29 | { 30 | $this->db = new OrientDB('localhost', 2424); 31 | } 32 | 33 | protected function tearDown() 34 | { 35 | $this->db = null; 36 | } 37 | 38 | public function testRecordCreateOnNotConnectedDB() 39 | { 40 | $this->setExpectedException('OrientDBWrongCommandException'); 41 | /** @noinspection PhpParamsInspection */ 42 | $list = $this->db->recordCreate(); 43 | } 44 | 45 | public function testRecordCreateOnConnectedDB() 46 | { 47 | $this->db->connect('root', $this->root_password); 48 | $this->setExpectedException('OrientDBWrongCommandException'); 49 | /** @noinspection PhpParamsInspection */ 50 | $list = $this->db->recordCreate(); 51 | } 52 | 53 | public function testRecordCreateOnNotOpenDB() 54 | { 55 | $this->setExpectedException('OrientDBWrongCommandException'); 56 | /** @noinspection PhpParamsInspection */ 57 | $list = $this->db->recordCreate(); 58 | } 59 | 60 | public function testRecordCreateOnOpenDB() 61 | { 62 | $this->db->DBOpen('demo', 'writer', 'writer'); 63 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 64 | $this->assertInternalType('integer', $recordPos); 65 | $this->db->recordDelete($this->clusterID . ':' . $recordPos); 66 | } 67 | 68 | public function testRecordCreateWithWrongOptionCount() 69 | { 70 | $this->db->DBOpen('demo', 'writer', 'writer'); 71 | $this->setExpectedException('OrientDBWrongParamsException'); 72 | /** @noinspection PhpParamsInspection */ 73 | $record = $this->db->recordCreate($this->clusterID); 74 | } 75 | 76 | public function testRecordCreateWithWrongClusterID() 77 | { 78 | $this->db->DBOpen('demo', 'writer', 'writer'); 79 | $this->setExpectedException('OrientDBException'); 80 | $record = $this->db->recordCreate(1000000, 'INVALID'); 81 | } 82 | 83 | public function testRecordCreateWithTypeBytes() 84 | { 85 | $this->db->DBOpen('demo', 'admin', 'admin'); 86 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent, OrientDB::RECORD_TYPE_BYTES); 87 | $this->assertInternalType('integer', $recordPos); 88 | $this->db->recordDelete($this->clusterID . ':' . $recordPos); 89 | } 90 | 91 | public function testRecordCreateWithTypeDocument() 92 | { 93 | $this->db->DBOpen('demo', 'admin', 'admin'); 94 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent, OrientDB::RECORD_TYPE_DOCUMENT); 95 | $this->assertInternalType('integer', $recordPos); 96 | $this->db->recordDelete($this->clusterID . ':' . $recordPos); 97 | } 98 | 99 | public function testRecordCreateWithTypeFlat() 100 | { 101 | $this->db->DBOpen('demo', 'admin', 'admin'); 102 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent, OrientDB::RECORD_TYPE_FLAT); 103 | $this->assertInternalType('integer', $recordPos); 104 | $this->db->recordDelete($this->clusterID . ':' . $recordPos); 105 | } 106 | 107 | public function testRecordCreateWithWrongType() 108 | { 109 | $this->db->DBOpen('demo', 'admin', 'admin'); 110 | $this->setExpectedException('OrientDBWrongParamsException'); 111 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent, '!'); 112 | } 113 | 114 | public function testRecordCreateWithOrientDBRecordType() 115 | { 116 | $this->db->DBOpen('demo', 'admin', 'admin'); 117 | $record = new OrientDBRecord(); 118 | $record->data->field = 'value'; 119 | $this->assertNull($record->recordPos); 120 | $this->assertNull($record->clusterID); 121 | $this->assertNull($record->recordID); 122 | $this->assertNull($record->version); 123 | 124 | $recordPos = $this->db->recordCreate($this->clusterID, $record); 125 | $this->db->recordDelete($this->clusterID . ':' . $recordPos); 126 | 127 | $this->assertInternalType('integer', $recordPos); 128 | $this->assertSame($recordPos, $record->recordPos); 129 | $this->assertSame($this->clusterID, $record->clusterID); 130 | $this->assertSame($this->clusterID . ':' . $recordPos, $record->recordID); 131 | $this->assertInternalType('integer', $record->version); 132 | } 133 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandRecordDeleteTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * recordDelete() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBRecordDeleteTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clusterID = 2; 25 | 26 | protected $recordContent = 'testrecord:0'; 27 | 28 | protected function setUp() 29 | { 30 | $this->db = new OrientDB('localhost', 2424); 31 | } 32 | 33 | protected function tearDown() 34 | { 35 | $this->db = null; 36 | } 37 | 38 | public function testRecordDeleteOnNotConnectedDB() 39 | { 40 | $this->setExpectedException('OrientDBWrongCommandException'); 41 | /** @noinspection PhpParamsInspection */ 42 | $list = $this->db->recordDelete(); 43 | } 44 | 45 | public function testRecordDeleteOnConnectedDB() 46 | { 47 | $this->db->connect('root', $this->root_password); 48 | $this->setExpectedException('OrientDBWrongCommandException'); 49 | /** @noinspection PhpParamsInspection */ 50 | $list = $this->db->recordDelete(); 51 | } 52 | 53 | public function testRecordDeleteOnNotOpenDB() 54 | { 55 | $this->setExpectedException('OrientDBWrongCommandException'); 56 | /** @noinspection PhpParamsInspection */ 57 | $list = $this->db->recordDelete(); 58 | } 59 | 60 | public function testRecordDeleteOnOpenDB() 61 | { 62 | $this->db->DBOpen('demo', 'writer', 'writer'); 63 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 64 | $this->assertInternalType('integer', $recordPos); 65 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos); 66 | $this->assertTrue($result); 67 | } 68 | 69 | public function testRecordDeleteWithWrongOptionCount() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $this->setExpectedException('OrientDBWrongParamsException'); 73 | /** @noinspection PhpParamsInspection */ 74 | $record = $this->db->recordDelete(); 75 | } 76 | 77 | public function testRecordDeleteWithWrongRecordIDOne() 78 | { 79 | $this->db->DBOpen('demo', 'writer', 'writer'); 80 | $this->setExpectedException('OrientDBWrongParamsException'); 81 | $record = $this->db->recordDelete('INVALID'); 82 | } 83 | 84 | public function testRecordDeleteWithWrongRecordIDTwo() 85 | { 86 | $this->db->DBOpen('demo', 'writer', 'writer'); 87 | $this->setExpectedException('OrientDBWrongParamsException'); 88 | $record = $this->db->recordDelete('INVALID:'); 89 | } 90 | 91 | public function testRecordDeleteWithWrongRecordIDThree() 92 | { 93 | $this->db->DBOpen('demo', 'writer', 'writer'); 94 | $this->setExpectedException('OrientDBWrongParamsException'); 95 | $record = $this->db->recordDelete(':INVALID'); 96 | } 97 | 98 | public function testRecordDeleteWithWrongRecordIDFour() 99 | { 100 | $this->db->DBOpen('demo', 'writer', 'writer'); 101 | $this->setExpectedException('OrientDBWrongParamsException'); 102 | $record = $this->db->recordDelete('1:INVALID'); 103 | } 104 | 105 | public function testRecordDeleteWithRecordPosZero() 106 | { 107 | $dbName = 'RecordZeroTest'; 108 | $clusterName = 'test'; 109 | $recordContent = 'testrecord:0'; 110 | $this->db->connect('root', $this->root_password); 111 | if ($this->db->DBExists($dbName)) { 112 | $this->db->DBDelete($dbName); 113 | } 114 | $result = $this->db->DBCreate($dbName, OrientDB::DB_TYPE_LOCAL); 115 | $this->assertTrue($result); 116 | $this->db->DBOpen($dbName, 'admin', 'admin'); 117 | $clusterID = $this->db->dataclusterAdd($clusterName, OrientDB::DATACLUSTER_TYPE_PHYSICAL); 118 | $this->assertInternalType('integer', $clusterID); 119 | $recordPos = $this->db->recordCreate($clusterID, $recordContent); 120 | $this->AssertSame(0, $recordPos); 121 | $result = $this->db->recordDelete($clusterID . ':' . $recordPos); 122 | $this->assertTrue($result); 123 | $this->db->DBDelete($dbName); 124 | } 125 | 126 | public function testRecordDeleteWithNonExistentRecordID() 127 | { 128 | $this->db->DBOpen('demo', 'writer', 'writer'); 129 | $recPos = $this->db->recordCreate($this->clusterID, 'name:"test"'); 130 | $result = $this->db->recordDelete($this->clusterID . ':' . $recPos); 131 | $this->assertTrue($result); 132 | $result = $this->db->recordDelete($this->clusterID . ':' . $recPos); 133 | } 134 | 135 | public function testRecordDeleteWithPessimisticVersion() 136 | { 137 | $this->db->DBOpen('demo', 'writer', 'writer'); 138 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 139 | $this->assertInternalType('integer', $recordPos); 140 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, -1); 141 | $this->assertTrue($result); 142 | } 143 | 144 | public function testRecordDeleteWithCorrectVersion() 145 | { 146 | $this->db->DBOpen('demo', 'writer', 'writer'); 147 | $record = new OrientDBRecord(); 148 | $record->content = $this->recordContent; 149 | $recordPos = $this->db->recordCreate($this->clusterID, $record); 150 | $this->assertInternalType('integer', $recordPos); 151 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, $record->version); 152 | $this->assertTrue($result); 153 | } 154 | 155 | public function testRecordDeleteWithIncorrectVersionIsLesser() 156 | { 157 | $this->db->DBOpen('demo', 'writer', 'writer'); 158 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 159 | $this->assertInternalType('integer', $recordPos); 160 | $updateVersion = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $this->recordContent); 161 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, 0); 162 | $this->assertFalse($result); 163 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, $updateVersion); 164 | $this->assertTrue($result); 165 | } 166 | 167 | public function testRecordDeleteWithIncorrectVersionIsGreater() 168 | { 169 | $this->db->DBOpen('demo', 'writer', 'writer'); 170 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 171 | $this->assertInternalType('integer', $recordPos); 172 | $updateVersion = $this->db->recordUpdate($this->clusterID . ':' . $recordPos, $this->recordContent); 173 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, $updateVersion + 1); 174 | $this->assertFalse($result); 175 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos, $updateVersion); 176 | $this->assertTrue($result); 177 | } 178 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandRecordLoadTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * recordLoad() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBRecordLoadTest extends OrientDB_TestCase 22 | { 23 | 24 | protected $clusterID = 2; 25 | 26 | protected $addressClusterID; 27 | 28 | protected $recordContent = 'testrecord:0'; 29 | 30 | protected function setUp() 31 | { 32 | $this->db = new OrientDB('localhost', 2424); 33 | } 34 | 35 | protected function tearDown() 36 | { 37 | $this->db = null; 38 | } 39 | 40 | public function testRecordLoadOnNotConnectedDB() 41 | { 42 | $this->setExpectedException('OrientDBWrongCommandException'); 43 | /** @noinspection PhpParamsInspection */ 44 | $list = $this->db->recordLoad(); 45 | } 46 | 47 | public function testRecordLoadOnConnectedDB() 48 | { 49 | $this->db->connect('root', $this->root_password); 50 | $this->setExpectedException('OrientDBWrongCommandException'); 51 | /** @noinspection PhpParamsInspection */ 52 | $list = $this->db->recordLoad(); 53 | } 54 | 55 | public function testRecordLoadOnNotOpenDB() 56 | { 57 | $this->setExpectedException('OrientDBWrongCommandException'); 58 | /** @noinspection PhpParamsInspection */ 59 | $list = $this->db->recordLoad(); 60 | } 61 | 62 | public function testRecordLoadOnOpenDB() 63 | { 64 | $this->db->DBOpen('demo', 'writer', 'writer'); 65 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 66 | $record = $this->db->recordLoad($this->clusterID . ':' . $recordPos); 67 | $this->assertInstanceOf('OrientDBRecord', $record); 68 | $this->AssertSame($this->recordContent, $record->content); 69 | $this->AssertSame($this->clusterID . ':' . $recordPos, $record->recordID); 70 | $this->assertSame($this->clusterID, $record->clusterID); 71 | $this->assertSame($recordPos, $record->recordPos); 72 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos); 73 | $this->assertTrue($result); 74 | } 75 | 76 | public function testRecordLoadWithWrongOptionCount() 77 | { 78 | $this->db->DBOpen('demo', 'writer', 'writer'); 79 | $this->setExpectedException('OrientDBWrongParamsException'); 80 | /** @noinspection PhpParamsInspection */ 81 | $record = $this->db->recordLoad(); 82 | } 83 | 84 | public function testRecordLoadWithWrongRecordIDOne() 85 | { 86 | $this->db->DBOpen('demo', 'writer', 'writer'); 87 | $this->setExpectedException('OrientDBWrongParamsException'); 88 | $record = $this->db->recordLoad('INVALID', ''); 89 | } 90 | 91 | public function testRecordLoadWithWrongRecordIDTwo() 92 | { 93 | $this->db->DBOpen('demo', 'writer', 'writer'); 94 | $this->setExpectedException('OrientDBWrongParamsException'); 95 | $record = $this->db->recordLoad('INVALID:', ''); 96 | } 97 | 98 | public function testRecordLoadWithWrongRecordIDThree() 99 | { 100 | $this->db->DBOpen('demo', 'writer', 'writer'); 101 | $this->setExpectedException('OrientDBWrongParamsException'); 102 | $record = $this->db->recordLoad(':INVALID', ''); 103 | } 104 | 105 | public function testRecordLoadWithWrongRecordIDFour() 106 | { 107 | $this->db->DBOpen('demo', 'writer', 'writer'); 108 | $this->setExpectedException('OrientDBWrongParamsException'); 109 | $record = $this->db->recordLoad('1:INVALID', ''); 110 | } 111 | 112 | public function testRecordLoadWithRecordPosZero() 113 | { 114 | $recordPos = 0; 115 | $this->db->DBOpen('demo', 'writer', 'writer'); 116 | $record = $this->db->recordLoad($this->clusterID . ':' . $recordPos, ''); 117 | $this->assertInstanceOf('OrientDBRecord', $record); 118 | } 119 | 120 | public function testRecordLoadWithDeletedRecordId() 121 | { 122 | $this->db->DBOpen('demo', 'writer', 'writer'); 123 | $recordPos = $this->db->recordCreate($this->clusterID, $this->recordContent); 124 | $this->assertInternalType('integer', $recordPos); 125 | $result = $this->db->recordDelete($this->clusterID . ':' . $recordPos); 126 | $this->assertTrue($result); 127 | $record = $this->db->recordLoad($this->clusterID . ':' . $recordPos); 128 | $this->assertFalse($record); 129 | } 130 | 131 | public function testRecordLoadWithOutOfBoundsRecordId() 132 | { 133 | $this->db->DBOpen('demo', 'writer', 'writer'); 134 | $record = $this->db->recordLoad($this->clusterID . ':' . 1000000, ''); 135 | $this->assertFalse($record); 136 | } 137 | 138 | public function testRecordLoadWithFetchPlan() 139 | { 140 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 141 | // Load record Address:100 142 | $this->addressClusterID = $this->getClusterIdByClusterName($info, 'address'); 143 | $record = $this->db->recordLoad($this->addressClusterID . ':' . 100, '*:-1'); 144 | $this->assertInstanceOf('OrientDBRecord', $record); 145 | } 146 | 147 | public function testRecordLoadWithFetchPlanAnyOneItem() 148 | { 149 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 150 | // Load record Address:100 151 | $this->addressClusterID = $this->getClusterIdByClusterName($info, 'address'); 152 | $this->assertEmpty($this->db->cachedRecords); 153 | $record = $this->db->recordLoad($this->addressClusterID . ':' . 100, '*:1'); 154 | $this->assertInstanceOf('OrientDBRecord', $record); 155 | $this->AssertSame(1, count($this->db->cachedRecords)); 156 | $record = $this->db->recordLoad($this->addressClusterID . ':' . 100, '*:0'); 157 | $this->assertEmpty($this->db->cachedRecords); 158 | } 159 | 160 | public function testRecordLoadWithFetchPlanAnyManyItems() 161 | { 162 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 163 | // Load record Address:100 164 | $this->addressClusterID = $this->getClusterIdByClusterName($info, 'address'); 165 | $this->assertEmpty($this->db->cachedRecords); 166 | $record = $this->db->recordLoad($this->addressClusterID . ':' . 100, '*:2'); 167 | $this->assertInstanceOf('OrientDBRecord', $record); 168 | $this->AssertSame(2, count($this->db->cachedRecords)); 169 | $record = $this->db->recordLoad($this->addressClusterID . ':' . 100, '*:0'); 170 | $this->assertEmpty($this->db->cachedRecords); 171 | } 172 | 173 | public function testRecordLoadWithFetchPlanFieldOneItem() 174 | { 175 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 176 | foreach ($info['clusters'] as $cluster) { 177 | if ($cluster->name === 'city') { 178 | $cityClusterID = $cluster->id; 179 | } 180 | } 181 | // Load record City:1 182 | $this->assertEmpty($this->db->cachedRecords); 183 | $record = $this->db->recordLoad($cityClusterID . ':' . 1, 'country:1'); 184 | $this->assertInstanceOf('OrientDBRecord', $record); 185 | $this->AssertSame(1, count($this->db->cachedRecords)); 186 | $record = $this->db->recordLoad($cityClusterID . ':' . 1, '*:0'); 187 | $this->assertEmpty($this->db->cachedRecords); 188 | } 189 | 190 | public function testRecordLoadWithFetchPlanInvalidFieldOneItem() 191 | { 192 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 193 | foreach ($info['clusters'] as $cluster) { 194 | if ($cluster->name === 'address') { 195 | $addressClusterID = $cluster->id; 196 | } 197 | } 198 | // Load record Address:1. Note, that Address hasn't field country 199 | $this->assertEmpty($this->db->cachedRecords); 200 | $record = $this->db->recordLoad($addressClusterID . ':' . 1, 'country:1'); 201 | $this->assertInstanceOf('OrientDBRecord', $record); 202 | $this->AssertEmpty($this->db->cachedRecords); 203 | } 204 | 205 | public function testRecordLoadWithIncorrectPlan() 206 | { 207 | $this->db->DBOpen('demo', 'writer', 'writer'); 208 | $recordsToFetch = array('1:0', '1:1', '1:2', '2:0', '2:1', '2:2', '3:0', '3:1', '3:2', '4:0', '4:1', '4:2'); 209 | $failedCnt = 0; 210 | $failedRIDs = array(); 211 | 212 | foreach ($recordsToFetch as $RID) { 213 | try { 214 | $record = $this->db->recordLoad($RID, 'INCORRECT'); 215 | } 216 | catch (OrientDBException $e) { 217 | $failedCnt++; 218 | $failedRIDs[] = $RID; 219 | } 220 | } 221 | if ($failedCnt != count($recordsToFetch)) { 222 | $passedRIDs = array_diff($recordsToFetch, $failedRIDs); 223 | $this->fail('Invalid fetchplan exception not thrown on: ' . join(', ', $passedRIDs)); 224 | } 225 | $this->assertSame(count($recordsToFetch), $failedCnt); 226 | } 227 | 228 | public function testRecordLoadFromZeroClusterPosZero() 229 | { 230 | $rid = '0:0'; 231 | $this->db->DBOpen('demo', 'writer', 'writer'); 232 | $record = $this->db->recordLoad($rid); 233 | $this->assertInstanceOf('OrientDBRecord', $record); 234 | $this->assertSame($rid, $record->recordID); 235 | $this->assertNotEmpty($record->data); 236 | } 237 | 238 | /** 239 | * @medium 240 | */ 241 | public function testRecordLoadFromZeroClusterPosOne() 242 | { 243 | $rid = '0:1'; 244 | $this->db->DBOpen('demo', 'writer', 'writer'); 245 | $record = $this->db->recordLoad($rid); 246 | $this->assertInstanceOf('OrientDBRecord', $record); 247 | $this->assertSame($rid, $record->recordID); 248 | } 249 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandSelectAsyncTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * selectAsync() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBSelectAsyncTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testSelectAsyncOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->selectAsync(''); 38 | } 39 | 40 | public function testSelectAsyncOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->selectAsync(''); 45 | } 46 | 47 | public function testSelectAsyncOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->selectAsync(''); 51 | } 52 | 53 | public function testSelectAsyncOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $records = $this->db->selectAsync('select * from city limit 7'); 57 | $this->assertInternalType('array', $records); 58 | $this->assertInstanceOf('OrientDBRecord', array_pop($records)); 59 | } 60 | 61 | public function testSelectAsyncWithWrongOptionCount() 62 | { 63 | $this->db->DBOpen('demo', 'writer', 'writer'); 64 | $this->setExpectedException('OrientDBWrongParamsException'); 65 | /** @noinspection PhpParamsInspection */ 66 | $record = $this->db->selectAsync(); 67 | } 68 | 69 | public function testSelectAsyncWithFetchPlan() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $records = $this->db->selectAsync('select from city limit 20', '*:-1'); 73 | $this->assertInternalType('array', $records); 74 | $this->assertInstanceOf('OrientDBRecord', array_pop($records)); 75 | } 76 | 77 | public function testSelectAsyncWithNoRecords() 78 | { 79 | $this->db->DBOpen('demo', 'writer', 'writer'); 80 | $records = $this->db->selectAsync('select from 11:4 where any() traverse(0,10) (address.city = "Rome")'); 81 | $this->assertFalse($records); 82 | } 83 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandSelectTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * select() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBSelectTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testSelectOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $list = $this->db->select(''); 38 | } 39 | 40 | public function testSelectOnConnectedDB() 41 | { 42 | $this->db->connect('root', $this->root_password); 43 | $this->setExpectedException('OrientDBWrongCommandException'); 44 | $list = $this->db->select(''); 45 | } 46 | 47 | public function testSelectOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $list = $this->db->select(''); 51 | } 52 | 53 | public function testSelectOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $records = $this->db->select('select * from city limit 7'); 57 | $this->assertInternalType('array', $records); 58 | $this->assertInstanceOf('OrientDBRecord', array_pop($records)); 59 | } 60 | 61 | public function testSelectWithWrongOptionCount() 62 | { 63 | $this->db->DBOpen('demo', 'writer', 'writer'); 64 | $this->setExpectedException('OrientDBWrongParamsException'); 65 | /** @noinspection PhpParamsInspection */ 66 | $record = $this->db->select(); 67 | } 68 | 69 | public function testSelectWithFetchPlan() 70 | { 71 | $this->db->DBOpen('demo', 'writer', 'writer'); 72 | $this->assertEmpty($this->db->cachedRecords); 73 | $this->setExpectedException('OrientDBWrongParamsException'); 74 | $records = $this->db->select('select from city limit 1', '*:1'); 75 | } 76 | 77 | public function testSelectWithNoRecordsSync() 78 | { 79 | $this->db->DBOpen('demo', 'writer', 'writer'); 80 | $records = $this->db->select('select from 11:4 where any() traverse(0,10) (address.city = "Rome")'); 81 | $this->assertFalse($records); 82 | } 83 | 84 | public function testFieldsSelect() 85 | { 86 | $this->db->DBOpen('demo', 'writer', 'writer'); 87 | $records = $this->db->select('SELECT name FROM City WHERE name = "Rome" LIMIT 1'); 88 | $this->assertInternalType('array', $records); 89 | $record = reset($records); 90 | $this->assertSame($record->data->name, 'Rome'); 91 | $this->assertSame(-2, $record->clusterID); 92 | $this->assertSame(1, $record->recordPos); 93 | $this->assertNull($record->recordID); 94 | } 95 | 96 | public function testFieldsSelectWithRid() 97 | { 98 | $info = $this->db->DBOpen('demo', 'writer', 'writer'); 99 | $city_cluster_id = $this->getClusterIdByClusterName($info, 'city'); 100 | $record = $this->db->select('SELECT name, @rid FROM City WHERE name = "Rome" LIMIT 1'); 101 | $record = reset($record); 102 | $this->assertSame('Rome', $record->data->name); 103 | $this->assertSame('#' . $city_cluster_id . ':0', (string) $record->data->rid); 104 | $this->assertSame(-2, $record->clusterID); 105 | $this->assertSame(1, $record->recordPos); 106 | $this->assertNull($record->recordID); 107 | } 108 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandShutdownTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * shutdown() test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBShutdownTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testShutdownOnNotConnectedDB() 35 | { 36 | $this->setExpectedException('OrientDBWrongCommandException'); 37 | $value = $this->db->shutdown('', ''); 38 | } 39 | 40 | public function testshutdownOnConnectedDB() 41 | { 42 | $this->markTestSkipped('Skipping shutdown'); 43 | $this->db->connect('root', $this->root_password); 44 | $this->db->shutdown('root', $this->root_password); 45 | } 46 | 47 | public function testshutdownOnNotOpenDB() 48 | { 49 | $this->setExpectedException('OrientDBWrongCommandException'); 50 | $value = $this->db->shutdown('', ''); 51 | } 52 | 53 | public function testshutdownOnOpenDB() 54 | { 55 | $this->db->DBOpen('demo', 'writer', 'writer'); 56 | $this->setExpectedException('OrientDBWrongCommandException'); 57 | $value = $this->db->shutdown('', ''); 58 | } 59 | 60 | public function testshutdownWithWrongPermissions() 61 | { 62 | $this->db->connect('root', $this->root_password); 63 | $this->setExpectedException('OrientDBException'); 64 | $value = $this->db->shutdown('root', ''); 65 | } 66 | 67 | public function testshutdownWithWrongOptionCount() 68 | { 69 | $this->db->connect('root', $this->root_password); 70 | $this->setExpectedException('OrientDBWrongParamsException'); 71 | /** @noinspection PhpParamsInspection */ 72 | $value = $this->db->shutdown(); 73 | } 74 | } -------------------------------------------------------------------------------- /Tests/OrientDBCommandsBasicTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | require_once 'OrientDB_TestCase.php'; 13 | 14 | /** 15 | * connect(), DBOpen() and related properties test in OrientDB tests 16 | * 17 | * @author Anton Terekhov 18 | * @package OrientDB-PHP 19 | * @subpackage Tests 20 | */ 21 | class OrientDBCommandsBasicTest extends OrientDB_TestCase 22 | { 23 | 24 | protected function setUp() 25 | { 26 | $this->db = new OrientDB('localhost', 2424); 27 | } 28 | 29 | protected function tearDown() 30 | { 31 | $this->db = null; 32 | } 33 | 34 | public function testConnectWithCorrectUserPassword() 35 | { 36 | $this->assertFalse($this->db->isConnected()); 37 | $this->assertTrue($this->db->connect('root', $this->root_password)); 38 | $this->assertTrue($this->db->isConnected()); 39 | $this->assertFalse($this->db->isDBOpen()); 40 | } 41 | 42 | public function testConnectWithIncorrectUserPassword() 43 | { 44 | $this->setExpectedException('OrientDBException'); 45 | $this->db->connect('toor', $this->root_password); 46 | } 47 | 48 | public function testConnectWithNotEnougnParams() 49 | { 50 | $this->setExpectedException('OrientDBWrongParamsException'); 51 | /** @noinspection PhpParamsInspection */ 52 | $this->db->connect('root'); 53 | } 54 | 55 | public function testConnectOnAlreadyConnectedDB() 56 | { 57 | $this->assertFalse($this->db->isConnected()); 58 | $result = $this->db->connect('root', $this->root_password); 59 | $this->assertTrue($this->db->connect('root', $this->root_password)); 60 | $this->assertTrue($this->db->isConnected()); 61 | $this->assertFalse($this->db->isDBOpen()); 62 | } 63 | 64 | public function testOpenDBWithCorrectUserPassword() 65 | { 66 | $this->assertFalse($this->db->isDBOpen()); 67 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 68 | $this->assertInternalType('array', $clusters); 69 | $this->assertFalse($this->db->isConnected()); 70 | $this->assertTrue($this->db->isDBOpen()); 71 | } 72 | 73 | public function testOpenDBWithIncorrectUserPassword() 74 | { 75 | $this->setExpectedException('OrientDBException'); 76 | $clusters = $this->db->DBOpen('demo', 'writer', 'INCORRECT'); 77 | } 78 | 79 | public function testOpenDBWithNonExistentDB() 80 | { 81 | $this->setExpectedException('OrientDBException'); 82 | $clusters = $this->db->DBOpen('NONEXISTENT', 'writer', 'writer'); 83 | } 84 | 85 | public function testOpenDBWithNotEnoughParams() 86 | { 87 | $this->setExpectedException('OrientDBWrongParamsException'); 88 | /** @noinspection PhpParamsInspection */ 89 | $clusters = $this->db->DBOpen('demo'); 90 | } 91 | 92 | public function testConnectOnAlreadyOpenedDB() 93 | { 94 | $this->assertFalse($this->db->isConnected()); 95 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 96 | $this->assertTrue($this->db->isDBOpen()); 97 | $this->assertTrue($this->db->connect('root', $this->root_password)); 98 | $this->assertTrue($this->db->isConnected()); 99 | } 100 | 101 | public function testOpenDBOnAlreadyConnectedDB() 102 | { 103 | $this->db->connect('root', $this->root_password); 104 | $clusters = $this->db->DBOpen('demo', 'writer', 'writer'); 105 | $this->assertTrue($this->db->isDBOpen()); 106 | $this->assertInternalType('array', $clusters); 107 | $this->assertTrue($this->db->isConnected()); 108 | } 109 | 110 | public function testOpenDBOnAlreadyOpenedDB() 111 | { 112 | $this->assertFalse($this->db->isDBOpen()); 113 | $clusters1 = $this->db->DBOpen('demo', 'writer', 'writer'); 114 | $clusters2 = $this->db->DBOpen('demo', 'admin', 'admin'); 115 | $this->assertInternalType('array', $clusters2); 116 | $this->assertTrue($this->db->isDBOpen()); 117 | $this->assertFalse($this->db->isConnected()); 118 | } 119 | 120 | public function testCloseDBOnNotConnectedDB() 121 | { 122 | $this->setExpectedException('OrientDBWrongCommandException'); 123 | $this->db->DBClose(); 124 | } 125 | 126 | public function testCloseDBOnNotOpenedDB() 127 | { 128 | $this->setExpectedException('OrientDBWrongCommandException'); 129 | $this->db->DBClose(); 130 | } 131 | 132 | public function testCloseDBOnConnectedDB() 133 | { 134 | $this->db->connect('root', $this->root_password); 135 | $this->setExpectedException('OrientDBWrongCommandException'); 136 | $this->db->DBClose(); 137 | } 138 | 139 | public function testCloseDBOnOpenedDB() 140 | { 141 | $this->db->DBOpen('demo', 'writer', 'writer'); 142 | $this->assertTrue($this->db->isDBOpen()); 143 | $this->db->DBClose(); 144 | $this->assertFalse($this->db->isDBOpen()); 145 | $this->assertEmpty($this->db->socket); 146 | } 147 | 148 | public function testAnyCommnandAfterDBClose() 149 | { 150 | $this->db->DBOpen('demo', 'writer', 'writer'); 151 | $this->db->DBClose(); 152 | $this->setExpectedException('OrientDBWrongCommandException'); 153 | $this->db->DBOpen('demo', 'writer', 'writer'); 154 | } 155 | 156 | /** 157 | * @large 158 | */ 159 | public function testDBOpenCount() 160 | { 161 | $i = 0; 162 | $tries = 1000; 163 | try { 164 | while ($i < $tries) { 165 | $clusters = $this->db->DBOpen('demo', 'admin', 'admin'); 166 | $i++; 167 | $this->db = new OrientDB('localhost', 2424); 168 | } 169 | } 170 | catch (OrientDBException $e) { 171 | // echo 'Tries: ' . $i . PHP_EOL; 172 | } 173 | if (isset($e)) { 174 | $message = 'New connections is not accepted, reason: ' . $e->getMessage(); 175 | } else { 176 | $message = ''; 177 | } 178 | $this->AssertSame($tries, $i, $message); 179 | } 180 | } -------------------------------------------------------------------------------- /Tests/OrientDBConnectTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * Socket test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBConnectTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testNewFailedConnection() 24 | { 25 | $this->setExpectedException('OrientDBConnectException'); 26 | $db = new OrientDB('localhost', 2000); 27 | } 28 | 29 | public function testNewSucsessfullConnection() 30 | { 31 | $db = new OrientDB('localhost', 2424); 32 | $this->assertInstanceOf('OrientDB', $db); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Tests/OrientDBConvertComplementTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBCommandAbstract::convertComplement() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBConvertComplementTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testConvertComplementIntx32NegativeBound() 24 | { 25 | $int = (int) -2147483648; 26 | 27 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($int)); 28 | } 29 | 30 | public function testConvertComplementIntx32PositiveBound() 31 | { 32 | $int = (int) 2147483647; 33 | 34 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($int)); 35 | } 36 | 37 | public function testConvertComplementIntZero() 38 | { 39 | $int = (int) 0; 40 | 41 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($int)); 42 | } 43 | 44 | public function testConvertComplementIntNegativeBoundViaUnpack() 45 | { 46 | $int = (int) -2147483648; 47 | 48 | $packed = pack('N', $int); 49 | $unpacked = unpack('N', $packed); 50 | $unpacked = reset($unpacked); 51 | 52 | if (PHP_INT_SIZE == 8) { 53 | $this->assertNotSame($int, $unpacked); 54 | } 55 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($unpacked)); 56 | } 57 | 58 | public function testConvertComplementIntMinusOneViaUnpack() 59 | { 60 | $int = (int) -1; 61 | 62 | $packed = pack('N', $int); 63 | $unpacked = unpack('N', $packed); 64 | $unpacked = reset($unpacked); 65 | 66 | if (PHP_INT_SIZE == 8) { 67 | $this->assertNotSame($int, $unpacked); 68 | } 69 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($unpacked)); 70 | } 71 | 72 | public function testConvertComplementIntPositiveBoundViaUnpack() 73 | { 74 | $int = (int) 2147483647; 75 | 76 | $packed = pack('N', $int); 77 | $unpacked = unpack('N', $packed); 78 | $unpacked = reset($unpacked); 79 | 80 | $this->assertSame($int, $unpacked); 81 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($unpacked)); 82 | } 83 | 84 | public function testConvertComplementIntZeroViaUnpack() 85 | { 86 | $int = (int) 0; 87 | 88 | $packed = pack('N', $int); 89 | $unpacked = unpack('N', $packed); 90 | $unpacked = reset($unpacked); 91 | 92 | $this->assertSame($int, $unpacked); 93 | $this->assertSame($int, OrientDBCommandAbstract::convertComplementInt($unpacked)); 94 | } 95 | 96 | public function testConvertComplementShortNegativeBound() 97 | { 98 | $short = -32768; 99 | 100 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($short)); 101 | } 102 | 103 | public function testConvertComplementShortPositiveBound() 104 | { 105 | $short = 32767; 106 | 107 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($short)); 108 | } 109 | 110 | public function testConvertComplementShortZero() 111 | { 112 | $short = 0; 113 | 114 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($short)); 115 | } 116 | 117 | public function testConvertComplementShortNegativeBoundViaUnpack() 118 | { 119 | $short = -32768; 120 | 121 | $packed = pack('n', $short); 122 | $unpacked = unpack('n', $packed); 123 | $unpacked = reset($unpacked); 124 | 125 | $this->assertNotSame($short, $unpacked); 126 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($unpacked)); 127 | } 128 | 129 | public function testConvertComplementShortMinusOneViaUnpack() 130 | { 131 | $short = -1; 132 | 133 | $packed = pack('n', $short); 134 | $unpacked = unpack('n', $packed); 135 | $unpacked = reset($unpacked); 136 | 137 | $this->assertNotSame($short, $unpacked); 138 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($unpacked)); 139 | } 140 | 141 | public function testConvertComplementShortPositiveBoundViaUnpack() 142 | { 143 | $short = 32767; 144 | 145 | $packed = pack('n', $short); 146 | $unpacked = unpack('n', $packed); 147 | $unpacked = reset($unpacked); 148 | 149 | $this->assertSame($short, $unpacked); 150 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($unpacked)); 151 | } 152 | 153 | public function testConvertComplementShortZeroViaUnpack() 154 | { 155 | $short = 0; 156 | 157 | $packed = pack('n', $short); 158 | $unpacked = unpack('n', $packed); 159 | $unpacked = reset($unpacked); 160 | 161 | $this->assertSame($short, $unpacked); 162 | $this->assertSame($short, OrientDBCommandAbstract::convertComplementShort($unpacked)); 163 | } 164 | } -------------------------------------------------------------------------------- /Tests/OrientDBDataTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBData() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBDataTest extends PHPUnit_Framework_TestCase 21 | { 22 | public function testConstructWithOrientDBRecord() 23 | { 24 | $record = $this->getMock('OrientDBRecord'); 25 | $data = new OrientDBData($record); 26 | $this->assertInstanceOf('OrientDBData', $data); 27 | } 28 | 29 | public function testConstructWithOther() 30 | { 31 | $this->setExpectedException('OrientDBException'); 32 | $data = new OrientDBData(true); 33 | } 34 | // @TODO: add more unittests 35 | } -------------------------------------------------------------------------------- /Tests/OrientDBI64Test.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBCommandAbstract::I64() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBI64Test extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testUnpackI64Zero() 24 | { 25 | $result = 0; 26 | $hi = 0x00000000; 27 | $low = 0x00000000; 28 | 29 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 30 | } 31 | 32 | public function testUnpackI64One() 33 | { 34 | $result = 1; 35 | $hi = 0x00000000; 36 | $low = 0x00000001; 37 | 38 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 39 | } 40 | 41 | public function testUnpackI64NegativeOne() 42 | { 43 | $result = -1; 44 | $hi = 0xFFFFFFFF; 45 | $low = 0xFFFFFFFF; 46 | 47 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 48 | } 49 | 50 | public function testUnpackI64NegativeTwo() 51 | { 52 | $result = -2; 53 | $hi = 0xFFFFFFFF; 54 | $low = 0xFFFFFFFE; 55 | 56 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 57 | } 58 | 59 | public function testUnpackI64AboveNegative32Bound() 60 | { 61 | $result = -2147483647; 62 | $hi = 0xFFFFFFFF; 63 | $low = 0x80000001; 64 | 65 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 66 | } 67 | 68 | public function testUnpackI64Negative32Bound() 69 | { 70 | $result = -2147483648; 71 | $hi = 0xFFFFFFFF; 72 | $low = 0x80000000; 73 | 74 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 75 | } 76 | 77 | public function testUnpackI64BelowNegative32Bound() 78 | { 79 | if (PHP_INT_SIZE == 8) { 80 | $result = -2147483649; 81 | } else { 82 | $result = '-2147483649'; 83 | } 84 | $hi = 0xFFFFFFFF; 85 | $low = 0x7FFFFFFF; 86 | 87 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 88 | } 89 | 90 | public function testUnpackI64AbovePositive32Bound() 91 | { 92 | $result = 2147483648; 93 | $hi = 0x00000000; 94 | $low = 0x80000000; 95 | 96 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 97 | } 98 | 99 | public function testUnpackI64Positive32Bound() 100 | { 101 | $result = 2147483647; 102 | $hi = 0x00000000; 103 | $low = 0x7FFFFFFF; 104 | 105 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 106 | } 107 | 108 | public function testUnpackI64BelowPositive32Bound() 109 | { 110 | $result = 2147483646; 111 | $hi = 0x00000000; 112 | $low = 0x7FFFFFFE; 113 | 114 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 115 | } 116 | 117 | public function testUnpackI64NegativeBound() 118 | { 119 | if (PHP_INT_SIZE == 8) { 120 | $result = (int) -9223372036854775808; 121 | } else { 122 | $result = '-9223372036854775808'; 123 | } 124 | 125 | $hi = 0x80000000; 126 | $low = 0x00000000; 127 | 128 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 129 | } 130 | 131 | public function testUnpackI64AboveNegativeBound() 132 | { 133 | if (PHP_INT_SIZE == 8) { 134 | $result = -9223372036854775807; 135 | } else { 136 | $result = '-9223372036854775807'; 137 | } 138 | 139 | $hi = 0x80000000; 140 | $low = 0x00000001; 141 | 142 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 143 | } 144 | 145 | public function testUnpackI64PositiveBound() 146 | { 147 | if (PHP_INT_SIZE == 8) { 148 | $result = 9223372036854775807; 149 | } else { 150 | $result = '9223372036854775807'; 151 | } 152 | 153 | $hi = 0x7FFFFFFF; 154 | $low = 0xFFFFFFFF; 155 | 156 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 157 | } 158 | 159 | public function testUnpackI64BelowPositiveBound() 160 | { 161 | if (PHP_INT_SIZE == 8) { 162 | $result = 9223372036854775806; 163 | } else { 164 | $result = '9223372036854775806'; 165 | } 166 | 167 | $hi = 0x7FFFFFFF; 168 | $low = 0xFFFFFFFE; 169 | 170 | $this->assertSame($result, OrientDBCommandAbstract::unpackI64($hi, $low)); 171 | } 172 | } -------------------------------------------------------------------------------- /Tests/OrientDBRecordEncoderTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBRecordEncoder test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBRecordEncoderTest extends PHPUnit_Framework_TestCase 21 | { 22 | public function testIsAssocWithNonArray() 23 | { 24 | $method = new ReflectionMethod('OrientDBRecordEncoder', 'isAssoc'); 25 | $method->setAccessible(true); 26 | 27 | $this->assertNull($method->invoke(null, null)); 28 | } 29 | 30 | public function testIsAssocWithSequentialArray() 31 | { 32 | $method = new ReflectionMethod('OrientDBRecordEncoder', 'isAssoc'); 33 | $method->setAccessible(true); 34 | 35 | $array = range(1, 10); 36 | 37 | $this->assertFalse($method->invoke(null, $array)); 38 | } 39 | 40 | public function testIsAssocWithAssocArray() 41 | { 42 | $method = new ReflectionMethod('OrientDBRecordEncoder', 'isAssoc'); 43 | $method->setAccessible(true); 44 | 45 | $array = array(1 => 1, 'two' => 2); 46 | 47 | $this->assertTrue($method->invoke(null, $array)); 48 | } 49 | 50 | public function testIsAssocWithPseudoAssocArray() 51 | { 52 | $method = new ReflectionMethod('OrientDBRecordEncoder', 'isAssoc'); 53 | $method->setAccessible(true); 54 | 55 | $array = array(1 => 1, '2' => 2); 56 | 57 | $this->assertFalse($method->invoke(null, $array)); 58 | } 59 | } -------------------------------------------------------------------------------- /Tests/OrientDBTypeDateTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBTypeDate() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBTypeDateTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testOrientDBTypeDateValueWithT() 24 | { 25 | $value = time(); 26 | $date = new OrientDBTypeDate($value . 't'); 27 | 28 | $this->assertSame($value . 't', (string) $date); 29 | $this->assertSame($value . 't', $date->getValue()); 30 | $this->assertSame($value, $date->getTime()); 31 | } 32 | 33 | public function testOrientDBTypeDateValueWithoutT() 34 | { 35 | $value = time(); 36 | $date = new OrientDBTypeDate($value); 37 | 38 | $this->assertSame($value . 't', (string) $date); 39 | $this->assertSame($value . 't', $date->getValue()); 40 | $this->assertSame($value, $date->getTime()); 41 | } 42 | 43 | public function testOrientDBTypeDateValueInvalid() 44 | { 45 | $value = ''; 46 | $date = new OrientDBTypeDate($value); 47 | 48 | $this->assertSame('', (string) $date); 49 | $this->assertNull($date->getValue()); 50 | $this->assertNull($date->getTime()); 51 | } 52 | } -------------------------------------------------------------------------------- /Tests/OrientDBTypeLinkTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 6 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 7 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 8 | * @package OrientDB-PHP 9 | */ 10 | 11 | require_once 'OrientDB/OrientDB.php'; 12 | 13 | /** 14 | * OrientDBTypeLink() test in OrientDB tests 15 | * 16 | * @author Anton Terekhov 17 | * @package OrientDB-PHP 18 | * @subpackage Tests 19 | */ 20 | class OrientDBTypeLinkTest extends PHPUnit_Framework_TestCase 21 | { 22 | 23 | public function testOrientDBTypeLinkValueWithHash() 24 | { 25 | $clusterID = 10; 26 | $recordPos = 0; 27 | $value = $clusterID . ':' . $recordPos; 28 | $link = new OrientDBTypeLink('#' . $value); 29 | 30 | $this->assertSame('#' . $value, (string) $link); 31 | $this->assertSame('#' . $value, $link->getHash()); 32 | $this->assertSame($value, $link->get()); 33 | $this->assertSame($clusterID, $link->clusterID); 34 | $this->assertSame($recordPos, $link->recordPos); 35 | } 36 | 37 | public function testOrientDBTypeLinkValueWithoutHash() 38 | { 39 | $clusterID = 10; 40 | $recordPos = 0; 41 | $value = $clusterID . ':' . $recordPos; 42 | $link = new OrientDBTypeLink($value); 43 | 44 | $this->assertSame('#' . $value, (string) $link); 45 | $this->assertSame('#' . $value, $link->getHash()); 46 | $this->assertSame($value, $link->get()); 47 | $this->assertSame($clusterID, $link->clusterID); 48 | $this->assertSame($recordPos, $link->recordPos); 49 | } 50 | 51 | public function testOrientDBTypeLinkValueInvalid() 52 | { 53 | $value = 10; 54 | $link = new OrientDBTypeLink($value); 55 | 56 | $this->assertSame('', (string) $link); 57 | $this->assertNull($link->get()); 58 | $this->assertSame('#', $link->getHash()); 59 | $this->assertNull($link->clusterID); 60 | $this->assertNull($link->recordPos); 61 | } 62 | 63 | public function testOrientDBTypeLinkValuesCorrect() 64 | { 65 | $clusterID = 100; 66 | $recordPos = 0; 67 | $value = $clusterID . ':' . $recordPos; 68 | 69 | $link = new OrientDBTypeLink($clusterID, $recordPos); 70 | 71 | $this->assertSame('#' . $value, (string) $link); 72 | $this->assertSame('#' . $value, $link->getHash()); 73 | $this->assertSame($value, $link->get()); 74 | $this->assertSame($clusterID, $link->clusterID); 75 | $this->assertSame($recordPos, $link->recordPos); 76 | } 77 | 78 | public function testOrientDBTypeLinkValuesInvalidOne() 79 | { 80 | $clusterID = 'one'; 81 | $recordPos = 0; 82 | 83 | $link = new OrientDBTypeLink($clusterID, $recordPos); 84 | 85 | $this->assertSame('', (string) $link); 86 | $this->assertSame('#', $link->getHash()); 87 | $this->assertNull($link->get()); 88 | $this->assertNull($link->clusterID); 89 | $this->assertNull($link->recordPos); 90 | } 91 | 92 | public function testOrientDBTypeLinkValuesInvalidTwo() 93 | { 94 | $clusterID = 101; 95 | $recordPos = ''; 96 | 97 | $link = new OrientDBTypeLink($clusterID, $recordPos); 98 | 99 | $this->assertSame('', (string) $link); 100 | $this->assertSame('#', $link->getHash()); 101 | $this->assertNull($link->get()); 102 | $this->assertNull($link->clusterID); 103 | $this->assertNull($link->recordPos); 104 | } 105 | 106 | public function testOrientDBTypeLinkValuesCorrectLong() 107 | { 108 | $clusterID = 100; 109 | if (PHP_INT_SIZE == 8) { 110 | $recordPos = 9223372036854775807; 111 | } else { 112 | $recordPos = '9223372036854775807'; 113 | } 114 | $value = $clusterID . ':' . $recordPos; 115 | 116 | $link = new OrientDBTypeLink($clusterID, $recordPos); 117 | 118 | $this->assertSame('#' . $value, (string) $link); 119 | $this->assertSame('#' . $value, $link->getHash()); 120 | $this->assertSame($value, $link->get()); 121 | $this->assertSame($clusterID, $link->clusterID); 122 | $this->assertSame($recordPos, $link->recordPos); 123 | } 124 | 125 | public function testOrientDBTypeLinkValuesincorrectLong() 126 | { 127 | $clusterID = 100; 128 | $recordPos = '9223372036854775807 '; 129 | $value = $clusterID . ':' . $recordPos; 130 | 131 | $link = new OrientDBTypeLink($clusterID, $recordPos); 132 | 133 | $this->assertSame('', (string) $link); 134 | $this->assertSame('#', $link->getHash()); 135 | $this->assertNull($link->get()); 136 | $this->assertNull($link->clusterID); 137 | $this->assertNull($link->recordPos); 138 | } 139 | } -------------------------------------------------------------------------------- /Tests/OrientDB_TestCase.php: -------------------------------------------------------------------------------- 1 | 4 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2013 5 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 6 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 7 | * @package OrientDB-PHP 8 | */ 9 | 10 | /** 11 | * Main class in OrientDB tests 12 | * 13 | * @author Anton Terekhov 14 | * @package OrientDB-PHP 15 | * @subpackage Tests 16 | */ 17 | abstract class OrientDB_TestCase extends PHPUnit_Framework_TestCase 18 | { 19 | 20 | /** 21 | * Correct password for root can be found at 22 | * config/orientdb-server-config.xml in your OrientDB installation 23 | * @var string 24 | */ 25 | protected $root_password = '60F3D52B4374C22B19F2EA5AD2812A45FB1C34985C2532D60E267AADB9E3E130'; 26 | 27 | /** 28 | * Instance of OrientDB-PHP 29 | * @var OrientDB 30 | */ 31 | protected $db; 32 | 33 | protected function getClusterIdByClusterName($info, $cluster_name) 34 | { 35 | foreach ($info['clusters'] as $cluster_info) { 36 | if ($cluster_info->name === $cluster_name) { 37 | return $cluster_info->id; 38 | } 39 | } 40 | return false; 41 | } 42 | 43 | protected function getClusterNameByClusterId($info, $cluster_id) 44 | { 45 | foreach ($info['clusters'] as $cluster_info) { 46 | if ($cluster_info->id === $cluster_id) { 47 | return $cluster_info->name; 48 | } 49 | } 50 | return false; 51 | } 52 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "orientdb-php/orientdb-php", 3 | "type": "library", 4 | "keywords": ["orientdb","graphdb"], 5 | "homepage": "https://github.com/AntonTerekhov/OrientDB-PHP", 6 | "description": "A plain PHP driver to OrientDB graph database using its binary protocol.", 7 | "license": "BSD-3-Clause", 8 | "authors": [ 9 | { 10 | "name": "Anton Terekhov", 11 | "email": "anton.a.terekhov@gmail.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.0" 16 | }, 17 | "autoload": { 18 | "files": ["OrientDB/OrientDB.php"] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011-2012 7 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 8 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 9 | * @package OrientDB-PHP 10 | * @subpackage Example 11 | */ 12 | 13 | $rootPassword = '60F3D52B4374C22B19F2EA5AD2812A45FB1C34985C2532D60E267AADB9E3E130'; 14 | $dbName = 'example'; 15 | $clusterName = 'default'; 16 | 17 | require_once 'OrientDB/OrientDB.php'; 18 | 19 | echo 'Connecting to server...' . PHP_EOL; 20 | try { 21 | $db = new OrientDB('localhost', 2424); 22 | } 23 | catch (Exception $e) { 24 | die('Failed to connect: ' . $e->getMessage()); 25 | } 26 | 27 | echo 'Connecting as root...' . PHP_EOL; 28 | try { 29 | $connect = $db->connect('root', $rootPassword); 30 | } 31 | catch (OrientDBException $e) { 32 | die('Failed to connect(): ' . $e->getMessage()); 33 | } 34 | 35 | try { 36 | $exists = $db->DBExists($dbName); 37 | } 38 | catch (OrientDBException $e) { 39 | die('Failed to execute DBExists(): ' . $e->getMessage()); 40 | } 41 | if ($exists) { 42 | echo 'Deleting DB (in case of previous run failed)...' . PHP_EOL; 43 | try { 44 | $db->DBDelete($dbName); 45 | } 46 | catch (OrientDBException $e) { 47 | die('Failed to DBDelete(): ' . $e->getMessage()); 48 | } 49 | } 50 | 51 | echo 'Creating DB...' . PHP_EOL; 52 | 53 | try { 54 | $result = $db->DBCreate($dbName, OrientDB::DB_TYPE_LOCAL); 55 | 56 | echo 'Opening DB...' . PHP_EOL; 57 | $clusters = $db->DBOpen($dbName, 'writer', 'writer'); 58 | foreach ($clusters['clusters'] as $cluster) { 59 | if ($cluster->name === $clusterName) { 60 | $clusterID = $cluster->id; 61 | } 62 | } 63 | 64 | echo 'Create record...' . PHP_EOL; 65 | $record = new OrientDBRecord(); 66 | $record->data->FirstName = 'Bruce'; 67 | $record->data->LastName = 'Wayne'; 68 | $record->data->appearance = 1938; 69 | 70 | $recordPos = $db->recordCreate($clusterID, $record); 71 | 72 | echo 'Created record position: ' . $recordPos . PHP_EOL . PHP_EOL; 73 | 74 | echo 'Load record...' . PHP_EOL; 75 | 76 | $recordLoaded = $db->recordLoad($clusterID . ':' . $recordPos); 77 | echo 'Load record result: ' . $recordLoaded . PHP_EOL . PHP_EOL; 78 | 79 | printf('%1$s %2$s first appears in %3$d' . PHP_EOL . PHP_EOL, $recordLoaded->data->FirstName, $recordLoaded->data->LastName, $recordLoaded->data->appearance); 80 | 81 | echo 'Update record...' . PHP_EOL; 82 | 83 | $recordLoaded->data->appearance = 1939; 84 | $version = $db->recordUpdate($recordLoaded->recordID, $recordLoaded); 85 | 86 | echo 'Updated record version: ' . $version . PHP_EOL . PHP_EOL; 87 | 88 | $recordReLoaded = $db->recordLoad($clusterID . ':' . $recordPos); 89 | 90 | printf('No, %1$s %2$s first appears in %3$d!' . PHP_EOL . PHP_EOL, $recordReLoaded->data->FirstName, $recordReLoaded->data->LastName, $recordReLoaded->data->appearance); 91 | 92 | echo 'Delete record with old version (' . $recordLoaded->version . ') ...' . PHP_EOL; 93 | 94 | $result = $db->recordDelete($recordLoaded->recordID, $recordLoaded->version); 95 | 96 | echo 'Delete record with correct version (' . $version . ') ...' . PHP_EOL; 97 | 98 | $result = $db->recordDelete($recordLoaded->recordID, $version); 99 | echo 'Delete record result: ' . var_export($result, true) . PHP_EOL . PHP_EOL; 100 | 101 | echo 'Retry load record...' . PHP_EOL; 102 | 103 | $recordLoaded2 = $db->recordLoad($recordLoaded->recordID); 104 | echo 'Load record result: ' . var_export($recordLoaded2, true) . PHP_EOL . PHP_EOL; 105 | } 106 | catch (OrientDBException $e) { 107 | echo $e->getMessage() . PHP_EOL; 108 | } 109 | 110 | echo 'Deleting DB...' . PHP_EOL; 111 | try { 112 | $db->DBDelete($dbName); 113 | } 114 | catch (OrientDBException $e) { 115 | die('Failed to DBDelete(): ' . $e->getMessage() . PHP_EOL); 116 | } -------------------------------------------------------------------------------- /gremlin.php: -------------------------------------------------------------------------------- 1 | DBOpen('tinkerpop', 'admin', 'admin'); 8 | $result = $db->selectGremlin('g.v1.outE', '*:-1'); 9 | 10 | var_dump(count($result)); 11 | 12 | var_dump(count($db->cachedRecords)); -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | -------------------------------------------------------------------------------- /speedtest.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright Anton Terekhov, NetMonsters LLC, 2011 9 | * @license https://github.com/AntonTerekhov/OrientDB-PHP/blob/master/LICENSE 10 | * @link https://github.com/AntonTerekhov/OrientDB-PHP 11 | * @package OrientDB-PHP 12 | * @subpackage Example 13 | */ 14 | 15 | require 'OrientDB/OrientDB.php'; 16 | 17 | $records = 100000; 18 | 19 | $time_c = microtime(true); 20 | echo 'Socket' . PHP_EOL; 21 | $db = new OrientDB('localhost', 2424); 22 | echo microtime(true) - $time_c . PHP_EOL; 23 | 24 | $time_c = microtime(true); 25 | echo 'OpenDB DB' . PHP_EOL; 26 | $clusters = $db->DBOpen('speedtest', 'admin', 'admin'); 27 | echo microtime(true) - $time_c . PHP_EOL; 28 | 29 | $time_c = microtime(true); 30 | $result = array(); 31 | for ($i = 0; $i < $records; $i++) { 32 | try { 33 | $position = $db->recordCreate(2, 'Name:"Bill",Id:' . $i); 34 | $result[] = $position; 35 | } 36 | catch (OrientDBException $e) { 37 | echo $e->getMessage() . PHP_EOL; 38 | } 39 | } 40 | echo 'Done create ' . $records . PHP_EOL; 41 | echo microtime(true) - $time_c . PHP_EOL; 42 | 43 | $callback = function (&$item, $key) { 44 | $item = '#2:' . $item; 45 | }; 46 | 47 | $time_c = microtime(true); 48 | $linked_records = array(); 49 | for ($i = 0; $i < $records / 100; $i++) { 50 | $rand_record = $result[array_rand($result)]; 51 | $keys = array_rand($result, $records / 100); 52 | $links = array(); 53 | foreach ($keys as $key) { 54 | $links[] = $result[$key]; 55 | } 56 | array_walk($links, $callback); 57 | try { 58 | $db->recordUpdate('2:' . $rand_record, 'Name:"Bill",Id:' . $i . ', map:[' . implode(',', $links) . ']'); 59 | $linked_records[] = $rand_record; 60 | } 61 | catch (OrientDBException $e) { 62 | echo $e->getMessage() . PHP_EOL; 63 | } 64 | } 65 | echo 'Done update ' . $records . PHP_EOL; 66 | echo microtime(true) - $time_c . PHP_EOL; 67 | 68 | $time_c = microtime(true); 69 | $record = $db->recordLoad('2:' . $result[count($result) - 1], '*:-1'); 70 | echo 'Done get last' . PHP_EOL; 71 | echo microtime(true) - $time_c . PHP_EOL; 72 | 73 | $time_c = microtime(true); 74 | $db->setDebug(true); 75 | try { 76 | $record = $db->recordLoad('2:' . $linked_records[count($linked_records) - 1], '*:10'); 77 | } 78 | catch (OrientDBException $e) { 79 | echo $e->getMessage() . PHP_EOL; 80 | } 81 | $db->setDebug(false); 82 | echo 'Done get linked' . PHP_EOL; 83 | echo microtime(true) - $time_c . PHP_EOL; 84 | var_dump($record->content); 85 | 86 | $time_c = microtime(true); 87 | for ($i = 0; $i < count($result); $i++) { 88 | try { 89 | $db->recordDelete('2:' . $result[$i]); 90 | } 91 | catch (OrientDBException $e) { 92 | echo $e->getMessage() . PHP_EOL; 93 | } 94 | } 95 | echo 'Done delete ' . $records . PHP_EOL; 96 | echo microtime(true) - $time_c . PHP_EOL; 97 | 98 | 99 | 100 | --------------------------------------------------------------------------------