diff --git a/buildSrc/src/main/groovy/nucleodb.app.gradle b/buildSrc/src/main/groovy/nucleodb.app.gradle index e0d8ff6..9a4c47c 100644 --- a/buildSrc/src/main/groovy/nucleodb.app.gradle +++ b/buildSrc/src/main/groovy/nucleodb.app.gradle @@ -3,7 +3,7 @@ plugins { } group = 'com.nucleodb' -version = '1.7.5' +version = '1.7.6' repositories { mavenCentral() diff --git a/buildSrc/src/main/groovy/nucleodb.library.gradle b/buildSrc/src/main/groovy/nucleodb.library.gradle index a26dc04..2b5032e 100644 --- a/buildSrc/src/main/groovy/nucleodb.library.gradle +++ b/buildSrc/src/main/groovy/nucleodb.library.gradle @@ -3,7 +3,7 @@ plugins { } group = 'com.nucleodb' -version = '1.9.5' +version = '1.9.6' repositories { mavenCentral() diff --git a/library/src/main/java/com/nucleocore/library/database/tables/ConnectionHandler.java b/library/src/main/java/com/nucleocore/library/database/tables/ConnectionHandler.java index e1bd92e..a0cd887 100644 --- a/library/src/main/java/com/nucleocore/library/database/tables/ConnectionHandler.java +++ b/library/src/main/java/com/nucleocore/library/database/tables/ConnectionHandler.java @@ -143,7 +143,7 @@ public void createTopics() { client.close(); } - public Set get(DataEntry de){ + public Set getByFrom(DataEntry de){ Set tmp = connections.get(de.getKey()); if(tmp!=null){ return tmp.stream().map(c->c.clone()).collect(Collectors.toSet()); @@ -151,38 +151,44 @@ public Set get(DataEntry de){ return null; } - public Set getByLabel(DataEntry de, String label){ - Set tmp = connections.get(de.getKey()+label); + public Set getByFromAndLabel(DataEntry from, String label){ + Set tmp = connections.get(from.getKey()+label); if(tmp!=null) { return tmp.stream().map(c->c.clone()).collect(Collectors.toSet()); } return null; } - public Set getByLabelTo(DataEntry de, String label, DataEntry toDe){ - Set tmp = connections.get(de.getKey()+toDe.getKey()+label); + public Set getByFromAndLabelAndTo(DataEntry from, String label, DataEntry to){ + Set 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 getByTo(DataEntry de, DataEntry toDe){ - Set tmp = connections.get(de.getKey()+toDe.getKey()); + public Set getByFromAndTo(DataEntry from, DataEntry to){ + Set tmp = connections.get(from.getKey()+to.getKey()); if(tmp!=null) { return tmp.stream().map(c->c.clone()).collect(Collectors.toSet()); } return null; } - - public Set getReverseByLabelTo(DataEntry de, String label, DataEntry toDe){ + public Set getReverseByLabelAndTo(String label, DataEntry to){ + Set tmp = connectionsReverse.get(to.getKey()+label); + if(tmp!=null) { + return tmp.stream().map(c->c.clone()).collect(Collectors.toSet()); + } + return null; + } + public Set getReverseByFromAndLabelAndTo(DataEntry de, String label, DataEntry toDe){ Set 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 getReverseByTo(DataEntry de, DataEntry toDe){ - Set tmp = connectionsReverse.get(de.getKey()+toDe.getKey()); + public Set getReverseByFromAndTo(DataEntry from, DataEntry to){ + Set tmp = connectionsReverse.get(from.getKey()+to.getKey()); if(tmp!=null) { return tmp.stream().map(c->c.clone()).collect(Collectors.toSet()); } @@ -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); @@ -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); diff --git a/testapps/src/main/java/com/nucleocore/test/AnimeTest.java b/testapps/src/main/java/com/nucleocore/test/AnimeTest.java index 8589473..1787949 100644 --- a/testapps/src/main/java/com/nucleocore/test/AnimeTest.java +++ b/testapps/src/main/java/com/nucleocore/test/AnimeTest.java @@ -28,7 +28,7 @@ public static void main(String[] args) throws IOException, InterruptedException Optional anime = nucleoDB.getTable("anime").get("name", "Kizumonogatari: Koyomi Vamp").stream().findFirst(); Optional 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 { @@ -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 connectionOptional = nucleoDB.getConnectionHandler().getByLabel(user.get(), "WATCHING").stream().findFirst(); + Serializer.log(nucleoDB.getConnectionHandler().getByFromAndLabel(user.get(), "WATCHING").stream().findFirst().get()); + Optional 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());