@SuppressWarnings("unchecked") private long executeCompositeMerge() { if (hasRow()) { // update SQLUpdateClause update = new SQLUpdateClause(connection, configuration, entity); populate(update); addKeyConditions(update); return update.execute(); } else { // insert SQLInsertClause insert = new SQLInsertClause(connection, configuration, entity); populate(insert); return insert.execute(); } }
@Override public Long doInSqlInsertWithKeyClause(SQLInsertClause insert) throws SQLException { return insert .columns(qCustomer.firstName, qCustomer.lastName, qCustomer.emailAddress) .values(customer.getFirstName(), customer.getLastName(), customer.getEmailAddress() == null ? null : customer.getEmailAddress().toString()) .executeWithKey(qCustomer.id); } });
@Override public <T> IdGeneratingSQLInsertClause set(final Path<T> path, final Expression<? extends T> expression) { return (IdGeneratingSQLInsertClause) super.set(path, expression); }
@Override public SQLDeleteClause delete(final RelationalPath<?> entity) { return new SQLDeleteClause(con, dialect, entity); }
/** * Execute the clause and return the generated key cast to the given type. * If no rows were created, null is returned, otherwise the key of the first * row is returned. * * @param <T> * @param type * @return */ public <T> T executeWithKey(Class<T> type) { return executeWithKey(type, null); }
@Override public SQLUpdateClause update(final RelationalPath<?> entity) { return new SQLUpdateClause(con, dialect, entity); }
@Override public IdGeneratingSQLInsertClause addFlag(final QueryFlag.Position position, final Expression<?> flag) { return (IdGeneratingSQLInsertClause) super.addFlag(position, flag); }
@Override public IdGeneratingSQLInsertClause columns(final Path<?>... columns) { return (IdGeneratingSQLInsertClause) super.columns(columns); }
@Override public <T> IdGeneratingSQLInsertClause populate(final T obj, final Mapper<T> mapper) { return (IdGeneratingSQLInsertClause) super.populate(obj, mapper); }
@Override public IdGeneratingSQLInsertClause values(final Object... v) { return (IdGeneratingSQLInsertClause) super.values(v); }
@Override public <T> IdGeneratingSQLInsertClause setNull(final Path<T> path) { return (IdGeneratingSQLInsertClause) super.setNull(path); }
@Override public IdGeneratingSQLInsertClause select(final SubQueryExpression<?> sq) { return (IdGeneratingSQLInsertClause) super.select(sq); }
@Override public long doInSqlUpdateClause(SQLUpdateClause update) { return update .where(qCustomer.id.eq(customer.getId())) .set(qCustomer.firstName, customer.getFirstName()) .set(qCustomer.lastName, customer.getLastName()) .set(qCustomer.emailAddress, customer.getEmailAddress() == null ? null : customer.getEmailAddress().toString()).execute(); } });
@Override public <T> IdGeneratingSQLInsertClause set(final Path<T> path, final T value) { return (IdGeneratingSQLInsertClause) super.set(path, value); }
@Override public IdGeneratingSQLInsertClause addFlag(final QueryFlag.Position position, final String flag) { return (IdGeneratingSQLInsertClause) super.addFlag(position, flag); } }