diff --git a/jOOQ/src/main/java/org/jooq/DAO.java b/jOOQ/src/main/java/org/jooq/DAO.java index 89f834f8b3..0463a38596 100644 --- a/jOOQ/src/main/java/org/jooq/DAO.java +++ b/jOOQ/src/main/java/org/jooq/DAO.java @@ -37,6 +37,25 @@ */ package org.jooq; +// ... +// ... +// ... +import static org.jooq.SQLDialect.CUBRID; +// ... +import static org.jooq.SQLDialect.DERBY; +import static org.jooq.SQLDialect.H2; +import static org.jooq.SQLDialect.HSQLDB; +// ... +import static org.jooq.SQLDialect.MARIADB; +// ... +import static org.jooq.SQLDialect.MYSQL; +// ... +import static org.jooq.SQLDialect.POSTGRES; +import static org.jooq.SQLDialect.SQLITE; +// ... +// ... +// ... + import java.util.Collection; import java.util.List; import java.util.Optional; @@ -101,7 +120,7 @@ public interface DAO, P, T> { RecordMapper mapper(); /** - * Performs an INSERT statement for a given POJO + * Performs an INSERT statement for a given POJO. * * @param object The POJO to be inserted * @throws DataAccessException if something went wrong executing the query @@ -110,7 +129,7 @@ public interface DAO, P, T> { void insert(P object) throws DataAccessException; /** - * Performs a batch INSERT statement for a given set of POJOs + * Performs a batch INSERT statement for a given set of POJOs. * * @param objects The POJOs to be inserted * @throws DataAccessException if something went wrong executing the query @@ -120,7 +139,7 @@ public interface DAO, P, T> { void insert(P... objects) throws DataAccessException; /** - * Performs a batch INSERT statement for a given set of POJOs + * Performs a batch INSERT statement for a given set of POJOs. * * @param objects The POJOs to be inserted * @throws DataAccessException if something went wrong executing the query @@ -130,7 +149,7 @@ public interface DAO, P, T> { void insert(Collection

objects) throws DataAccessException; /** - * Performs an UPDATE statement for a given POJO + * Performs an UPDATE statement for a given POJO. * * @param object The POJO to be updated * @throws DataAccessException if something went wrong executing the query @@ -139,7 +158,7 @@ public interface DAO, P, T> { void update(P object) throws DataAccessException; /** - * Performs a batch UPDATE statement for a given set of POJOs + * Performs a batch UPDATE statement for a given set of POJOs. * * @param objects The POJOs to be updated * @throws DataAccessException if something went wrong executing the query @@ -149,7 +168,7 @@ public interface DAO, P, T> { void update(P... objects) throws DataAccessException; /** - * Performs a batch UPDATE statement for a given set of POJOs + * Performs a batch UPDATE statement for a given set of POJOs. * * @param objects The POJOs to be updated * @throws DataAccessException if something went wrong executing the query @@ -158,6 +177,35 @@ public interface DAO, P, T> { @Support void update(Collection

objects) throws DataAccessException; + /** + * Performs an MERGE statement for a given POJO. + * + * @param object The POJO to be merged + * @throws DataAccessException if something went wrong executing the query + */ + @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + void merge(P object) throws DataAccessException; + + /** + * Performs a batch MERGE statement for a given set of POJOs. + * + * @param objects The POJOs to be merged + * @throws DataAccessException if something went wrong executing the query + * @see #update(Collection) + */ + @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + void merge(P... objects) throws DataAccessException; + + /** + * Performs a batch MERGE statement for a given set of POJOs. + * + * @param objects The POJOs to be merged + * @throws DataAccessException if something went wrong executing the query + * @see #update(Object...) + */ + @Support({ CUBRID, DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE }) + void merge(Collection

objects) throws DataAccessException; + /** * Performs a DELETE statement for a POJO * @@ -169,7 +217,7 @@ public interface DAO, P, T> { void delete(P object) throws DataAccessException; /** - * Performs a DELETE statement for a given set of POJOs + * Performs a DELETE statement for a given set of POJOs. * * @param objects The POJOs to be deleted * @throws DataAccessException if something went wrong executing the query @@ -179,7 +227,7 @@ public interface DAO, P, T> { void delete(P... objects) throws DataAccessException; /** - * Performs a DELETE statement for a given set of POJOs + * Performs a DELETE statement for a given set of POJOs. * * @param objects The POJOs to be deleted * @throws DataAccessException if something went wrong executing the query @@ -189,7 +237,7 @@ public interface DAO, P, T> { void delete(Collection

objects) throws DataAccessException; /** - * Performs a DELETE statement for a given set of IDs + * Performs a DELETE statement for a given set of IDs. * * @param ids The IDs to be deleted * @throws DataAccessException if something went wrong executing the query @@ -199,7 +247,7 @@ public interface DAO, P, T> { void deleteById(T... ids) throws DataAccessException; /** - * Performs a DELETE statement for a given set of IDs + * Performs a DELETE statement for a given set of IDs. * * @param ids The IDs to be deleted * @throws DataAccessException if something went wrong executing the query @@ -209,7 +257,7 @@ public interface DAO, P, T> { void deleteById(Collection ids) throws DataAccessException; /** - * Checks if a given POJO exists + * Checks if a given POJO exists. * * @param object The POJO whose existence is checked * @return Whether the POJO already exists @@ -219,7 +267,7 @@ public interface DAO, P, T> { boolean exists(P object) throws DataAccessException; /** - * Checks if a given ID exists + * Checks if a given ID exists. * * @param id The ID whose existence is checked * @return Whether the ID already exists diff --git a/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java b/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java index a451cc1652..9810c00417 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/DAOImpl.java @@ -209,6 +209,36 @@ public abstract class DAOImpl, P, T> implements DAO records(objects, true).get(0).update(); } + @Override + public /* non-final */ void merge(P object) { + merge(singletonList(object)); + } + + @SuppressWarnings("unchecked") + @Override + public /* non-final */ void merge(P... objects) { + merge(asList(objects)); + } + + @Override + public /* non-final */ void merge(Collection

objects) { + + // Execute a batch MERGE + if (objects.size() > 1) + + // [#2536] [#3327] We cannot batch MERGE RETURNING calls yet + if (!FALSE.equals(settings().isReturnRecordToPojo()) && + TRUE.equals(settings().isReturnAllOnUpdatableRecord())) + for (R record : records(objects, false)) + record.merge(); + else + ctx().batchMerge(records(objects, false)).execute(); + + // Execute a regular MERGE + else if (objects.size() == 1) + records(objects, false).get(0).merge(); + } + @Override public /* non-final */ void delete(P object) { delete(singletonList(object));