Validate the unique constraints for the entity
171759
def _validate_unique(self, create=True):
        
        # Build the filters from the unique constraints
        filters, excludes = {}, {}

        for field_name, field_obj in self.meta_.unique_fields:
            lookup_value = getattr(self, field_name, None)
            # Ignore empty lookup values
            if lookup_value in Field.empty_values:
                continue
            # Ignore identifiers on updates
            if not create and field_obj.identifier:
                excludes[field_name] = lookup_value
                continue
            filters[field_name] = lookup_value

        # Lookup the objects by the filters and raise error on results
        for filter_key, lookup_value in filters.items():
            if self.exists(excludes, **{filter_key: lookup_value}):
                field_obj = self.meta_.declared_fields[filter_key]
                field_obj.fail('unique',
                               entity_name=self.__class__.__name__,
                               field_name=filter_key)
149315
private void validate(Entity entity) {
    MailSettingsImpl mailSettings = new MailSettingsImpl(entity);
    if (mailSettings.isTestConnection()
        && mailSettings.getUsername() != null
        && mailSettings.getPassword() != null) {
      mailSenderFactory.validateConnection(mailSettings);
    }
  }
645319
public function isUniqueKey(Fluent $constraint)
    {
        foreach ($this->unique as $index) {

            // We only need to consider cases, when UNIQUE KEY is presented by only ONE column
            if (count($index->columns) === 1 && isset($index->columns[0])) {
                if (in_array($index->columns[0], $constraint->columns)) {
                    return true;
                }
            }
        }

        return false;
    }
440505
public boolean validate(E entity)
    {
        if (entity != null)
        {
            // entity metadata could be null.
            if (entityMetadata == null)
            {
                throw new IllegalArgumentException(
                        "Entity object is invalid, operation failed. Please check previous log message for details");
            }

            return false;

        }

        // will return false if entity is null.
        return true;
    }
1071167
def _validate_data(self, path, obj, _):
        
        errs = []

        if obj.type == None and getattr(obj, '$ref') == None:
            errs.append('type or $ref should be existed.')

        # make sure there is 'item' along with 'array'
        if not (obj.type == 'array') == (obj.items != None):
            errs.append('array should be existed along with items')
        if obj.uniqueItems != None and obj.type != 'array':
            errs.append('uniqueItems is only used for array type.')

        return path, obj.__class__.__name__, errs
1117659
def check_uniqe(self, obj_class, error_msg=_('Must be unique'), **kwargs):
        
        if obj_class.objects.filter(**kwargs).exclude(pk=self.instance.pk):
            raise forms.ValidationError(error_msg)
1217246
protected function prepareUniqueConstraint(DOMElement $table, DOMXPath $xpath, Table $schemaTable)
    {
        $uniqueTags = $xpath->query(sprintf('/database/table[@name="%s"]/unique', $table->getAttribute('name')));

        /** @var DOMElement $uniqueTag */
        foreach ($uniqueTags as $uniqueTag) {
            $uniqueColumns = $uniqueTag->getElementsByTagName('unique-column');
            $constraintName = $uniqueTag->getAttribute('name');

            $tmpUniqueColumn = [];
            /** @var DOMElement $uniqueColumn */
            foreach ($uniqueColumns as $uniqueColumn) {
                $tmpUniqueColumn[] = $uniqueColumn->getAttribute('name');
            }

            if (empty(trim($constraintName))) {
                $constraintName = sprintf(
                    '%s_%s_%s',
                    $table->getAttribute('name'),
                    implode('_', $tmpUniqueColumn),
                    'unique'
                );
            }

            $schemaTable->addConstraint(
                $constraintName,
                [
                    'type' => 'unique',
                    'columns' => $tmpUniqueColumn
                ]
            );
        }
    }
1009336
function (entity, options, callback) {
                if (entity instanceof Entity) {
                    entity.validate(options, callback);
                } else {
                    callback("parameter is not an entity");
                }
            }
972491
protected function _validate_unique($value)
    {
        $context = $this->_context;

        $modelName = $context->model;
        return ($value && $modelName::exists([$context->field => $value])) ? null : $value;
    }
