function getIdGenerator(IdentifiableOrmEntity $entity) { Assert::isTrue($this->type->isGenerated()); $orm = call_user_func(array(get_class($entity), 'orm')); $identifier = $orm->getLogicalSchema()->getIdentifier(); Assert::isTrue($identifier->getType() == $this, 'plz pass the corresponding entity'); $fields = $identifier->getFields(); // *Important* // We use dirty hack to obtain RdbmsDao because IOrmEntityAccessor // does not provide (and should not provide!) an API to access the database // because it is a limited interface to an abstract storage. // In most cases this type would be used for databases so we can use this hack here. $dao = call_user_func(array(get_class($entity), 'dao')); Assert::isTrue($dao instanceof RdbmsDao); $db = $dao->getDB(); $generator = $db->getGenerator($orm->getPhysicalSchema()->getTable(), reset($fields), $this->type); return new PropertyValueGenerator($this, $generator); }
function getTypeRepresentation(DBType $dbType) { $type = $dbType->getId(); if ($size = $dbType->getSize()) { $type .= '(' . $size . ')'; } if ($precision = $dbType->getPrecision()) { $type .= '(' . $precision; if ($scale = $dbType->getScale()) { $type .= ',' . $scale; } $type .= ')'; } if (!$dbType->isNullable()) { $type .= ' NOT NULL'; } if ($dbType->isGenerated()) { $type .= ' GENERATED'; } return $type; }