Skip to content

Commit

Permalink
Revert "Add Support to Upsert/Insert Ignore on PDB"
Browse files Browse the repository at this point in the history
This reverts commit d626297.
  • Loading branch information
victorcmg-fdz committed Jul 4, 2023
1 parent 23817e8 commit 3cd2cc6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ protected AbstractBatch(final DatabaseEngine de, final int batchSize, final long
* @param <R> the type of the second argument to the operation.
*/
@FunctionalInterface
private interface FlushConsumer<T, R> {
void accept(T t, R r) throws DatabaseEngineException;
public interface ThrowingBiConsumer<T, R> {
void accept(T t, R r) throws Exception;
}

/**
Expand Down Expand Up @@ -480,7 +480,7 @@ public void flushUpsert() {
*
* @param processBatch A (throwing) BiConsumer to process the batch entries.
*/
private void flush(final FlushConsumer<DatabaseEngine, List<BatchEntry>> processBatch) {
private void flush(final ThrowingBiConsumer<DatabaseEngine, List<BatchEntry>> processBatch) {
this.metricsListener.onFlushTriggered();
final long flushTriggeredMs = System.currentTimeMillis();
List<BatchEntry> temp;
Expand Down Expand Up @@ -539,7 +539,7 @@ private void flush(final FlushConsumer<DatabaseEngine, List<BatchEntry>> process
de.rollback();
}

processBatch.accept(de, temp);
processBatch(de, temp);

success = true;
} catch (final InterruptedException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ When done, the future removes itself (if done already, all this can be skipped).

@Override
public void flushUpsert() {
logger.error("Flush ignoring not available for MultithreadedBatch.");
throw new UnsupportedOperationException("Flushing pending batches upserting duplicated entries is not implemented using multiple threads/connections.");
logger.trace("Flush ignoring not available for MultithreadedBatch. Skipping ...");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ protected MappedEntity createPreparedStatementForInserts(final DbEntity entity)
insertIntoWithAutoInc.add("(" + join(columnsWithAutoInc, ", ") + ")");
insertIntoWithAutoInc.add("VALUES (" + join(valuesWithAutoInc, ", ") + ")");

final String statementWithMerge = buildUpsertStatement(entity, columns, values);
final String statementWithMerge = buildMergeStatement(entity, columns, values);

final String statement = join(insertInto, " ");
// The H2 DB doesn't implement INSERT RETURNING. Therefore, we just create a dummy statement, which will
Expand Down Expand Up @@ -504,7 +504,7 @@ protected MappedEntity createPreparedStatementForInserts(final DbEntity entity)
*
* @return A merge statement.
*/
private String buildUpsertStatement(final DbEntity entity, final List<String> columns, final List<String> values) {
private String buildMergeStatement(final DbEntity entity, final List<String> columns, final List<String> values) {

if (entity.getPkFields().isEmpty() || columns.isEmpty() || values.isEmpty()) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,21 +406,21 @@ protected MappedEntity createPreparedStatementForInserts(final DbEntity entity)
final String insertStatement = join(insertInto, " ");
final String insertReturnStatement = join(insertIntoReturn, " ");
final String statementWithAutoInt = join(insertIntoWithAutoInc, " ");
final String upsert = buildUpsertStatement(entity, columns, values);
final String insertIgnoring = buildInsertOnConflictStatement(entity, columns, values);

logger.trace(insertStatement);
logger.trace(insertReturnStatement);
logger.trace(upsert);
logger.trace(insertIgnoring);

PreparedStatement ps, psReturn, psWithAutoInc, psUpsert;
PreparedStatement ps, psReturn, psWithAutoInc, psWithInsertIgnoring;
try {

ps = conn.prepareStatement(insertStatement);
psReturn = conn.prepareStatement(insertReturnStatement);
psWithAutoInc = conn.prepareStatement(statementWithAutoInt);
psUpsert = conn.prepareStatement(upsert);
psWithInsertIgnoring = conn.prepareStatement(insertIgnoring);

return new MappedEntity().setInsert(ps).setInsertReturning(psReturn).setInsertWithAutoInc(psWithAutoInc).setUpsert(psUpsert).setAutoIncColumn(returning);
return new MappedEntity().setInsert(ps).setInsertReturning(psReturn).setInsertWithAutoInc(psWithAutoInc).setUpsert(psWithInsertIgnoring).setAutoIncColumn(returning);
} catch (final SQLException ex) {
throw new DatabaseEngineException("Something went wrong handling statement", ex);
}
Expand All @@ -435,7 +435,7 @@ protected MappedEntity createPreparedStatementForInserts(final DbEntity entity)
*
* @return A insert on conflict statement.
*/
private String buildUpsertStatement(final DbEntity entity, final List<String> columns, final List<String> values) {
private String buildInsertOnConflictStatement(final DbEntity entity, final List<String> columns, final List<String> values) {

if (entity.getPkFields().isEmpty() || columns.isEmpty() || values.isEmpty()) {
return "";
Expand Down

0 comments on commit 3cd2cc6

Please sign in to comment.