Skip to content

Commit 1a5dfeb

Browse files
committed
Added Sequence generation support
Signed-off-by: mipo256 <[email protected]>
1 parent b51c77b commit 1a5dfeb

File tree

40 files changed

+778
-58
lines changed

40 files changed

+778
-58
lines changed

Diff for: pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
</developers>
127127

128128
<profiles>
129-
130129
<profile>
131130
<id>no-jacoco</id>
132131
<build>

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package org.springframework.data.jdbc.core.convert;
1717

18-
import static org.springframework.data.jdbc.core.convert.SqlGenerator.*;
18+
import static org.springframework.data.jdbc.core.convert.SqlGenerator.ID_SQL_PARAMETER;
19+
import static org.springframework.data.jdbc.core.convert.SqlGenerator.ROOT_ID_PARAMETER;
20+
import static org.springframework.data.jdbc.core.convert.SqlGenerator.VERSION_SQL_PARAMETER;
1921

2022
import java.sql.ResultSet;
2123
import java.sql.SQLException;
@@ -62,6 +64,7 @@
6264
* @author Chirag Tailor
6365
* @author Diego Krupitza
6466
* @author Sergey Korotaev
67+
* @author Mikhail Polivakha
6568
* @since 1.1
6669
*/
6770
public class DefaultDataAccessStrategy implements DataAccessStrategy {
@@ -105,30 +108,35 @@ public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, Relation
105108
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, IdValueSource idValueSource) {
106109

107110
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forInsert(instance, domainType, identifier,
108-
idValueSource);
111+
idValueSource);
109112

110113
String insertSql = sql(domainType).getInsert(parameterSource.getIdentifiers());
111114

112115
return insertStrategyFactory.insertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
113-
parameterSource);
116+
parameterSource);
114117
}
115118

116119
@Override
117120
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, IdValueSource idValueSource) {
118121

119122
Assert.notEmpty(insertSubjects, "Batch insert must contain at least one InsertSubject");
120123
SqlIdentifierParameterSource[] sqlParameterSources = insertSubjects.stream()
121-
.map(insertSubject -> sqlParametersFactory.forInsert(insertSubject.getInstance(), domainType,
122-
insertSubject.getIdentifier(), idValueSource))
123-
.toArray(SqlIdentifierParameterSource[]::new);
124+
.map(insertSubject -> sqlParametersFactory.forInsert( //
125+
insertSubject.getInstance(), //
126+
domainType, //
127+
insertSubject.getIdentifier(), //
128+
idValueSource //
129+
) //
130+
) //
131+
.toArray(SqlIdentifierParameterSource[]::new);
124132

125133
String insertSql = sql(domainType).getInsert(sqlParameterSources[0].getIdentifiers());
126134

127135
return insertStrategyFactory.batchInsertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
128-
sqlParameterSources);
136+
sqlParameterSources);
129137
}
130138

131-
@Override
139+
@Override
132140
public <S> boolean update(S instance, Class<S> domainType) {
133141

134142
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forUpdate(instance, domainType);
@@ -479,5 +487,4 @@ private Class<?> getBaseType(PersistentPropertyPath<RelationalPersistentProperty
479487

480488
return baseProperty.getOwner().getType();
481489
}
482-
483490
}

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/InsertStrategyFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,4 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
101101
return new Object[sqlParameterSources.length];
102102
}
103103
}
104-
105104
}

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
* @since 3.2
6868
*/
6969
public class MappingJdbcConverter extends MappingRelationalConverter implements JdbcConverter, ApplicationContextAware {
70-
70+
7171
private static final Log LOG = LogFactory.getLog(MappingJdbcConverter.class);
7272
private static final Converter<Iterable<?>, Map<?, ?>> ITERABLE_OF_ENTRY_TO_MAP_CONVERTER = new IterableOfEntryToMapConverter();
7373

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlIdentifierParameterSource.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
*/
3636
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
3737

38-
private final Set<SqlIdentifier> identifiers = new HashSet<>();
38+
private final Set<SqlIdentifier> sqlIdentifiers = new HashSet<>();
3939
private final Map<String, Object> namesToValues = new HashMap<>();
4040

41-
@Override
41+
@Override
4242
public boolean hasValue(String paramName) {
4343
return namesToValues.containsKey(paramName);
4444
}
@@ -54,30 +54,34 @@ public String[] getParameterNames() {
5454
}
5555

5656
Set<SqlIdentifier> getIdentifiers() {
57-
return Collections.unmodifiableSet(identifiers);
57+
return Collections.unmodifiableSet(sqlIdentifiers);
5858
}
5959

6060
void addValue(SqlIdentifier name, Object value) {
6161
addValue(name, value, Integer.MIN_VALUE);
6262
}
6363

64-
void addValue(SqlIdentifier identifier, Object value, int sqlType) {
64+
void addValue(SqlIdentifier sqlIdentifier, Object value, int sqlType) {
6565

66-
identifiers.add(identifier);
67-
String name = BindParameterNameSanitizer.sanitize(identifier.getReference());
66+
sqlIdentifiers.add(sqlIdentifier);
67+
String name = prepareSqlIdentifierName(sqlIdentifier);
6868
namesToValues.put(name, value);
6969
registerSqlType(name, sqlType);
7070
}
7171

72-
void addAll(SqlIdentifierParameterSource others) {
72+
void addAll(SqlIdentifierParameterSource others) {
7373

7474
for (SqlIdentifier identifier : others.getIdentifiers()) {
7575

76-
String name = BindParameterNameSanitizer.sanitize( identifier.getReference());
76+
String name = prepareSqlIdentifierName(identifier);
7777
addValue(identifier, others.getValue(name), others.getSqlType(name));
7878
}
7979
}
8080

81+
private static String prepareSqlIdentifierName(SqlIdentifier sqlIdentifier) {
82+
return BindParameterNameSanitizer.sanitize(sqlIdentifier.getReference());
83+
}
84+
8185
int size() {
8286
return namesToValues.size();
8387
}

0 commit comments

Comments
 (0)