public function save($datas, array $identifier = array(), $shardingKey = null, &$affectedRows = null)
    {
        $datasWithoutIdentifiers=array();
        foreach ($datas as $key => $value) {
            if (isset($this->mapping[$key])) {
                $identifier[$key] = $value;
            } else {
                $datasWithoutIdentifiers[$key]=$value;
            }
        }
        $datas = $datasWithoutIdentifiers;
        //Get new identifiers
        $mappedIdentifier = $this->mapIdentifier($identifier);

        //Extract sharding key from identifier
        $shardingKey = null;
        if (isset($mappedIdentifier['sharding_key'])) {
            $shardingKey = $mappedIdentifier['sharding_key'];
            unset($mappedIdentifier['sharding_key']);
        }

        //Get Connection and table name
        $connection = $this->connectionManager->getConnection(
            $this->schemaManager->getConnectionName($this->tableName, $shardingKey, true),
            true
        );
        $shardingIdentifier = $this->schemaManager->getShardingIdentifier($this->tableName, $shardingKey);
        $tableName = $this->tableName;
        if (isset($shardingIdentifier)) {
            $tableName = sprintf('%1$s_%2$s', $this->tableName, $shardingIdentifier);
        }

        //First, remove all
        if (false === empty($identifier)) {
            $this->remove($identifier);
        }

        //then Insert
        $affectedRows = 0;
        foreach ($datas as $key => $value) {
            if (false === array_key_exists($key, $identifier)) {
                $connection->insert(
                    $tableName,
                    array_merge(
                        $mappedIdentifier,
                        array(
                            $this->nameField=>$key,
                            $this->valueField=>$value,
                        )
                    )
                );
                $affectedRows++;
            }
        }

        return $identifier;
    }
public function save($datas, array $identifier = array(), $shardingKey = null, &$affectedRows = null)
    {
        $datasWithoutIdentifiers=array();
        foreach ($datas as $key => $value) {
            if (isset($this->mapping[$key])) {
                $identifier[$key] = $value;
            } else {
                $datasWithoutIdentifiers[$key]=$value;
            }
        }
        $datas = $datasWithoutIdentifiers;
        //Get new identifiers
        $mappedIdentifier = $this->mapIdentifier($identifier);

        //Extract sharding key from identifier
        $shardingKey = null;
        if (isset($mappedIdentifier['sharding_key'])) {
            $shardingKey = $mappedIdentifier['sharding_key'];
            unset($mappedIdentifier['sharding_key']);
        }

        //Get Connection and table name
        $connection = $this->connectionManager->getConnection(
            $this->schemaManager->getConnectionName($this->tableName, $shardingKey, true),
            true
        );
        $shardingIdentifier = $this->schemaManager->getShardingIdentifier($this->tableName, $shardingKey);
        $tableName = $this->tableName;
        if (isset($shardingIdentifier)) {
            $tableName = sprintf('%1$s_%2$s', $this->tableName, $shardingIdentifier);
        }

        //First, remove all
        if (false === empty($identifier)) {
            $this->remove($identifier);
        }

        //then Insert
        $affectedRows = 0;
        foreach ($datas as $key => $value) {
            if (false === array_key_exists($key, $identifier)) {
                $connection->insert(
                    $tableName,
                    array_merge(
                        $mappedIdentifier,
                        array(
                            $this->nameField=>$key,
                            $this->valueField=>$value,
                        )
                    )
                );
                $affectedRows++;
            }
        }

        return $identifier;
    }
@param array $datas
@param array $identifier
@param null  $shardingKey
@param null  $affectedRows

@return array
@throws \Exception