Skip to content

Enums stopped to be supported as repository method parameters #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
- Update OrientDB driver to 3.2.36
- Update Couchbase client 3.7.6
- Update DynamoDB driver 2.29.45
- Update ArangoDb driver to 7.17.0

=== Fixed

Expand Down
2 changes: 1 addition & 1 deletion jnosql-arangodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<description>The Eclipse JNoSQL layer to ArangoDB</description>

<properties>
<arango.driver>7.16.0</arango.driver>
<arango.driver>7.17.0</arango.driver>

</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2025 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.databases.arangodb.integration;


import jakarta.inject.Inject;
import org.assertj.core.api.SoftAssertions;
import org.eclipse.jnosql.databases.arangodb.communication.ArangoDBConfigurations;
import org.eclipse.jnosql.mapping.Database;
import org.eclipse.jnosql.mapping.core.Converters;
import org.eclipse.jnosql.mapping.core.config.MappingConfigurations;
import org.eclipse.jnosql.mapping.core.spi.EntityMetadataExtension;
import org.eclipse.jnosql.mapping.document.DocumentTemplate;
import org.eclipse.jnosql.mapping.document.spi.DocumentExtension;
import org.eclipse.jnosql.mapping.reflection.Reflections;
import org.eclipse.jnosql.mapping.semistructured.EntityConverter;
import org.jboss.weld.junit5.auto.AddExtensions;
import org.jboss.weld.junit5.auto.AddPackages;
import org.jboss.weld.junit5.auto.EnableAutoWeld;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;

import java.util.List;
import java.util.function.Predicate;

import static org.eclipse.jnosql.communication.driver.IntegrationTest.MATCHES;
import static org.eclipse.jnosql.communication.driver.IntegrationTest.NAMED;
import static org.eclipse.jnosql.databases.arangodb.communication.DocumentDatabase.INSTANCE;

@EnableAutoWeld
@AddPackages(value = {Database.class, EntityConverter.class, DocumentTemplate.class})
@AddPackages(Magazine.class)
@AddExtensions({EntityMetadataExtension.class,
DocumentExtension.class})
@AddPackages(Reflections.class)
@AddPackages(Converters.class)
@EnabledIfSystemProperty(named = NAMED, matches = MATCHES)
public class ArangoDBEnumIntegrationTest {


static {
INSTANCE.get("library");
System.setProperty(ArangoDBConfigurations.HOST.get() + ".1", INSTANCE.host());
System.setProperty(MappingConfigurations.DOCUMENT_DATABASE.get(), "library");
}

@Inject
private DocumentTemplate template;


@Inject
private MailTemplateRepository repository;

@Test
void shouldCreateAndQueryByEnumAndDefaultTrue() {
template.insert(MailTemplate.builder()
.category(MailCategory.TIMER)
.from("otavio@email.com")
.to("mateusz@email.com")
.isDefault(true)
.build());

List<MailTemplate> result = template.select(MailTemplate.class) .where("category")
.eq(MailCategory.TIMER).result();

SoftAssertions.assertSoftly(soft -> {
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER);
Predicate<MailTemplate> isTrue = m -> m.isDefault();
soft.assertThat(result).allMatch(isTimer.and(isTrue));
});
}

@Test
void shouldCreateAndQueryByEnumAndDefaultFalse() {
var emailTemplate = MailTemplate.builder()
.category(MailCategory.TRANSITION_ALTERNATIVE)
.from("otavio@email.com")
.to("mateusz@email.com")
.isDefault(false)
.build();

template.insert(emailTemplate);

List<MailTemplate> result = template.select(MailTemplate.class)
.where("category")
.eq(MailCategory.TRANSITION_ALTERNATIVE)
.and("isDefault")
.eq(false).result();

SoftAssertions.assertSoftly(soft -> {
Predicate<MailTemplate> isAlternative = m -> m.getCategory().equals(MailCategory.TRANSITION_ALTERNATIVE);
Predicate<MailTemplate> isFalse = m -> !m.isDefault();
soft.assertThat(result).hasSize(1).allMatch(
isAlternative.and(isFalse));
});
}

@Test
void shouldQueryUsingRepository() {
repository.save(MailTemplate.builder()
.category(MailCategory.TIMER)
.from("otavio@email.com")
.to("mateusz@email.com")
.isDefault(true)
.build());

repository.save(MailTemplate.builder()
.category(MailCategory.TRANSITION_ALTERNATIVE)
.from("otavio@email.com")
.to("mateusz@email.com")
.isDefault(true)
.build());

List<MailTemplate> categoryAndIsDefaultTrue = repository.findByCategoryAndIsDefaultTrue(MailCategory.TIMER);

SoftAssertions.assertSoftly(soft -> {
Predicate<MailTemplate> isTimer = m -> m.getCategory().equals(MailCategory.TIMER);
Predicate<MailTemplate> isTrue = m -> m.isDefault();
soft.assertThat(categoryAndIsDefaultTrue).hasSize(1).allMatch(
isTimer.and(isTrue));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2025 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.databases.arangodb.integration;

public enum MailCategory {
TIMER,
TRANSITION_MAIN,
TRANSITION_ALTERNATIVE,
TRANSITION_FALLBACK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2025 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.databases.arangodb.integration;

import jakarta.nosql.Column;
import jakarta.nosql.Entity;
import jakarta.nosql.Id;

import java.util.Objects;
import java.util.UUID;

@Entity
public class MailTemplate {

@Id
private String id;

@Column
private String to;

@Column
private String from;

@Column
private MailCategory category;

@Column
private boolean isDefault;

public String getId() {
return id;
}

public String getTo() {
return to;
}

public String getFrom() {
return from;
}

public MailCategory getCategory() {
return category;
}

public boolean isDefault() {
return isDefault;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
MailTemplate that = (MailTemplate) o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hashCode(id);
}

@Override
public String toString() {
return "MailTemplate{" +
"id=" + id +
", to='" + to + '\'' +
", from='" + from + '\'' +
", category=" + category +
", isDefault=" + isDefault +
'}';
}

public static MailTemplateBuilder builder(){
return new MailTemplateBuilder();
}


public static class MailTemplateBuilder{

private String to;

private String from;

private MailCategory category;

private boolean isDefault;

public MailTemplateBuilder to(String to) {
this.to = to;
return this;
}

public MailTemplateBuilder from(String from) {
this.from = from;
return this;
}

public MailTemplateBuilder category(MailCategory category) {
this.category = category;
return this;
}

public MailTemplateBuilder isDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}

public MailTemplate build(){
MailTemplate mailTemplate = new MailTemplate();
mailTemplate.id = UUID.randomUUID().toString();
mailTemplate.to = this.to;
mailTemplate.from = this.from;
mailTemplate.category = this.category;
mailTemplate.isDefault = this.isDefault;
return mailTemplate;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2025 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.databases.arangodb.integration;

import jakarta.data.repository.Repository;
import org.eclipse.jnosql.mapping.NoSQLRepository;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@Repository
public interface MailTemplateRepository extends NoSQLRepository<MailTemplate, String> {

List<MailTemplate> findByCategoryAndIsDefaultTrue(@NotNull MailCategory mailCategory);
}