Skip to content
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

Add UUID mongodb #284

Merged
merged 6 commits into from
Sep 3, 2024
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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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> T read(Class<T> type, Object value) {
if (value instanceof UUID) {
return (T) value;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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<UUID, String> {

@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;
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader
org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader
org.eclipse.jnosql.databases.mongodb.communication.UUIDValueReader
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.jnosql.databases.mongodb.communication.UUIDValueWriter
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,21 @@ void shouldUpdateNull(){
});
}

@Test
void shouldInsertUUID() {
var entity = getEntity();
entity.add("uuid", UUID.randomUUID());
var documentEntity = entityManager.insert(entity);
Optional<Element> 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");
Expand Down