I want to persist daily close entities, representing close prices of stocks.
public class DailyData {
private Long id;
private String ticker;
private BigDecimal open;
private BigDecimal high;
private BigDecimal low;
private BigDecimal close;
private Timestamp date;
//getters, setters
}
Because of the limited API of the data provider, I may get duplicate entries for certain dates (if, for example, I only need two days, I still need to ask for a month worth of data). Obviously, I only want to have one record per date, so any date that already exists in the DB should not be persisted.
This may have already been answered here, but I am having trouble implementing it in practice. In particular, I don't understand how to pass actual values to be persisted. This is adapted from the example in the link:
Param<Integer> myId = param("date", Timestamp.class);
create.insertInto(DATA, DATA.TICKER, DATA.OPEN, DATA.HIGH, DATA.LOW, DATA.CLOSE, DATA.DATE)
.select(
select(
date,
param("ticker", DATA.TICKER.getType()),
param("open", DATA.OPEN.getType()),
param("high", DATA.HIGH.getType()),
param("low", DATA.LOW.getType()),
param("close", DATA.CLOSE.getType()),
param("date", DATA.DATE.getType())
)
.whereNotExists(
selectOne()
.from(DATA)
.where(DATA.DATE.eq(date))
)
);
- Where are the actual values passed on in the example? There is no call to .values() DSL command, which normally appears in jOOQ documentation to tell it what values are to be inserted.
- Is .execute at the end not needed?
- There is a batchInsert() command to persist many entities/rows at once. Is there a batch variety of the above mentioned example? Or do I simply have to iterate through all the entities and perform the uniqueness check on each one separately?