-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include document validation to person
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
2af7b0c
commit 40ec744
Showing
4 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
...src/main/java/org/eclipse/jnosql/mapping/document/query/CustomRepositoryDocumentBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.document.query; | ||
|
||
import jakarta.enterprise.context.spi.CreationalContext; | ||
import org.eclipse.jnosql.mapping.DatabaseQualifier; | ||
import org.eclipse.jnosql.mapping.DatabaseType; | ||
import org.eclipse.jnosql.mapping.core.Converters; | ||
import org.eclipse.jnosql.mapping.core.spi.AbstractBean; | ||
import org.eclipse.jnosql.mapping.core.util.AnnotationLiteralUtil; | ||
import org.eclipse.jnosql.mapping.document.DocumentTemplate; | ||
import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata; | ||
import org.eclipse.jnosql.mapping.semistructured.query.CustomRepositoryHandler; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Proxy; | ||
import java.lang.reflect.Type; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
|
||
/** | ||
* This class serves as a JNoSQL discovery bean for CDI extension, responsible for registering Custom Repository instances. | ||
* It extends {@link AbstractBean} and is parameterized with type {@code T} representing the repository type. | ||
* <p> | ||
* Upon instantiation, it initializes with the provided repository type, provider name, and qualifiers. | ||
* The provider name specifies the database provider for the repository. | ||
* </p> | ||
* | ||
* @param <T> the type of the repository | ||
* @see AbstractBean | ||
*/ | ||
public class CustomRepositoryDocumentBean<T> extends AbstractBean<T> { | ||
|
||
private final Class<T> type; | ||
|
||
private final Set<Type> types; | ||
|
||
private final String provider; | ||
|
||
private final Set<Annotation> qualifiers; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param type the tye | ||
* @param provider the provider name, that must be a | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public CustomRepositoryDocumentBean(Class<?> type, String provider) { | ||
this.type = (Class<T>) type; | ||
this.types = Collections.singleton(type); | ||
this.provider = provider; | ||
if (provider.isEmpty()) { | ||
this.qualifiers = new HashSet<>(); | ||
qualifiers.add(DatabaseQualifier.ofDocument()); | ||
qualifiers.add(AnnotationLiteralUtil.DEFAULT_ANNOTATION); | ||
qualifiers.add(AnnotationLiteralUtil.ANY_ANNOTATION); | ||
} else { | ||
this.qualifiers = Collections.singleton(DatabaseQualifier.ofDocument(provider)); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<?> getBeanClass() { | ||
return type; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public T create(CreationalContext<T> context) { | ||
var entities = getInstance(EntitiesMetadata.class); | ||
var template = provider.isEmpty() ? getInstance(DocumentTemplate.class) : | ||
getInstance(DocumentTemplate.class, DatabaseQualifier.ofDocument(provider)); | ||
|
||
var converters = getInstance(Converters.class); | ||
|
||
var handler = CustomRepositoryHandler.builder() | ||
.entitiesMetadata(entities) | ||
.template(template) | ||
.customRepositoryType(type) | ||
.converters(converters) | ||
.build(); | ||
|
||
return (T) Proxy.newProxyInstance(type.getClassLoader(), | ||
new Class[]{type}, | ||
handler); | ||
} | ||
|
||
|
||
@Override | ||
public Set<Type> getTypes() { | ||
return types; | ||
} | ||
|
||
@Override | ||
public Set<Annotation> getQualifiers() { | ||
return qualifiers; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return type.getName() + '@' + DatabaseType.DOCUMENT + "-" + provider; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters