Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
14 / 14 |
MySQLCreateStatementFactory | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
14 / 14 |
buildSequencer | |
100.00% |
1 / 1 |
1 | |
100.00% |
6 / 6 |
|||
buildCreateTable | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
buildCreateDelimitTable | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
<?php | |
declare(strict_types = 1); | |
namespace Siesta\Driver\MySQL; | |
use Siesta\Database\CreateStatementFactory; | |
use Siesta\Model\Entity; | |
use Siesta\Util\File; | |
/** | |
* @author Gregor Müller | |
*/ | |
class MySQLCreateStatementFactory implements CreateStatementFactory | |
{ | |
const CREATE_SEQUENCE_TABLE = "CREATE TABLE IF NOT EXISTS `%s` (`TECHNICALNAME` VARCHAR(120) NOT NULL PRIMARY KEY, `SEQ` INT ) ENGINE = InnoDB;"; | |
const DROP_SEQUENCER_SP = "DROP PROCEDURE IF EXISTS %s"; | |
/** | |
* @return string[] | |
*/ | |
public function buildSequencer() : array | |
{ | |
$sequencerFile = new File(__DIR__ . "/Sequencer/Sequencer.sql"); | |
$statementList = []; | |
$statementList[] = sprintf(self::CREATE_SEQUENCE_TABLE, CreateStatementFactory::SEQUENCER_TABLE_NAME); | |
$statementList[] = sprintf(self::DROP_SEQUENCER_SP, CreateStatementFactory::SEQUENCER_SP_NAME); | |
$statementList[] = preg_replace('/\s\s+/', ' ', $sequencerFile->getContents()); | |
return $statementList; | |
} | |
/** | |
* @param Entity $entity | |
* | |
* @return string[] | |
*/ | |
public function buildCreateTable(Entity $entity) : array | |
{ | |
$statementList = []; | |
$tableBuilder = new MySQLTableCreator($entity); | |
$statementList = array_merge($tableBuilder->buildCreateTable(), $statementList); | |
return $statementList; | |
} | |
/** | |
* @param Entity $entity | |
* | |
* @return string[] | |
*/ | |
public function buildCreateDelimitTable(Entity $entity) : array | |
{ | |
$statementList = []; | |
$tableBuilder = new MySQLTableCreator($entity); | |
$statementList[] = $tableBuilder->buildCreateDelimitTable(); | |
return $statementList; | |
} | |
} |