Duplicates this record set wrapper

@return SwatDBRecordsetWrapper a duplicate of this object.
@see SwatDBDataobject::duplicate()
344857
public function duplicate()
    {
        $class = get_class($this);
        $new_wrapper = new $class();

        foreach ($this->getArray() as $object) {
            $object->setDatabase($this->db);
            $duplicate_object = $object->duplicate();
            $duplicate_object->setDatabase($this->db);
            $new_wrapper->add($duplicate_object);
        }

        $new_wrapper->setDatabase($this->db);

        return $new_wrapper;
    }
1358720
public function duplicateInstance($srcInstanceName, $destInstanceName = null) {
		if (!isset($this->declaredInstances[$srcInstanceName])) {
			throw new MoufContainerException("Error while duplicating instance: unable to find source instance ".$srcInstanceName);
		}
		if ($destInstanceName == null) {
			if (!$this->isInstanceAnonymous($srcInstanceName)) {
				throw new MoufContainerException("Error while duplicating instance: you need to give a destination name.");
			}
			$destInstanceName = $this->getFreeAnonymousName();
		}
		
		if (isset($this->declaredInstances[$destInstanceName])) {
			throw new MoufContainerException("Error while duplicating instance: the dest instance already exists: ".$destInstanceName);
		}
		$this->declaredInstances[$destInstanceName] = $this->declaredInstances[$srcInstanceName];
		
		// TODO: special case: if an instance is pointing to itself, it might be a good idea to keep the copy
		// pointing to the copy instead of the original.
		
		// We should also recursively duplicate anonymous instances:
		if (isset($this->declaredInstances[$destInstanceName]["fieldBinds"])) {
			foreach ($this->declaredInstances[$destInstanceName]["fieldBinds"] as $key=>$boundInstance) {
				if (is_array($boundInstance)) {
					foreach ($boundInstance as $key2=>$item) {
						if ($this->isInstanceAnonymous($item)) {
							$this->declaredInstances[$destInstanceName]["fieldBinds"][$key][$key2] = $this->duplicateInstance($item);
						}
					}
				} else {
					if ($this->isInstanceAnonymous($boundInstance)) {
						$this->declaredInstances[$destInstanceName]["fieldBinds"][$key] = $this->duplicateInstance($boundInstance);
					}
				}
			}
		}

		if (isset($this->declaredInstances[$destInstanceName]["setterBinds"])) {
			foreach ($this->declaredInstances[$destInstanceName]["setterBinds"] as $key=>$boundInstance) {
				if (is_array($boundInstance)) {
					foreach ($boundInstance as $key2=>$item) {
						if ($this->isInstanceAnonymous($item)) {
							$this->declaredInstances[$destInstanceName]["setterBinds"][$key][$key2] = $this->duplicateInstance($item);
						}
					}
				} else {
					if ($this->isInstanceAnonymous($boundInstance)) {
						$this->declaredInstances[$destInstanceName]["setterBinds"][$key] = $this->duplicateInstance($boundInstance);
					}
				}
			}
		}
		
		if (isset($this->declaredInstances[$destInstanceName]["constructor"])) {
			foreach ($this->declaredInstances[$destInstanceName]["constructor"] as $index=>$parameter) {
				if ($parameter['parametertype'] == 'object' && $parameter['type'] == 'string') {
					$boundInstance = $parameter['value'];
					if (is_array($boundInstance)) {
						foreach ($boundInstance as $key2=>$item) {
							if ($this->isInstanceAnonymous($item)) {
								$this->declaredInstances[$destInstanceName]["constructor"][$index][$key2] = $this->duplicateInstance($item);
							}
						}
					} else {
						if ($this->isInstanceAnonymous($boundInstance)) {
							$this->declaredInstances[$destInstanceName]["constructor"][$index] = $this->duplicateInstance($boundInstance);
						}
					}
				}
			}
		}
				
		return $destInstanceName;
	}
478414
public function duplicate()
    {
        if (false === $this->is_duplicated) {
            $this->_duplicate();
            $this->is_duplicated = true;
            $this->node = parent::getNode();
        }
        return $this;
    }
686081
public function duplicate($id)
    {
        return $this->_table->save($this->duplicateEntity($id), $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain')]);
    }
1001468
public function duplicateAction()
    {
        $id     = $this->getRequest()->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);

        if (!$object) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }

        if (false === $this->admin->isGranted('DUPLICATE', $object)) {
            throw new AccessDeniedException();
        }

        $newObject = clone $object;

        if (method_exists($newObject, 'setTitle')) {
            $newObject->setTitle('[COPY] - ' . $newObject->getTitle());
        }

        $objectManager = $this->getDoctrine()->getManager();
        $objectManager->persist($newObject);
        $objectManager->flush();

        $this->addFlash(
            'sonata_flash_success',
            $this->admin->trans('flash_duplicate_success')
        );

        return new RedirectResponse($this->admin->generateObjectUrl('edit', $newObject));
    }
