Search in sources :

Example 6 with MarshallerException

use of org.apache.ignite.internal.schema.marshaller.MarshallerException in project ignite-3 by apache.

the class RecordViewImpl method unmarshal.

/**
 * Unmarshal value object from given binary row.
 *
 * @param binaryRow Binary row.
 * @return Value object.
 */
private R unmarshal(BinaryRow binaryRow) {
    if (binaryRow == null || !binaryRow.hasValue()) {
        return null;
    }
    Row row = schemaReg.resolve(binaryRow);
    RecordMarshaller<R> marshaller = marshaller(row.schemaVersion());
    try {
        return marshaller.unmarshal(row);
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

Example 7 with MarshallerException

use of org.apache.ignite.internal.schema.marshaller.MarshallerException in project ignite-3 by apache.

the class KeyValueViewImpl method unmarshalKeys.

/**
 * Marshal keys.
 *
 * @param rows Binary rows.
 * @return Keys.
 */
@NotNull
public Collection<K> unmarshalKeys(Collection<BinaryRow> rows) {
    if (rows.isEmpty()) {
        return Collections.emptyList();
    }
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<K> keys = new ArrayList<>(rows.size());
    try {
        for (Row row : schemaReg.resolve(rows)) {
            if (row != null) {
                keys.add(marsh.unmarshalKey(row));
            }
        }
        return keys;
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with MarshallerException

use of org.apache.ignite.internal.schema.marshaller.MarshallerException in project ignite-3 by apache.

the class KeyValueViewImpl method marshal.

/**
 * Marshal key-value pairs.
 *
 * @param pairs Key-value map.
 * @return Binary rows.
 */
@NotNull
public List<BinaryRow> marshal(@NotNull Map<K, V> pairs) {
    final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
    List<BinaryRow> rows = new ArrayList<>(pairs.size());
    try {
        for (Map.Entry<K, V> pair : pairs.entrySet()) {
            final BinaryRow row = marsh.marshal(Objects.requireNonNull(pair.getKey()), pair.getValue());
            rows.add(row);
        }
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
    return rows;
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) ArrayList(java.util.ArrayList) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with MarshallerException

use of org.apache.ignite.internal.schema.marshaller.MarshallerException in project ignite-3 by apache.

the class KeyValueViewImpl method unmarshalValue.

/**
 * Unmarshal value object from given binary row.
 *
 * @param binaryRow Binary row.
 * @return Value object.
 */
private V unmarshalValue(BinaryRow binaryRow) {
    if (binaryRow == null || !binaryRow.hasValue()) {
        return null;
    }
    Row row = schemaReg.resolve(binaryRow);
    KvMarshaller<K, V> marshaller = marshaller(row.schemaVersion());
    try {
        return marshaller.unmarshalValue(row);
    } catch (MarshallerException e) {
        throw new IgniteException(e);
    }
}
Also used : MarshallerException(org.apache.ignite.internal.schema.marshaller.MarshallerException) IgniteException(org.apache.ignite.lang.IgniteException) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row)

Aggregations

BinaryRow (org.apache.ignite.internal.schema.BinaryRow)9 MarshallerException (org.apache.ignite.internal.schema.marshaller.MarshallerException)9 IgniteException (org.apache.ignite.lang.IgniteException)9 ArrayList (java.util.ArrayList)6 Row (org.apache.ignite.internal.schema.row.Row)5 NotNull (org.jetbrains.annotations.NotNull)5 HashMap (java.util.HashMap)2 Map (java.util.Map)1