|
|
|
|
@ -25,6 +25,7 @@ import org.assertj.core.api.SoftAssertions;
@@ -25,6 +25,7 @@ import org.assertj.core.api.SoftAssertions;
|
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.springframework.data.annotation.Id; |
|
|
|
|
import org.springframework.data.annotation.ReadOnlyProperty; |
|
|
|
|
import org.springframework.data.jdbc.core.mapping.AggregateReference; |
|
|
|
|
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; |
|
|
|
|
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils; |
|
|
|
|
@ -40,6 +41,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
@@ -40,6 +41,7 @@ import org.springframework.data.relational.core.mapping.RelationalPersistentProp
|
|
|
|
|
* |
|
|
|
|
* @author Jens Schauder |
|
|
|
|
* @author Greg Turnquist |
|
|
|
|
* @author Oleksandr Kucher |
|
|
|
|
*/ |
|
|
|
|
public class SqlGeneratorUnitTests { |
|
|
|
|
|
|
|
|
|
@ -226,6 +228,87 @@ public class SqlGeneratorUnitTests {
@@ -226,6 +228,87 @@ public class SqlGeneratorUnitTests {
|
|
|
|
|
"id1 = :id"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyExcludedFromQuery_when_generateUpdateSql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getUpdate()).isEqualToIgnoringCase( //
|
|
|
|
|
"UPDATE entity_with_read_only_property " //
|
|
|
|
|
+ "SET x_name = :x_name " //
|
|
|
|
|
+ "WHERE x_id = :x_id" //
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyExcludedFromQuery_when_generateInsertSql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getInsert(emptySet())).isEqualToIgnoringCase( //
|
|
|
|
|
"INSERT INTO entity_with_read_only_property (x_name) " //
|
|
|
|
|
+ "VALUES (:x_name)" //
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyIncludedIntoQuery_when_generateFindAllSql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getFindAll()).isEqualToIgnoringCase("SELECT " |
|
|
|
|
+ "entity_with_read_only_property.x_id AS x_id, " + "entity_with_read_only_property.x_name AS x_name, " |
|
|
|
|
+ "entity_with_read_only_property.x_read_only_value AS x_read_only_value " |
|
|
|
|
+ "FROM entity_with_read_only_property"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyIncludedIntoQuery_when_generateFindAllByPropertySql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getFindAllByProperty("back-ref", "key-column", true)).isEqualToIgnoringCase( //
|
|
|
|
|
"SELECT " //
|
|
|
|
|
+ "entity_with_read_only_property.x_id AS x_id, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_name AS x_name, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_read_only_value AS x_read_only_value, " //
|
|
|
|
|
+ "entity_with_read_only_property.key-column AS key-column " //
|
|
|
|
|
+ "FROM entity_with_read_only_property " //
|
|
|
|
|
+ "WHERE back-ref = :back-ref " //
|
|
|
|
|
+ "ORDER BY key-column" //
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyIncludedIntoQuery_when_generateFindAllInListSql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getFindAllInList()).isEqualToIgnoringCase( //
|
|
|
|
|
"SELECT " //
|
|
|
|
|
+ "entity_with_read_only_property.x_id AS x_id, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_name AS x_name, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_read_only_value AS x_read_only_value " //
|
|
|
|
|
+ "FROM entity_with_read_only_property " //
|
|
|
|
|
+ "WHERE entity_with_read_only_property.x_id in(:ids)" //
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // DATAJDBC-324
|
|
|
|
|
public void readOnlyPropertyIncludedIntoQuery_when_generateFindOneSql() { |
|
|
|
|
|
|
|
|
|
final SqlGenerator sqlGenerator = createSqlGenerator(EntityWithReadOnlyProperty.class); |
|
|
|
|
|
|
|
|
|
assertThat(sqlGenerator.getFindOne()).isEqualToIgnoringCase( //
|
|
|
|
|
"SELECT " //
|
|
|
|
|
+ "entity_with_read_only_property.x_id AS x_id, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_name AS x_name, " //
|
|
|
|
|
+ "entity_with_read_only_property.x_read_only_value AS x_read_only_value " //
|
|
|
|
|
+ "FROM entity_with_read_only_property " //
|
|
|
|
|
+ "WHERE entity_with_read_only_property.x_id = :id" //
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private PersistentPropertyPath<RelationalPersistentProperty> getPath(String path, Class<?> base) { |
|
|
|
|
return PersistentPropertyPathTestUtils.getPath(context, path, base); |
|
|
|
|
} |
|
|
|
|
@ -289,4 +372,10 @@ public class SqlGeneratorUnitTests {
@@ -289,4 +372,10 @@ public class SqlGeneratorUnitTests {
|
|
|
|
|
@Id Long id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class EntityWithReadOnlyProperty { |
|
|
|
|
|
|
|
|
|
@Id Long id; |
|
|
|
|
String name; |
|
|
|
|
@ReadOnlyProperty String readOnlyValue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|