Browse Source

DATAJDBC-264 - Polishing.

Added a test.
Added an author tag.
Minor formatting.

Original pull request: #88.
pull/82/merge
Jens Schauder 7 years ago
parent
commit
84de41a87d
  1. 2
      src/main/java/org/springframework/data/jdbc/core/SqlGenerator.java
  2. 31
      src/test/java/org/springframework/data/jdbc/core/SqlGeneratorUnitTests.java

2
src/main/java/org/springframework/data/jdbc/core/SqlGenerator.java

@ -39,6 +39,7 @@ import org.springframework.util.Assert; @@ -39,6 +39,7 @@ import org.springframework.util.Assert;
* Generates SQL statements to be used by {@link SimpleJdbcRepository}
*
* @author Jens Schauder
* @author Yoichi Imai
*/
class SqlGenerator {
@ -260,6 +261,7 @@ class SqlGenerator { @@ -260,6 +261,7 @@ class SqlGenerator {
columnNamesForInsert.addAll(additionalColumns);
String tableColumns = String.join(", ", columnNamesForInsert);
String parameterNames = columnNamesForInsert.stream()//
.map(n -> String.format(":%s", n))//
.collect(Collectors.joining(", "));

31
src/test/java/org/springframework/data/jdbc/core/SqlGeneratorUnitTests.java

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
*/
package org.springframework.data.jdbc.core;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Map;
@ -26,11 +27,10 @@ import org.junit.Test; @@ -26,11 +27,10 @@ import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.mapping.PersistentPropertyPathTestUtils;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.NamingStrategy;
/**
* Unit tests for the {@link SqlGenerator}.
@ -46,10 +46,16 @@ public class SqlGeneratorUnitTests { @@ -46,10 +46,16 @@ public class SqlGeneratorUnitTests {
@Before
public void setUp() {
this.sqlGenerator = createSqlGenerator(DummyEntity.class);
}
SqlGenerator createSqlGenerator(Class<?> type) {
NamingStrategy namingStrategy = new PrefixingNamingStrategy();
RelationalMappingContext context = new RelationalMappingContext(namingStrategy);
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(DummyEntity.class);
this.sqlGenerator = new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
RelationalPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(type);
return new SqlGenerator(context, persistentEntity, new SqlGeneratorSource(context));
}
@Test // DATAJDBC-112
@ -170,10 +176,20 @@ public class SqlGeneratorUnitTests { @@ -170,10 +176,20 @@ public class SqlGeneratorUnitTests {
+ "WHERE back-ref = :back-ref " + "ORDER BY key-column");
}
@Test // DATAJDBC-264
public void getInsertForEmptyColumnList() {
SqlGenerator sqlGenerator = createSqlGenerator(IdOnlyEntity.class);
String insert = sqlGenerator.getInsert(emptySet());
assertThat(insert).endsWith("()");
}
private PersistentPropertyPath<RelationalPersistentProperty> getPath(String path, Class<?> base) {
return PersistentPropertyPathTestUtils.getPath(context, path, base);
}
@SuppressWarnings("unused")
static class DummyEntity {
@ -212,4 +228,11 @@ public class SqlGeneratorUnitTests { @@ -212,4 +228,11 @@ public class SqlGeneratorUnitTests {
}
}
@SuppressWarnings("unused")
static class IdOnlyEntity {
@Id Long id;
}
}

Loading…
Cancel
Save