Skip to content

Commit

Permalink
add connections between entries
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Oct 3, 2023
1 parent 6ea45a2 commit 0f3a185
Show file tree
Hide file tree
Showing 14 changed files with 1,364 additions and 255 deletions.
472 changes: 248 additions & 224 deletions library/src/main/java/com/nucleocore/library/NucleoDB.java

Large diffs are not rendered by default.

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;
}
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.nucleocore.library.database.utils;

import com.nucleocore.library.database.modifications.Create;
import com.nucleocore.library.database.modifications.Delete;
import com.nucleocore.library.database.modifications.Update;
package com.nucleocore.library.database.modifications;

public enum Modification {
DELETE(Delete.class),
UPDATE(Update.class),
CREATE(Create.class);
CREATE(Create.class),

CONNECTIONCREATE(ConnectionCreate.class),
CONNECTIONDELETE(ConnectionDelete.class),
CONNECTIONUPDATE(ConnectionUpdate.class);

private final Class modification;
Modification(Class modification){
this.modification = modification;
Expand Down
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());
}
}
Loading

0 comments on commit 0f3a185

Please sign in to comment.