Skip to content

Commit

Permalink
Merge pull request #1180 from domaframework/fix/native-sql-insert
Browse files Browse the repository at this point in the history
Fix an issue where calling `peek` on `NativeSql` caused a `ClassCastException`
  • Loading branch information
nakamura-to committed Sep 6, 2024
2 parents 2acdc6d + e8eada1 commit 75811e7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.seasar.doma.jdbc.query.DuplicateKeyType;

public class NativeSqlUpsertOnDuplicateKeyIgnoreSelectingKeys
extends AbstractStatement<NativeSqlUpsertTerminal, Integer> {
extends AbstractStatement<NativeSqlUpsertOnDuplicateKeyIgnoreSelectingKeys, Integer> {
private final Config config;
private final InsertDeclaration declaration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.seasar.doma.jdbc.query.DuplicateKeyType;

public class NativeSqlUpsertOnDuplicateKeyUpdateSelectingKeys
extends AbstractStatement<NativeSqlUpsertTerminal, Integer> {
extends AbstractStatement<NativeSqlUpsertOnDuplicateKeyUpdateSelectingKeys, Integer> {
private final Config config;
private final InsertDeclaration declaration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.seasar.doma.jdbc.criteria.declaration.InsertOnDuplicateKeyUpdateSetValuesDeclaration;

public class NativeSqlUpsertOnDuplicateKeyUpdateSelectingSet
extends AbstractStatement<NativeSqlUpsertTerminal, Integer> {
extends AbstractStatement<NativeSqlUpsertOnDuplicateKeyUpdateSelectingSet, Integer> {
private final Config config;
private final InsertDeclaration declaration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.seasar.doma.it.criteria;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.seasar.doma.it.Dbms;
Expand Down Expand Up @@ -591,4 +593,65 @@ void insert_select_using_same_entityMetamodel() {

assertEquals(4, count);
}

@Test
void onDuplicateKeyIgnore_peek() {
Department_ d = new Department_();
final AtomicBoolean invoked = new AtomicBoolean(false);
nativeSql
.insert(d)
.values(
c -> {
c.value(d.departmentId, 1);
c.value(d.departmentNo, 60);
c.value(d.departmentName, "DEVELOPMENT");
c.value(d.location, "KYOTO");
c.value(d.version, 2);
})
.onDuplicateKeyIgnore()
.peek(it -> invoked.set(true))
.execute();
assertTrue(invoked.get());
}

@Test
void onDuplicateKeyUpdate_peek() {
Department_ d = new Department_();
final AtomicBoolean invoked = new AtomicBoolean(false);
nativeSql
.insert(d)
.values(
c -> {
c.value(d.departmentId, 1);
c.value(d.departmentNo, 60);
c.value(d.departmentName, "DEVELOPMENT");
c.value(d.location, "KYOTO");
c.value(d.version, 2);
})
.onDuplicateKeyUpdate()
.peek(it -> invoked.set(true))
.execute();
assertTrue(invoked.get());
}

@Test
void onDuplicateKeyUpdate_keys_peek() {
var d = new Department_();
final AtomicBoolean invoked = new AtomicBoolean(false);
nativeSql
.insert(d)
.values(
c -> {
c.value(d.departmentId, 6);
c.value(d.departmentNo, 60);
c.value(d.departmentName, "DEVELOPMENT");
c.value(d.location, "KYOTO");
c.value(d.version, 2);
})
.onDuplicateKeyUpdate()
.keys(d.departmentId)
.peek(it -> invoked.set(true))
.execute();
assertTrue(invoked.get());
}
}

0 comments on commit 75811e7

Please sign in to comment.