From d115f0d8f0e8cdd02e3869d6cdf339f0e5ed41a2 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 18:44:08 +0100 Subject: [PATCH 1/6] feat: create UUIDValueReader Signed-off-by: Otavio Santana --- .../communication/UUIDValueReader.java | 37 +++++++++++++++++++ .../communication/UUIDValueWriter.java | 2 + ...g.eclipse.jnosql.communication.ValueWriter | 0 3 files changed, 39 insertions(+) create mode 100644 jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueReader.java create mode 100644 jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java create mode 100644 jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter diff --git a/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueReader.java b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueReader.java new file mode 100644 index 000000000..8c89a4629 --- /dev/null +++ b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueReader.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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.mongodb.communication; + +import org.eclipse.jnosql.communication.ValueReader; + +import java.util.UUID; + +public class UUIDValueReader implements ValueReader { + + @Override + public boolean test(Class type) { + return UUID.class.equals(type); + } + + + @SuppressWarnings("unchecked") + @Override + public T read(Class type, Object value) { + if (value instanceof UUID) { + return (T) value; + } + return null; + } +} diff --git a/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java new file mode 100644 index 000000000..7e4082428 --- /dev/null +++ b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java @@ -0,0 +1,2 @@ +package org.eclipse.jnosql.databases.mongodb.communication;public class UUIDValueWriter { +} diff --git a/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter b/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter new file mode 100644 index 000000000..e69de29bb From 63ac7588a12d36522596eb2a2e41502e2d621857 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 18:44:24 +0100 Subject: [PATCH 2/6] feat: create value writer Signed-off-by: Otavio Santana --- .../communication/UUIDValueWriter.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java index 7e4082428..40cdbd1ab 100644 --- a/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java +++ b/jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/UUIDValueWriter.java @@ -1,2 +1,38 @@ -package org.eclipse.jnosql.databases.mongodb.communication;public class UUIDValueWriter { +/* + * Copyright (c) 2024 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.mongodb.communication; + +import org.eclipse.jnosql.communication.ValueWriter; + +import java.util.Objects; +import java.util.UUID; + +public class UUIDValueWriter implements ValueWriter { + + @Override + public boolean test(Class type) { + return UUID.class.equals(type); + } + + + @Override + public String write(UUID uuid) { + if(Objects.nonNull(uuid)) { + return uuid.toString(); + } + return null; + } + } From 81b24081630a1ee0971a3c4552c2c5e196ff0519 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 18:44:45 +0100 Subject: [PATCH 3/6] feat: include valuereader to mongodb Signed-off-by: Otavio Santana --- .../services/org.eclipse.jnosql.communication.ValueReader | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueReader b/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueReader index 98dd20367..d76361057 100644 --- a/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueReader +++ b/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueReader @@ -1 +1,2 @@ -org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader \ No newline at end of file +org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader +org.eclipse.jnosql.databases.mongodb.communication.UUIDValueReader From d1d750e7a603b605715e4ef7bd32e30f3ecbeb00 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 18:45:01 +0100 Subject: [PATCH 4/6] chore: include configuration to valuewriter Signed-off-by: Otavio Santana --- .../services/org.eclipse.jnosql.communication.ValueWriter | 1 + 1 file changed, 1 insertion(+) diff --git a/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter b/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter index e69de29bb..1c499b074 100644 --- a/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter +++ b/jnosql-mongodb/src/main/resources/META-INF/services/org.eclipse.jnosql.communication.ValueWriter @@ -0,0 +1 @@ +org.eclipse.jnosql.databases.mongodb.communication.UUIDValueWriter From d8d2ac0438baa8e465d9b60c28b7aa6b14582c29 Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 19:00:17 +0100 Subject: [PATCH 5/6] test: create scenarios to mongodb Signed-off-by: Otavio Santana --- .../communication/MongoDBDocumentManagerTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManagerTest.java b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManagerTest.java index ec063a2b2..0d00df439 100644 --- a/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManagerTest.java +++ b/jnosql-mongodb/src/test/java/org/eclipse/jnosql/databases/mongodb/communication/MongoDBDocumentManagerTest.java @@ -607,6 +607,21 @@ void shouldUpdateNull(){ }); } + @Test + void shouldInsertUUID() { + var entity = getEntity(); + entity.add("uuid", UUID.randomUUID()); + var documentEntity = entityManager.insert(entity); + Optional uuid = documentEntity.find("uuid"); + SoftAssertions.assertSoftly(soft -> { + soft.assertThat(uuid).isPresent(); + Element element = uuid.orElseThrow(); + soft.assertThat(element.name()).isEqualTo("uuid"); + soft.assertThat(element.get(UUID.class)).isInstanceOf(UUID.class); + }); + + } + private CommunicationEntity createDocumentList() { CommunicationEntity entity = CommunicationEntity.of("AppointmentBook"); From bc053ed7628768d75a371b9218ebf75900013fbf Mon Sep 17 00:00:00 2001 From: Otavio Santana Date: Tue, 3 Sep 2024 20:37:55 +0100 Subject: [PATCH 6/6] docs: include changelog about mongodb Signed-off-by: Otavio Santana --- CHANGELOG.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index f1fbcc2ce..fa2395370 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version - Include between query support at MongoDB - Include Graph as Apache TinkerPop +- Include UUID support to MongoDB === Changed