/**
  * @param ClassMetadata $class
  * @param array         $entityData
  * @param string        $revType
  */
 private function saveRevisionEntityData($class, $entityData, $revType)
 {
     $params = array($this->getRevisionId(), $revType);
     $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR);
     foreach ($class->fieldNames as $field) {
         $params[] = $entityData[$field];
         $types[] = $class->fieldMappings[$field]['type'];
     }
     foreach ($class->associationMappings as $field => $assoc) {
         if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             if ($entityData[$field] !== null) {
                 $relatedId = $this->uow->getEntityIdentifier($entityData[$field]);
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
                 if ($entityData[$field] === null) {
                     $params[] = null;
                     $types[] = \PDO::PARAM_STR;
                 } else {
                     $params[] = $relatedId[$targetClass->fieldNames[$targetColumn]];
                     $types[] = $targetClass->getTypeOfColumn($targetColumn);
                 }
             }
         }
     }
     $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types);
 }
 public function insertRows(PersistentCollection $coll)
 {
     $insertDiff = $coll->getInsertDiff();
     $sql = $this->_getInsertRowSQL($coll);
     foreach ($insertDiff as $element) {
         $this->_conn->executeUpdate($sql, $this->_getInsertRowSQLParameters($coll, $element));
     }
 }
    /**
     * Performs an UPDATE statement for an entity on a specific table.
     * The UPDATE can optionally be versioned, which requires the entity to have a version field.
     *
     * @param object $entity The entity object being updated.
     * @param string $quotedTableName The quoted name of the table to apply the UPDATE on.
     * @param array $updateData The map of columns to update (column => value).
     * @param boolean $versioned Whether the UPDATE should be versioned.
     */
    protected final function _updateTable($entity, $quotedTableName, array $updateData, $versioned = false)
    {
        $set = $params = $types = array();

        foreach ($updateData as $columnName => $value) {
            if (isset($this->_class->fieldNames[$columnName])) {
                $set[] = $this->_class->getQuotedColumnName($this->_class->fieldNames[$columnName], $this->_platform) . ' = ?';
            } else {
                $set[] = $columnName . ' = ?';
            }
            $params[] = $value;
            $types[] = $this->_columnTypes[$columnName];
        }

        $where = array();
        $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
        foreach ($this->_class->identifier as $idField) {
            if (isset($this->_class->associationMappings[$idField])) {
                $targetMapping = $this->_em->getClassMetadata($this->_class->associationMappings[$idField]['targetEntity']);
                $where[] = $this->_class->associationMappings[$idField]['joinColumns'][0]['name'];
                $params[] = $id[$idField];
                $types[] = $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
            } else {
                $where[] = $this->_class->getQuotedColumnName($idField, $this->_platform);
                $params[] = $id[$idField];
                $types[] = $this->_class->fieldMappings[$idField]['type'];
            }
        }

        if ($versioned) {
            $versionField = $this->_class->versionField;
            $versionFieldType = $this->_class->fieldMappings[$versionField]['type'];
            $versionColumn = $this->_class->getQuotedColumnName($versionField, $this->_platform);
            if ($versionFieldType == Type::INTEGER) {
                $set[] = $versionColumn . ' = ' . $versionColumn . ' + 1';
            } else if ($versionFieldType == Type::DATETIME) {
                $set[] = $versionColumn . ' = CURRENT_TIMESTAMP';
            }
            $where[] = $versionColumn;
            $params[] = $this->_class->reflFields[$versionField]->getValue($entity);
            $types[] = $this->_class->fieldMappings[$versionField]['type'];
        }

        $sql = "UPDATE $quotedTableName SET " . implode(', ', $set)
            . ' WHERE ' . implode(' = ? AND ', $where) . ' = ?';

        $result = $this->_conn->executeUpdate($sql, $params, $types);

        if ($this->_class->isVersioned && ! $result) {
            throw OptimisticLockException::lockFailed($entity);
        }
    }
 /**
  * @author "Lionel Lecaque, <*****@*****.**>"
  */
 public function destroyTaoDatabase()
 {
     $platform = $this->connection->getDatabasePlatform();
     $queries = $this->schema->toDropSql($platform);
     foreach ($queries as $query) {
         $this->connection->executeUpdate($query);
     }
     //drop sequence
     $sm = $this->getSchemaManager();
     $sequences = $sm->listSequences();
     foreach ($sequences as $name) {
         $sm->dropSequence($name);
     }
 }