package org.datacite.mds.validation.constraints;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;

import org.datacite.mds.validation.constraints.impl.UniqueValidator;

@Documented
@Constraint(validatedBy = UniqueValidator.class)
@Target( { ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@ReportAsSingleViolation
public @interface Unique {

    public String field();
    
    public String idField() default "id"; 

    public abstract String message() default "{org.datacite.mds.validation.constraints.Unique.message}";

    public abstract Class<?>[] groups() default {};

    public abstract Class<? extends Payload>[] payload() default {};

}
@@ -434,16 +434,646 @@
 dator;%0A%0A
+/**%0A * %3Cp%3E%0A * This annotation checks an entity field for uniqueness. It has to be placed on%0A * type level.%0A * %3C/p%3E%0A * %0A * %3Cp%3E%0A * It looks up for objects with the same field value in the persistence backend. If%0A * there is none the constraint is valid. If there is exactly one matching%0A * object we check for id field (%22id%22 by default) matching. If so this indicates%0A * an update operation and the constraint is valid. Otherwise it fails.%0A * %3C/p%3E%0A * %0A * %3Cp%3E%0A * Example:%0A * %0A * %3Cpre%3E%0A * &#064;Entity%0A * &#064;Unique(field=%22myfield%22)%0A * public class Domain %7B%0A *   Long id;%0A *   String myField;%0A * %7D%0A * %0A * %3C/p%3E%0A * %0A * %0A * %3C/pre%3E%0A */%0A
 @Documen
@@ -1274,16 +1274,88 @@
 ique %7B%0A%0A
+    /**%0A     * @return name of the field which should be unique%0A     */%0A
     publ
@@ -1373,20 +1373,92 @@
 ield();%0A
+%0A
     
+/**%0A     * @return name of entity's id field (defaults to %22id%22)%0A     */
 %0A    pub
@@ -1491,17 +1491,16 @@
 lt %22id%22;
- 
 %0A%0A    pu

add javadoc