-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
...java/org/eclipse/jnosql/databases/arangodb/communication/ArangoDBValueWriteDecorator.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,48 @@ | ||
/* | ||
* 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.arangodb.communication; | ||
|
||
import org.eclipse.jnosql.communication.ValueWriter; | ||
import org.eclipse.jnosql.communication.ValueWriterDecorator; | ||
|
||
import java.util.UUID; | ||
|
||
final class ArangoDBValueWriteDecorator<T, S> implements ValueWriter<T, S> { | ||
|
||
@SuppressWarnings("rawtypes") | ||
static final ValueWriter ARANGO_DB_VALUE_WRITER = new ArangoDBValueWriteDecorator(); | ||
|
||
@SuppressWarnings("rawtypes") | ||
private static final ValueWriter DEFAULT = ValueWriterDecorator.getInstance(); | ||
|
||
private static final UUIDValueWriter UUID_VALUE_WRITER = new UUIDValueWriter(); | ||
|
||
|
||
@Override | ||
public boolean test(Class<?> type) { | ||
return UUID_VALUE_WRITER.test(type) || DEFAULT.test(type); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public S write(T type) { | ||
if(type != null && UUID_VALUE_WRITER.test(type.getClass())) { | ||
return (S) UUID_VALUE_WRITER.write((UUID) type); | ||
} else { | ||
return (S) DEFAULT.write(type); | ||
} | ||
} | ||
|
||
} |
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
38 changes: 38 additions & 0 deletions
38
...db/src/main/java/org/eclipse/jnosql/databases/arangodb/communication/UUIDValueWriter.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,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.arangodb.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; | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
.../org/eclipse/jnosql/databases/arangodb/communication/ArangoDBValueWriteDecoratorTest.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,33 @@ | ||
/* | ||
* 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.arangodb.communication; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@SuppressWarnings("rawtypes") | ||
class ArangoDBValueWriteDecoratorTest { | ||
|
||
private final ArangoDBValueWriteDecorator<Object, String> valueWriter = new ArangoDBValueWriteDecorator<>(); | ||
|
||
@Test | ||
void shouldTestUUIDType() { | ||
assertTrue(valueWriter.test(UUID.class)); | ||
} | ||
|
||
} |
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