From 78d076768ea7721155656a75d05dcc120ae6c72b Mon Sep 17 00:00:00 2001 From: Albert Shift Date: Sun, 7 Jun 2015 12:35:33 -0700 Subject: [PATCH] Constraint name for the data integrity annotation --- .../casser/mapping/annotation/Constraint.java | 237 ++++++++++++++++++ .../noorq/casser/mapping/annotation/Data.java | 136 ---------- 2 files changed, 237 insertions(+), 136 deletions(-) create mode 100644 src/main/java/com/noorq/casser/mapping/annotation/Constraint.java delete mode 100644 src/main/java/com/noorq/casser/mapping/annotation/Data.java diff --git a/src/main/java/com/noorq/casser/mapping/annotation/Constraint.java b/src/main/java/com/noorq/casser/mapping/annotation/Constraint.java new file mode 100644 index 0000000..9496f24 --- /dev/null +++ b/src/main/java/com/noorq/casser/mapping/annotation/Constraint.java @@ -0,0 +1,237 @@ +/* + * 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.mapping.annotation; + +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; + +/** + * Constraint annotations are using for data integrity mostly for @java.lang.String types. + * The place of the annotation is the particular method in model interface. + * + * All of them does not have effect on selects and data retrieval operations. + * + * Support types: + * - @NotNull supports any @java.lang.Object type + * - All annotations support @java.lang.String type + * + * @author Albert Shift + * + */ + +public final class Constraint { + + private Constraint() { + } + + /** + * NotNull annotation is using to check that value is not null before storing it + * + * It does not check on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface NotNull { + + } + + /** + * NotEmptyText annotation is using to check that value has text before storing it + * + * It does not check on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface NotEmptyText { + + } + + /** + * Email annotation is using to check that value has a valid email before storing it + * + * It does not check on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Email { + + } + + /** + * Number annotation is using to check that all letters in value are digits before storing it + * + * It does not check on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Number { + + } + + + /** + * Alphabet annotation is using to check that all letters in value are in specific alphabet before storing it + * + * It does not check on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Alphabet { + + char[] value(); + + } + + /** + * Length annotation is using to ensure that value has exact length before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Length { + + int value(); + + } + + /** + * MaxLength annotation is using to ensure that value has length less or equal to some threshold before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface MaxLength { + + int value(); + + } + + /** + * MinLength annotation is using to ensure that value has length greater or equal to some threshold before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface MinLength { + + int value(); + + } + + /** + * LowerCase annotation is using to ensure that value is in lower case before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface LowerCase { + + } + + /** + * UpperCase annotation is using to ensure that value is in upper case before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface UpperCase { + + } + + /** + * Pattern annotation is LowerCase annotation is using to ensure that value is upper case before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Pattern { + + /** + * User defined regex expression to check match of the value + * + * @return Regex pattern + */ + + String value(); + + } + + /** + * Custom annotation is using special implementation to check value before storing it + * + * It does not have effect on selects and data retrieval operations + * + */ + + @Documented + @Retention(RetentionPolicy.RUNTIME) + @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) + public @interface Custom { + + /** + * Defines class name of the custom implementation of the checker. + * Class must implement special interface for this and be thread-safe and do not relay that it will be a singleton. + * + * @return className of the custom implementation + */ + + String value(); + + } + +} diff --git a/src/main/java/com/noorq/casser/mapping/annotation/Data.java b/src/main/java/com/noorq/casser/mapping/annotation/Data.java deleted file mode 100644 index 413dfa6..0000000 --- a/src/main/java/com/noorq/casser/mapping/annotation/Data.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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.mapping.annotation; - -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; - -/** - * Data annotations are using for data integrity. Annotations helps to build simple data model without complex operations in repositories. - * All of them are placing for particular columns under the methods in model DSL. - * - * Some of them are using for validation only, like @NotNull or @Length - * Some of them, like @LowerCase and @UpperCase are doing actual modifications under the data and working as preprocessors. - * - * All of them does not have effect on selects and data retrieval operations. - * - * Support types: - * - @NotNull supports any @Object type - * - All annotations support @String type - * - * @author Albert Shift - * - */ - -public final class Data { - - private Data() { - } - - /** - * NotNull annotation is using to check that value is not null before storing it - * - * It does not check on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface NotNull { - - } - - /** - * Length annotation is using to ensure that value has exact length before storing it - * - * It does not have effect on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface Length { - - int value(); - - } - - /** - * MaxLength annotation is using to ensure that value has length less or equal to some threshold before storing it - * - * It does not have effect on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface MaxLength { - - int value(); - - } - - /** - * MinLength annotation is using to ensure that value has length greater or equal to some threshold before storing it - * - * It does not have effect on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface MinLength { - - int value(); - - } - - /** - * LowerCase annotation is the preprocessor annotation that converts String value to lower case if it is not null - * - * It does not have effect on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface LowerCase { - - } - - /** - * UpperCase annotation is the preprocessor annotation that converts String value to upper case if it is not null - * - * It does not have effect on selects and data retrieval operations - * - */ - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE }) - public @interface UpperCase { - - } - -}