Skip to content

Commit

Permalink
Custom properties now are returned from schema:types in queries
Browse files Browse the repository at this point in the history
Fixed issue #590
  • Loading branch information
lvca committed Oct 27, 2022
1 parent 1574f38 commit 995fc7b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.arcadedb.graph.Edge;
import com.arcadedb.graph.Vertex;
import com.arcadedb.index.Index;
import com.arcadedb.index.IndexInternal;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.Schema;

Expand Down Expand Up @@ -84,22 +83,33 @@ else if (type.getType() == Edge.RECORD_TYPE)
propRes.setProperty("id", property.getId());
propRes.setProperty("name", property.getName());
propRes.setProperty("type", property.getType());

final List<ResultInternal> customs = new ArrayList<>();
for (Object customKey : property.getCustomKeys().stream().sorted(String::compareToIgnoreCase).toArray())
customs.add(new ResultInternal().setProperty((String) customKey, property.getCustomValue((String) customKey)));
propRes.setProperty("custom", customs);

return propRes;
}).collect(Collectors.toList());
r.setProperty("properties", propertiesTypes);

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

final List<ResultInternal> customs = new ArrayList<>();
for (Object customKey : type.getCustomKeys().stream().sorted(String::compareToIgnoreCase).toArray())
customs.add(new ResultInternal().setProperty((String) customKey, type.getCustomValue((String) customKey)));
r.setProperty("custom", customs);

}
} finally {
if (profilingEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public Set<String> getTemporaryProperties() {
return temporaryContent == null ? Collections.emptySet() : temporaryContent.keySet();
}

public void setProperty(final String name, Object value) {
public ResultInternal setProperty(final String name, Object value) {
if (value instanceof Optional)
value = ((Optional) value).orElse(null);

if (value instanceof Result && ((Result) value).isElement()) {
if (value instanceof Result && ((Result) value).isElement())
content.put(name, ((Result) value).getElement().get());
} else {
else
content.put(name, value);
}

return this;
}

public void removeProperty(final String name) {
Expand Down Expand Up @@ -301,8 +302,9 @@ public Set<String> getMetadataKeys() {
return metadata == null ? Collections.emptySet() : metadata.keySet();
}

public void setElement(final Document element) {
public ResultInternal setElement(final Document element) {
this.element = element;
return this;
}

@Override
Expand Down Expand Up @@ -346,7 +348,8 @@ public int hashCode() {
return content.hashCode();
}

public void setPropertiesFromMap(final Map<String, Object> stats) {
public ResultInternal setPropertiesFromMap(final Map<String, Object> stats) {
content.putAll(stats);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@
public class TraverseResult extends ResultInternal {
protected Integer depth;

@Override public <T> T getProperty(String name) {
if ("$depth".equalsIgnoreCase(name)) {
@Override
public <T> T getProperty(final String name) {
if ("$depth".equalsIgnoreCase(name))
return (T) depth;
}

return super.getProperty(name);
}

@Override public void setProperty(String name, Object value) {
@Override
public ResultInternal setProperty(final String name, final Object value) {
if ("$depth".equalsIgnoreCase(name)) {
if (value instanceof Number) {
depth = ((Number) value).intValue();
}
} else {
super.setProperty(name, value);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public Document toElement() {
}

@Override
public void setProperty(final String name, final Object value) {
public ResultInternal setProperty(final String name, final Object value) {
element.set(name, value);
return this;
}

public void removeProperty(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ public boolean equals(Object o) {
return false;
if (!identifierListAddRemove.equals(that.identifierListAddRemove))
return false;
if (numberValue != null ? !numberValue.equals(that.numberValue) : that.numberValue != null)
if (!Objects.equals(numberValue, that.numberValue))
return false;
if (booleanValue != null ? !booleanValue.equals(that.booleanValue) : that.booleanValue != null)
if (!Objects.equals(booleanValue, that.booleanValue))
return false;
if (customKey != null ? !customKey.equals(that.customKey) : that.customKey != null)
if (!Objects.equals(customKey, that.customKey))
return false;
return customValue != null ? customValue.equals(that.customValue) : that.customValue == null;
return Objects.equals(customValue, that.customValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,8 @@ public void testQueryAsTarget() {

@Test
public void testQuerySchema() {
database.getSchema().createDocumentType("testQuerySchema");
DocumentType type = database.getSchema().createDocumentType("testQuerySchema");
type.setCustomValue("description", "this is just a test");

ResultSet result = database.query("sql", "select from schema:types");
printExecutionPlan(result);
Expand All @@ -994,6 +995,12 @@ public void testQuerySchema() {
Result item = result.next();
Assertions.assertEquals("testQuerySchema", item.getProperty("name"));

List<Result> customType = item.getProperty("custom");
Assertions.assertNotNull(customType);
Assertions.assertEquals(1, customType.size());

Assertions.assertEquals("this is just a test", customType.get(0).getProperty("description"));

Assertions.assertFalse(result.hasNext());
result.close();
}
Expand Down

0 comments on commit 995fc7b

Please sign in to comment.