Skip to content

Commit d500fed

Browse files
committed
Added Sequence generation support
1 parent e4ba477 commit d500fed

File tree

40 files changed

+803
-51
lines changed

40 files changed

+803
-51
lines changed

pom.xml

Lines changed: 0 additions & 1 deletion
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>

spring-data-jdbc/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,37 @@
299299
</plugins>
300300
</build>
301301
</profile>
302+
<profile>
303+
<id>mariadb</id>
304+
<build>
305+
<plugins>
306+
<plugin>
307+
<groupId>org.apache.maven.plugins</groupId>
308+
<artifactId>maven-failsafe-plugin</artifactId>
309+
<executions>
310+
<execution>
311+
<id>mariadb-test</id>
312+
<phase>integration-test</phase>
313+
<goals>
314+
<goal>integration-test</goal>
315+
</goals>
316+
<configuration>
317+
<includes>
318+
<include>**/*IntegrationTests.java</include>
319+
</includes>
320+
<excludes>
321+
<exclude/>
322+
</excludes>
323+
<systemPropertyVariables>
324+
<spring.profiles.active>mariadb</spring.profiles.active>
325+
</systemPropertyVariables>
326+
</configuration>
327+
</execution>
328+
</executions>
329+
</plugin>
330+
</plugins>
331+
</build>
332+
</profile>
302333
<profile>
303334
<id>all-dbs</id>
304335
<build>

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@
1919

2020
import java.sql.ResultSet;
2121
import java.sql.SQLException;
22+
import java.util.Arrays;
2223
import java.util.Collections;
2324
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Objects;
2427
import java.util.Optional;
28+
import java.util.Set;
29+
import java.util.stream.Collectors;
30+
import java.util.stream.IntStream;
31+
import java.util.stream.LongStream;
2532

2633
import org.springframework.dao.EmptyResultDataAccessException;
2734
import org.springframework.dao.OptimisticLockingFailureException;
@@ -37,6 +44,7 @@
3744
import org.springframework.data.relational.core.query.Query;
3845
import org.springframework.data.relational.core.sql.LockMode;
3946
import org.springframework.data.relational.core.sql.SqlIdentifier;
47+
import org.springframework.data.util.Pair;
4048
import org.springframework.jdbc.core.RowMapper;
4149
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
4250
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
@@ -60,6 +68,7 @@
6068
* @author Radim Tlusty
6169
* @author Chirag Tailor
6270
* @author Diego Krupitza
71+
* @author Mikhail Polivakha
6372
* @since 1.1
6473
*/
6574
public class DefaultDataAccessStrategy implements DataAccessStrategy {
@@ -103,30 +112,35 @@ public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, Relation
103112
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, IdValueSource idValueSource) {
104113

105114
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forInsert(instance, domainType, identifier,
106-
idValueSource);
115+
idValueSource);
107116

108117
String insertSql = sql(domainType).getInsert(parameterSource.getIdentifiers());
109118

110119
return insertStrategyFactory.insertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
111-
parameterSource);
120+
parameterSource);
112121
}
113122

114123
@Override
115124
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, IdValueSource idValueSource) {
116125

117126
Assert.notEmpty(insertSubjects, "Batch insert must contain at least one InsertSubject");
118127
SqlIdentifierParameterSource[] sqlParameterSources = insertSubjects.stream()
119-
.map(insertSubject -> sqlParametersFactory.forInsert(insertSubject.getInstance(), domainType,
120-
insertSubject.getIdentifier(), idValueSource))
121-
.toArray(SqlIdentifierParameterSource[]::new);
128+
.map(insertSubject -> sqlParametersFactory.forInsert(
129+
insertSubject.getInstance(),
130+
domainType,
131+
insertSubject.getIdentifier(),
132+
idValueSource
133+
)
134+
)
135+
.toArray(SqlIdentifierParameterSource[]::new);
122136

123137
String insertSql = sql(domainType).getInsert(sqlParameterSources[0].getIdentifiers());
124138

125139
return insertStrategyFactory.batchInsertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
126-
sqlParameterSources);
140+
sqlParameterSources);
127141
}
128142

129-
@Override
143+
@Override
130144
public <S> boolean update(S instance, Class<S> domainType) {
131145

132146
SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forUpdate(instance, domainType);
@@ -445,5 +459,4 @@ private Class<?> getBaseType(PersistentPropertyPath<RelationalPersistentProperty
445459

446460
return baseProperty.getOwner().getType();
447461
}
448-
449462
}

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

Lines changed: 0 additions & 1 deletion
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
}

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

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Set;
2323

2424
import org.springframework.data.relational.core.sql.SqlIdentifier;
25+
import org.springframework.data.util.Pair;
2526
import org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource;
2627

2728
/**
@@ -35,9 +36,11 @@
3536
*/
3637
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
3738

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

42+
private Pair<SqlIdentifier, Object> idToValue;
43+
4144
@Override
4245
public boolean hasValue(String paramName) {
4346
return namesToValues.containsKey(paramName);
@@ -54,30 +57,34 @@ public String[] getParameterNames() {
5457
}
5558

5659
Set<SqlIdentifier> getIdentifiers() {
57-
return Collections.unmodifiableSet(identifiers);
60+
return Collections.unmodifiableSet(sqlIdentifiers);
5861
}
5962

6063
void addValue(SqlIdentifier name, Object value) {
6164
addValue(name, value, Integer.MIN_VALUE);
6265
}
6366

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

66-
identifiers.add(identifier);
67-
String name = BindParameterNameSanitizer.sanitize(identifier.getReference());
69+
sqlIdentifiers.add(sqlIdentifier);
70+
String name = prepareSqlIdentifierName(sqlIdentifier);
6871
namesToValues.put(name, value);
6972
registerSqlType(name, sqlType);
7073
}
7174

72-
void addAll(SqlIdentifierParameterSource others) {
75+
void addAll(SqlIdentifierParameterSource others) {
7376

7477
for (SqlIdentifier identifier : others.getIdentifiers()) {
7578

76-
String name = BindParameterNameSanitizer.sanitize( identifier.getReference());
79+
String name = prepareSqlIdentifierName(identifier);
7780
addValue(identifier, others.getValue(name), others.getSqlType(name));
7881
}
7982
}
8083

84+
private static String prepareSqlIdentifierName(SqlIdentifier sqlIdentifier) {
85+
return BindParameterNameSanitizer.sanitize(sqlIdentifier.getReference());
86+
}
87+
8188
int size() {
8289
return namesToValues.size();
8390
}

0 commit comments

Comments
 (0)