Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Fix support for JSON operators in DAO #798

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ private List<QueryPart> createQueryParts(String sqlInput, Method method) throws

sqlInput = sqlPreProcess(sqlInput);

if (sqlInput.indexOf('?') != -1) {
throw new RuntimeException("Unnamed parameters are not supported: " + sqlInput);
}

int pos = 0;
Matcher matcher = NAMED_PARAMETER_PATTERN.matcher(sqlInput);
if (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import java.util.Map;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class ParameterizedQueryTest {

MockDb db = new MockDb();
DbProxy dbProxy = new DbProxy(new DatabaseConfig(), db.getConnectionProvider());
TestDao dao = dbProxy.create(TestDao.class);
Expand Down Expand Up @@ -65,25 +64,21 @@ void shouldResolveParametersWithoutAnnotationFromQuery() throws SQLException {
}

@Test
void shouldThrowExceptionIfUnnamedParamsUsedInQuery() {
try {
dao.unnamedParameters("myid", "myname").blockLast();
fail("Exptected exception");
} catch (Exception e) {
assertThat(e.getMessage())
.isEqualTo("Unnamed parameters are not supported: SELECT * FROM foo WHERE id=? AND name=?");
}
void shouldNotThrowExceptionIfUnnamedParamsUsedInQuery() {
assertThatNoException()
.isThrownBy(() -> dao.unnamedParameters("myid", "myname").blockLast());
}

@Test
void shouldAllowJsonOperators() {
assertThatNoException().isThrownBy(() -> dao.jsonOperators().blockLast());
}

@Test
void shouldThrowExceptionIfNotAllParametersAreFound() {
try {
dao.missingParamName("myid", "myname").blockLast();
fail("Exptected exception");
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo(
"Query contains placeholder \"name\" but method noes not have such argument");
}
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> dao.missingParamName("myid", "myname").blockLast())
.withMessage("Query contains placeholder \"name\" but method noes not have such argument");
}

@Test
Expand Down Expand Up @@ -323,10 +318,11 @@ interface TestDao {
@Query("SELECT x FROM y WHERE z IN (:param)")
Flux<String> inClauseUuid(List<UUID> param);

@Query("SELECT x FROM y WHERE z IN (:param)")
Flux<String> unsupportedArrayType(List<Boolean> param);
@Query("SELECT * FROM message_projections WHERE message_json->'categories' ?| array['newsletter', 'spam']")
Flux<String> jsonOperators();
}

@SuppressWarnings("unused")
public class TestObject {
TestEnum myEnum;
boolean finished;
Expand Down
Loading