support annotaiton on constraint annotation
This commit is contained in:
parent
52c3f19ea2
commit
1eb3c17d6b
3 changed files with 70 additions and 18 deletions
|
@ -55,14 +55,36 @@ public final class MappingUtil {
|
|||
|
||||
for (Annotation constraintAnnotation : getterMethod.getDeclaredAnnotations()) {
|
||||
|
||||
list = addValidators(constraintAnnotation, list);
|
||||
|
||||
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
|
||||
|
||||
Constraint constraint = annotationType.getDeclaredAnnotation(Constraint.class);
|
||||
for (Annotation possibleConstraint : annotationType.getDeclaredAnnotations()) {
|
||||
|
||||
list = addValidators(possibleConstraint, list);
|
||||
|
||||
if (constraint == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (list == null) {
|
||||
return EMPTY_VALIDATORS;
|
||||
}
|
||||
else {
|
||||
return list.toArray(EMPTY_VALIDATORS);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ConstraintValidator<? extends Annotation, ?>> addValidators(Annotation constraintAnnotation, List<ConstraintValidator<? extends Annotation, ?>> list) {
|
||||
|
||||
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
|
||||
|
||||
for (Annotation possibleConstraint : annotationType.getDeclaredAnnotations()) {
|
||||
|
||||
if (possibleConstraint instanceof Constraint) {
|
||||
|
||||
Constraint constraint = (Constraint) possibleConstraint;
|
||||
|
||||
for (Class<? extends ConstraintValidator<?, ?>> clazz : constraint.validatedBy()) {
|
||||
|
||||
ConstraintValidator<? extends Annotation, ?> validator = ReflectionInstantiator.instantiateClass(clazz);
|
||||
|
@ -79,12 +101,10 @@ public final class MappingUtil {
|
|||
|
||||
}
|
||||
|
||||
if (list == null) {
|
||||
return EMPTY_VALIDATORS;
|
||||
}
|
||||
else {
|
||||
return list.toArray(EMPTY_VALIDATORS);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
public static Optional<IdentityName> getIndexName(Method getterMethod) {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package com.noorq.casser.test.integration.core.simple;
|
||||
|
||||
import com.noorq.casser.mapping.annotation.Column;
|
||||
import com.noorq.casser.mapping.annotation.Constraints;
|
||||
import com.noorq.casser.mapping.annotation.PartitionKey;
|
||||
import com.noorq.casser.mapping.annotation.Table;
|
||||
|
||||
|
@ -26,7 +25,7 @@ public interface User {
|
|||
@PartitionKey
|
||||
Long id();
|
||||
|
||||
@Constraints.LowerCase
|
||||
@Username
|
||||
@Column("override_name")
|
||||
String name();
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Noorq, Inc.
|
||||
*
|
||||
* 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 com.noorq.casser.test.integration.core.simple;
|
||||
|
||||
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 com.noorq.casser.mapping.annotation.Constraints;
|
||||
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE })
|
||||
@Constraints.LowerCase
|
||||
public @interface Username {
|
||||
|
||||
}
|
Loading…
Reference in a new issue