forked from hugegraph/hugegraph
improve error message with readable HugeType (#546)
Change-Id: I633eee63fe9458cdc910f977fccec8fd0109f1d2
This commit is contained in:
parent
abebfac25c
commit
b63277e583
|
|
@ -130,7 +130,8 @@ public class API {
|
|||
String id) {
|
||||
if (!iter.hasNext()) {
|
||||
throw new NotFoundException(String.format(
|
||||
"%s with id '%s' does not exist", type, id));
|
||||
"%s with id '%s' does not exist",
|
||||
type.readableName(), id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ public class HugeGraph implements GremlinGraph {
|
|||
|
||||
public PropertyKey propertyKey(Id id) {
|
||||
PropertyKey pk = this.schemaTransaction().getPropertyKey(id);
|
||||
E.checkArgument(pk != null, "Undefined property key id: '%s'", id);
|
||||
E.checkArgument(pk != null, "Undefined property key with id: '%s'", id);
|
||||
return pk;
|
||||
}
|
||||
|
||||
|
|
@ -423,7 +423,7 @@ public class HugeGraph implements GremlinGraph {
|
|||
|
||||
public VertexLabel vertexLabel(Id id) {
|
||||
VertexLabel vl = this.schemaTransaction().getVertexLabel(id);
|
||||
E.checkArgument(vl != null, "Undefined vertex label id: '%s'", id);
|
||||
E.checkArgument(vl != null, "Undefined vertex label with id: '%s'", id);
|
||||
return vl;
|
||||
}
|
||||
|
||||
|
|
@ -435,7 +435,7 @@ public class HugeGraph implements GremlinGraph {
|
|||
|
||||
public EdgeLabel edgeLabel(Id id) {
|
||||
EdgeLabel el = this.schemaTransaction().getEdgeLabel(id);
|
||||
E.checkArgument(el != null, "Undefined edge label id: '%s'", id);
|
||||
E.checkArgument(el != null, "Undefined edge label with id: '%s'", id);
|
||||
return el;
|
||||
}
|
||||
|
||||
|
|
@ -447,7 +447,7 @@ public class HugeGraph implements GremlinGraph {
|
|||
|
||||
public IndexLabel indexLabel(Id id) {
|
||||
IndexLabel il = this.schemaTransaction().getIndexLabel(id);
|
||||
E.checkArgument(il != null, "Undefined index label id: '%s'", id);
|
||||
E.checkArgument(il != null, "Undefined index label with id: '%s'", id);
|
||||
return il;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,8 @@ public abstract class AbstractTransaction implements Transaction {
|
|||
BackendEntry entry = this.query(type, id);
|
||||
if (entry == null) {
|
||||
throw new NotFoundException(
|
||||
"Not found the %s entry with id '%s'", type, id);
|
||||
"Not found the %s entry with id '%s'",
|
||||
type.readableName(), id);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -280,7 +280,8 @@ public class SchemaTransaction extends IndexableTransaction {
|
|||
}
|
||||
|
||||
protected <T extends SchemaElement> T getSchema(HugeType type, Id id) {
|
||||
LOG.debug("SchemaTransaction get {} by id '{}'", type, id);
|
||||
LOG.debug("SchemaTransaction get {} by id '{}'",
|
||||
type.readableName(), id);
|
||||
this.beforeRead();
|
||||
BackendEntry entry = this.query(type, id);
|
||||
if (entry == null) {
|
||||
|
|
@ -300,7 +301,8 @@ public class SchemaTransaction extends IndexableTransaction {
|
|||
*/
|
||||
protected <T extends SchemaElement> T getSchema(HugeType type,
|
||||
String name) {
|
||||
LOG.debug("SchemaTransaction get {} by name '{}'", type, name);
|
||||
LOG.debug("SchemaTransaction get {} by name '{}'",
|
||||
type.readableName(), name);
|
||||
this.beforeRead();
|
||||
ConditionQuery query = new ConditionQuery(type);
|
||||
query.eq(HugeKeys.NAME, name);
|
||||
|
|
@ -436,7 +438,7 @@ public class SchemaTransaction extends IndexableTransaction {
|
|||
"Must provide schema id if in RESTORING mode");
|
||||
SchemaElement element = this.getSchema(type, id);
|
||||
if (element != null) {
|
||||
throw new ExistedException(type.toString() + " id", id);
|
||||
throw new ExistedException(type.readableName() + " id", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,16 @@
|
|||
package com.baidu.hugegraph.exception;
|
||||
|
||||
import com.baidu.hugegraph.HugeException;
|
||||
import com.baidu.hugegraph.type.HugeType;
|
||||
|
||||
public class ExistedException extends HugeException {
|
||||
|
||||
private static final long serialVersionUID = 5152465646323494840L;
|
||||
|
||||
public ExistedException(HugeType type, Object arg) {
|
||||
this(type.readableName(), arg);
|
||||
}
|
||||
|
||||
public ExistedException(String type, Object arg) {
|
||||
super("The %s '%s' has existed", type, arg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class SchemaManager {
|
|||
private static void checkExists(HugeType type, Object object, String name) {
|
||||
if (object == null) {
|
||||
throw new NotFoundException("%s with name '%s' does not exist",
|
||||
type, name);
|
||||
type.readableName(), name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,16 +114,17 @@ public class EdgeLabelBuilder implements EdgeLabel.Builder {
|
|||
|
||||
@Override
|
||||
public EdgeLabel create() {
|
||||
HugeType type = HugeType.EDGE_LABEL;
|
||||
SchemaTransaction tx = this.transaction;
|
||||
SchemaElement.checkName(this.name, tx.graph().configuration());
|
||||
EdgeLabel edgeLabel = tx.getEdgeLabel(this.name);
|
||||
if (edgeLabel != null) {
|
||||
if (this.checkExist) {
|
||||
throw new ExistedException("edge label", this.name);
|
||||
throw new ExistedException(type, this.name);
|
||||
}
|
||||
return edgeLabel;
|
||||
}
|
||||
tx.checkIdIfRestoringMode(HugeType.EDGE_LABEL, this.id);
|
||||
tx.checkIdIfRestoringMode(type, this.id);
|
||||
|
||||
if (this.frequency == Frequency.DEFAULT) {
|
||||
this.frequency = Frequency.SINGLE;
|
||||
|
|
|
|||
|
|
@ -92,16 +92,17 @@ public class IndexLabelBuilder implements IndexLabel.Builder {
|
|||
*/
|
||||
@Override
|
||||
public IndexLabel.CreatedIndexLabel createWithTask() {
|
||||
HugeType type = HugeType.INDEX_LABEL;
|
||||
SchemaTransaction tx = this.transaction;
|
||||
SchemaElement.checkName(this.name, tx.graph().configuration());
|
||||
IndexLabel indexLabel = tx.getIndexLabel(this.name);
|
||||
if (indexLabel != null) {
|
||||
if (this.checkExist) {
|
||||
throw new ExistedException("index label", this.name);
|
||||
throw new ExistedException(type, this.name);
|
||||
}
|
||||
return new IndexLabel.CreatedIndexLabel(indexLabel, null);
|
||||
}
|
||||
tx.checkIdIfRestoringMode(HugeType.INDEX_LABEL, this.id);
|
||||
tx.checkIdIfRestoringMode(type, this.id);
|
||||
|
||||
SchemaLabel schemaLabel = this.loadElement();
|
||||
|
||||
|
|
@ -290,7 +291,7 @@ public class IndexLabelBuilder implements IndexLabel.Builder {
|
|||
}
|
||||
|
||||
E.checkArgumentNotNull(schemaLabel, "Can't find the %s with name '%s'",
|
||||
this.baseType, this.baseValue);
|
||||
this.baseType.readableName(), this.baseValue);
|
||||
return schemaLabel;
|
||||
}
|
||||
|
||||
|
|
@ -301,9 +302,10 @@ public class IndexLabelBuilder implements IndexLabel.Builder {
|
|||
for (String field : fields) {
|
||||
PropertyKey pkey = this.transaction.getPropertyKey(field);
|
||||
// In general this will not happen
|
||||
E.checkArgumentNotNull(pkey, "Can't build index on undefined " +
|
||||
"property key '%s' for '%s': '%s'",
|
||||
field, this.baseType, this.baseValue);
|
||||
E.checkArgument(pkey != null,
|
||||
"Can't build index on undefined property key " +
|
||||
"'%s' for '%s': '%s'", field,
|
||||
this.baseType.readableName(), this.baseValue);
|
||||
E.checkArgument(pkey.cardinality() == Cardinality.SINGLE,
|
||||
"Not allowed to build index on property key " +
|
||||
"'%s' whose cardinality is list or set",
|
||||
|
|
|
|||
|
|
@ -76,16 +76,17 @@ public class PropertyKeyBuilder implements PropertyKey.Builder {
|
|||
|
||||
@Override
|
||||
public PropertyKey create() {
|
||||
HugeType type = HugeType.PROPERTY_KEY;
|
||||
SchemaTransaction tx = this.transaction;
|
||||
SchemaElement.checkName(this.name, tx.graph().configuration());
|
||||
PropertyKey propertyKey = tx.getPropertyKey(this.name);
|
||||
if (propertyKey != null) {
|
||||
if (this.checkExist) {
|
||||
throw new ExistedException("property key", this.name);
|
||||
throw new ExistedException(type, this.name);
|
||||
}
|
||||
return propertyKey;
|
||||
}
|
||||
tx.checkIdIfRestoringMode(HugeType.PROPERTY_KEY, this.id);
|
||||
tx.checkIdIfRestoringMode(type, this.id);
|
||||
|
||||
this.checkUserdata(Action.INSERT);
|
||||
|
||||
|
|
|
|||
|
|
@ -107,16 +107,17 @@ public class VertexLabelBuilder implements VertexLabel.Builder {
|
|||
|
||||
@Override
|
||||
public VertexLabel create() {
|
||||
HugeType type = HugeType.VERTEX_LABEL;
|
||||
SchemaTransaction tx = this.transaction;
|
||||
SchemaElement.checkName(this.name, tx.graph().configuration());
|
||||
VertexLabel vertexLabel = tx.getVertexLabel(this.name);
|
||||
if (vertexLabel != null) {
|
||||
if (this.checkExist) {
|
||||
throw new ExistedException("vertex label", this.name);
|
||||
throw new ExistedException(type, this.name);
|
||||
}
|
||||
return vertexLabel;
|
||||
}
|
||||
tx.checkIdIfRestoringMode(HugeType.VERTEX_LABEL, this.id);
|
||||
tx.checkIdIfRestoringMode(type, this.id);
|
||||
|
||||
this.checkProperties(Action.INSERT);
|
||||
this.checkIdStrategy();
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ public enum HugeType implements SerialEnum {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public String readableName() {
|
||||
return this.name().replace('_', ' ').toLowerCase();
|
||||
}
|
||||
|
||||
public boolean isSchema() {
|
||||
return this == HugeType.VERTEX_LABEL ||
|
||||
this == HugeType.EDGE_LABEL ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue