Are tuples supported in the Java API?

Hi All,

I’m trying to learn how tuple schema types ( :db.type/tuple) are handled in the Java API. I see no mention of it anywhere. Can someone please point me in the right direction?

Thanks!
Joe

Nothing special in Java, API wise. Tuples are just Lists

The example from the docs works just fine:

public class TupleDemo {

    @Rule
    public final DatomicTestDb datomic = new DatomicTestDb("tupleDemo");

    @Test
    public void tuplesWorkWithJava() throws ExecutionException, InterruptedException {
        datomic.connection().transact(Util.list(
                Util.map(":db/ident", ":player/location",
                        ":db/valueType", ":db.type/tuple",
                        ":db/tupleTypes", Util.read("[ :db.type/long :db.type/long]"),
                        ":db/cardinality", ":db.cardinality/one")

        )).get();

        Map txResult = datomic.connection().transact(Util.list(Util.list(":db/add", "newPlayer", ":player/location", Util.list(100L, 50L)))).get();

        Database db = (Database) txResult.get(Connection.DB_AFTER);
        Object newPlayerE = Peer.resolveTempid(
                db,
                txResult.get(Connection.TEMPIDS),
                "newPlayer"
        );

        Object locationTuple = Peer.query("[:find ?location . :where [?player :player/location ?location] :in $ ?player]", db, newPlayerE);

        assertThat(locationTuple).isInstanceOf(List.class);
        assertThat((List)locationTuple).hasSize(2);
        assertThat((List)locationTuple).containsExactly(100L, 50L);

    }

}

(If you want to run this, the @Rule above is just a test harness helper I have for crating mem dbs for testing, assertions provided by assertj)

Ahhh. I must have missed that example in the docs. This should get me started. Thanks Adam!

Well, maybe you didn’t, the docs example is written in clojure, so I just adapted from that for my post: https://docs.datomic.com/on-prem/schema.html#heterogeneous-tuples

Anyway, tuples don’t really add any new data types on the API side, just schema.

OK, well that would explain it. I would, at the very least, have expected there to be a TYPE_TUPLE constant in the Attribute class. But there are no mentions of tuples anywhere at all that I can see! The Java API could use a spruce-up, but I’m good on my end thanks to the code snippet you gave me.

Thanks again!