-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create jnosql oracle based on redis
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
78eeed3
commit 19a23af
Showing
45 changed files
with
4,093 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2022 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 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.jnosql.databases</groupId> | ||
<artifactId>jnosql-databases-parent</artifactId> | ||
<version>1.0.5-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jnosql-redis</artifactId> | ||
<description>The Eclipse JNoSQL layer implementation Redis</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jnosql.communication</groupId> | ||
<artifactId>jnosql-communication-key-value</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jnosql.mapping</groupId> | ||
<artifactId>jnosql-mapping-key-value</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
<version>5.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jnosql-database-commons</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
79 changes: 79 additions & 0 deletions
79
jnosql-oracle/src/main/java/org/eclipse/jnosql/databases/redis/communication/Counter.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,79 @@ | ||
/* | ||
* Copyright (c) 2022 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.redis.communication; | ||
|
||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* The redis counter structure | ||
*/ | ||
public interface Counter { | ||
|
||
/** | ||
* @return The counter value | ||
*/ | ||
Number get(); | ||
|
||
/** | ||
* Increments by one the counter | ||
* | ||
* @return the increment by one result | ||
*/ | ||
Number increment(); | ||
|
||
/** | ||
* Increments the counter | ||
* | ||
* @param value the value to be increased | ||
* @return the increment result | ||
* @throws NullPointerException when value is null | ||
*/ | ||
Number increment(Number value) throws NullPointerException; | ||
|
||
/** | ||
* Decrements by one the counter | ||
* | ||
* @return the increment by one result | ||
*/ | ||
Number decrement(); | ||
|
||
/** | ||
* Decrements | ||
* | ||
* @param value the value to be decreased | ||
* @return the decrement result | ||
*/ | ||
Number decrement(Number value); | ||
|
||
/** | ||
* Delete this Counter | ||
*/ | ||
void delete(); | ||
|
||
|
||
/** | ||
* Defines a ttl to SortedSet | ||
* | ||
* @param ttl the ttl | ||
* @throws NullPointerException when either key and ttl are null | ||
*/ | ||
void expire(Duration ttl) throws NullPointerException; | ||
|
||
/** | ||
* Removes the ttl | ||
*/ | ||
void persist(); | ||
} |
112 changes: 112 additions & 0 deletions
112
...oracle/src/main/java/org/eclipse/jnosql/databases/redis/communication/DefaultCounter.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,112 @@ | ||
/* | ||
* Copyright (c) 2022 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.redis.communication; | ||
|
||
import redis.clients.jedis.Jedis; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
|
||
/** | ||
* The default {@link Counter} | ||
*/ | ||
class DefaultCounter implements Counter { | ||
|
||
private static final Predicate<String> IS_EMPTY = String::isEmpty; | ||
private static final Predicate<String> IS_NOT_EMPTY = IS_EMPTY.negate(); | ||
|
||
private final String key; | ||
|
||
private Jedis jedis; | ||
|
||
DefaultCounter(String key, Jedis jedis) { | ||
this.key = key; | ||
this.jedis = jedis; | ||
} | ||
|
||
|
||
@Override | ||
public Number get() { | ||
return Optional.ofNullable(jedis.get(key)) | ||
.filter(IS_NOT_EMPTY) | ||
.map(Double::valueOf) | ||
.orElse(0D); | ||
} | ||
|
||
@Override | ||
public Number increment() { | ||
return increment(1); | ||
} | ||
|
||
@Override | ||
public Number increment(Number value) throws NullPointerException { | ||
Objects.requireNonNull(value, "value is required"); | ||
return jedis.incrByFloat(key, value.doubleValue()); | ||
} | ||
|
||
@Override | ||
public Number decrement() { | ||
return increment(-1); | ||
} | ||
|
||
@Override | ||
public Number decrement(Number value) { | ||
Objects.requireNonNull(value, "value is required"); | ||
return jedis.incrByFloat(key, -value.doubleValue()); | ||
} | ||
|
||
@Override | ||
public void delete() { | ||
jedis.del(key); | ||
} | ||
|
||
@Override | ||
public void expire(Duration ttl) throws NullPointerException { | ||
Objects.requireNonNull(ttl, "ttl is required"); | ||
jedis.expire(key, (int) ttl.getSeconds()); | ||
} | ||
|
||
@Override | ||
public void persist() { | ||
jedis.persist(key); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof DefaultCounter that)) { | ||
return false; | ||
} | ||
return Objects.equals(key, that.key); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(key); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("Counter{"); | ||
sb.append("key='").append(key).append('\''); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...oracle/src/main/java/org/eclipse/jnosql/databases/redis/communication/DefaultRanking.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,66 @@ | ||
/* | ||
* Copyright (c) 2022 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.redis.communication; | ||
|
||
import java.util.Objects; | ||
|
||
class DefaultRanking implements Ranking { | ||
|
||
private final Number point; | ||
|
||
private final String member; | ||
|
||
DefaultRanking(String member, Number point) { | ||
this.point = Objects.requireNonNull(point, "point is required"); | ||
this.member = Objects.requireNonNull(member, "member is required"); | ||
} | ||
|
||
@Override | ||
public Number getPoints() { | ||
return point; | ||
} | ||
|
||
@Override | ||
public String getMember() { | ||
return member; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof Ranking that)) { | ||
return false; | ||
} | ||
return Objects.equals(point, that.getPoints()) && | ||
Objects.equals(member, that.getMember()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(point, member); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("DefaultRanking{"); | ||
sb.append("point=").append(point); | ||
sb.append(", member='").append(member).append('\''); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.