use of herddb.utils.ByteArrayCursor in project herddb by diennea.
the class DataAccessorForFullRecord method forEach.
@Override
public void forEach(BiConsumer<String, Object> consumer) {
// best case
if (table.physicalLayoutLikeLogicalLayout) {
// no need to create a Map
if (table.primaryKey.length == 1) {
String pkField = table.primaryKey[0];
Object value = RecordSerializer.deserialize(record.key, table.getColumn(pkField).type);
consumer.accept(pkField, value);
if (value instanceof RawString) {
((RawString) value).recycle();
}
} else {
try (final ByteArrayCursor din = record.key.newCursor()) {
for (String primaryKeyColumn : table.primaryKey) {
Bytes value = din.readBytesNoCopy();
Object theValue = RecordSerializer.deserialize(value, table.getColumn(primaryKeyColumn).type);
consumer.accept(primaryKeyColumn, theValue);
if (theValue instanceof RawString) {
((RawString) theValue).recycle();
}
}
} catch (IOException err) {
throw new IllegalStateException("bad data:" + err, err);
}
}
try (ByteArrayCursor din = record.value.newCursor()) {
while (!din.isEof()) {
int serialPosition;
serialPosition = din.readVIntNoEOFException();
if (din.isEof()) {
break;
}
Column col = table.getColumnBySerialPosition(serialPosition);
if (col != null) {
Object value = RecordSerializer.deserializeTypeAndValue(din);
consumer.accept(col.name, value);
} else {
// we have to deserialize always the value, even the column is no more present
RecordSerializer.skipTypeAndValue(din);
}
}
} catch (IOException err) {
throw new IllegalStateException("bad data:" + err, err);
}
} else {
// bad case
for (int i = 0; i < table.columnNames.length; i++) {
String columnName = table.columnNames[i];
Object value = get(i);
consumer.accept(columnName, value);
if (value instanceof RawString) {
((RawString) value).recycle();
}
}
}
}
use of herddb.utils.ByteArrayCursor in project herddb by diennea.
the class RecordSerializer method accessRawDataFromValue.
static Object accessRawDataFromValue(int index, Bytes value, Table table) throws IOException {
Column column = table.getColumn(index);
try (ByteArrayCursor din = value.newCursor()) {
while (!din.isEof()) {
int serialPosition;
serialPosition = din.readVIntNoEOFException();
if (din.isEof()) {
return null;
}
Column col = table.getColumnBySerialPosition(serialPosition);
if (col != null && col.serialPosition == column.serialPosition) {
return deserializeTypeAndValue(din);
} else {
// we have to deserialize always the value, even the column is no more present
skipTypeAndValue(din);
}
}
return null;
}
}
Aggregations