Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
persistence refactoring
  • Loading branch information
rashtao committed Mar 3, 2025
commit 25db55018f95e2e854d35e10b2debdf7217a9db1
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public ArangoCursor<EdgeData> getGraphEdges(List<String> ids) {
return getGraphDocuments(ids, prefixedColNames, EdgeData.class);
}

private <T> ArangoCursor<T> getGraphDocuments(List<String> ids, List<String> prefixedColNames, Class<T> clazz) {
private <V> ArangoCursor<V> getGraphDocuments(List<String> ids, List<String> prefixedColNames, Class<V> clazz) {
Map<String, Object> bindVars = new HashMap<>();
ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder();
if (ids.isEmpty()) {
Expand Down Expand Up @@ -539,7 +539,7 @@ public ArangoGraph getArangoGraph() {
/**
* Execute AQL query.
*
* @param <T> the generic type of the returned values
* @param <V> the generic type of the returned values
* @param query the query string
* @param bindVars the value of the bind parameters
* @param aqlQueryOptions the aql query options
Expand All @@ -548,11 +548,11 @@ public ArangoGraph getArangoGraph() {
* @throws ArangoDBGraphException if executing the query raised an exception
*/

public <T> ArangoCursor<T> executeAqlQuery(
public <V> ArangoCursor<V> executeAqlQuery(
String query,
Map<String, Object> bindVars,
AqlQueryOptions aqlQueryOptions,
final Class<T> type)
final Class<V> type)
throws ArangoDBGraphException {
logger.debug("Executing AQL query ({}) against db, with bind vars: {}", query, bindVars);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public class ArangoDBGremlinPlugin extends AbstractGremlinPlugin {
ArangoDBGraphVariables.class,

// persistence
AbstractElementData.class,
PersistentData.class,
AdbValue.class,
EdgeData.class,
ElementData.class,
PropertyData.class,
VertexData.class,
VertexPropertyData.class
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
AdbValue that = (AdbValue) o;
return Objects.equals(value, that.value) && Objects.equals(valueType, that.valueType);
if (!(o instanceof AdbValue)) return false;
AdbValue adbValue = (AdbValue) o;
return Objects.equals(value, adbValue.value) && Objects.equals(valueType, adbValue.valueType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@

import java.util.*;

public class EdgeData extends AbstractElementData<AdbValue> {
public class EdgeData extends PersistentData<AdbValue> {

@InternalFrom
private String from;

@InternalTo
private String to;

private final Map<String, AdbValue> properties = new HashMap<>();

public EdgeData() {
}

Expand Down Expand Up @@ -64,25 +66,31 @@ public void setTo(String to) {
this.to = to;
}

@Override
public Map<String, AdbValue> getProperties() {
return properties;
}

@Override
public String toString() {
return "EdgeData{" +
"from='" + from + '\'' +
", to='" + to + '\'' +
", properties=" + properties +
", super=" + super.toString() +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof EdgeData)) return false;
if (!super.equals(o)) return false;
EdgeData that = (EdgeData) o;
return Objects.equals(from, that.from) && Objects.equals(to, that.to);
EdgeData edgeData = (EdgeData) o;
return Objects.equals(from, edgeData.from) && Objects.equals(to, edgeData.to) && Objects.equals(properties, edgeData.properties);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), from, to);
return Objects.hash(super.hashCode(), from, to, properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
import com.arangodb.serde.InternalKey;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public abstract class AbstractElementData<T> implements ElementData<T> {
public abstract class PersistentData<V> implements PropertyData<V> {

private String label;
@InternalKey
private String key;
private final Map<String, T> properties = new HashMap<>();

public AbstractElementData() {
public PersistentData() {
}

public AbstractElementData(String label, String key) {
public PersistentData(String label, String key) {
ElementHelper.validateLabel(label);
if (key != null && key.isEmpty()) throw new IllegalArgumentException("empty key");

Expand All @@ -56,30 +53,24 @@ public String getLabel() {
return label;
}

@Override
public Map<String, T> getProperties() {
return properties;
}

@Override
public String toString() {
return "AbstractElementData{" +
return "PersistentData{" +
"key='" + key + '\'' +
", label='" + label + '\'' +
", properties=" + properties +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
AbstractElementData<?> that = (AbstractElementData<?>) o;
return Objects.equals(key, that.key) && Objects.equals(label, that.label) && Objects.equals(properties, that.properties);
if (!(o instanceof PersistentData)) return false;
PersistentData<?> that = (PersistentData<?>) o;
return Objects.equals(label, that.label) && Objects.equals(key, that.key);
}

@Override
public int hashCode() {
return Objects.hash(key, label, properties);
return Objects.hash(label, key);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import java.util.Map;

public interface ElementData<T> {

Map<String, T> getProperties();

public interface PropertyData<P> {
Map<String, P> getProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

package com.arangodb.tinkerpop.gremlin.persistence;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class VertexData extends AbstractElementData<List<VertexPropertyData>> {
public class VertexData extends PersistentData<List<VertexPropertyData>> {

private final Map<String, List<VertexPropertyData>> properties = new HashMap<>();

public VertexData() {
}
Expand All @@ -30,10 +35,29 @@ public VertexData(String label, String key) {
super(label, key);
}

@Override
public Map<String, List<VertexPropertyData>> getProperties() {
return properties;
}

@Override
public String toString() {
return "VertexData{" +
"super=" + super.toString() +
"}";
"properties=" + properties +
", super=" + super.toString() +
'}';
}

@Override
public boolean equals(Object o) {
if (!(o instanceof VertexData)) return false;
if (!super.equals(o)) return false;
VertexData that = (VertexData) o;
return Objects.equals(properties, that.properties);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Map;
import java.util.Objects;

public class VertexPropertyData extends AdbValue implements ElementData<AdbValue> {
public class VertexPropertyData extends AdbValue implements PropertyData<AdbValue> {

private final String id;
private final Map<String, AdbValue> properties;
Expand Down Expand Up @@ -68,7 +68,7 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof VertexPropertyData)) return false;
if (!super.equals(o)) return false;
VertexPropertyData that = (VertexPropertyData) o;
return Objects.equals(id, that.id) && Objects.equals(properties, that.properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.arangodb.tinkerpop.gremlin.structure;

import com.arangodb.tinkerpop.gremlin.persistence.ElementData;
import com.arangodb.tinkerpop.gremlin.persistence.PropertyData;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
Expand All @@ -30,7 +30,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class ArangoDBElement<P, D extends ElementData<P>> implements Element {
public abstract class ArangoDBElement<P, D extends PropertyData<P>> implements Element {

protected final ArangoDBGraph graph;
protected final D data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

package com.arangodb.tinkerpop.gremlin.structure;

import com.arangodb.tinkerpop.gremlin.persistence.AbstractElementData;
import com.arangodb.tinkerpop.gremlin.persistence.PersistentData;

import java.util.*;

public abstract class ArangoDBEntityElement<P, D extends AbstractElementData<P>> extends ArangoDBElement<P, D> {
public abstract class ArangoDBEntityElement<P, D extends PersistentData<P>> extends ArangoDBElement<P, D> {

public ArangoDBEntityElement(ArangoDBGraph graph, D data) {
super(graph, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class ArangoDBGraphProvider extends AbstractGraphProvider {
* The Constant IMPLEMENTATIONS.
*/
private static final Set<Class> IMPLEMENTATIONS = new HashSet<Class>() {{
add(AbstractElementData.class);
add(PersistentData.class);
add(AdbValue.class);
add(EdgeData.class);
add(ElementData.class);
add(PropertyData.class);
add(VertexData.class);
add(VertexPropertyData.class);
}};
Expand Down