Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions engine/src/main/java/com/arcadedb/graph/MutableVertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public byte getRecordType() {
return Vertex.RECORD_TYPE;
}

@Override
public MutableEdge newEdge(final String edgeType, final Identifiable toVertex, final Object... properties) {
return database.getGraphEngine().newEdge(this, edgeType, toVertex, properties);
}
Expand All @@ -147,11 +148,13 @@ public MutableEdge newEdge(final String edgeType, final Identifiable toVertex, f
return database.getGraphEngine().newEdge(this, edgeType, toVertex, properties);
}

@Override
public ImmutableLightEdge newLightEdge(final String edgeType, final Identifiable toVertex) {
return database.getGraphEngine().newLightEdge(this, edgeType, toVertex);
}

@Deprecated
@Override
public ImmutableLightEdge newLightEdge(final String edgeType, final Identifiable toVertex, final boolean bidirectional) {
if (!bidirectional && ((EdgeType) database.getSchema().getType(edgeType)).isBidirectional())
throw new IllegalArgumentException("Edge type '" + edgeType + "' is not bidirectional");
Expand Down
28 changes: 12 additions & 16 deletions network/src/main/java/com/arcadedb/remote/RemoteDocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@
import com.arcadedb.index.TypeIndex;
import com.arcadedb.index.lsm.LSMTreeIndexAbstract;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.Property;
import com.arcadedb.schema.Schema;
import com.arcadedb.schema.Type;
import com.arcadedb.serializer.json.JSONObject;

import java.util.*;
import java.util.stream.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Document type used by {@link RemoteDatabase} class. The metadata are cached from the server until the schema is changed or
Expand Down Expand Up @@ -86,19 +94,6 @@

if (record.hasProperty("custom"))
custom = record.getProperty("custom");
//
// final List<ResultInternal> indexes = type.getAllIndexes(false).stream().sorted(Comparator.comparing(Index::getName))
// .map(typeIndex -> {
// final ResultInternal propRes = new ResultInternal();
// propRes.setProperty("name", typeIndex.getName());
// propRes.setProperty("typeName", typeIndex.getTypeName());
// propRes.setProperty("type", typeIndex.getType());
// propRes.setProperty("unique", typeIndex.isUnique());
// propRes.setProperty("properties", typeIndex.getPropertyNames());
// propRes.setProperty("automatic", typeIndex.isAutomatic());
// return propRes;
// }).collect(Collectors.toList());
// r.setProperty("indexes",indexes);
}

@Override
Expand Down Expand Up @@ -440,7 +435,8 @@

