Search in sources :

Example 11 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeVertex method primaryValues.

@Watched(prefix = "vertex")
protected List<Object> primaryValues() {
    E.checkArgument(this.label.idStrategy() == IdStrategy.PRIMARY_KEY, "The id strategy '%s' don't have primary keys", this.label.idStrategy());
    List<Id> primaryKeys = this.label.primaryKeys();
    E.checkArgument(!primaryKeys.isEmpty(), "Primary key can't be empty for id strategy '%s'", IdStrategy.PRIMARY_KEY);
    boolean encodeNumber = this.graph().option(CoreOptions.VERTEX_ENCODE_PK_NUMBER);
    List<Object> propValues = new ArrayList<>(primaryKeys.size());
    for (Id pk : primaryKeys) {
        HugeProperty<?> property = this.getProperty(pk);
        E.checkState(property != null, "The value of primary key '%s' can't be null", this.graph().propertyKey(pk).name());
        Object propValue = property.serialValue(encodeNumber);
        if (Strings.EMPTY.equals(propValue)) {
            propValue = ConditionQuery.INDEX_VALUE_EMPTY;
        }
        propValues.add(propValue);
    }
    return propValues;
}
Also used : ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 12 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeVertex method remove.

@Watched(prefix = "vertex")
@Override
public void remove() {
    this.removed(true);
    /*
         * Call by tx or by graph to remove vertex,
         * call by tx if the vertex is new because the context is dependent
         */
    GraphTransaction tx = this.tx();
    if (tx != null) {
        assert this.fresh();
        tx.removeVertex(this);
    } else {
        assert !this.fresh();
        this.graph().removeVertex(this);
    }
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 13 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initClassicSchema.

@Watched
public void initClassicSchema(IdStrategy idStrategy) {
    SchemaManager schema = this.graph.schema();
    schema.propertyKey("id").asInt().ifNotExist().create();
    schema.propertyKey("weight").asFloat().ifNotExist().create();
    schema.propertyKey("name").ifNotExist().create();
    schema.propertyKey("lang").ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    switch(idStrategy) {
        case AUTOMATIC:
            schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").ifNotExist().create();
            break;
        case CUSTOMIZE_STRING:
            schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").useCustomizeStringId().ifNotExist().create();
            break;
        default:
            throw new AssertionError(String.format("Id strategy must be customize or automatic"));
    }
    schema.edgeLabel("knows").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("created").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.indexLabel("vertexByName").onV("vertex").by("name").secondary().ifNotExist().create();
    schema.indexLabel("vertexByAge").onV("vertex").by("age").range().ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 14 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initBackend.

@Watched
protected void initBackend() {
    BackendStoreSystemInfo sysInfo = this.graph.backendStoreSystemInfo();
    if (!sysInfo.exists()) {
        this.graph.initBackend();
    } else {
        // May reopen a closed graph
        assert sysInfo.exists() && !this.graph.closed();
    }
    Id id = IdGenerator.of("server-tinkerpop");
    this.graph.serverStarted(id, NodeRole.MASTER);
    this.initedBackend = true;
}
Also used : BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 15 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method clearSchema.

@Watched
protected void clearSchema() {
    // Clear schema and graph data will be cleared at same time
    SchemaManager schema = this.graph.schema();
    schema.getIndexLabels().stream().forEach(elem -> {
        schema.indexLabel(elem.name()).remove();
    });
    schema.getEdgeLabels().stream().forEach(elem -> {
        schema.edgeLabel(elem.name()).remove();
    });
    schema.getVertexLabels().stream().forEach(elem -> {
        schema.vertexLabel(elem.name()).remove();
    });
    schema.getPropertyKeys().stream().forEach(elem -> {
        schema.propertyKey(elem.name()).remove();
    });
    TaskScheduler scheduler = this.graph.taskScheduler();
    scheduler.tasks(null, -1, null).forEachRemaining(elem -> {
        scheduler.delete(elem.id());
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) TaskScheduler(com.baidu.hugegraph.task.TaskScheduler) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)65 Id (com.baidu.hugegraph.backend.id.Id)30 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)9 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)7 ArrayList (java.util.ArrayList)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)4 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)4 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)4 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)4 Query (com.baidu.hugegraph.backend.query.Query)4 SchemaJob (com.baidu.hugegraph.job.schema.SchemaJob)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4