use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class MemoryDataStorageManager method getIndexStatus.
@Override
public IndexStatus getIndexStatus(String tableSpace, String indexName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
final String checkPoint = checkpointName(tableSpace, indexName, sequenceNumber);
byte[] data = indexStatuses.get(checkPoint);
if (data == null) {
throw new DataStorageManagerException("no such index checkpoint: " + checkPoint);
}
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
return IndexStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class MemoryDataStorageManager method getTableStatus.
@Override
public TableStatus getTableStatus(String tableSpace, String tableName, LogSequenceNumber sequenceNumber) throws DataStorageManagerException {
final String checkPoint = checkpointName(tableSpace, tableName, sequenceNumber);
byte[] data = tableStatuses.get(checkPoint);
if (data == null) {
throw new DataStorageManagerException("no such tablee checkpoint: " + checkPoint);
}
try {
try (InputStream input = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
return TableStatus.deserialize(dataIn);
}
} catch (IOException err) {
throw new DataStorageManagerException(err);
}
}
use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class RecordSerializer method deserializeMultiColumnPrimaryKey.
private static void deserializeMultiColumnPrimaryKey(byte[] data, Table table, Map<String, Object> res) {
try (SimpleByteArrayInputStream key_in = new SimpleByteArrayInputStream(data);
ExtendedDataInputStream din = new ExtendedDataInputStream(key_in)) {
for (String primaryKeyColumn : table.primaryKey) {
byte[] value = din.readArray();
res.put(primaryKeyColumn, deserialize(value, table.getColumn(primaryKeyColumn).type));
}
} catch (IOException err) {
throw new IllegalArgumentException("malformed record", err);
}
}
use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class RecordSerializer method accessRawDataFromValue.
static Object accessRawDataFromValue(String property, Bytes value, Table table) throws IOException {
if (table.getColumn(property) == null) {
throw new herddb.utils.IllegalDataAccessException("table " + table.tablespace + "." + table.name + " does not define column " + property);
}
SimpleByteArrayInputStream s = new SimpleByteArrayInputStream(value.data);
ExtendedDataInputStream din = new ExtendedDataInputStream(s);
while (!din.isEof()) {
int serialPosition;
serialPosition = din.readVIntNoEOFException();
if (din.isEof()) {
return null;
}
Column col = table.getColumnBySerialPosition(serialPosition);
if (col != null && col.name.equals(property)) {
return deserializeTypeAndValue(din);
} else {
// we have to deserialize always the value, even the column is no more present
skipTypeAndValue(din);
}
}
return null;
}
use of herddb.utils.ExtendedDataInputStream in project herddb by diennea.
the class RecordSerializer method toBean.
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static Map<String, Object> toBean(Record record, Table table) {
try {
ImmutableMap.Builder<String, Object> res = new ImmutableMap.Builder<>();
if (table.primaryKey.length == 1) {
Object key = deserializeSingleColumnPrimaryKey(record.key.data, table);
res.put(table.primaryKey[0], key);
} else {
deserializeMultiColumnPrimaryKey(record.key.data, table, res);
}
if (record.value != null && record.value.data.length > 0) {
SimpleByteArrayInputStream s = new SimpleByteArrayInputStream(record.value.data);
ExtendedDataInputStream din = new ExtendedDataInputStream(s);
while (true) {
int serialPosition;
serialPosition = din.readVIntNoEOFException();
if (din.isEof()) {
break;
}
// we have to deserialize always the value, even the column is no more present
Object v = deserializeTypeAndValue(din);
Column col = table.getColumnBySerialPosition(serialPosition);
if (col != null) {
res.put(col.name, v);
}
}
}
return res.build();
} catch (IOException err) {
throw new IllegalArgumentException("malformed record", err);
}
}
Aggregations