File tree Expand file tree Collapse file tree 6 files changed +94
-1
lines changed
java/org/eclipse/jnosql/databases/mongodb/communication
resources/META-INF/services
test/java/org/eclipse/jnosql/databases/mongodb/communication Expand file tree Collapse file tree 6 files changed +94
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
1212
1313- Include between query support at MongoDB
1414- Include Graph as Apache TinkerPop
15+ - Include UUID support to MongoDB
1516
1617=== Changed
1718
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2024 Contributors to the Eclipse Foundation
3+ * All rights reserved. This program and the accompanying materials
4+ * are made available under the terms of the Eclipse Public License v1.0
5+ * and Apache License v2.0 which accompanies this distribution.
6+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+ * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+ *
9+ * You may elect to redistribute this code under either of these licenses.
10+ *
11+ * Contributors:
12+ *
13+ * Otavio Santana
14+ */
15+ package org .eclipse .jnosql .databases .mongodb .communication ;
16+
17+ import org .eclipse .jnosql .communication .ValueReader ;
18+
19+ import java .util .UUID ;
20+
21+ public class UUIDValueReader implements ValueReader {
22+
23+ @ Override
24+ public boolean test (Class <?> type ) {
25+ return UUID .class .equals (type );
26+ }
27+
28+
29+ @ SuppressWarnings ("unchecked" )
30+ @ Override
31+ public <T > T read (Class <T > type , Object value ) {
32+ if (value instanceof UUID ) {
33+ return (T ) value ;
34+ }
35+ return null ;
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2024 Contributors to the Eclipse Foundation
3+ * All rights reserved. This program and the accompanying materials
4+ * are made available under the terms of the Eclipse Public License v1.0
5+ * and Apache License v2.0 which accompanies this distribution.
6+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+ * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+ *
9+ * You may elect to redistribute this code under either of these licenses.
10+ *
11+ * Contributors:
12+ *
13+ * Otavio Santana
14+ */
15+ package org .eclipse .jnosql .databases .mongodb .communication ;
16+
17+ import org .eclipse .jnosql .communication .ValueWriter ;
18+
19+ import java .util .Objects ;
20+ import java .util .UUID ;
21+
22+ public class UUIDValueWriter implements ValueWriter <UUID , String > {
23+
24+ @ Override
25+ public boolean test (Class <?> type ) {
26+ return UUID .class .equals (type );
27+ }
28+
29+
30+ @ Override
31+ public String write (UUID uuid ) {
32+ if (Objects .nonNull (uuid )) {
33+ return uuid .toString ();
34+ }
35+ return null ;
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 1- org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader
1+ org.eclipse.jnosql.databases.mongodb.communication.BinaryValueReader
2+ org.eclipse.jnosql.databases.mongodb.communication.UUIDValueReader
Original file line number Diff line number Diff line change 1+ org.eclipse.jnosql.databases.mongodb.communication.UUIDValueWriter
Original file line number Diff line number Diff line change @@ -607,6 +607,21 @@ void shouldUpdateNull(){
607607 });
608608 }
609609
610+ @ Test
611+ void shouldInsertUUID () {
612+ var entity = getEntity ();
613+ entity .add ("uuid" , UUID .randomUUID ());
614+ var documentEntity = entityManager .insert (entity );
615+ Optional <Element > uuid = documentEntity .find ("uuid" );
616+ SoftAssertions .assertSoftly (soft -> {
617+ soft .assertThat (uuid ).isPresent ();
618+ Element element = uuid .orElseThrow ();
619+ soft .assertThat (element .name ()).isEqualTo ("uuid" );
620+ soft .assertThat (element .get (UUID .class )).isInstanceOf (UUID .class );
621+ });
622+
623+ }
624+
610625
611626 private CommunicationEntity createDocumentList () {
612627 CommunicationEntity entity = CommunicationEntity .of ("AppointmentBook" );
You can’t perform that action at this time.
0 commit comments