This commit is contained in:
Lukas Eder 2020-04-06 17:17:58 +02:00
parent 48074e08a6
commit e62581488c
2 changed files with 90 additions and 12 deletions

View File

@ -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<R extends TableRecord<R>, P, T> {
RecordMapper<R, P> mapper();
/**
* Performs an <code>INSERT</code> statement for a given POJO
* Performs an <code>INSERT</code> 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<R extends TableRecord<R>, P, T> {
void insert(P object) throws DataAccessException;
/**
* Performs a batch <code>INSERT</code> statement for a given set of POJOs
* Performs a batch <code>INSERT</code> 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<R extends TableRecord<R>, P, T> {
void insert(P... objects) throws DataAccessException;
/**
* Performs a batch <code>INSERT</code> statement for a given set of POJOs
* Performs a batch <code>INSERT</code> 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<R extends TableRecord<R>, P, T> {
void insert(Collection<P> objects) throws DataAccessException;
/**
* Performs an <code>UPDATE</code> statement for a given POJO
* Performs an <code>UPDATE</code> 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<R extends TableRecord<R>, P, T> {
void update(P object) throws DataAccessException;
/**
* Performs a batch <code>UPDATE</code> statement for a given set of POJOs
* Performs a batch <code>UPDATE</code> 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<R extends TableRecord<R>, P, T> {
void update(P... objects) throws DataAccessException;
/**
* Performs a batch <code>UPDATE</code> statement for a given set of POJOs
* Performs a batch <code>UPDATE</code> 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<R extends TableRecord<R>, P, T> {
@Support
void update(Collection<P> objects) throws DataAccessException;
/**
* Performs an <code>MERGE</code> 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 <code>MERGE</code> 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 <code>MERGE</code> 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<P> objects) throws DataAccessException;
/**
* Performs a <code>DELETE</code> statement for a POJO
*
@ -169,7 +217,7 @@ public interface DAO<R extends TableRecord<R>, P, T> {
void delete(P object) throws DataAccessException;
/**
* Performs a <code>DELETE</code> statement for a given set of POJOs
* Performs a <code>DELETE</code> 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<R extends TableRecord<R>, P, T> {
void delete(P... objects) throws DataAccessException;
/**
* Performs a <code>DELETE</code> statement for a given set of POJOs
* Performs a <code>DELETE</code> 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<R extends TableRecord<R>, P, T> {
void delete(Collection<P> objects) throws DataAccessException;
/**
* Performs a <code>DELETE</code> statement for a given set of IDs
* Performs a <code>DELETE</code> 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<R extends TableRecord<R>, P, T> {
void deleteById(T... ids) throws DataAccessException;
/**
* Performs a <code>DELETE</code> statement for a given set of IDs
* Performs a <code>DELETE</code> 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<R extends TableRecord<R>, P, T> {
void deleteById(Collection<T> 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<R extends TableRecord<R>, 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

View File

@ -209,6 +209,36 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, 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<P> 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));