Skip to content

Commit

Permalink
Merge pull request #805 from jeffgbutler/misc-updates
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
jeffgbutler authored Jun 3, 2024
2 parents 623aa00 + ef5dd4c commit deb1815
Show file tree
Hide file tree
Showing 45 changed files with 870 additions and 855 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Existing converters may be reused if they are marked with this additional interface.
*
* <p>The converter is only used for parameters in a parameter map. It is not used for result set processing.
* It is also not used for insert statements that are based on an external record class. The converter will be called
* It is also not used for insert statements that are based on an external row class. The converter will be called
* in the following circumstances:
*
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String formatParameterMapKey(AtomicInteger sequence) {
public abstract String getFormattedJdbcPlaceholder(String prefix, String parameterName);

/**
* This method generates a binding for a parameter to a placeholder in a record based insert statement.
* This method generates a binding for a parameter to a placeholder in a row based insert statement.
*
* <p>This binding is specifically for use with insert, batch insert, and multirow insert statements.
* These statements bind parameters to properties of a row class. The Spring implementation changes the binding
Expand All @@ -102,7 +102,7 @@ public String getRecordBasedInsertBinding(BindableColumn<?> column, String prefi
}

/**
* This method generates a binding for a parameter to a placeholder in a record based insert statement.
* This method generates a binding for a parameter to a placeholder in a row based insert statement.
*
* <p>This binding is specifically for use with insert, batch insert, and multirow insert statements and the
* MapToRow mapping. These statements bind parameters to the row class directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* </pre>
*
* <p>You could also implement a helper method that would set fields based on values of a record. For example,
* the following method would set all fields of a record based on whether or not the values are null:
* the following method would set all fields of a row based on whether the values are null:
*
* <pre>
* static UpdateDSL&lt;UpdateModel&gt; updateSelectiveColumns(PersonRecord record,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* insert statements that do NOT expect generated keys.
*
* @param <T>
* the type of record associated with this mapper
* the type of row associated with this mapper
*/
public interface CommonInsertMapper<T> extends CommonGeneralInsertMapper {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/site/markdown/docs/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ case String values to enable case-insensitive queries. There are extension point
mapping if you so desire.

Starting with version 1.5.2, we made a change to the rendering rules for the "in" conditions. This was done to limit the
danger of conditions failing to render and thus affecting more rows than expected. For the base conditions ("isIn",
danger of conditions failing to render and thus affecting more rows than expected. For the base conditions ("isIn",
"isNotIn", etc.), if the list of values is empty, then the condition will still render, but the resulting SQL will
be invalid and will cause a runtime exception. We believe this is the safest outcome. For example, suppose
a DELETE statement was coded as follows:
Expand All @@ -220,7 +220,7 @@ This statement will be rendered as follows:
delete from foo where status = ? and id in ()
```

This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALLs rows with
This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALL rows with
active status. If you want to allow the "in" condition to drop from the SQL if the list is empty, then use the
"inWhenPresent" condition.

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/config/TestContainersConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* Utility interface to hold Docker image tags for the test containers we use
*/
public interface TestContainersConfiguration {
DockerImageName POSTGRES_LATEST = DockerImageName.parse("postgres:15.4");
DockerImageName MARIADB_LATEST = DockerImageName.parse("mariadb:11.0.3");
DockerImageName POSTGRES_LATEST = DockerImageName.parse("postgres:16.3");
DockerImageName MARIADB_LATEST = DockerImageName.parse("mariadb:11.4.2");
}
397 changes: 234 additions & 163 deletions src/test/java/examples/animal/data/AnimalDataTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CommonSelectMapperTest {
void setup() throws Exception {
Class.forName(JDBC_DRIVER);
InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
assert is != null;
try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
ScriptRunner sr = new ScriptRunner(connection);
sr.setLogWriter(null);
Expand Down
23 changes: 13 additions & 10 deletions src/test/java/examples/animal/data/FetchFirstTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static examples.animal.data.AnimalDataDynamicSqlSupport.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

Expand Down Expand Up @@ -50,6 +51,7 @@ class FetchFirstTest {
void setup() throws Exception {
Class.forName(JDBC_DRIVER);
InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
assert is != null;
try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
ScriptRunner sr = new ScriptRunner(connection);
sr.setLogWriter(null);
Expand Down Expand Up @@ -78,7 +80,7 @@ void testOffsetAndFetchFirstAfterFrom() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData offset #{parameters.p1} rows fetch first #{parameters.p2} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
Expand All @@ -100,7 +102,7 @@ void testFetchFirstOnlyAfterFrom() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData fetch first #{parameters.p1} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
);
Expand All @@ -124,10 +126,9 @@ void testOffsetAndFetchFirstAfterWhere() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(45),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(45),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} and id > #{parameters.p2,jdbcType=INTEGER} offset #{parameters.p3} rows fetch first #{parameters.p4} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p4", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p3", 22L)
() -> assertThat(selectStatement.getParameters()).contains(entry("p4", 3L), entry("p3", 22L))
);
}
}
Expand All @@ -147,7 +148,7 @@ void testFetchFirstOnlyAfterWhere() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} fetch first #{parameters.p2} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L)
);
Expand All @@ -170,10 +171,12 @@ void testOffsetAndFetchFirstAfterOrderBy() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id offset #{parameters.p1} rows fetch first #{parameters.p2} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
() -> assertThat(selectStatement)
.extracting(SelectStatementProvider::getParameters)
.extracting("p2", "p1")
.containsExactly(3L, 22L)
);
}
}
Expand All @@ -193,7 +196,7 @@ void testLimitOnlyAfterOrderBy() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id fetch first #{parameters.p1} rows only"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
);
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/examples/animal/data/LimitAndOffsetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LimitAndOffsetTest {
void setup() throws Exception {
Class.forName(JDBC_DRIVER);
InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
assert is != null;
try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
ScriptRunner sr = new ScriptRunner(connection);
sr.setLogWriter(null);
Expand Down Expand Up @@ -78,7 +79,7 @@ void testLimitAndOffsetAfterFrom() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData limit #{parameters.p1} offset #{parameters.p2}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 22L)
Expand All @@ -100,7 +101,7 @@ void testLimitOnlyAfterFrom() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData limit #{parameters.p1}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
);
Expand All @@ -121,7 +122,7 @@ void testOffsetOnlyAfterFrom() {

assertAll(
() -> assertThat(records).hasSize(43),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData offset #{parameters.p1} rows"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
);
Expand All @@ -145,7 +146,7 @@ void testLimitAndOffsetAfterWhere() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(45),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(45),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} and id > #{parameters.p2,jdbcType=INTEGER} limit #{parameters.p3} offset #{parameters.p4}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p3", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p4", 22L)
Expand All @@ -168,7 +169,7 @@ void testLimitOnlyAfterWhere() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} limit #{parameters.p2}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 3L)
);
Expand All @@ -190,7 +191,7 @@ void testOffsetOnlyAfterWhere() {

assertAll(
() -> assertThat(records).hasSize(27),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} offset #{parameters.p2} rows"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 22L)
);
Expand All @@ -213,7 +214,7 @@ void testLimitAndOffsetAfterOrderBy() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id limit #{parameters.p1} offset #{parameters.p2}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L),
() -> assertThat(selectStatement.getParameters()).containsEntry("p2", 22L)
Expand All @@ -236,7 +237,7 @@ void testLimitOnlyAfterOrderBy() {

assertAll(
() -> assertThat(records).hasSize(3),
() -> assertThat(records.get(0).getId()).isEqualTo(1),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(1),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id limit #{parameters.p1}"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 3L)
);
Expand All @@ -258,7 +259,7 @@ void testOffsetOnlyAfterOrderBy() {

assertAll(
() -> assertThat(records).hasSize(43),
() -> assertThat(records.get(0).getId()).isEqualTo(23),
() -> assertThat(records).first().isNotNull().extracting(AnimalData::getId).isEqualTo(23),
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id offset #{parameters.p1} rows"),
() -> assertThat(selectStatement.getParameters()).containsEntry("p1", 22L)
);
Expand Down
Loading

0 comments on commit deb1815

Please sign in to comment.