use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.
the class RocksDBStore method mutate.
@Override
public void mutate(BackendMutation mutation) {
Lock readLock = this.storeLock.readLock();
readLock.lock();
try {
this.checkOpened();
if (LOG.isDebugEnabled()) {
LOG.debug("Store {} mutation: {}", this.store, mutation);
}
for (HugeType type : mutation.types()) {
Session session = this.session(type);
for (Iterator<BackendAction> it = mutation.mutation(type); it.hasNext(); ) {
this.mutate(session, it.next());
}
}
} finally {
readLock.unlock();
}
}
use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.
the class HbaseStore method mutate.
@Override
public void mutate(BackendMutation mutation) {
if (LOG.isDebugEnabled()) {
LOG.debug("Store {} mutation: {}", this.store, mutation);
}
this.checkOpened();
Session session = this.sessions.session();
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
this.mutate(session, it.next());
}
}
use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.
the class MysqlStore method mutate.
@Override
public void mutate(BackendMutation mutation) {
if (LOG.isDebugEnabled()) {
LOG.debug("Store {} mutation: {}", this.store, mutation);
}
this.checkOpened();
Session session = this.sessions.session();
for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
this.mutate(session, it.next());
}
}
use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.
the class StoreSerializerTest method testSerializeBackendMutation.
@Test
public void testSerializeBackendMutation() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
entry.column(new byte[] { 1 }, new byte[] { 1 });
entry.column(new byte[] { 2 }, new byte[] { 2 });
entry.column(new byte[] { 127 }, new byte[] { 127 });
BackendMutation origin = new BackendMutation();
origin.add(entry, Action.INSERT);
byte[] bytes = StoreSerializer.writeMutation(origin);
BytesBuffer buffer = BytesBuffer.wrap(bytes);
BackendMutation actual = StoreSerializer.readMutation(buffer);
Assert.assertEquals(1, actual.size());
Iterator<BackendAction> iter = actual.mutation();
while (iter.hasNext()) {
BackendAction item = iter.next();
Assert.assertEquals(Action.INSERT, item.action());
BackendEntry e = item.entry();
Assert.assertEquals(entry.type(), e.type());
Assert.assertEquals(entry.id(), e.id());
Assert.assertEquals(entry.subId(), e.subId());
Assert.assertEquals(entry.ttl(), e.ttl());
Assert.assertEquals(entry.columnsSize(), e.columnsSize());
Assert.assertEquals(entry.columns(), e.columns());
}
}
use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.
the class StoreSerializer method writeMutation.
public static byte[] writeMutation(BackendMutation mutation) {
BytesBuffer buffer = BytesBuffer.allocate(MUTATION_SIZE);
// write mutation size
buffer.writeVInt(mutation.size());
for (Iterator<BackendAction> items = mutation.mutation(); items.hasNext(); ) {
BackendAction item = items.next();
// write Action
buffer.write(item.action().code());
BackendEntry entry = item.entry();
// write HugeType
buffer.write(entry.type().code());
// write id
buffer.writeBytes(entry.id().asBytes());
// write subId
if (entry.subId() != null) {
buffer.writeId(entry.subId());
} else {
buffer.writeId(IdGenerator.ZERO);
}
// write ttl
buffer.writeVLong(entry.ttl());
// write columns
buffer.writeVInt(entry.columns().size());
for (BackendColumn column : entry.columns()) {
buffer.writeBytes(column.name);
buffer.writeBytes(column.value);
}
}
return buffer.bytes();
}
Aggregations