45102
protected function _deduplicateResultSet($subject)
    {
        $resultSet = clone $subject->entities;
        $ids = [];
        $keys = (array)$subject->query->getRepository()->getPrimaryKey();
        foreach ($subject->entities as $entity) {
            $id = $entity->extract($keys);
            if (!in_array($id, $ids)) {
                $entities[] = $entity;
                $ids[] = $id;
            }
        }

        if (isset($entities)) {
            $resultSet->unserialize(serialize($entities));
        }

        return $resultSet;
    }
1054796
public function replay()
    {
        $mockClassName = parent::replay();

        $mockClassReflector = new \ReflectionClass($mockClassName);
        return $mockClassReflector->newInstanceArgs($this->constructor_arguments);
    }
463974
public SameDiff dup() {
        Cloner cloner = newCloner();
        SameDiff clone = cloner.deepClone(this);
        //TODO don't clone sessions in the first place!
        clone.sessions.clear();
        return clone;
    }
815453
public function duplicate(string $id = null): ResourceInterface
    {
        $resource = new self($this->type(), $id ?? $this->id(), $this->attributes()->all());

        $resource->metaInformation()->mergeCollection($this->metaInformation());

        foreach ($this->relationships()->all() as $relationship) {
            $resource->relationships()->set($relationship->duplicate());
        }

        foreach ($this->links()->all() as $link) {
            $resource->links()->set($link->duplicate());
        }

        return $resource;
    }
1188759
public function findExistingObject($record)
    {
        // checking for existing records (only if not already found)
        foreach ($this->duplicateChecks as $fieldName => $duplicateCheck) {
            //plain duplicate checks on fields and relations
            if (is_string($duplicateCheck)) {
                $fieldName = $duplicateCheck;
                //If the dupilcate check is a dot notation, then convert to ID relation
                if (strpos($duplicateCheck, '.') !== false) {
                    list($relationName, $columnName) = explode('.', $duplicateCheck);
                    $fieldName = $relationName."ID";
                }
                //TODO: also convert plain relation names to include ID

                //skip current duplicate check if field value is empty
                if (!isset($record[$fieldName]) || empty($record[$fieldName])) {
                    continue;
                }
                $existingRecord = $this->getDataList()
                                    ->filter($fieldName, $record[$fieldName])
                                    ->first();
                if ($existingRecord) {
                    return $existingRecord;
                }
            }
            //callback duplicate checks
            elseif (
                is_array($duplicateCheck) &&
                isset($duplicateCheck['callback']) &&
                is_callable($duplicateCheck['callback'])
            ) {
                $callback = $duplicateCheck['callback'];
                if ($existingRecord = $callback($fieldName, $record)) {
                    return $existingRecord;
                }
            } else {
                user_error('BulkLoader::processRecord(): Wrong format for $duplicateChecks',
                    E_USER_WARNING
                );
            }
        }

        return false;
    }
659403
public function copyEmpty()
    {
        $class_name = get_class($this);
        $wrapper = new $class_name();

        $wrapper->row_wrapper_class = $this->row_wrapper_class;
        $wrapper->index_field = $this->index_field;
        $wrapper->options = $this->options;

        return $wrapper;
    }
842265
public function copy() {
        $copied = clone $this;

        $worksheetCount = count($this->_workSheetCollection);
        for ($i = 0; $i < $worksheetCount; ++$i) {
            $this->_workSheetCollection[$i] = $this->_workSheetCollection[$i]->copy();
            $this->_workSheetCollection[$i]->rebindParent($this);
        }

        return $copied;
    }
928245
protected function getResultSet()
    {
        if (!$this->resultSetPrototype instanceof HydratingResultSet) {
            $resultSetPrototype = new HydratingResultSet;
            $resultSetPrototype->setHydrator($this->getHydrator());
            $resultSetPrototype->setObjectPrototype($this->getModel());
            $this->resultSetPrototype = $resultSetPrototype;
        }

        return clone $this->resultSetPrototype;
    }
1354960
public static function duplicate(string $name): self
    {
        $e = sprintf(self::DUPLICATE, $name);

        return new static($e);
    }
1113313
public function duplicateWithChildren()
    {
        /** @var SiteTree $clone */
        $clone = $this->duplicate();
        $children = $this->AllChildren();

        if ($children) {
            /** @var SiteTree $child */
            $sort = 0;
            foreach ($children as $child) {
                $childClone = method_exists($child, 'duplicateWithChildren')
                    ? $child->duplicateWithChildren()
                    : $child->duplicate();
                $childClone->ParentID = $clone->ID;
                //retain sort order by manually setting sort values
                $childClone->Sort = ++$sort;
                $childClone->write();
            }
        }

        return $clone;
    }
1346941
function duplicate()
    {
        $forwardCopy = $this->ForwardHandler->duplicate();
        $copy = new eZForwardCompressionHandler( $forwardCopy, $this->name(), $this->identifier() );
        return $copy;
    }
1313797
protected T getObject() {
		final T object;
		if (reusedObject != null) {
			// REUSE THE SAME RECORD AFTER HAVING RESETTED IT
			object = reusedObject;
			object.reset();
		} else
			// CREATE A NEW ONE
			object = (T) database.newInstance(className);
		return object;
	}