Search in sources :

Example 1 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream 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);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 2 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream 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);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 3 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream 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);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) RawString(herddb.utils.RawString) IOException(java.io.IOException)

Example 4 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream 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;
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) Column(herddb.model.Column) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream)

Example 5 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream 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);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) Column(herddb.model.Column) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) RawString(herddb.utils.RawString) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)16 ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)15 IOException (java.io.IOException)11 InputStream (java.io.InputStream)6 DataStorageManagerException (herddb.storage.DataStorageManagerException)5 Column (herddb.model.Column)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 RawString (herddb.utils.RawString)2 BufferedInputStream (java.io.BufferedInputStream)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 LogSequenceNumber (herddb.log.LogSequenceNumber)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 TableSpace (herddb.model.TableSpace)1 TableStatus (herddb.storage.TableStatus)1 ArrayList (java.util.ArrayList)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1