Search in sources :

Example 66 with IonStruct

use of com.amazon.ion.IonStruct in project amazon-qldb-dmv-sample-java by aws-samples.

the class GetBlock method main.

public static void main(String[] args) {
    try {
        List<IonStruct> results = ConnectToLedger.getDriver().execute(txn -> {
            final String vin = SampleData.VEHICLES.get(1).getVin();
            return GetRevision.queryRegistrationsByVin(txn, vin);
        });
        BlockAddress blockAddress = Constants.MAPPER.readValue(results.get(0), QldbRevision.class).getBlockAddress();
        verifyBlock(Constants.LEDGER_NAME, blockAddress);
    } catch (Exception e) {
        log.error("Unable to query vehicle registration by Vin.", e);
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) BlockAddress(software.amazon.qldb.tutorial.qldb.BlockAddress) QldbRevision(software.amazon.qldb.tutorial.qldb.QldbRevision) IOException(java.io.IOException)

Example 67 with IonStruct

use of com.amazon.ion.IonStruct in project amazon-qldb-dmv-sample-java by aws-samples.

the class InsertIonTypes method main.

public static void main(final String... args) {
    final IonBlob ionBlob = Constants.SYSTEM.newBlob("hello".getBytes());
    final IonBool ionBool = Constants.SYSTEM.newBool(true);
    final IonClob ionClob = Constants.SYSTEM.newClob("{{'This is a CLOB of text.'}}".getBytes());
    final IonDecimal ionDecimal = Constants.SYSTEM.newDecimal(0.1);
    final IonFloat ionFloat = Constants.SYSTEM.newFloat(0.2);
    final IonInt ionInt = Constants.SYSTEM.newInt(1);
    final IonList ionList = Constants.SYSTEM.newList(new int[] { 1, 2 });
    final IonNull ionNull = Constants.SYSTEM.newNull();
    final IonSexp ionSexp = Constants.SYSTEM.newSexp(new int[] { 2, 3 });
    final IonString ionString = Constants.SYSTEM.newString("string");
    final IonStruct ionStruct = Constants.SYSTEM.newEmptyStruct();
    ionStruct.put("brand", Constants.SYSTEM.newString("ford"));
    final IonSymbol ionSymbol = Constants.SYSTEM.newSymbol("abc");
    final IonTimestamp ionTimestamp = Constants.SYSTEM.newTimestamp(Timestamp.now());
    final IonBlob ionNullBlob = Constants.SYSTEM.newNullBlob();
    final IonBool ionNullBool = Constants.SYSTEM.newNullBool();
    final IonClob ionNullClob = Constants.SYSTEM.newNullClob();
    final IonDecimal ionNullDecimal = Constants.SYSTEM.newNullDecimal();
    final IonFloat ionNullFloat = Constants.SYSTEM.newNullFloat();
    final IonInt ionNullInt = Constants.SYSTEM.newNullInt();
    final IonList ionNullList = Constants.SYSTEM.newNullList();
    final IonSexp ionNullSexp = Constants.SYSTEM.newNullSexp();
    final IonString ionNullString = Constants.SYSTEM.newNullString();
    final IonStruct ionNullStruct = Constants.SYSTEM.newNullStruct();
    final IonSymbol ionNullSymbol = Constants.SYSTEM.newNullSymbol();
    final IonTimestamp ionNullTimestamp = Constants.SYSTEM.newNullTimestamp();
    ConnectToLedger.getDriver().execute(txn -> {
        CreateTable.createTable(txn, TABLE_NAME);
        final Document document = new Document(Constants.SYSTEM.newString("val"));
        InsertDocument.insertDocuments(txn, TABLE_NAME, Collections.singletonList(document));
        updateRecordAndVerifyType(txn, ionBlob);
        updateRecordAndVerifyType(txn, ionBool);
        updateRecordAndVerifyType(txn, ionClob);
        updateRecordAndVerifyType(txn, ionDecimal);
        updateRecordAndVerifyType(txn, ionFloat);
        updateRecordAndVerifyType(txn, ionInt);
        updateRecordAndVerifyType(txn, ionList);
        updateRecordAndVerifyType(txn, ionNull);
        updateRecordAndVerifyType(txn, ionSexp);
        updateRecordAndVerifyType(txn, ionString);
        updateRecordAndVerifyType(txn, ionStruct);
        updateRecordAndVerifyType(txn, ionSymbol);
        updateRecordAndVerifyType(txn, ionTimestamp);
        updateRecordAndVerifyType(txn, ionNullBlob);
        updateRecordAndVerifyType(txn, ionNullBool);
        updateRecordAndVerifyType(txn, ionNullClob);
        updateRecordAndVerifyType(txn, ionNullDecimal);
        updateRecordAndVerifyType(txn, ionNullFloat);
        updateRecordAndVerifyType(txn, ionNullInt);
        updateRecordAndVerifyType(txn, ionNullList);
        updateRecordAndVerifyType(txn, ionNullSexp);
        updateRecordAndVerifyType(txn, ionNullString);
        updateRecordAndVerifyType(txn, ionNullStruct);
        updateRecordAndVerifyType(txn, ionNullSymbol);
        updateRecordAndVerifyType(txn, ionNullTimestamp);
        deleteTable(txn, TABLE_NAME);
    });
}
Also used : IonList(com.amazon.ion.IonList) IonInt(com.amazon.ion.IonInt) IonNull(com.amazon.ion.IonNull) IonBool(com.amazon.ion.IonBool) IonDecimal(com.amazon.ion.IonDecimal) IonSymbol(com.amazon.ion.IonSymbol) IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonString(com.amazon.ion.IonString) IonTimestamp(com.amazon.ion.IonTimestamp) IonBlob(com.amazon.ion.IonBlob) IonClob(com.amazon.ion.IonClob) IonFloat(com.amazon.ion.IonFloat)

Example 68 with IonStruct

use of com.amazon.ion.IonStruct in project amazon-qldb-dmv-sample-java by aws-samples.

the class QldbRevision method verifyRevisionHash.

/**
 * Throws an IllegalArgumentException if the hash of the revision data and metadata
 * does not match the hash provided by QLDB with the revision.
 */
public void verifyRevisionHash() {
    // the journal block.
    if (blockAddress == null || metadata == null || data == null) {
        return;
    }
    try {
        IonStruct metadataIon = (IonStruct) Constants.MAPPER.writeValueAsIonValue(metadata);
        verifyRevisionHash(metadataIon, data, hash);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not encode revision metadata to ion.", e);
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IOException(java.io.IOException)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3