Skip to content

Commit 7106b00

Browse files
committed
feat: create implementation to duration
Signed-off-by: Otavio Santana <[email protected]>
1 parent db27abe commit 7106b00

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

jnosql-nosql-oracle/src/main/java/org/eclipse/jnosql/databases/oracle/communication/DefaultOracleNoSQLDocumentManager.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import jakarta.json.JsonValue;
2121
import jakarta.json.bind.Jsonb;
2222
import oracle.nosql.driver.NoSQLHandle;
23+
import oracle.nosql.driver.TimeToLive;
2324
import oracle.nosql.driver.ops.DeleteRequest;
2425
import oracle.nosql.driver.ops.GetRequest;
2526
import oracle.nosql.driver.ops.GetResult;
@@ -86,26 +87,17 @@ public String name() {
8687
@Override
8788
public DocumentEntity insert(DocumentEntity entity) {
8889
Objects.requireNonNull(entity, "entity is required");
89-
Map<String, Object> entityMap = new HashMap<>(entity.toMap());
90-
entityMap.put(ENTITY, entity.name());
91-
String id = entity.find(ID).map(Document::get)
92-
.map(Object::toString)
93-
.orElseGet(() -> UUID.randomUUID().toString());
94-
95-
MapValue mapValue = new MapValue().put(ORACLE_ID, id).put(ENTITY, entity.name());
96-
MapValue contentVal = mapValue.putFromJson("content", jsonB.toJson(entityMap),
97-
OPTIONS);
98-
PutRequest putRequest = new PutRequest()
99-
.setValue(contentVal)
100-
.setTableName(name());
101-
102-
serviceHandle.put(putRequest);
90+
put(entity, TimeToLive.DO_NOT_EXPIRE);
10391
return entity;
10492
}
10593

94+
10695
@Override
10796
public DocumentEntity insert(DocumentEntity entity, Duration ttl) {
108-
throw new UnsupportedOperationException("Oracle NoSQL database does not support TTL");
97+
Objects.requireNonNull(entity, "entity is required");
98+
Objects.requireNonNull(ttl, "ttl is required");
99+
put(entity, TimeToLive.ofHours(ttl.toHours()));
100+
return entity;
109101
}
110102

111103
@Override
@@ -117,7 +109,10 @@ public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities) {
117109

118110
@Override
119111
public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities, Duration ttl) {
120-
throw new UnsupportedOperationException("Oracle NoSQL database does not support TTL");
112+
Objects.requireNonNull(entities, "entities is required");
113+
Objects.requireNonNull(ttl, "ttl is required");
114+
StreamSupport.stream(entities.spliterator(), false).forEach(d -> insert(d, ttl));
115+
return entities;
121116
}
122117

123118
@Override
@@ -286,4 +281,23 @@ private List<DocumentEntity> executeSQL(String sql, List<FieldValue> params) {
286281
} while (!queryRequest.isDone());
287282
return entities;
288283
}
284+
285+
private void put(DocumentEntity entity, TimeToLive ttl) {
286+
Map<String, Object> entityMap = new HashMap<>(entity.toMap());
287+
entityMap.put(ENTITY, entity.name());
288+
String id = entity.find(ID).map(Document::get)
289+
.map(Object::toString)
290+
.orElseGet(() -> UUID.randomUUID().toString());
291+
292+
MapValue mapValue = new MapValue().put(ORACLE_ID, id).put(ENTITY, entity.name());
293+
MapValue contentVal = mapValue.putFromJson("content", jsonB.toJson(entityMap),
294+
OPTIONS);
295+
PutRequest putRequest = new PutRequest()
296+
.setValue(contentVal)
297+
.setTTL(ttl)
298+
.setTableName(name());
299+
300+
serviceHandle.put(putRequest);
301+
}
302+
289303
}

jnosql-nosql-oracle/src/main/java/org/eclipse/jnosql/databases/oracle/communication/NoSQLHandleConfigConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
import java.util.List;
2222
import java.util.function.Function;
23+
import java.util.logging.Logger;
2324

2425
enum NoSQLHandleConfigConfiguration implements Function<Settings, NoSQLHandleConfiguration> {
2526

2627
INSTANCE;
2728

29+
private static final Logger LOGGER = Logger.getLogger(NoSQLHandleConfigConfiguration.class.getName());
30+
2831
private static final String DEFAULT_HOST = "http://localhost:8080";
2932
private static final int DEFAULT_TABLE_READ_LIMITS = 25;
3033
private static final int DEFAULT_TABLE_WRITE_LIMITS = 25;
@@ -40,6 +43,9 @@ public NoSQLHandleConfiguration apply(Settings settings) {
4043

4144
DeploymentType deploymentType = settings.get(OracleNoSQLConfigurations.DEPLOYMENT.get())
4245
.map(Object::toString).map(DeploymentType::parse).orElse(DeploymentType.ON_PREMISES);
46+
47+
LOGGER.info("Connecting to Oracle NoSQL database at " + host + " using " + deploymentType + " deployment type");
48+
4349
NoSQLHandleConfig config = new NoSQLHandleConfig(host);
4450

4551
deploymentType.apply(settings).ifPresent(config::setAuthorizationProvider);

0 commit comments

Comments
 (0)