finished location

This commit is contained in:
Jörg Henke 2023-03-11 21:37:08 +01:00
parent 00a42a35e3
commit 7ced264763

View File

@ -21,6 +21,7 @@ import org.jooq.DeleteConditionStep;
import org.jooq.Field; import org.jooq.Field;
import org.jooq.InsertResultStep; import org.jooq.InsertResultStep;
import org.jooq.InsertReturningStep; import org.jooq.InsertReturningStep;
import org.jooq.InsertValuesStep3;
import org.jooq.Record4; import org.jooq.Record4;
import org.jooq.Record5; import org.jooq.Record5;
import org.jooq.SelectConditionStep; import org.jooq.SelectConditionStep;
@ -324,7 +325,32 @@ public class AdminRepository {
* @return number of affected database rows; should be 1 * @return number of affected database rows; should be 1
*/ */
public Integer upsertLocation(@Valid LocationBean bean) { public Integer upsertLocation(@Valid LocationBean bean) {
// TODO: implement LambdaResultWrapper lrw = new LambdaResultWrapper();
throw new DataAccessException("not yet implemented"); jooq.transaction(t -> {
if (bean.getPk() == null) {
InsertValuesStep3<TLocationRecord, String, Integer, String> sql = DSL.using(t)
// @formatter:off
.insertInto(T_LOCATION,
T_LOCATION.NAME,
T_LOCATION.FK_DOCUMENT,
T_LOCATION.URL)
.values(bean.getName(), bean.getFkDocument(), bean.getUrl());
// @formatter:on
LOGGER.debug(sql.toString());
lrw.add(sql.execute());
} else {
UpdateConditionStep<TLocationRecord> sql = DSL.using(t)
// @formatter:off
.update(T_LOCATION)
.set(T_LOCATION.NAME, bean.getName())
.set(T_LOCATION.FK_DOCUMENT, bean.getFkDocument())
.set(T_LOCATION.URL, bean.getUrl())
.where(T_LOCATION.PK.eq(bean.getPk()));
// @formatter:on
LOGGER.debug(sql.toString());
lrw.add(sql.execute());
}
});
return lrw.getCounter();
} }
} }