JDBC Driver - PolyDocument

org.polypheny.jdbc.types.PolyDocument extends HashMap<String, TypedValue>. Use the normal Java map methods to read PolyDocument objects from a DocumentResult. A key can be absent or present with a Prism null value. Check containsKey and then the value’s isNull() to distinguish them. For a present nested document, call asDocument() on its TypedValue.

Constructors

Constructor Use
PolyDocument() Creates an empty mutable map.
PolyDocument(HashMap<String, TypedValue> entries) Copies the supplied map entries.
PolyDocument(ProtoDocument document) Reads the entries from a document in the driver’s bundled Prism API.

serialize() returns the corresponding Prism ProtoDocument. For Prism null values in a document you construct, use TypedValue.fromNull(). Changing a document in memory does not update its collection.

Reading a nested value

This standalone example constructs a document in memory and round-trips it through the Prism representation. It requires the JDBC JAR on the classpath and runs without a server.

import org.polypheny.jdbc.types.PolyDocument;
import org.polypheny.jdbc.types.TypedValue;

public class JdbcDocumentValueExample {
    public static void main(String[] args) throws Exception {
        PolyDocument address = new PolyDocument();
        address.put("city", TypedValue.fromString("Basel"));

        PolyDocument person = new PolyDocument();
        person.put("address", TypedValue.fromDocument(address));
        person.put("nickname", TypedValue.fromNull());

        PolyDocument decoded = new PolyDocument(person.serialize());
        System.out.println(decoded.get("address").asDocument().get("city").asString());
        System.out.println(decoded.get("nickname").isNull());
        System.out.println(decoded.containsKey("email"));
    }
}

The example prints Basel, true, and false on separate lines.

© Polypheny GmbH. All Rights Reserved.