Skip to content

Commit

Permalink
Merge pull request #8 from Koboo/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Koboo authored Jan 29, 2023
2 parents c0959c1 + 14619ea commit 3dfd19b
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 51 deletions.
13 changes: 2 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@ test {
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withJavadocJar()
withSourcesJar()
}

tasks.withType(JavaCompile).configureEach {
options.fork = true
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 {
Expand All @@ -66,8 +59,6 @@ publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
}
}
Expand Down
Binary file removed gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions src/main/java/eu/koboo/en2do/internal/MethodCallable.java
Original file line number Diff line number Diff line change
@@ -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;
}
23 changes: 21 additions & 2 deletions src/main/java/eu/koboo/en2do/internal/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,17 +21,35 @@
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) {
return null;
}
}

public static <E, ID, R extends Repository<E, ID>> 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 <E> The generic type of the entity
* @param <ID> The generic type of the id of the entity
* @param <R> The generic type of the repository
* @throws Exception if type class is not valid.
*/
public <E, ID, R extends Repository<E, ID>> void validateCompatibility(
Class<R> repositoryClass, Class<?> typeClass) throws Exception {
if (typeClass == null) {
throw new RuntimeException("Class for validation is null! Please open an issue on github!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class> {

/**
* 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public Map<K, T> 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<K, T> getInstance() {
if (encoderClass.isInterface()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>, 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)) {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

import java.lang.reflect.Method;

/**
* This class is a representation of a predefined method from the repository
* @param <E> The generic type of the entity
* @param <ID> The generic type of the id of the entity
* @param <R> The generic type of the repository
*/
@FieldDefaults(level = AccessLevel.PROTECTED, makeFinal = true)
@RequiredArgsConstructor
public abstract class PredefinedMethod<E, ID, R extends Repository<E, ID>> {
Expand All @@ -19,5 +25,12 @@ public abstract class PredefinedMethod<E, ID, R extends Repository<E, ID>> {
RepositoryMeta<E, ID, R> repositoryMeta;
MongoCollection<E> 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;
}
36 changes: 23 additions & 13 deletions src/main/java/eu/koboo/en2do/repository/AsyncRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,104 +20,114 @@ public interface AsyncRepository<E, ID> {

/**
* Async representation
*
* @see Repository#countAll()
* @return Future, with the count of all entities
*/
@Async
CompletableFuture<Long> asyncCountAll();

/**
* Async representation
*
* @see Repository#delete(Object)
* @param entity The entity, which should be deleted
* @return Future, with a boolean of success
*/
@Async
CompletableFuture<Boolean> 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<Boolean> asyncDeleteAll(List<E> 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<Boolean> asyncDeleteById(ID identifier);

/**
* Async representation
*
* @see Repository#drop()
* @return Future, with a boolean of success
*/
@Async
CompletableFuture<Boolean> 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<Boolean> 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<Boolean> asyncExistsById(ID identifier);

/**
* Async representation
*
* @see Repository#findAll()
* @return Future, with all entities
*/
@Async
CompletableFuture<List<E>> 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<E> 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<List<E>> 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<Boolean> 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<Boolean> asyncSaveAll(List<E> 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<List<E>> asyncSortAll(Sort sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* This annotation disables the creating of the unique index of the "@Id" field.
* See documentation: <a href="https://koboo.gitbook.io/en2do/usage/index/identifier-index">...</a>
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Loading

0 comments on commit 3dfd19b

Please sign in to comment.