/** * Crea un nuovo record con un model * assegnando a quest'ultimo un <b>ID</b> ed una <b>versione</b> * * @param Model $model * @return Model nuovo model [senza id e versione] * @throws GraphException * @internal param $ <b>Model</b> $model */ public function create(Model $model) { Graphene::getInstance()->startStat('storageCreate'); Log::debug('calling storage driver for create'); $model->setLazy(false); if (!$model->isValid()) { Graphene::getInstance()->stopStat('storageCreate'); throw new GraphException('Model, ' . $model->getModelName() . ' is not valid for storage: ' . $model->getLastTestErrors(), ExceptionsCodes::BEAN_STORAGE_CORRUPTED_BEAN, 400); } $model->setVersion(1); $model->setId(uniqid($model->getIdPrefix())); $created = $this->driver->create($this->serializeForDb($model)); if (($retb = ModelFactory::createByDbSerialization($created)) == null) { Graphene::getInstance()->stopStat('storageCreate'); throw new GraphException('Error when create, Stored ' . $model->getModelName() . ' is corrupt', ExceptionsCodes::BEAN_STORAGE_CORRUPTED_BEAN, 400); } else { Graphene::getInstance()->stopStat('storageCreate'); return $retb[0]; } }