@Override
public DocumentType addBucket(Bucket bucket) {
throw new UnsupportedOperationException();
ResultSet resultSet = remoteDatabase.command("sql", "alter type `" + name + "` bucket +`" + bucket.getName() + "`");

Check warning on line 438 in network/src/main/java/com/arcadedb/remote/RemoteDocumentType.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

network/src/main/java/com/arcadedb/remote/RemoteDocumentType.java#L438

Avoid unused local variables such as 'resultSet'.
return remoteDatabase.getSchema().reload().getType(name);
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions network/src/main/java/com/arcadedb/remote/RemoteSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public void dropIndex(final String indexName) {
}

@Override
public LocalBucket createBucket(final String bucketName) {
public Bucket createBucket(final String bucketName) {
final ResultSet result = remoteDatabase.command("sql", "create bucket `" + bucketName + "`");
return null;
return new RemoteBucket(result.next().getProperty("bucketName"));
}

@Override
Expand Down Expand Up @@ -579,7 +579,9 @@ public DocumentType getInvolvedTypeByBucketId(final int bucketId) {
@Deprecated
@Override
public DocumentType getTypeByBucketName(final String bucketName) {
throw new UnsupportedOperationException();
ResultSet resultSet = remoteDatabase.command("sql", "select from schema:types where buckets contains `" + bucketName + "`");

return remoteDatabase.getSchema().getType(resultSet.nextIfAvailable().getProperty("name"));
}

@Deprecated
Expand Down
28 changes: 25 additions & 3 deletions network/src/main/java/com/arcadedb/remote/RemoteVertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import com.arcadedb.graph.MutableEdge;
import com.arcadedb.graph.Vertex;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.EdgeType;

import java.util.*;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;

/**
* Vertex type used by {@link RemoteDatabase} class. The metadata are cached from the server until the schema is changed or
Expand Down Expand Up @@ -140,9 +143,28 @@ public MutableEdge newEdge(final String edgeType, final Identifiable toVertex, f
return newEdge(edgeType, toVertex, properties);
}

public MutableEdge newEdge(final String edgeType, final Identifiable toVertex, Object... properties) {
public MutableEdge newEdge(String edgeType, final Identifiable toVertex, Object... properties) {

final String bucketName;
if (edgeType.startsWith("bucket:")) {
bucketName = edgeType.substring("bucket:".length());
final DocumentType type = remoteDatabase.getSchema().getTypeByBucketName(bucketName);
if (type == null)
edgeType = null;
else
edgeType = type.getName();
} else
bucketName = null;

StringBuilder query = new StringBuilder(
"create edge `" + edgeType + "` from " + vertex.getIdentity() + " to " + toVertex.getIdentity());
"create edge `" + edgeType + "`");

if (bucketName != null) {
query.append(" bucket `");
query.append(bucketName);
query.append("`");
}
query.append(" from " + vertex.getIdentity() + " to " + toVertex.getIdentity());

if (properties != null && properties.length > 0) {
query.append(" set ");
Expand Down
45 changes: 24 additions & 21 deletions server/src/test/java/com/arcadedb/remote/RemoteDatabaseIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.arcadedb.graph.MutableEdge;
import com.arcadedb.graph.MutableVertex;
import com.arcadedb.graph.Vertex;
import com.arcadedb.graph.Vertex.DIRECTION;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.Schema;
Expand All @@ -44,6 +45,7 @@
import java.util.*;
import java.util.concurrent.atomic.*;

import static com.arcadedb.graph.Vertex.DIRECTION.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

Expand Down Expand Up @@ -254,32 +256,32 @@ record = (Vertex) database.lookupByRID(rid2);

kimbal.toJSON();

final Iterator<Vertex> connected = kimbal.getVertices(Vertex.DIRECTION.IN).iterator();
final Iterator<Vertex> connected = kimbal.getVertices(IN).iterator();
assertThat(connected.hasNext()).isTrue();
final Vertex albert = connected.next();
assertThat(albert.getString("lastName")).isEqualTo("Red");

assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, null)).isEqualTo(1L);
assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)).isEqualTo(1L);
assertThat(kimbal.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)).isEqualTo(0L);
assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, null)).isEqualTo(0);
assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)).isEqualTo(0);
assertThat(kimbal.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)).isEqualTo(0L);
assertThat(kimbal.countEdges(IN, null)).isEqualTo(1L);
assertThat(kimbal.countEdges(IN, EDGE1_TYPE_NAME)).isEqualTo(1L);
assertThat(kimbal.countEdges(IN, EDGE2_TYPE_NAME)).isEqualTo(0L);
assertThat(kimbal.countEdges(OUT, null)).isEqualTo(0);
assertThat(kimbal.countEdges(OUT, EDGE1_TYPE_NAME)).isEqualTo(0);
assertThat(kimbal.countEdges(OUT, EDGE2_TYPE_NAME)).isEqualTo(0L);

assertThat(albert.countEdges(Vertex.DIRECTION.OUT, null)).isEqualTo(1L);
assertThat(albert.countEdges(Vertex.DIRECTION.OUT, EDGE1_TYPE_NAME)).isEqualTo(1L);
assertThat(albert.countEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME)).isEqualTo(0L);
assertThat(albert.countEdges(Vertex.DIRECTION.IN, null)).isEqualTo(0);
assertThat(albert.countEdges(Vertex.DIRECTION.IN, EDGE1_TYPE_NAME)).isEqualTo(0);
assertThat(albert.countEdges(Vertex.DIRECTION.IN, EDGE2_TYPE_NAME)).isEqualTo(0);
assertThat(albert.countEdges(OUT, null)).isEqualTo(1L);
assertThat(albert.countEdges(OUT, EDGE1_TYPE_NAME)).isEqualTo(1L);
assertThat(albert.countEdges(OUT, EDGE2_TYPE_NAME)).isEqualTo(0L);
assertThat(albert.countEdges(IN, null)).isEqualTo(0);
assertThat(albert.countEdges(IN, EDGE1_TYPE_NAME)).isEqualTo(0);
assertThat(albert.countEdges(IN, EDGE2_TYPE_NAME)).isEqualTo(0);

assertThat(kimbal.isConnectedTo(albert.getIdentity())).isTrue();
assertThat(kimbal.isConnectedTo(albert.getIdentity(), Vertex.DIRECTION.IN)).isTrue();
assertThat(kimbal.isConnectedTo(albert.getIdentity(), Vertex.DIRECTION.OUT)).isFalse();
assertThat(kimbal.isConnectedTo(albert.getIdentity(), IN)).isTrue();
assertThat(kimbal.isConnectedTo(albert.getIdentity(), OUT)).isFalse();

assertThat(albert.isConnectedTo(kimbal.getIdentity())).isTrue();
assertThat(albert.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.OUT)).isTrue();
assertThat(albert.isConnectedTo(kimbal.getIdentity(), Vertex.DIRECTION.IN)).isFalse();
assertThat(albert.isConnectedTo(kimbal.getIdentity(), OUT)).isTrue();
assertThat(albert.isConnectedTo(kimbal.getIdentity(), IN)).isFalse();

final MutableEdge newEdge = albert.newEdge(EDGE2_TYPE_NAME, kimbal, "since", "today");
assertThat(albert.getIdentity()).isEqualTo(newEdge.getOut());
Expand All @@ -298,7 +300,7 @@ record = (Vertex) database.lookupByRID(rid2);
assertThat(kimbal).isEqualTo(newEdge2.getInVertex());
newEdge2.delete();

final Edge edge = albert.getEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME).iterator().next();
final Edge edge = albert.getEdges(OUT, EDGE2_TYPE_NAME).iterator().next();
assertThat(albert.getIdentity()).isEqualTo(edge.getOut());
assertThat(albert).isEqualTo(edge.getOutVertex());
assertThat(kimbal.getIdentity()).isEqualTo(edge.getIn());
Expand All @@ -307,7 +309,7 @@ record = (Vertex) database.lookupByRID(rid2);

// DELETE THE EDGE
edge.delete();
assertThat(albert.getEdges(Vertex.DIRECTION.OUT, EDGE2_TYPE_NAME).iterator().hasNext()).isFalse();
assertThat(albert.getEdges(OUT, EDGE2_TYPE_NAME).iterator().hasNext()).isFalse();

// DELETE ONE VERTEX
albert.delete();
Expand Down Expand Up @@ -434,8 +436,6 @@ public void testDropRemoteInheritanceBroken() throws Exception {
final RemoteDatabase database = new RemoteDatabase("127.0.0.1", 2480 + serverIndex, DATABASE_NAME, "root",
BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS);

//
//
database.command("sqlscript", """
CREATE VERTEX TYPE AVtx;
CREATE VERTEX TYPE BVtx EXTENDS AVtx;
Expand Down Expand Up @@ -632,6 +632,9 @@ public void testDatabaseMVCC() throws Exception {
});
}




@BeforeEach
public void beginTest() {
super.beginTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
import com.arcadedb.ContextConfiguration;
import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.RID;
import com.arcadedb.engine.Bucket;
import com.arcadedb.engine.LocalBucket;
import com.arcadedb.graph.Edge;
import com.arcadedb.graph.MutableEdge;
import com.arcadedb.graph.MutableVertex;
import com.arcadedb.graph.Vertex;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.EdgeType;
import com.arcadedb.server.BaseGraphServerTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.*;

import static com.arcadedb.graph.Vertex.DIRECTION.IN;
import static com.arcadedb.graph.Vertex.DIRECTION.OUT;
import static org.assertj.core.api.Assertions.assertThat;

public class RemoteDatabaseJavaApiIT extends BaseGraphServerTest {
Expand Down Expand Up @@ -45,14 +51,14 @@ void createUnidirectionalEdge() {
assertThat(friendOf.getOut()).isEqualTo(me);
assertThat(friendOf.getIn()).isEqualTo(you);

assertThat(me.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isTrue();
assertThat(me.getVertices(Vertex.DIRECTION.OUT).iterator().next()).isEqualTo(you);
assertThat(me.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isFalse();
assertThat(me.getVertices(OUT).iterator().hasNext()).isTrue();
assertThat(me.getVertices(OUT).iterator().next()).isEqualTo(you);
assertThat(me.getVertices(IN).iterator().hasNext()).isFalse();

assertThat(you.getVertices(Vertex.DIRECTION.IN).iterator().hasNext()).isTrue();
assertThat(you.getVertices(Vertex.DIRECTION.OUT).iterator().hasNext()).isFalse();
assertThat(you.getVertices(IN).iterator().hasNext()).isTrue();
assertThat(you.getVertices(OUT).iterator().hasNext()).isFalse();

Iterable<Edge> friends = me.getEdges(Vertex.DIRECTION.IN, "FriendOf");
Iterable<Edge> friends = me.getEdges(IN, "FriendOf");
assertThat(friends).containsExactly(friendOf);

assertThat(me.getString("name")).isEqualTo("me");
Expand Down Expand Up @@ -175,6 +181,25 @@ public void testExplicitLock() {
database.close();
}

@Test
void saveRemoteEdgeOnGivenBucket() {
final RemoteDatabase db = new RemoteDatabase("127.0.0.1", 2480, DATABASE_NAME, "root",
BaseGraphServerTest.DEFAULT_PASSWORD_FOR_TESTS);

Bucket edgeBucket = db.getSchema().createBucket("EdgeBucket");
db.getSchema().createVertexType("Person");
EdgeType friendOf1 = db.getSchema().createEdgeType("FriendOf");
DocumentType documentType = friendOf1.addBucket(edgeBucket);

MutableVertex me = db.newVertex("Person").set("name", "me").save();
MutableVertex you = db.newVertex("Person").set("name", "you").save();
MutableEdge friendOf = me.newEdge("bucket:EdgeBucket", you);

assertThat(friendOf.getOut()).isEqualTo(me.getIdentity());
assertThat(friendOf.getIn()).isEqualTo(you.getIdentity());

}

@BeforeEach
public void beginTest() {
super.beginTest();
Expand Down
Loading