use of com.baidu.hugegraph.type.define.IdStrategy in project incubator-hugegraph by apache.
the class VertexLabelBuilder method checkIdStrategy.
private void checkIdStrategy() {
IdStrategy strategy = this.idStrategy;
boolean hasPrimaryKey = this.primaryKeys.size() > 0;
switch(strategy) {
case DEFAULT:
if (hasPrimaryKey) {
this.idStrategy = IdStrategy.PRIMARY_KEY;
} else {
this.idStrategy = IdStrategy.AUTOMATIC;
}
break;
case AUTOMATIC:
case CUSTOMIZE_STRING:
case CUSTOMIZE_NUMBER:
case CUSTOMIZE_UUID:
E.checkArgument(!hasPrimaryKey, "Not allowed to assign primary keys " + "when using '%s' id strategy", strategy);
break;
case PRIMARY_KEY:
E.checkArgument(hasPrimaryKey, "Must assign some primary keys " + "when using '%s' id strategy", strategy);
break;
default:
throw new AssertionError(String.format("Unknown id strategy '%s'", strategy));
}
if (this.idStrategy == IdStrategy.PRIMARY_KEY) {
this.checkPrimaryKeys();
}
}
use of com.baidu.hugegraph.type.define.IdStrategy in project incubator-hugegraph by apache.
the class TestGraph method addVertex.
@Watched
@Override
public Vertex addVertex(Object... keyValues) {
boolean needRedefineSchema = false;
boolean hasId = false;
IdStrategy idStrategy = IdStrategy.AUTOMATIC;
String defaultVL = DEFAULT_VL;
for (int i = 0; i < keyValues.length; i += 2) {
if (keyValues[i] == null) {
continue;
}
if (keyValues[i].equals(T.id)) {
hasId = true;
}
if (keyValues[i].equals(T.label) && i + 1 < keyValues.length && "person".equals(keyValues[i + 1]) && this.loadedGraph == null && !this.autoPerson) {
needRedefineSchema = true;
defaultVL = "person";
}
}
if (needRedefineSchema && this.loadedGraph == null) {
this.clearSchema();
this.tx().commit();
this.initBasicSchema(idStrategy, defaultVL);
this.tx().commit();
if (!this.autoPerson && "person".equals(defaultVL) && idStrategy == IdStrategy.AUTOMATIC) {
this.autoPerson = true;
}
this.isLastIdCustomized = idStrategy == IdStrategy.CUSTOMIZE_STRING;
}
if (!hasId && (this.isLastIdCustomized || needAddIdToLoadGraph())) {
List<Object> kvs = new ArrayList<>(Arrays.asList(keyValues));
kvs.add(T.id);
kvs.add(String.valueOf(id++));
keyValues = kvs.toArray();
}
return this.graph.addVertex(keyValues);
}
use of com.baidu.hugegraph.type.define.IdStrategy in project incubator-hugegraph by apache.
the class TestGraphProvider method idStrategy.
private static IdStrategy idStrategy(Configuration config) {
Class<?> testClass = (Class<?>) config.getProperty(TEST_CLASS);
String testMethod = config.getString(TEST_METHOD);
// Set id strategy
IdStrategy idStrategy = IdStrategy.AUTOMATIC;
if (config.getBoolean(EXPECT_CUSTOMIZED_ID) || isIoTest(testClass) || CUSTOMIZED_ID_METHODS.contains(testMethod)) {
/*
* Use CUSTOMIZED_ID if the following case are met:
* 1.Expect CUSTOMIZED_ID for some specific features
* 2.IoTest, it will copy vertex from IO or other graph
* 3.Some tests that need to pass vertex id manually
*/
idStrategy = IdStrategy.CUSTOMIZE_STRING;
}
return idStrategy;
}
use of com.baidu.hugegraph.type.define.IdStrategy in project incubator-hugegraph by apache.
the class TestGraphProvider method loadGraphData.
@Watched
public void loadGraphData(final Graph graph, final LoadGraphWith.GraphData loadGraphWith) {
TestGraph testGraph = (TestGraph) graph;
// Clear basic schema initiated in openTestGraph
testGraph.clearAll("");
if (testGraph.loadedGraph() == null) {
testGraph.loadedGraph(REGULAR_LOAD);
}
boolean standard = testGraph.hugegraph().name().endsWith(STANDARD);
IdStrategy idStrategy = standard && !testGraph.ioTest() ? IdStrategy.AUTOMATIC : IdStrategy.CUSTOMIZE_STRING;
switch(loadGraphWith) {
case GRATEFUL:
testGraph.initGratefulSchema(idStrategy);
break;
case MODERN:
testGraph.initModernSchema(idStrategy);
break;
case CLASSIC:
testGraph.initClassicSchema(idStrategy);
break;
case CREW:
break;
case SINK:
testGraph.initSinkSchema();
break;
default:
throw new AssertionError(String.format("Only support GRATEFUL, MODERN and CLASSIC " + "for @LoadGraphWith(), but '%s' is used ", loadGraphWith));
}
LOG.debug("Load graph with {} schema", loadGraphWith);
testGraph.tx().commit();
}
Aggregations