Skip to content

Added Sequence generation support #1955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
</developers>

<profiles>

<profile>
<id>no-jacoco</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package org.springframework.data.jdbc.core.convert;

import static org.springframework.data.jdbc.core.convert.SqlGenerator.*;
import static org.springframework.data.jdbc.core.convert.SqlGenerator.ID_SQL_PARAMETER;
import static org.springframework.data.jdbc.core.convert.SqlGenerator.ROOT_ID_PARAMETER;
import static org.springframework.data.jdbc.core.convert.SqlGenerator.VERSION_SQL_PARAMETER;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -62,6 +64,7 @@
* @author Chirag Tailor
* @author Diego Krupitza
* @author Sergey Korotaev
* @author Mikhail Polivakha
* @since 1.1
*/
public class DefaultDataAccessStrategy implements DataAccessStrategy {
Expand Down Expand Up @@ -105,30 +108,35 @@ public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, Relation
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, IdValueSource idValueSource) {

SqlIdentifierParameterSource parameterSource = sqlParametersFactory.forInsert(instance, domainType, identifier,
idValueSource);
idValueSource);

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

return insertStrategyFactory.insertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
parameterSource);
parameterSource);
}

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

Assert.notEmpty(insertSubjects, "Batch insert must contain at least one InsertSubject");
SqlIdentifierParameterSource[] sqlParameterSources = insertSubjects.stream()
.map(insertSubject -> sqlParametersFactory.forInsert(insertSubject.getInstance(), domainType,
insertSubject.getIdentifier(), idValueSource))
.toArray(SqlIdentifierParameterSource[]::new);
.map(insertSubject -> sqlParametersFactory.forInsert( //
insertSubject.getInstance(), //
domainType, //
insertSubject.getIdentifier(), //
idValueSource //
) //
) //
.toArray(SqlIdentifierParameterSource[]::new);

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

return insertStrategyFactory.batchInsertStrategy(idValueSource, getIdColumn(domainType)).execute(insertSql,
sqlParameterSources);
sqlParameterSources);
}

@Override
@Override
public <S> boolean update(S instance, Class<S> domainType) {

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

return baseProperty.getOwner().getType();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
return new Object[sqlParameterSources.length];
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* @since 3.2
*/
public class MappingJdbcConverter extends MappingRelationalConverter implements JdbcConverter, ApplicationContextAware {


private static final Log LOG = LogFactory.getLog(MappingJdbcConverter.class);
private static final Converter<Iterable<?>, Map<?, ?>> ITERABLE_OF_ENTRY_TO_MAP_CONVERTER = new IterableOfEntryToMapConverter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
*/
class SqlIdentifierParameterSource extends AbstractSqlParameterSource {

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

@Override
@Override
public boolean hasValue(String paramName) {
return namesToValues.containsKey(paramName);
}
Expand All @@ -54,30 +54,34 @@ public String[] getParameterNames() {
}

Set<SqlIdentifier> getIdentifiers() {
return Collections.unmodifiableSet(identifiers);
return Collections.unmodifiableSet(sqlIdentifiers);
}

void addValue(SqlIdentifier name, Object value) {
addValue(name, value, Integer.MIN_VALUE);
}

void addValue(SqlIdentifier identifier, Object value, int sqlType) {
void addValue(SqlIdentifier sqlIdentifier, Object value, int sqlType) {

identifiers.add(identifier);
String name = BindParameterNameSanitizer.sanitize(identifier.getReference());
sqlIdentifiers.add(sqlIdentifier);
String name = prepareSqlIdentifierName(sqlIdentifier);
namesToValues.put(name, value);
registerSqlType(name, sqlType);
}

void addAll(SqlIdentifierParameterSource others) {
void addAll(SqlIdentifierParameterSource others) {

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

String name = BindParameterNameSanitizer.sanitize( identifier.getReference());
String name = prepareSqlIdentifierName(identifier);
addValue(identifier, others.getValue(name), others.getSqlType(name));
}
}

private static String prepareSqlIdentifierName(SqlIdentifier sqlIdentifier) {
return BindParameterNameSanitizer.sanitize(sqlIdentifier.getReference());
}

int size() {
return namesToValues.size();
}
Expand Down
Loading
Loading