diff --git a/build.gradle b/build.gradle index 5f6c3170..22cea029 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,8 @@ test { java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 + withJavadocJar() + withSourcesJar() } tasks.withType(JavaCompile).configureEach { @@ -44,15 +46,6 @@ tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } -task sourcesJar(type: Jar) { - from sourceSets.main.allJava - archiveClassifier.set('sources') -} -task javadocJar(type: Jar) { - from javadoc - archiveClassifier.set('javadocs') -} - publishing { repositories { maven { @@ -66,8 +59,6 @@ publishing { publications { maven(MavenPublication) { from components.java - artifact sourcesJar - artifact javadocJar } } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 41d9927a..00000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb879..070cb702 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/eu/koboo/en2do/internal/MethodCallable.java b/src/main/java/eu/koboo/en2do/internal/MethodCallable.java index 2b81a1bb..82f84100 100644 --- a/src/main/java/eu/koboo/en2do/internal/MethodCallable.java +++ b/src/main/java/eu/koboo/en2do/internal/MethodCallable.java @@ -1,6 +1,14 @@ package eu.koboo.en2do.internal; +/** + * This interface is used to retrieve a return value of the dynamic method + */ public interface MethodCallable { + /** + * Called to get the object + * @return The return value of the method + * @throws Exception if anything bad happens + */ Object call() throws Exception; } diff --git a/src/main/java/eu/koboo/en2do/internal/Validator.java b/src/main/java/eu/koboo/en2do/internal/Validator.java index 9c1c24ba..b02ec4e5 100644 --- a/src/main/java/eu/koboo/en2do/internal/Validator.java +++ b/src/main/java/eu/koboo/en2do/internal/Validator.java @@ -6,6 +6,7 @@ import eu.koboo.en2do.repository.entity.TransformField; import eu.koboo.en2do.repository.entity.Transient; import eu.koboo.en2do.utility.FieldUtils; +import lombok.experimental.UtilityClass; import org.bson.codecs.Codec; import java.beans.BeanInfo; @@ -20,9 +21,18 @@ import java.util.Locale; import java.util.Set; +/** + * Represents the validation of a class. This can be an entity or an embedded class inside the entity. + */ +@UtilityClass public class Validator { - private static Codec getCodec(Class typeClass) { + /** + * Returns a codec for the given type class or if no codec is found, it returns null. + * @param typeClass The type class to search a codec for. + * @return The codec if found, otherwise null. + */ + private Codec getCodec(Class typeClass) { try { return MongoClientSettings.getDefaultCodecRegistry().get(typeClass); } catch (Exception ignored) { @@ -30,7 +40,16 @@ private static Codec getCodec(Class typeClass) { } } - public static > void validateCompatibility( + /** + * Validates the compatibility of the given type class + * @param repositoryClass The class of the repository + * @param typeClass The type class, which should be validated + * @param The generic type of the entity + * @param The generic type of the id of the entity + * @param The generic type of the repository + * @throws Exception if type class is not valid. + */ + public > void validateCompatibility( Class repositoryClass, Class typeClass) throws Exception { if (typeClass == null) { throw new RuntimeException("Class for validation is null! Please open an issue on github!"); diff --git a/src/main/java/eu/koboo/en2do/internal/codec/InternalPropertyCodecProvider.java b/src/main/java/eu/koboo/en2do/internal/codec/InternalPropertyCodecProvider.java index bef2a25d..142579ef 100644 --- a/src/main/java/eu/koboo/en2do/internal/codec/InternalPropertyCodecProvider.java +++ b/src/main/java/eu/koboo/en2do/internal/codec/InternalPropertyCodecProvider.java @@ -11,7 +11,7 @@ import java.util.Map; /** - * This codec provider enables the usage of the en2do custom codecs and adds them to the CodecRegistry + * This codec provider enables the usage of the en2do custom codecs and adds them to the CodecRegistry. */ @Log public class InternalPropertyCodecProvider implements PropertyCodecProvider { diff --git a/src/main/java/eu/koboo/en2do/internal/codec/lang/ClassCodec.java b/src/main/java/eu/koboo/en2do/internal/codec/lang/ClassCodec.java index 400aebdd..c6345b39 100644 --- a/src/main/java/eu/koboo/en2do/internal/codec/lang/ClassCodec.java +++ b/src/main/java/eu/koboo/en2do/internal/codec/lang/ClassCodec.java @@ -8,14 +8,13 @@ import org.bson.codecs.EncoderContext; /** - * ClassCodec is used to encode and decode java.lang.Class objects to mongodb document fields + * ClassCodec is used to encode and decode java.lang.Class objects to mongodb document fields. */ @SuppressWarnings("rawtypes") public class ClassCodec implements Codec { /** - * See org.bson.codecs.Encoder - * + * @see org.bson.codecs.Encoder * @param writer the BSON writer to encode into * @param value the value to encode * @param encoderContext the encoder context @@ -26,8 +25,7 @@ public void encode(BsonWriter writer, Class value, EncoderContext encoderContext } /** - * See org.bson.codecs.Decoder - * + * @see org.bson.codecs.Decoder * @param reader the BSON reader * @param decoderContext the decoder context * @return the decoded Class diff --git a/src/main/java/eu/koboo/en2do/internal/codec/map/GenericMapCodec.java b/src/main/java/eu/koboo/en2do/internal/codec/map/GenericMapCodec.java index 950878cb..dc339733 100644 --- a/src/main/java/eu/koboo/en2do/internal/codec/map/GenericMapCodec.java +++ b/src/main/java/eu/koboo/en2do/internal/codec/map/GenericMapCodec.java @@ -110,8 +110,8 @@ public Map decode(BsonReader reader, DecoderContext context) { } /** - * Used to get a new instance of the saved map - * @return The new created map instance + * Used to get a new instance of the saved map. + * @return The new created map instance. */ private Map getInstance() { if (encoderClass.isInterface()) { diff --git a/src/main/java/eu/koboo/en2do/internal/convention/AnnotationConvention.java b/src/main/java/eu/koboo/en2do/internal/convention/AnnotationConvention.java index 442ce001..6a61acf8 100644 --- a/src/main/java/eu/koboo/en2do/internal/convention/AnnotationConvention.java +++ b/src/main/java/eu/koboo/en2do/internal/convention/AnnotationConvention.java @@ -14,12 +14,23 @@ import java.lang.annotation.Annotation; import java.util.Map; +/** + * This convention implementation enables the usage of the annotations from en2do + * inside entity classes. This convention checks the annotations in the class model + * and modifies it accordingly. + */ @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) @RequiredArgsConstructor public class AnnotationConvention implements Convention { Map, RepositoryMeta> repositoryMetaRegistry; + /** + * This method is used to get the RepositoryMeta object by the given typeClass, + * and if non is found, it returns null. + * @param typeClass The type of RepositoryMeta (should be the entity class) + * @return The RepositoryMeta if found, otherwise "null" + */ private RepositoryMeta findRepositoryMetaOf(Class typeClass) { for (RepositoryMeta meta : repositoryMetaRegistry.values()) { if (!meta.getEntityClass().equals(typeClass)) { @@ -30,6 +41,10 @@ public class AnnotationConvention implements Convention { return null; } + /** + * @see Convention + * @param classModelBuilder the ClassModelBuilder to apply the convention to + */ @Override public void apply(ClassModelBuilder classModelBuilder) { for (PropertyModelBuilder propertyModelBuilder : classModelBuilder.getPropertyModelBuilders()) { diff --git a/src/main/java/eu/koboo/en2do/internal/methods/dynamic/FilterType.java b/src/main/java/eu/koboo/en2do/internal/methods/dynamic/FilterType.java index 0fefced1..c2ba1be2 100644 --- a/src/main/java/eu/koboo/en2do/internal/methods/dynamic/FilterType.java +++ b/src/main/java/eu/koboo/en2do/internal/methods/dynamic/FilterType.java @@ -4,5 +4,11 @@ import java.lang.reflect.Field; +/** + * Represents a segment of a method filter. + * @param field The field, which should be filtered + * @param notFilter is true if the filter is negotiated + * @param operator The operator of the filter + */ public record FilterType(Field field, boolean notFilter, FilterOperator operator) { } diff --git a/src/main/java/eu/koboo/en2do/internal/methods/dynamic/MethodFilterPart.java b/src/main/java/eu/koboo/en2do/internal/methods/dynamic/MethodFilterPart.java index 6cecd98d..8f0456cb 100644 --- a/src/main/java/eu/koboo/en2do/internal/methods/dynamic/MethodFilterPart.java +++ b/src/main/java/eu/koboo/en2do/internal/methods/dynamic/MethodFilterPart.java @@ -1,4 +1,9 @@ package eu.koboo.en2do.internal.methods.dynamic; +/** + * Represents a filter part of the method. + * @param filterType The type of the filter + * @param nextParameterIndex The parameter index + */ public record MethodFilterPart(FilterType filterType, int nextParameterIndex) { } diff --git a/src/main/java/eu/koboo/en2do/internal/methods/operators/ReturnTypeValidator.java b/src/main/java/eu/koboo/en2do/internal/methods/operators/ReturnTypeValidator.java index b572bfc9..56b584c1 100644 --- a/src/main/java/eu/koboo/en2do/internal/methods/operators/ReturnTypeValidator.java +++ b/src/main/java/eu/koboo/en2do/internal/methods/operators/ReturnTypeValidator.java @@ -2,7 +2,18 @@ import java.lang.reflect.Method; +/** + * Represents the validation of the return type from a method. + */ public interface ReturnTypeValidator { + /** + * Gets executed on the validation of the repository. + * @param method The method, which should be validated + * @param returnType The return type, of the method + * @param entityClass The class of the entity of the repository + * @param repoClass The class of the repository + * @throws Exception if return type isn't valid + */ void check(Method method, Class returnType, Class entityClass, Class repoClass) throws Exception; } diff --git a/src/main/java/eu/koboo/en2do/internal/methods/predefined/PredefinedMethod.java b/src/main/java/eu/koboo/en2do/internal/methods/predefined/PredefinedMethod.java index f63f54a3..35fc1092 100644 --- a/src/main/java/eu/koboo/en2do/internal/methods/predefined/PredefinedMethod.java +++ b/src/main/java/eu/koboo/en2do/internal/methods/predefined/PredefinedMethod.java @@ -10,6 +10,12 @@ import java.lang.reflect.Method; +/** + * This class is a representation of a predefined method from the repository + * @param The generic type of the entity + * @param The generic type of the id of the entity + * @param The generic type of the repository + */ @FieldDefaults(level = AccessLevel.PROTECTED, makeFinal = true) @RequiredArgsConstructor public abstract class PredefinedMethod> { @@ -19,5 +25,12 @@ public abstract class PredefinedMethod> { RepositoryMeta repositoryMeta; MongoCollection entityCollection; + /** + * Invokes the method and returns the created object. + * @param method The method, which should be invoked + * @param arguments The object array, which represents the arguments of the method + * @return The object created by the method invocation + * @throws Exception any, if something bad happens + */ public abstract Object handle(Method method, Object[] arguments) throws Exception; } diff --git a/src/main/java/eu/koboo/en2do/repository/AsyncRepository.java b/src/main/java/eu/koboo/en2do/repository/AsyncRepository.java index e75c79d5..41337b70 100644 --- a/src/main/java/eu/koboo/en2do/repository/AsyncRepository.java +++ b/src/main/java/eu/koboo/en2do/repository/AsyncRepository.java @@ -20,104 +20,114 @@ public interface AsyncRepository { /** * Async representation - * * @see Repository#countAll() + * @return Future, with the count of all entities */ @Async CompletableFuture asyncCountAll(); /** * Async representation - * * @see Repository#delete(Object) + * @param entity The entity, which should be deleted + * @return Future, with a boolean of success */ @Async CompletableFuture asyncDelete(E entity); /** * Async representation - * * @see Repository#deleteAll(List) + * @param entityList The List with entities, which should be deleted + * @return Future, with a boolean of success */ @Async CompletableFuture asyncDeleteAll(List entityList); /** * Async representation - * * @see Repository#deleteById(Object) + * @param identifier The identifier of the entity, which should be deleted + * @return Future, with a boolean of success */ @Async CompletableFuture asyncDeleteById(ID identifier); /** * Async representation - * * @see Repository#drop() + * @return Future, with a boolean of success */ @Async CompletableFuture asyncDrop(); /** * Async representation - * * @see Repository#exists(Object) + * @param entity The entity, which should be checked + * @return Future, with a boolean, which indicates if the entity exists */ @Async CompletableFuture asyncExists(E entity); /** * Async representation - * * @see Repository#existsById(Object) + * @param identifier The identifier of the entity, which should be checked + * @return Future, with a boolean, which indicates if an entity with the id exists */ @Async CompletableFuture asyncExistsById(ID identifier); /** * Async representation - * * @see Repository#findAll() + * @return Future, with all entities */ @Async CompletableFuture> asyncFindAll(); /** * Async representation - * * @see Repository#findFirstById(Object) + * @param identifier The identifier of the entity, which should be found + * @return Future, with the first entity with the id */ @Async CompletableFuture asyncFindFirstById(ID identifier); /** * Async representation - * * @see Repository#pageAll(Pagination) + * @param pagination The options, which should be used for pagination + * @return Future, with all entities, paged by the Pagination object */ @Async CompletableFuture> asyncPageAll(Pagination pagination); /** * Async representation - * * @see Repository#save(Object) + * @param entity The entity, which should be saved + * @return Future, with a boolean of success */ @Async CompletableFuture asyncSave(E entity); /** * Async representation - * * @see Repository#saveAll(List) + * @param entityList The List of entities, which should be saved + * @return Future, with a boolean of success */ @Async CompletableFuture asyncSaveAll(List entityList); /** * Async representation - * * @see Repository#sortAll(Sort) + * @param sort The options, which should be used for sorting + * @return Future, with all entities, sorted by the Sort object */ @Async CompletableFuture> asyncSortAll(Sort sort); diff --git a/src/main/java/eu/koboo/en2do/repository/entity/NonIndex.java b/src/main/java/eu/koboo/en2do/repository/entity/NonIndex.java index bfb5bf29..86f3c9ab 100644 --- a/src/main/java/eu/koboo/en2do/repository/entity/NonIndex.java +++ b/src/main/java/eu/koboo/en2do/repository/entity/NonIndex.java @@ -4,6 +4,7 @@ /** * This annotation disables the creating of the unique index of the "@Id" field. + * See documentation: ... */ @Inherited @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/eu/koboo/en2do/repository/entity/compound/CompoundIndex.java b/src/main/java/eu/koboo/en2do/repository/entity/compound/CompoundIndex.java index 3915b2c0..d8118146 100644 --- a/src/main/java/eu/koboo/en2do/repository/entity/compound/CompoundIndex.java +++ b/src/main/java/eu/koboo/en2do/repository/entity/compound/CompoundIndex.java @@ -2,13 +2,27 @@ import java.lang.annotation.*; +/** + * This annotation is used to create new indexes for the repository. + * If the CompoundIndex is set as "uniqueIndex = true" and two documents contain the same + * values in indexed fields, an exception is thrown by mongodb-driver. + * See documentation: ... + */ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Repeatable(CompoundIndexArray.class) public @interface CompoundIndex { + /** + * An array of all indexed field in this compound index. + * @return The array with the index annotations. + */ Index[] value(); + /** + * Defines if the index array is unique. This speeds up the usage of queries on the indexed fields drastically. + * @return true, if the compound index is unique on every document. + */ boolean uniqueIndex() default false; } diff --git a/src/main/java/eu/koboo/en2do/repository/entity/compound/Index.java b/src/main/java/eu/koboo/en2do/repository/entity/compound/Index.java index d2b735c7..195f70b9 100644 --- a/src/main/java/eu/koboo/en2do/repository/entity/compound/Index.java +++ b/src/main/java/eu/koboo/en2do/repository/entity/compound/Index.java @@ -2,13 +2,25 @@ import java.lang.annotation.*; +/** + * This annotation is used to index the field by its name. + * See documentation: ... + */ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @Repeatable(CompoundIndex.class) public @interface Index { + /** + * Sets the name of the field, which should be used to index. + * @return The field name, which should be indexed. + */ String value(); + /** + * Sets the direction of the index. + * @return true, if the direction is ascending. false, if the direction is descending. + */ boolean ascending() default true; } diff --git a/src/main/java/eu/koboo/en2do/repository/entity/ttl/TTLIndex.java b/src/main/java/eu/koboo/en2do/repository/entity/ttl/TTLIndex.java index 135e0897..76e20ebd 100644 --- a/src/main/java/eu/koboo/en2do/repository/entity/ttl/TTLIndex.java +++ b/src/main/java/eu/koboo/en2do/repository/entity/ttl/TTLIndex.java @@ -15,9 +15,21 @@ @Repeatable(TTLIndexArray.class) public @interface TTLIndex { + /** + * Indicates, which field should be checked for the time-to-live index + * @return The name of the field in the entity + */ String value(); + /** + * Sets the amount of the time unit + * @return The amount of time + */ long ttl() default 0; + /** + * Sets the unit of the time-to-live index + * @return The unit of the ttl value + */ TimeUnit time() default TimeUnit.SECONDS; } diff --git a/src/main/java/eu/koboo/en2do/repository/methods/async/Async.java b/src/main/java/eu/koboo/en2do/repository/methods/async/Async.java index 3cf38163..bed891b2 100644 --- a/src/main/java/eu/koboo/en2do/repository/methods/async/Async.java +++ b/src/main/java/eu/koboo/en2do/repository/methods/async/Async.java @@ -5,8 +5,12 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * This annotation is used to mark a method as asynchronous. + * If this annotation is used, the method needs to return a CompletableFuture, + * with the type it normally returns. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Async { - -} +} \ No newline at end of file diff --git a/src/main/java/eu/koboo/en2do/repository/methods/sort/Sort.java b/src/main/java/eu/koboo/en2do/repository/methods/sort/Sort.java index 6f4b4381..92e5e73f 100644 --- a/src/main/java/eu/koboo/en2do/repository/methods/sort/Sort.java +++ b/src/main/java/eu/koboo/en2do/repository/methods/sort/Sort.java @@ -15,11 +15,6 @@ @FieldDefaults(level = AccessLevel.PRIVATE) public class Sort { - @Deprecated - public static Sort create() { - return of(); - } - /** * Use this method to create a new Sort object * diff --git a/src/main/java/eu/koboo/en2do/utility/DateUtils.java b/src/main/java/eu/koboo/en2do/utility/DateUtils.java index ddf68576..4df06120 100644 --- a/src/main/java/eu/koboo/en2do/utility/DateUtils.java +++ b/src/main/java/eu/koboo/en2do/utility/DateUtils.java @@ -84,15 +84,6 @@ public LocalDate dateToLocalDate(Date date, ZoneId zoneId) { return date.toInstant().atZone(zoneId).toLocalDate(); } - - public Date localDateToDate(LocalDate localDateTime) { - return localDateToDate(localDateTime, ZoneId.systemDefault()); - } - - public Date localDateToDate(LocalDate localDateTime, TimeZone timeZone) { - return localDateToDate(localDateTime, timeZone.toZoneId()); - } - public Date localDateToDate(LocalDate localDateTime, ZoneId zoneId) { return Date.from(localDateTime.atStartOfDay(zoneId).toInstant()); } diff --git a/src/main/java/eu/koboo/en2do/utility/GenericUtils.java b/src/main/java/eu/koboo/en2do/utility/GenericUtils.java index da6de4c7..88f0b162 100644 --- a/src/main/java/eu/koboo/en2do/utility/GenericUtils.java +++ b/src/main/java/eu/koboo/en2do/utility/GenericUtils.java @@ -13,12 +13,23 @@ @UtilityClass public class GenericUtils { + /** + * Gets the generic type of the return type from the given method + * @param method The method with the return type + * @return The class of the generic type + */ public Class getGenericTypeOfReturnType(Method method) { Type returnType = method.getGenericReturnType(); ParameterizedType type = (ParameterizedType) returnType; return (Class) type.getActualTypeArguments()[0]; } + /** + * Gets the generic type of the parameter at the given from the given method + * @param method The method with the parameter + * @param paramIndex The index of the parameter + * @return The class of the generic type of the parameter + */ public Class getGenericTypeOfParameter(Method method, int paramIndex) { Parameter parameter = method.getParameters()[paramIndex]; Type parameterType = parameter.getParameterizedType(); @@ -26,6 +37,12 @@ public Class getGenericTypeOfParameter(Method method, int paramIndex) { return (Class) type.getActualTypeArguments()[0]; } + /** + * Checks if class1 and class2 is not the same type + * @param class1 The first given class + * @param class2 The second given class + * @return true if class1 and class2 are not same type type + */ public boolean isNotTypeOf(Class class1, Class class2) { if (isBoolean(class1) && isBoolean(class2)) { return false; @@ -51,30 +68,65 @@ public boolean isNotTypeOf(Class class1, Class class2) { return !class1.isAssignableFrom(class2); } + /** + * Checks if the given class is a type of "boolean" + * @param clazz The class to check + * @return true, if the class is type boolean + */ private boolean isBoolean(Class clazz) { return clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(boolean.class); } + /** + * Checks if the given class is a type of "short" + * @param clazz The class to check + * @return true, if the class is type short + */ private boolean isShort(Class clazz) { return clazz.isAssignableFrom(Short.class) || clazz.isAssignableFrom(short.class); } + /** + * Checks if the given class is a type of "float" + * @param clazz The class to check + * @return true, if the class is type float + */ private boolean isFloat(Class clazz) { return clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(float.class); } + /** + * Checks if the given class is a type of "int" + * @param clazz The class to check + * @return true, if the class is type int + */ private boolean isInteger(Class clazz) { return clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(int.class); } + /** + * Checks if the given class is a type of "long" + * @param clazz The class to check + * @return true, if the class is type long + */ private boolean isLong(Class clazz) { return clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(long.class); } + /** + * Checks if the given class is a type of "double" + * @param clazz The class to check + * @return true, if the class is type double + */ private boolean isDouble(Class clazz) { return clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(double.class); } + /** + * Checks if the given class is a type of "char" + * @param clazz The class to check + * @return true, if the class is type char + */ private boolean isChar(Class clazz) { return clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(char.class); }