Hi,

Is there a nicer way of executing
SELECT max(ordering) FROM user_bookmark WHERE userid=293130

then this:
SQLTemplate template = new SQLTemplate(UserBookmark.class, "SELECT
max(ordering) FROM user_bookmark WHERE userid=$uid");
template.setParameters(Collections.singletonMap("uid", user.getId()));
template.setFetchingDataRows(true);
List<UserBookmark> res = context.performQuery(template);

Integer maxOrdering = null;
if (res != null) {
    Map row = (Map)res.get(0);
    if (row != null) {
        maxOrdering = (Integer) row.get("max(ordering)");
    }
}
if (maxOrdering == null) {
    maxOrdering = 0;
}

userBookmark.setOrdering(maxOrdering + 1);

I took me some time to figure out the name of the key in the map. Note that
userid is a FK, so it is not mapped in the modeler.

Regards,
Borut

Reply via email to