/* * Copyright 2011 Martin Grotzke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.hashcode.validation; 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; /** * Is used to mark a bean property (e.g. a username) as unique compared to other * entity instances. The validator {@link UniqueKeyValidator} allows the * annotated bean to use read-only properties (immutable). Also an update of the * entity is allowed. * * @author <a href="mailto:martin.grotzke@googlemail.com">Martin Grotzke</a> */ @Constraint(validatedBy = { UniqueKeyValidator.class }) @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface UniqueKey { String property(); String message() default "{validation.constraints.UniqueKey.message}"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Documented @interface List { UniqueKey[] value(); } }