use of com.baidu.hugegraph.backend.serializer.TextBackendEntry in project incubator-hugegraph by apache.
the class BackendMutationTest method constructBackendEntry.
private static BackendEntry constructBackendEntry(String id, String... columns) {
assert (columns.length == 0 || columns.length == 2);
TextBackendEntry entry = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(id));
if (columns.length == 2) {
String subId = SplicingIdGenerator.concat(id, columns[0]);
entry.subId(IdGenerator.of(subId));
}
for (int i = 0; i < columns.length; i = i + 2) {
entry.column(columns[i], columns[i + 1]);
}
return entry;
}
use of com.baidu.hugegraph.backend.serializer.TextBackendEntry in project incubator-hugegraph by apache.
the class InMemoryDBTable method insert.
@Override
public void insert(BackendSession session, TextBackendEntry entry) {
if (!this.store.containsKey(entry.id())) {
this.store.put(entry.id(), entry);
} else {
// Merge columns if the entry exists
BackendEntry origin = this.store.get(entry.id());
// TODO: Compatible with BackendEntry
origin.merge(entry);
}
}
use of com.baidu.hugegraph.backend.serializer.TextBackendEntry in project incubator-hugegraph by apache.
the class InMemoryDBTable method matchCondition.
private static boolean matchCondition(BackendEntry item, Condition c) {
// TODO: Compatible with BackendEntry
TextBackendEntry entry = (TextBackendEntry) item;
// Not supported by memory
if (!(c instanceof Condition.Relation)) {
throw new BackendException("Unsupported condition: " + c);
}
Condition.Relation r = (Condition.Relation) c;
String key = r.serialKey().toString();
// TODO: deal with others Relation like: <, >=, ...
if (r.relation() == Condition.RelationType.CONTAINS_KEY) {
return entry.contains(r.serialValue().toString());
} else if (r.relation() == Condition.RelationType.CONTAINS_VALUE) {
return entry.containsValue(r.serialValue().toString());
} else if (r.relation() == Condition.RelationType.EQ) {
return entry.contains(key, r.serialValue().toString());
} else if (entry.contains(key)) {
return r.test(entry.column(key));
}
return false;
}
use of com.baidu.hugegraph.backend.serializer.TextBackendEntry in project incubator-hugegraph by apache.
the class TextBackendEntryTest method testEquals.
@Test
public void testEquals() {
TextBackendEntry entry = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(1));
TextBackendEntry entry2 = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(2));
TextBackendEntry entry3 = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(1));
TextBackendEntry entry4 = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(1));
TextBackendEntry entry5 = new TextBackendEntry(HugeType.VERTEX, IdGenerator.of(1));
entry.column(HugeKeys.NAME, "tom");
entry2.column(HugeKeys.NAME, "tom");
entry3.column(HugeKeys.NAME, "tom2");
entry4.column(HugeKeys.NAME, "tom");
entry4.column(HugeKeys.LABEL, "person");
entry5.column(HugeKeys.NAME, "tom");
Assert.assertNotEquals(entry, entry2);
Assert.assertNotEquals(entry, entry3);
Assert.assertNotEquals(entry, entry4);
Assert.assertNotEquals(entry4, entry);
Assert.assertEquals(entry, entry5);
}
use of com.baidu.hugegraph.backend.serializer.TextBackendEntry in project incubator-hugegraph by apache.
the class InMemoryDBStore method mutate.
protected void mutate(BackendAction item) {
BackendEntry e = item.entry();
assert e instanceof TextBackendEntry;
TextBackendEntry entry = (TextBackendEntry) e;
InMemoryDBTable table = this.table(entry.type());
switch(item.action()) {
case INSERT:
LOG.debug("[store {}] add entry: {}", this.store, entry);
table.insert(null, entry);
break;
case DELETE:
LOG.debug("[store {}] remove id: {}", this.store, entry.id());
table.delete(null, entry);
break;
case APPEND:
LOG.debug("[store {}] append entry: {}", this.store, entry);
table.append(null, entry);
break;
case ELIMINATE:
LOG.debug("[store {}] eliminate entry: {}", this.store, entry);
table.eliminate(null, entry);
break;
default:
throw new BackendException("Unsupported mutate type: %s", item.action());
}
}
Aggregations