1173885
public function validate($entity, Constraint $constraint): void
    {
        /** @var HasEnabledEntity $constraint */
        Assert::isInstanceOf($constraint, HasEnabledEntity::class);

        $enabled = $this->accessor->getValue($entity, $constraint->enabledPath);

        if ($enabled === true) {
            return;
        }

        $objectManager = $this->getProperObjectManager($constraint->objectManager, $entity);

        $this->ensureEntityHasProvidedEnabledField($objectManager, $entity, $constraint->enabledPath);

        $criteria = [$constraint->enabledPath => true];

        $repository = $objectManager->getRepository(get_class($entity));
        $results = $repository->{$constraint->repositoryMethod}($criteria);

        /* If the result is a MongoCursor, it must be advanced to the first
         * element. Rewinding should have no ill effect if $result is another
         * iterator implementation.
         */
        if ($results instanceof \Iterator) {
            $results->rewind();
        } elseif (is_array($results)) {
            reset($results);
        }

        if ($this->isLastEnabledEntity($results, $entity)) {
            $errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $constraint->enabledPath;

            $this->context->buildViolation($constraint->message)->atPath($errorPath)->addViolation();
        }
    }
1073193
public List<String> validateUniques(Identifiable<?> entity) {
        return newArrayList(concat( //
                validateCompositeUniqueConstraints(entity), //
                validateSimpleUniqueConstraints(entity) //
        ));
    }
804267
def validate_unique(self):
        
        unique_checks, date_checks = self.instance._get_unique_checks(exclude=[])
        errors = self.instance._perform_unique_checks(unique_checks)
        if errors:
            self.add_error(None, errors)
511527
public function validate($entity, Constraint $constraint): void
    {
        /** @var UniqueEntity $constraint */
        $em = Util::getObjectManager($this->registry, $entity, $constraint);
        $fields = (array) $constraint->fields;
        $criteria = $this->getCriteria($entity, $constraint, $em);

        if (null === $criteria) {
            return;
        }

        $result = $this->getResult($entity, $constraint, $criteria, $em);

        if (!$this->isValidResult($result, $entity)) {
            $errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0];
            $invalidValue = $criteria[$errorPath] ?? $criteria[$fields[0]];

            $this->context->buildViolation($constraint->message)
                ->atPath($errorPath)
                ->setInvalidValue($invalidValue)
                ->addViolation()
            ;
        }
    }
847373
public void addUniqueConstraint(UniqueConstraint uc) {
		if (uc.isPrimaryKey()) {
			if (pk != null)
				throw new IllegalArgumentException("Duplicate PK " + pk + " " + uc);
			pk = uc;
		}
		else {
			if (pk != null)
				if (uc.getAttributes().equals(pk.getAttributes()))
					// ignore the unique index created for the primary key
					return;
		}
		ucs.add(uc);
	}
42352
def validate_unique_slug(self):
        
        clashes_qs = type(self).objects.filter(slug=self.slug)
        if self.pk:
            clashes_qs = clashes_qs.exclude(pk=self.pk)
        if isinstance(self, PublishingModel):
            clashes_qs = clashes_qs.filter(
                publishing_is_draft=self.publishing_is_draft)
        if clashes_qs:
            raise ValidationError(
                "Slug '%s' clashes with other items: %s"
                % (self.slug, clashes_qs))
294291
public function createSchemaUniqueConstraint($label, $property, $transformIndexInConstraint = false, $conn = null)
    {
        $q = 'CREATE CONSTRAINT ON (n:'.$label.') ASSERT n.'.$property.' IS UNIQUE';
        try {
            $this->sendCypherQuery($q);

            return new UniqueConstraint($label, $property);
        } catch (Neo4jException $e) {
            if (true === $transformIndexInConstraint && 8000 === $e->getCode()) {
                // do remove constraint
            }

            throw $e;
        }
    }
256558
private void addUniqueConstraintForTableBasedSequence(IdSourceKeyMetadata generatorKeyMetadata) {
		Label generatorKeyLabel = Label.label( generatorKeyMetadata.getName() );
		if ( isMissingUniqueConstraint( generatorKeyLabel ) ) {
			neo4jDb.schema().constraintFor( generatorKeyLabel ).assertPropertyIsUnique( generatorKeyMetadata.getKeyColumnName() ).create();
		}
	}