Changeset 1897
- Timestamp:
- 10/24/08 12:22:57 (2 months ago)
- Files:
-
- framework/trunk/src/main/php/net/stubbles/rdbms/persistence/annotation/stubDBColumnAnnotation.php (modified) (2 diffs)
- framework/trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilder.php (modified) (4 diffs)
- framework/trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumn.php (modified) (3 diffs)
- framework/trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php (modified) (3 diffs)
- framework/trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumnTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
framework/trunk/src/main/php/net/stubbles/rdbms/persistence/annotation/stubDBColumnAnnotation.php
r1763 r1897 6 6 * @package stubbles 7 7 * @subpackage rdbms_persistence_annotation 8 * @version $Id$ 8 9 */ 9 10 stubClassLoader::load('net::stubbles::reflection::annotations::stubAnnotation', … … 135 136 136 137 /** 138 * set whether the column is unique or not 139 * 140 * @param bool $isUnique 141 */ 142 public function setIsUnique($isUnique) 143 { 144 $this->dbTableColumn->setIsUnique($this->castToBool($isUnique)); 145 } 146 147 /** 137 148 * set the name of the setter method 138 149 * framework/trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilder.php
r1895 r1897 6 6 * @package stubbles 7 7 * @subpackage rdbms_querybuilder 8 * @version $Id$ 8 9 */ 9 10 stubClassLoader::load('net::stubbles::rdbms::querybuilder::stubDatabaseQueryBuilder'); … … 215 216 $primaryKeys = array(); 216 217 $keys = array(); 218 $uniques = array(); 217 219 $counter = 0; 218 220 foreach ($columns as $column) { … … 265 267 } elseif ($column->isKey() === true) { 266 268 $keys[] = $column->getName(); 269 } elseif ($column->isUnique() === true) { 270 $uniques[] = $column->getName(); 267 271 } 268 272 } … … 280 284 } 281 285 286 if (count($uniques) > 0) { 287 foreach ($uniques as $unique) { 288 $query .= ",\n UNIQUE (`" . $unique . '`)'; 289 } 290 } 291 282 292 $query .= "\n)"; 283 293 if ($tableDescription->hasType() === true) { framework/trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumn.php
r1763 r1897 6 6 * @package stubbles 7 7 * @subpackage rdbms_querybuilder 8 * @version $Id$ 8 9 */ 9 10 /** … … 88 89 protected $isKey = false; 89 90 /** 91 * switch whether column is unique or not 92 * 93 * @var bool 94 */ 95 protected $isUnique = false; 96 /** 90 97 * the name of the setter method to use for restoring the value from database 91 98 * … … 352 359 { 353 360 return (false == $this->isPrimaryKey && true == $this->isKey); 361 } 362 363 /** 364 * set whether the column is unique or not 365 * 366 * @param bool $isUnique 367 */ 368 public function setIsUnique($isUnique) 369 { 370 $this->isUnique = $isUnique; 371 } 372 373 /** 374 * check whether the column is unique or not 375 * 376 * @return bool 377 */ 378 public function isUnique() 379 { 380 return (false == $this->isPrimaryKey && true == $this->isUnique); 354 381 } 355 382 framework/trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php
r1895 r1897 6 6 * @package stubbles 7 7 * @subpackage rdbms_querybuilder_test 8 * @version $Id$ 8 9 */ 9 10 stubClassLoader::load('net::stubbles::rdbms::querybuilder::stubDatabaseMySQLQueryBuilder'); … … 245 246 $column4->setName('column4'); 246 247 $column4->setType('DATETIME'); 248 $column4->setIsUnique(true); 247 249 $tableDescription->addColumn($column4); 248 250 … … 277 279 " column8 YEAR DEFAULT NULL,\n" . 278 280 " PRIMARY KEY (`column2`),\n" . 279 " KEY (`column3`)\n" . 281 " KEY (`column3`),\n" . 282 " UNIQUE (`column4`)\n" . 280 283 ") ENGINE = InnoDB", 281 284 $this->mySqlQueryBuilder->createTable($tableDescription)); framework/trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumnTestCase.php
r1763 r1897 6 6 * @package stubbles 7 7 * @subpackage rdbms_querybuilder_test 8 * @version $Id$ 8 9 */ 9 10 stubClassLoader::load('net::stubbles::rdbms::querybuilder::stubDatabaseTableColumn'); … … 214 215 215 216 /** 217 * check that setting and getting the isUnique property works as expected 218 * 219 * @test 220 */ 221 public function isUnique() 222 { 223 $this->assertFalse($this->tableColumn->isUnique()); 224 $this->tableColumn->setIsUnique(true); 225 $this->assertTrue($this->tableColumn->isUnique()); 226 $this->tableColumn->setIsPrimaryKey(true); 227 $this->assertFalse($this->tableColumn->isUnique()); 228 $this->tableColumn->setIsUnique(false); 229 $this->assertFalse($this->tableColumn->isUnique()); 230 } 231 232 /** 216 233 * check that setting and getting the setter method works as expected 217 234 *
