use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class CassandraTable method setPageState.
protected void setPageState(Query query, List<Select> selects) {
if (query.noLimit() && !query.paging()) {
return;
}
for (Select select : selects) {
int total = (int) query.total();
if (!query.noLimit()) {
E.checkArgument(total == query.total(), "Invalid query limit %s", query.limit());
} else {
assert total == -1 : total;
}
String page = query.page();
if (page == null) {
// Set limit
assert total > 0 : total;
select.limit(total);
} else {
/*
* NOTE: the `total` may be -1 when query.noLimit(),
* setFetchSize(-1) means the default fetch size will be used.
*/
assert total > 0 || total == -1 : total;
select.setFetchSize(total);
// It's the first time if page is empty, skip setPagingState
if (!page.isEmpty()) {
byte[] position = PageState.fromString(page).position();
try {
select.setPagingState(PagingState.fromBytes(position));
} catch (PagingStateException e) {
throw new BackendException(e);
}
}
}
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class CassandraTable method condition2Cql.
protected Clause condition2Cql(Condition condition) {
switch(condition.type()) {
case AND:
Condition.And and = (Condition.And) condition;
Clause left = condition2Cql(and.left());
Clause right = condition2Cql(and.right());
return Clauses.and(left, right);
case OR:
throw new BackendException("Not support OR currently");
case RELATION:
Condition.Relation r = (Condition.Relation) condition;
return relation2Cql(r);
default:
final String msg = "Unsupported condition: " + condition;
throw new AssertionError(msg);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class TableSerializer method parseProperty.
protected void parseProperty(Id key, Object colValue, HugeElement owner) {
// Get PropertyKey by PropertyKey id
PropertyKey pkey = owner.graph().propertyKey(key);
// Parse value
Object value = this.readProperty(pkey, colValue);
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
owner.addProperty(pkey, value);
} else {
if (!(value instanceof Collection)) {
throw new BackendException("Invalid value of non-single property: %s", value);
}
owner.addProperty(pkey, value);
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class TextSerializer method parseProperty.
private void parseProperty(String colName, String colValue, HugeElement owner) {
String[] colParts = SplicingIdGenerator.split(colName);
assert colParts.length == 2 : colName;
// Get PropertyKey by PropertyKey id
PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1]));
// Parse value
Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
// Set properties of vertex/edge
if (pkey.cardinality() == Cardinality.SINGLE) {
owner.addProperty(pkey, value);
} else {
if (!(value instanceof Collection)) {
throw new BackendException("Invalid value of non-single property: %s", colValue);
}
for (Object v : (Collection<?>) value) {
v = JsonUtil.castNumber(v, pkey.dataType().clazz());
owner.addProperty(pkey, v);
}
}
}
use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.
the class RaftClosure method run.
@Override
public void run(Status status) {
if (status.isOk()) {
this.complete(status);
} else {
LOG.error("Failed to apply command: {}", status);
String msg = "Failed to apply command in raft node with error: " + status.getErrorMsg();
this.failure(status, new BackendException(msg));
}
}
Aggregations