Skip to content

Commit

Permalink
added reverse lookup, better naming for connections
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Oct 27, 2023
1 parent 0156dd2 commit fab7667
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/nucleodb.app.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.nucleodb'
version = '1.7.5'
version = '1.7.6'

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/nucleodb.library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.nucleodb'
version = '1.9.5'
version = '1.9.6'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,46 +143,52 @@ public void createTopics() {
client.close();
}

public Set<Connection> get(DataEntry de){
public Set<Connection> getByFrom(DataEntry de){
Set<Connection> tmp = connections.get(de.getKey());
if(tmp!=null){
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}

public Set<Connection> getByLabel(DataEntry de, String label){
Set<Connection> tmp = connections.get(de.getKey()+label);
public Set<Connection> getByFromAndLabel(DataEntry from, String label){
Set<Connection> tmp = connections.get(from.getKey()+label);
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}

public Set<Connection> getByLabelTo(DataEntry de, String label, DataEntry toDe){
Set<Connection> tmp = connections.get(de.getKey()+toDe.getKey()+label);
public Set<Connection> getByFromAndLabelAndTo(DataEntry from, String label, DataEntry to){
Set<Connection> tmp = connections.get(from.getKey()+to.getKey()+label);
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}
public Set<Connection> getByTo(DataEntry de, DataEntry toDe){
Set<Connection> tmp = connections.get(de.getKey()+toDe.getKey());
public Set<Connection> getByFromAndTo(DataEntry from, DataEntry to){
Set<Connection> tmp = connections.get(from.getKey()+to.getKey());
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}

public Set<Connection> getReverseByLabelTo(DataEntry de, String label, DataEntry toDe){
public Set<Connection> getReverseByLabelAndTo(String label, DataEntry to){
Set<Connection> tmp = connectionsReverse.get(to.getKey()+label);
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}
public Set<Connection> getReverseByFromAndLabelAndTo(DataEntry de, String label, DataEntry toDe){
Set<Connection> tmp = connectionsReverse.get(de.getKey()+toDe.getKey()+label);
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
return null;
}
public Set<Connection> getReverseByTo(DataEntry de, DataEntry toDe){
Set<Connection> tmp = connectionsReverse.get(de.getKey()+toDe.getKey());
public Set<Connection> getReverseByFromAndTo(DataEntry from, DataEntry to){
Set<Connection> tmp = connectionsReverse.get(from.getKey()+to.getKey());
if(tmp!=null) {
return tmp.stream().map(c->c.clone()).collect(Collectors.toSet());
}
Expand Down Expand Up @@ -211,6 +217,7 @@ private void addConnection(Connection connection){
this.putConnectionInKey(connection.getFromKey()+connection.getLabel(), connection);
this.putConnectionInKey(connection.getFromKey()+connection.getToKey(), connection);
this.putConnectionInKey(connection.getFromKey()+connection.getToKey()+connection.getLabel(), connection);
this.putReverseConnectionInKey(connection.getToKey()+connection.getLabel(), connection);
this.putReverseConnectionInKey(connection.getToKey()+connection.getFromKey()+connection.getLabel(), connection);
this.putReverseConnectionInKey(connection.getToKey()+connection.getFromKey(), connection);
allConnections.add(connection);
Expand All @@ -234,6 +241,7 @@ private void removeConnection(Connection connection){
this.removeByKey(connection.getFromKey()+connection.getLabel(), connection);
this.removeByKey(connection.getFromKey()+connection.getToKey(), connection);
this.removeByKey(connection.getFromKey()+connection.getToKey()+connection.getLabel(), connection);
this.removeReverseByKey(connection.getToKey()+connection.getLabel(), connection);
this.removeReverseByKey(connection.getToKey()+connection.getFromKey()+connection.getLabel(), connection);
this.removeReverseByKey(connection.getToKey()+connection.getFromKey(), connection);

Expand Down
8 changes: 4 additions & 4 deletions testapps/src/main/java/com/nucleocore/test/AnimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void main(String[] args) throws IOException, InterruptedException
Optional<DataEntry> anime = nucleoDB.getTable("anime").get("name", "Kizumonogatari: Koyomi Vamp").stream().findFirst();
Optional<DataEntry> user = nucleoDB.getTable("user").get("name", "dave").stream().findFirst();
if(anime.isPresent()) {
Serializer.log(nucleoDB.getConnectionHandler().getByLabel(anime.get(), "ADMIN_USER"));
Serializer.log(nucleoDB.getConnectionHandler().getByFromAndLabel(anime.get(), "ADMIN_USER"));
}
if(user.isPresent()) {
try {
Expand All @@ -40,12 +40,12 @@ public static void main(String[] args) throws IOException, InterruptedException
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Serializer.log(nucleoDB.getConnectionHandler().getByLabel(user.get(), "WATCHING").stream().findFirst().get());
Optional<Connection> connectionOptional = nucleoDB.getConnectionHandler().getByLabel(user.get(), "WATCHING").stream().findFirst();
Serializer.log(nucleoDB.getConnectionHandler().getByFromAndLabel(user.get(), "WATCHING").stream().findFirst().get());
Optional<Connection> connectionOptional = nucleoDB.getConnectionHandler().getByFromAndLabel(user.get(), "WATCHING").stream().findFirst();
if(connectionOptional.isPresent()) {
nucleoDB.getConnectionHandler().deleteSync(connectionOptional.get());
}
connectionOptional = nucleoDB.getConnectionHandler().getByLabel(user.get(), "WATCHING").stream().findFirst();
connectionOptional = nucleoDB.getConnectionHandler().getByFromAndLabel(user.get(), "WATCHING").stream().findFirst();
if(connectionOptional.isPresent()) {
Serializer.log("connection failed to delete.");
Serializer.log(connectionOptional.get());
Expand Down

0 comments on commit fab7667

Please sign in to comment.