use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method ridBagSize.
private void ridBagSize(OClientConnection connection) throws IOException {
setDataCommandInfo(connection, "RidBag get size");
OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
final byte[] changeStream = channel.readBytes();
final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
if (tree == null)
throw new ORecordContentNotFoundException(collectionPointer);
try {
final Map<OIdentifiable, OSBTreeRidBag.Change> changes = OSBTreeRidBag.ChangeSerializationHelper.INSTANCE.deserializeChanges(changeStream, 0);
int realSize = tree.getRealBagSize(changes);
beginResponse();
try {
sendOk(connection, clientTxId);
channel.writeInt(realSize);
} finally {
endResponse(connection);
}
} finally {
sbTreeCollectionManager.releaseSBTree(collectionPointer);
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method sbTreeBonsaiGetEntriesMajor.
private void sbTreeBonsaiGetEntriesMajor(OClientConnection connection) throws IOException {
setDataCommandInfo(connection, "SB-Tree bonsai get values major");
OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
byte[] keyStream = channel.readBytes();
boolean inclusive = channel.readBoolean();
int pageSize = 128;
if (connection.getData().protocolVersion >= 21)
pageSize = channel.readInt();
final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
if (tree == null)
throw new ORecordContentNotFoundException(collectionPointer);
try {
final OBinarySerializer<OIdentifiable> keySerializer = tree.getKeySerializer();
OIdentifiable key = keySerializer.deserialize(keyStream, 0);
final OBinarySerializer<Integer> valueSerializer = tree.getValueSerializer();
OTreeInternal.AccumulativeListener<OIdentifiable, Integer> listener = new OTreeInternal.AccumulativeListener<OIdentifiable, Integer>(pageSize);
tree.loadEntriesMajor(key, inclusive, true, listener);
List<Entry<OIdentifiable, Integer>> result = listener.getResult();
byte[] stream = serializeSBTreeEntryCollection(result, keySerializer, valueSerializer);
beginResponse();
try {
sendOk(connection, clientTxId);
channel.writeBytes(stream);
} finally {
endResponse(connection);
}
} finally {
sbTreeCollectionManager.releaseSBTree(collectionPointer);
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method sbTreeBonsaiGet.
private void sbTreeBonsaiGet(OClientConnection connection) throws IOException {
setDataCommandInfo(connection, "SB-Tree bonsai get");
OBonsaiCollectionPointer collectionPointer = OCollectionNetworkSerializer.INSTANCE.readCollectionPointer(channel);
final byte[] keyStream = channel.readBytes();
final OSBTreeCollectionManager sbTreeCollectionManager = connection.getDatabase().getSbTreeCollectionManager();
final OSBTreeBonsai<OIdentifiable, Integer> tree = sbTreeCollectionManager.loadSBTree(collectionPointer);
if (tree == null)
throw new ORecordContentNotFoundException(collectionPointer);
try {
final OIdentifiable key = tree.getKeySerializer().deserialize(keyStream, 0);
Integer result = tree.get(key);
final OBinarySerializer<? super Integer> valueSerializer;
if (result == null) {
valueSerializer = ONullSerializer.INSTANCE;
} else {
valueSerializer = tree.getValueSerializer();
}
byte[] stream = new byte[OByteSerializer.BYTE_SIZE + valueSerializer.getObjectSize(result)];
OByteSerializer.INSTANCE.serialize(valueSerializer.getId(), stream, 0);
valueSerializer.serialize(result, stream, OByteSerializer.BYTE_SIZE);
beginResponse();
try {
sendOk(connection, clientTxId);
channel.writeBytes(stream);
} finally {
endResponse(connection);
}
} finally {
sbTreeCollectionManager.releaseSBTree(collectionPointer);
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method createSBTreeBonsai.
private void createSBTreeBonsai(OClientConnection connection) throws IOException {
setDataCommandInfo(connection, "Create SB-Tree bonsai instance");
int clusterId = channel.readInt();
OBonsaiCollectionPointer collectionPointer = connection.getDatabase().getSbTreeCollectionManager().createSBTree(clusterId, null);
beginResponse();
try {
sendOk(connection, clientTxId);
OCollectionNetworkSerializer.INSTANCE.writeCollectionPointer(channel, collectionPointer);
} finally {
endResponse(connection);
}
}
Aggregations