Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
java-version: '23'
cache: "sbt"
- uses: sbt/setup-sbt@v1
- uses: actions/cache@v4
with:
path: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
java-version: '23'
cache: "sbt"
- uses: sbt/setup-sbt@v1
- uses: actions/cache@v4
with:
path: |
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "overflowdb2"
ThisBuild / organization := "io.appthreat"
ThisBuild / version := "1.0.1"
ThisBuild / scalaVersion := "3.5.2"
ThisBuild / version := "2.0.0"
ThisBuild / scalaVersion := "3.6.4"
publish / skip := true

lazy val core = project.in(file("core"))
Expand Down
104 changes: 54 additions & 50 deletions core/src/main/java/overflowdb/AdjacentNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,65 +35,69 @@ public class AdjacentNodes {
* getOffset(2 * kindOffset + 1) gets the length of the relevant slice in nodesWithEdgeProperties of the desired kindOffset (get the kindOffset from layout info)
*/
public int getOffset(int pos){
if(offsets instanceof byte[]){
return ((byte[]) offsets)[pos];
} else if(offsets instanceof short[]){
return ((short[]) offsets)[pos];
} else if (offsets instanceof int[]){
return ((int[]) offsets)[pos];
} else throw new RuntimeException("corrupt state: offsets of type " + offsets.getClass().getName());
return switch (offsets) {
case byte[] bytes -> bytes[pos];
case short[] shorts -> shorts[pos];
case int[] ints -> ints[pos];
case null, default -> {
assert offsets != null;
throw new RuntimeException("corrupt state: offsets of type " + offsets.getClass().getName());
}
};
}

/** Attempts to update AdjacentNodes in-place and return this; otherwise, create a new AdjacentNodes and return that.
* */
AdjacentNodes setOffset(int pos, int val){
if(offsets instanceof byte[]) {
if(val == (byte) val){
((byte[]) offsets)[pos] = (byte) val;
return this;
} else if (val == (short) val){
byte[] oldOffsets = (byte[]) offsets;
short[] newOffsets = new short[oldOffsets.length];
for(int i = 0; i < oldOffsets.length; i++){
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = (short) val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
} else {
byte[] oldOffsets = (byte[]) offsets;
int[] newOffsets = new int[oldOffsets.length];
for(int i = 0; i < oldOffsets.length; i++){
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
switch (offsets) {
case byte[] oldOffsets -> {
if (val == (byte) val) {
oldOffsets[pos] = (byte) val;
return this;
} else if (val == (short) val) {
short[] newOffsets = new short[oldOffsets.length];
for (int i = 0; i < oldOffsets.length; i++) {
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = (short) val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
} else {
int[] newOffsets = new int[oldOffsets.length];
for (int i = 0; i < oldOffsets.length; i++) {
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
}
}
case short[] oldOffsets -> {
if (val == (short) val) {
oldOffsets[pos] = (short) val;
return this;
} else {
int[] newOffsets = new int[oldOffsets.length];
for (int i = 0; i < oldOffsets.length; i++) {
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
}
}
case int[] ints -> {
ints[pos] = val;
return this;
}
default -> throw new RuntimeException("corrupt state: offsets of type " + offsets.getClass().getName());
}
} else if (offsets instanceof short[]){
if(val == (short) val){
((short[]) offsets)[pos] = (short) val;
return this;
} else {
short[] oldOffsets = (short[]) offsets;
int[] newOffsets = new int[oldOffsets.length];
for(int i = 0; i < oldOffsets.length; i++){
newOffsets[i] = oldOffsets[i];
}
newOffsets[pos] = val;
return new AdjacentNodes(nodesWithEdgeProperties, newOffsets);
}
} else if (offsets instanceof int[]){
((int[]) offsets)[pos] = val;
return this;
} else {
throw new RuntimeException("corrupt state: offsets of type " + offsets.getClass().getName());
}
}

public int offsetLengths(){
if(offsets instanceof int[]) return ((int[]) offsets).length;
else if (offsets instanceof short[]) return ((short[]) offsets).length;
else if (offsets instanceof byte[]) return ((byte[]) offsets).length;
else throw new RuntimeException();
return switch (offsets) {
case int[] ints -> ints.length;
case short[] shorts -> shorts.length;
case byte[] bytes -> bytes.length;
case null, default -> throw new RuntimeException();
};
}

}
40 changes: 18 additions & 22 deletions core/src/main/java/overflowdb/BatchedUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ public static AppliedDiff applyDiff(Graph graph, DiffOrBuilder diff, KeyPool key
}

public interface KeyPool {
public long next();
long next();
}

public interface DiffOrBuilder {
public int size();
int size();

Iterator<Change> iterator();
}

public interface ModificationListener {
public abstract void onAfterInitNewNode(Node node);
void onAfterInitNewNode(Node node);

public abstract void onAfterAddNewEdge(Edge edge);
void onAfterAddNewEdge(Edge edge);

public abstract void onBeforePropertyChange(Node node, String key);
void onBeforePropertyChange(Node node, String key);

public abstract void onAfterPropertyChange(Node node, String key, Object value);
void onAfterPropertyChange(Node node, String key, Object value);

public abstract void onBeforeRemoveNode(Node node);
void onBeforeRemoveNode(Node node);

public abstract void onBeforeRemoveEdge(Edge edge);
void onBeforeRemoveEdge(Edge edge);

public abstract void finish();
void finish();
}


Expand Down Expand Up @@ -144,9 +144,9 @@ public DiffGraphBuilder removeEdge(Edge edge) {

public static class AppliedDiff {
public DiffOrBuilder diffGraph;
private ModificationListener listener;
private int transitiveModifications;
private Graph graph;
private final ModificationListener listener;
private final int transitiveModifications;
private final Graph graph;

AppliedDiff(Graph graph, DiffOrBuilder diffGraph, ModificationListener listener, int transitiveModifications) {
this.graph = graph;
Expand Down Expand Up @@ -265,8 +265,8 @@ private Node mapDetached(DetachedNodeData detachedNode) {
} else {
linkedNode = graph.addNode(keyPool.next(), detachedNode.label());
}
} else if (linkedNode instanceof Long) {
linkedNode = graph.addNode(((Long) linkedNode).longValue(), detachedNode.label());
} else {
linkedNode = graph.addNode((Long) linkedNode, detachedNode.label());
}
detachedNode.setRefOrId(linkedNode);
deferredInitializers.addLast(detachedNode);
Expand All @@ -290,9 +290,8 @@ private void applyChange(Change change) {
if (change instanceof DetachedNodeData) {
mapDetached((DetachedNodeData) change);
drainDeferred();
} else if (change instanceof CreateEdge) {
} else if (change instanceof CreateEdge create) {
nChanges += 1;
CreateEdge create = (CreateEdge) change;
Node src = create.src instanceof DetachedNodeData ? mapDetached((DetachedNodeData) create.src) : (Node) create.src;
Node dst = create.dst instanceof DetachedNodeData ? mapDetached((DetachedNodeData) create.dst) : (Node) create.dst;
drainDeferred();
Expand All @@ -303,22 +302,19 @@ private void applyChange(Change change) {
} else {
src.addEdgeSilentInternal(create.label, dst, properties);
}
} else if (change instanceof RemoveEdge) {
} else if (change instanceof RemoveEdge remove) {
nChanges += 1;
RemoveEdge remove = (RemoveEdge) change;
if (listener != null)
listener.onBeforeRemoveEdge(remove.edge);
remove.edge.removeInternal();
} else if (change instanceof RemoveNode) {
} else if (change instanceof RemoveNode remove) {
nChanges += 1;
RemoveNode remove = (RemoveNode) change;
if (listener != null)
listener.onBeforeRemoveNode(remove.node);
remove.node.removeInternal();

} else if (change instanceof SetNodeProperty) {
} else if (change instanceof SetNodeProperty setProp) {
nChanges += 1;
SetNodeProperty setProp = (SetNodeProperty) change;
if (listener != null)
listener.onBeforePropertyChange(setProp.node, setProp.label);
setProp.node.setPropertyInternal(setProp.label, setProp.value);
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/overflowdb/DetachedNodeData.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package overflowdb;

import overflowdb.BatchedUpdate;
import overflowdb.Node;

public interface DetachedNodeData extends BatchedUpdate.Change, NodeOrDetachedNode {
public String label();
String label();
/** RefOrId is initially null, and can be a Long if a specific id is required,
* and is set to Node once the node has been added to the graph.
* */
public Object getRefOrId();
public void setRefOrId(Object refOrId);
Object getRefOrId();
void setRefOrId(Object refOrId);
}
14 changes: 8 additions & 6 deletions core/src/main/java/overflowdb/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public <A> A property(String key, A defaultValue) {
}

public <A> A property(PropertyKey<A> key, A defaultValue) {
Object value = property(key);
return value != null ? (A) value : defaultValue;
A value = property(key);
return value != null ? value : defaultValue;
}

/** override this in specific element class, to define a default value */
Expand All @@ -38,8 +38,9 @@ public Object propertyDefaultValue(String propertyKey) {
public abstract Map<String, Object> propertiesMap();


@Deprecated public final void setProperty(String key, Object value) {setPropertyImpl(key, value);};
protected abstract void setPropertyImpl(String key, Object value);
@Deprecated public final void setProperty(String key, Object value) {setPropertyImpl(key, value);}

protected abstract void setPropertyImpl(String key, Object value);
final void setPropertyInternal(String key, Object value) {setPropertyImpl(key, value);}

@Deprecated public final <A> void setProperty(PropertyKey<A> key, A value){setPropertyImpl(key, value);}
Expand All @@ -57,8 +58,9 @@ public Object propertyDefaultValue(String propertyKey) {
final void removePropertyInternal(String key){removePropertyImpl(key);}


@Deprecated public final void remove(){removeImpl();};
@Deprecated public final void remove(){removeImpl();}

protected abstract void removeImpl();
final void removeInternal(){removeImpl();};
final void removeInternal(){removeImpl();}

}
Loading