Skip to content
Advertisement

Java JOOQ parse query to ArrayList with object

I have a problem. I am using JOOQ, with that I created the following query:

create.select(
        DSL.field("Mainkey"),
        DSL.field("Market"),
        DSL.field("Coin"),
        DSL.field("Period"),
        DSL.field("DateTimeGMT0"),
        DSL.field("DateTimeLocal"),
        DSL.field("Close"))
        .from(DSL.table("vwCD_All_Selection_" + market + "_" + coin + "_1m_Order_DateTime_DESC"))
        .where(DSL.field("DateTimeLocal").greaterOrEqual(startDateTime.minusMinutes(1))).fetch();

Now I also have the following class:

public class Candlestick implements Comparable<Candlestick> {

    private long MainKey;
    private LocalDateTime DateTimeGMT0;
    private LocalDateTime DateTimeLocal;
    private String Market;
    private String Coin;
    private String Period;
    public Double Close;

}

Now I want the result of the query to be parsed to an ArrayList<Candlestick>. I found this page: https://www.jooq.org/doc/3.0/manual/sql-execution/fetching/arrays-maps-and-lists/ that shows how to parse the result to a List, bu that is for a specific column of the select. I want to parse the entire object.

How can I achieve this?

Advertisement

Answer

You can use

.fetchInto(Candlestick.class);

instead of

.fetch();

That will give you a collection of Canldestick.

Advertisement