-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
1,364 additions
and
255 deletions.
There are no files selected for viewing
472 changes: 248 additions & 224 deletions
472
library/src/main/java/com/nucleocore/library/NucleoDB.java
Large diffs are not rendered by default.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
library/src/main/java/com/nucleocore/library/database/modifications/ConnectionCreate.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,60 @@ | ||
package com.nucleocore.library.database.modifications; | ||
|
||
import com.nucleocore.library.database.tables.Connection; | ||
import com.nucleocore.library.database.utils.DataEntry; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public class ConnectionCreate extends Modify { | ||
public Connection connection; | ||
|
||
public long version; | ||
public Instant time; | ||
public String changeUUID = UUID.randomUUID().toString(); | ||
|
||
public ConnectionCreate() { | ||
} | ||
|
||
public ConnectionCreate(Connection connection) throws IOException { | ||
this.connection = connection; | ||
} | ||
|
||
public ConnectionCreate(String changeUUID, Connection connection) { | ||
this.connection = connection; | ||
this.changeUUID = changeUUID; | ||
} | ||
|
||
public Connection getConnection() { | ||
return connection; | ||
} | ||
|
||
public void setConnection(Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(long version) { | ||
this.version = version; | ||
} | ||
|
||
public Instant getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(Instant time) { | ||
this.time = time; | ||
} | ||
|
||
public String getChangeUUID() { | ||
return changeUUID; | ||
} | ||
|
||
public void setChangeUUID(String changeUUID) { | ||
this.changeUUID = changeUUID; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
library/src/main/java/com/nucleocore/library/database/modifications/ConnectionDelete.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,61 @@ | ||
package com.nucleocore.library.database.modifications; | ||
|
||
import com.nucleocore.library.database.tables.Connection; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
|
||
public class ConnectionDelete extends Modify { | ||
public long version; | ||
public Instant time; | ||
public String uuid; | ||
public String changeUUID = UUID.randomUUID().toString(); | ||
|
||
public ConnectionDelete() { | ||
} | ||
|
||
public ConnectionDelete(Connection connection) throws IOException { | ||
this.uuid = connection.getUuid(); | ||
} | ||
public ConnectionDelete(String changeUUID, Connection connection) throws IOException { | ||
this.uuid = connection.getUuid(); | ||
this.changeUUID = changeUUID; | ||
} | ||
|
||
public ConnectionDelete(String uuid) throws IOException { | ||
this.uuid = uuid; | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(long version) { | ||
this.version = version; | ||
} | ||
|
||
public Instant getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(Instant time) { | ||
this.time = time; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public String getChangeUUID() { | ||
return changeUUID; | ||
} | ||
|
||
public void setChangeUUID(String changeUUID) { | ||
this.changeUUID = changeUUID; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
library/src/main/java/com/nucleocore/library/database/modifications/ConnectionUpdate.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,97 @@ | ||
package com.nucleocore.library.database.modifications; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.github.fge.jsonpatch.JsonPatch; | ||
import com.nucleocore.library.database.tables.Connection; | ||
import com.nucleocore.library.database.utils.JsonOperations; | ||
import com.nucleocore.library.database.utils.Serializer; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class ConnectionUpdate extends Modify{ | ||
public long version; | ||
public Instant time; | ||
public String changes; | ||
public String uuid; | ||
public String changeUUID = UUID.randomUUID().toString(); | ||
|
||
public ConnectionUpdate() throws IOException { | ||
|
||
} | ||
|
||
public ConnectionUpdate(String changes, String changeUUID, String uuid) { | ||
this.changes = changes; | ||
this.changeUUID = changeUUID; | ||
this.uuid = uuid; | ||
} | ||
|
||
public ConnectionUpdate(long version, Instant time, String changes, String uuid) { | ||
this.version = version; | ||
this.time = time; | ||
this.changes = changes; | ||
this.uuid = uuid; | ||
} | ||
|
||
@JsonIgnore | ||
public JsonPatch getChangesPatch() { | ||
try { | ||
return Serializer.getObjectMapper().getOm().readValue(changes, JsonPatch.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@JsonIgnore | ||
public List<JsonOperations> getOperations() { | ||
try { | ||
return Serializer.getObjectMapper().getOm().readValue(changes, new TypeReference<List<JsonOperations>>(){}); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(long version) { | ||
this.version = version; | ||
} | ||
|
||
public Instant getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(Instant time) { | ||
this.time = time; | ||
} | ||
|
||
public String getChanges() { | ||
return changes; | ||
} | ||
|
||
public void setChanges(String changes) { | ||
this.changes = changes; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public String getChangeUUID() { | ||
return changeUUID; | ||
} | ||
|
||
public void setChangeUUID(String changeUUID) { | ||
this.changeUUID = changeUUID; | ||
} | ||
} |
13 changes: 7 additions & 6 deletions
13
.../library/database/utils/Modification.java → .../database/modifications/Modification.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
138 changes: 138 additions & 0 deletions
138
library/src/main/java/com/nucleocore/library/database/tables/Connection.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,138 @@ | ||
package com.nucleocore.library.database.tables; | ||
|
||
import com.nucleocore.library.NucleoDB; | ||
import com.nucleocore.library.database.utils.DataEntry; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.UUID; | ||
|
||
public class Connection implements Serializable, Comparable<Connection>{ | ||
private static final long serialVersionUID = 1; | ||
|
||
private String uuid; | ||
|
||
private String fromKey; | ||
private String fromTable; | ||
private String toKey; | ||
private String toTable; | ||
private String label; | ||
|
||
public long version = 0; | ||
|
||
private Map<String, String> metadata = new TreeMap<>(); | ||
|
||
public Connection() { | ||
this.setUuid(UUID.randomUUID().toString()); | ||
} | ||
|
||
public Connection(DataEntry from, String label, DataEntry to) { | ||
this.setUuid(UUID.randomUUID().toString()); | ||
this.fromKey = from.getKey(); | ||
this.toKey = to.getKey(); | ||
this.label = label; | ||
this.toTable = to.getTableName(); | ||
this.fromTable = from.getTableName(); | ||
} | ||
|
||
public Connection(DataEntry from, String label, DataEntry to, Map<String, String> metadata) { | ||
this.setUuid(UUID.randomUUID().toString()); | ||
this.fromKey = from.getKey(); | ||
this.toKey = to.getKey(); | ||
this.label = label; | ||
this.metadata = metadata; | ||
this.toTable = to.getTableName(); | ||
this.fromTable = from.getTableName(); | ||
} | ||
|
||
public String getFromKey() { | ||
return fromKey; | ||
} | ||
|
||
public void setFromKey(String fromKey) { | ||
this.fromKey = fromKey; | ||
} | ||
|
||
public String getToKey() { | ||
return toKey; | ||
} | ||
|
||
public void setToKey(String toKey) { | ||
this.toKey = toKey; | ||
} | ||
|
||
public Map<String, String> getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(Map<String, String> metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(String uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getFromTable() { | ||
return fromTable; | ||
} | ||
|
||
public void setFromTable(String fromTable) { | ||
this.fromTable = fromTable; | ||
} | ||
|
||
public String getToTable() { | ||
return toTable; | ||
} | ||
|
||
public void setToTable(String toTable) { | ||
this.toTable = toTable; | ||
} | ||
|
||
public long getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(long version) { | ||
this.version = version; | ||
} | ||
|
||
public void versionIncrease(){ | ||
version+=1; | ||
} | ||
|
||
@Override | ||
protected Connection clone() { | ||
Connection clonedConnection = new Connection(); | ||
clonedConnection.uuid = this.uuid; | ||
clonedConnection.fromKey = this.fromKey; | ||
clonedConnection.fromTable = this.fromTable; | ||
clonedConnection.toKey = this.toKey; | ||
clonedConnection.toTable = this.toTable; | ||
clonedConnection.label = this.label; | ||
clonedConnection.version = this.version; | ||
clonedConnection.metadata = new TreeMap<>(this.metadata); // Create a copy of the metadata map | ||
|
||
return clonedConnection; | ||
} | ||
|
||
@Override | ||
public int compareTo(@NotNull Connection o) { | ||
return this.getUuid().compareTo(o.getUuid()); | ||
} | ||
} |
Oops, something went wrong.