enhancing query capabilities
This commit is contained in:
parent
4d62dc6a6a
commit
b62f51e53c
|
@ -26,75 +26,73 @@ public class JsonQueryIsRelatedTo extends JsonQueryERElement{
|
||||||
this.requestedResourceType = requestedResourceType;
|
this.requestedResourceType = requestedResourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private StringBuffer traverseThisEdge(StringBuffer stringBuffer) throws InvalidQueryException {
|
||||||
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException {
|
StringBuffer buffer = new StringBuffer();
|
||||||
StringBuffer isRelatedToBuffer = new StringBuffer();
|
|
||||||
|
|
||||||
JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY);
|
|
||||||
JsonNode targetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY);
|
|
||||||
|
|
||||||
JsonNode resourceJsonNode = null;
|
|
||||||
|
|
||||||
if(targetJsonNode!=null) {
|
|
||||||
resourceJsonNode = targetJsonNode;
|
|
||||||
direction = Direction.IN;
|
|
||||||
}else if(sourceJsonNode!=null) {
|
|
||||||
resourceJsonNode = sourceJsonNode;
|
|
||||||
direction = Direction.OUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
isRelatedToBuffer.append("TRAVERSE ");
|
|
||||||
isRelatedToBuffer.append(direction.opposite().name().toLowerCase());
|
|
||||||
isRelatedToBuffer.append("V(\"");
|
|
||||||
isRelatedToBuffer.append(requestedResourceType);
|
|
||||||
isRelatedToBuffer.append("\") FROM ("); // Open ( 1
|
|
||||||
|
|
||||||
int size = jsonNode.size();
|
int size = jsonNode.size();
|
||||||
if(size > 2) {
|
if(size > 2) {
|
||||||
isRelatedToBuffer.append("SELECT FROM ( "); // Open ( SELECT
|
buffer.append("SELECT FROM ( "); // Open ( SELECT
|
||||||
}
|
}
|
||||||
|
|
||||||
isRelatedToBuffer.append("TRAVERSE ");
|
|
||||||
isRelatedToBuffer.append(direction.name().toLowerCase());
|
|
||||||
isRelatedToBuffer.append("E(\"");
|
|
||||||
isRelatedToBuffer.append(type);
|
|
||||||
isRelatedToBuffer.append("\") FROM ("); // Open ( 2
|
|
||||||
|
|
||||||
if(!entryPoint) {
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
buffer.append("TRAVERSE ");
|
buffer.append("TRAVERSE ");
|
||||||
buffer.append(direction.opposite().name().toLowerCase());
|
buffer.append(direction.opposite().name().toLowerCase());
|
||||||
buffer.append("V(\"");
|
|
||||||
buffer.append(requestedResourceType);
|
|
||||||
buffer.append("\").");
|
|
||||||
buffer.append(direction.opposite().name().toLowerCase());
|
|
||||||
buffer.append("E(\"");
|
buffer.append("E(\"");
|
||||||
buffer.append(type);
|
buffer.append(type);
|
||||||
buffer.append("\") FROM (");
|
buffer.append("\") FROM (");
|
||||||
buffer.append(stringBuffer);
|
buffer.append(stringBuffer);
|
||||||
buffer.append(")");
|
buffer.append(")");
|
||||||
|
|
||||||
|
|
||||||
stringBuffer = buffer;
|
stringBuffer = buffer;
|
||||||
|
|
||||||
|
// Size 2 means that only '@class' and 'target'/'source' properties are present
|
||||||
|
if(size > 2) {
|
||||||
|
stringBuffer.append(") WHERE "); // Close ) SELECT
|
||||||
|
stringBuffer = addWhereConstraint(jsonNode, buffer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return stringBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected StringBuffer analize(StringBuffer stringBuffer) throws SchemaNotFoundException, InvalidQueryException {
|
||||||
|
|
||||||
|
|
||||||
|
JsonNode sourceJsonNode = jsonNode.get(ConsistsOf.SOURCE_PROPERTY);
|
||||||
|
JsonNode targetJsonNode = jsonNode.get(ConsistsOf.TARGET_PROPERTY);
|
||||||
|
|
||||||
|
JsonNode resourceJsonNode = null;
|
||||||
|
|
||||||
|
if(sourceJsonNode!=null) {
|
||||||
|
resourceJsonNode = sourceJsonNode;
|
||||||
|
direction = Direction.OUT;
|
||||||
|
} else if(targetJsonNode!=null) {
|
||||||
|
resourceJsonNode = targetJsonNode;
|
||||||
|
direction = Direction.IN;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuffer = traverseThisEdge(stringBuffer);
|
||||||
|
|
||||||
JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode);
|
JsonQueryResource jsonQueryResource = new JsonQueryResource(resourceJsonNode);
|
||||||
jsonQueryResource.setDirection(direction);
|
jsonQueryResource.setDirection(direction);
|
||||||
jsonQueryResource.setEntryPoint(false);
|
jsonQueryResource.setEntryPoint(false);
|
||||||
stringBuffer = jsonQueryResource.analize(stringBuffer);
|
stringBuffer = jsonQueryResource.analize(stringBuffer);
|
||||||
|
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append(" TRAVERSE ");
|
||||||
|
buffer.append(direction.opposite().name().toLowerCase());
|
||||||
|
buffer.append("V(\"");
|
||||||
|
buffer.append(requestedResourceType);
|
||||||
|
buffer.append("\").");
|
||||||
|
buffer.append(direction.name().toLowerCase());
|
||||||
|
buffer.append("E(\"");
|
||||||
|
buffer.append(type);
|
||||||
|
buffer.append("\") FROM (");
|
||||||
|
buffer.append(stringBuffer);
|
||||||
|
buffer.append(")");
|
||||||
|
stringBuffer = buffer;
|
||||||
|
|
||||||
isRelatedToBuffer.append(stringBuffer);
|
return stringBuffer;
|
||||||
isRelatedToBuffer.append(")"); // Close ) 2
|
|
||||||
|
|
||||||
// Size 2 means that only '@class' and 'target'/'source' properties are present
|
|
||||||
if(size > 2) {
|
|
||||||
isRelatedToBuffer.append(") WHERE "); // Close ) SELECT
|
|
||||||
isRelatedToBuffer = addWhereConstraint(jsonNode, isRelatedToBuffer, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
isRelatedToBuffer.append(")"); // Close ) 1
|
|
||||||
|
|
||||||
return isRelatedToBuffer;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class JsonQueryResource extends JsonQueryERElement {
|
||||||
JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfJsonNode);
|
JsonQueryConsistsOf jsonQueryConsistsOf = new JsonQueryConsistsOf(consistsOfJsonNode);
|
||||||
jsonQueryConsistsOf.setRequestedResourceType(type);
|
jsonQueryConsistsOf.setRequestedResourceType(type);
|
||||||
jsonQueryConsistsOf.setDirection(Direction.IN);
|
jsonQueryConsistsOf.setDirection(Direction.IN);
|
||||||
jsonQueryConsistsOf.setEntryPoint(i==0);
|
jsonQueryConsistsOf.setEntryPoint(entryPoint && i==0);
|
||||||
stringBuffer = jsonQueryConsistsOf.analize(stringBuffer);
|
stringBuffer = jsonQueryConsistsOf.analize(stringBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class JsonQueryResource extends JsonQueryERElement {
|
||||||
JsonNode isRelatedToJsonNode = isRelatedToArray.get(i);
|
JsonNode isRelatedToJsonNode = isRelatedToArray.get(i);
|
||||||
JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode);
|
JsonQueryIsRelatedTo jsonQueryIsRelatedTo = new JsonQueryIsRelatedTo(isRelatedToJsonNode);
|
||||||
jsonQueryIsRelatedTo.setRequestedResourceType(type);
|
jsonQueryIsRelatedTo.setRequestedResourceType(type);
|
||||||
jsonQueryIsRelatedTo.setEntryPoint(!initFound && i==0);
|
jsonQueryIsRelatedTo.setEntryPoint(entryPoint && !initFound && i==0);
|
||||||
stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer);
|
stringBuffer = jsonQueryIsRelatedTo.analize(stringBuffer);
|
||||||
}
|
}
|
||||||
initFound = true; // Must be set after the cycle and not before
|
initFound = true; // Must be set after the cycle and not before
|
||||||
|
|
|
@ -32,7 +32,16 @@
|
||||||
{
|
{
|
||||||
"@class": "Activates",
|
"@class": "Activates",
|
||||||
"source": {
|
"source": {
|
||||||
"@class": "HostingNode"
|
"@class": "HostingNode",
|
||||||
|
"consistsOf": [
|
||||||
|
{
|
||||||
|
"@class": "ConsistsOf",
|
||||||
|
"target": {
|
||||||
|
"@class": "CPUFacet",
|
||||||
|
"vendor": "GenuineIntel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue