Skip to content
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-386-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-386-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-386-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
<version>1.2.0.DATAJDBC-386-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private Object getIdFrom(DbAction.WithEntity<?> idOwningAction) {
.getRequiredPersistentEntity(idOwningAction.getEntityType());
Object identifier = persistentEntity.getIdentifierAccessor(idOwningAction.getEntity()).getIdentifier();

Assert.state(identifier != null, "Couldn't get obtain a required id value");
Assert.state(identifier != null, "Couldn't obtain a required id value");

return identifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
*/
package org.springframework.data.jdbc.core;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.lang.Nullable;

/**
* Specifies a operations one can perform on a database, based on an <em>Domain Type</em>.
*
* @author Jens Schauder
* @author Thomas Lang
* @author Milan Milanov
*/
public interface JdbcAggregateOperations {

Expand Down Expand Up @@ -128,4 +132,24 @@ public interface JdbcAggregateOperations {
* @return whether the aggregate exists.
*/
<T> boolean existsById(Object id, Class<T> domainType);

/**
* Load all aggregates of a given type, sorted.
*
* @param domainType the type of the aggregate roots. Must not be {@code null}.
* @param <T> the type of the aggregate roots. Must not be {@code null}.
* @param sort the sorting information. Must not be {@code null}.
* @return Guaranteed to be not {@code null}.
*/
<T> Iterable<T> findAll(Class<T> domainType, Sort sort);

/**
* Load a page of (potentially sorted) aggregates of a given type.
*
* @param domainType the type of the aggregate roots. Must not be {@code null}.
* @param <T> the type of the aggregate roots. Must not be {@code null}.
* @param pageable the pagination information. Must not be {@code null}.
* @return Guaranteed to be not {@code null}.
*/
<T> Page<T> findAll(Class<T> domainType, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.mapping.IdentifierAccessor;
import org.springframework.data.mapping.callback.EntityCallbacks;
Expand Down Expand Up @@ -56,6 +62,7 @@
* @author Mark Paluch
* @author Thomas Lang
* @author Christoph Strobl
* @author Milan Milanov
*/
public class JdbcAggregateTemplate implements JdbcAggregateOperations {

Expand Down Expand Up @@ -234,6 +241,35 @@ public <T> boolean existsById(Object id, Class<T> domainType) {
return accessStrategy.existsById(id, domainType);
}

/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.JdbcAggregateOperations#findAll(java.lang.Class, org.springframework.data.domain.Sort)
*/
@Override
public <T> Iterable<T> findAll(Class<T> domainType, Sort sort) {

Assert.notNull(domainType, "Domain type must not be null!");

Iterable<T> all = accessStrategy.findAll(domainType, sort);
return triggerAfterLoad(all);
}

/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.JdbcAggregateOperations#findAll(java.lang.Class, org.springframework.data.domain.Pageable)
*/
@Override
public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {

Assert.notNull(domainType, "Domain type must not be null!");

Iterable<T> items = triggerAfterLoad(accessStrategy.findAll(domainType, pageable));
long totalCount = accessStrategy.count(domainType);

return new PageImpl<>(StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList()), pageable,
totalCount);
}

/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.JdbcAggregateOperations#findAll(java.lang.Class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.relational.domain.IdentifierProcessing;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
Expand All @@ -69,6 +71,7 @@ public class BasicJdbcConverter extends BasicRelationalConverter implements Jdbc
private static final Converter<Iterable<?>, Map<?, ?>> ITERABLE_OF_ENTRY_TO_MAP_CONVERTER = new IterableOfEntryToMapConverter();

private final JdbcTypeFactory typeFactory;
private final IdentifierProcessing identifierProcessing = HsqlDbDialect.INSTANCE.getIdentifierProcessing();

private RelationResolver relationResolver;

Expand Down Expand Up @@ -374,7 +377,8 @@ private Object readFrom(RelationalPersistentProperty property) {
return readEntityFrom(property, path);
}

Object value = getObjectFromResultSet(path.extendBy(property).getColumnAlias());
Object value = getObjectFromResultSet(
path.extendBy(property).getColumnAlias().toColumnName(identifierProcessing));
return readValue(value, property.getTypeInformation());
}

Expand Down Expand Up @@ -428,7 +432,8 @@ private Object readEntityFrom(RelationalPersistentProperty property, PersistentP
if (idProperty != null) {
idValue = newContext.readFrom(idProperty);
} else {
idValue = newContext.getObjectFromResultSet(path.extendBy(property).getReverseColumnNameAlias());
idValue = newContext.getObjectFromResultSet(
path.extendBy(property).getReverseColumnNameAlias().toColumnName(identifierProcessing));
}

if (idValue == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import java.util.function.Consumer;
import java.util.function.Function;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.relational.domain.SqlIdentifier;

/**
* Delegates each methods to the {@link DataAccessStrategy}s passed to the constructor in turn until the first that does
Expand All @@ -32,6 +35,7 @@
* @author Jens Schauder
* @author Mark Paluch
* @author Tyler Van Gorder
* @author Milan Milanov
* @since 1.1
*/
public class CascadingDataAccessStrategy implements DataAccessStrategy {
Expand All @@ -47,7 +51,7 @@ public CascadingDataAccessStrategy(List<DataAccessStrategy> strategies) {
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
*/
@Override
public <T> Object insert(T instance, Class<T> domainType, Map<String, Object> additionalParameters) {
public <T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters) {
return collect(das -> das.insert(instance, domainType, additionalParameters));
}

Expand Down Expand Up @@ -187,6 +191,24 @@ public <T> boolean existsById(Object id, Class<T> domainType) {
return collect(das -> das.existsById(id, domainType));
}

/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.JdbcAggregateOperations#findAll(java.lang.Class, org.springframework.data.domain.Sort)
*/
@Override
public <T> Iterable<T> findAll(Class<T> domainType, Sort sort) {
return collect(das -> das.findAll(domainType, sort));
}

/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.JdbcAggregateOperations#findAll(java.lang.Class, org.springframework.data.domain.Pageable)
*/
@Override
public <T> Iterable<T> findAll(Class<T> domainType, Pageable pageable) {
return collect(das -> das.findAll(domainType, pageable));
}

private <T> T collect(Function<DataAccessStrategy, T> function) {

// Keep <T> as Eclipse fails to compile if <> is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import java.util.Map;

import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.relational.domain.SqlIdentifier;
import org.springframework.lang.Nullable;

/**
Expand All @@ -31,6 +34,7 @@
*
* @author Jens Schauder
* @author Tyler Van Gorder
* @author Milan Milanov
*/
public interface DataAccessStrategy extends RelationResolver {

Expand All @@ -46,7 +50,8 @@ public interface DataAccessStrategy extends RelationResolver {
* @deprecated since 1.1, use {@link #insert(Object, Class, Identifier)} instead.
*/
@Deprecated
<T> Object insert(T instance, Class<T> domainType, Map<String, Object> additionalParameters);
@Nullable
<T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters);

/**
* Inserts a the data of a single entity. Referenced entities don't get handled.
Expand Down Expand Up @@ -76,8 +81,8 @@ default <T> Object insert(T instance, Class<T> domainType, Identifier identifier
<T> boolean update(T instance, Class<T> domainType);

/**
* Updates the data of a single entity in the database and enforce optimistic record locking using the {@code previousVersion}
* property. Referenced entities don't get handled.
* Updates the data of a single entity in the database and enforce optimistic record locking using the
* {@code previousVersion} property. Referenced entities don't get handled.
* <P>
* The statement will be of the form : {@code UPDATE … SET … WHERE ID = :id and VERSION_COLUMN = :previousVersion }
* and throw an optimistic record locking exception if no rows have been updated.
Expand All @@ -87,7 +92,8 @@ default <T> Object insert(T instance, Class<T> domainType, Identifier identifier
* @param previousVersion The previous version assigned to the instance being saved.
* @param <T> the type of the instance to save.
* @return whether the update actually updated a row.
* @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the optimistic locking version check failed.
* @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the
* optimistic locking version check failed.
* @since 2.0
*/
<T> boolean updateWithVersion(T instance, Class<T> domainType, Number previousVersion);
Expand All @@ -113,7 +119,8 @@ default <T> Object insert(T instance, Class<T> domainType, Identifier identifier
* @param domainType the type of entity to be deleted. Implicitly determines the table to operate on. Must not be
* {@code null}.
* @param previousVersion The previous version assigned to the instance being saved.
* @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the optimistic locking version check failed.
* @throws OptimisticLockingFailureException if the update fails to update at least one row assuming the the
* optimistic locking version check failed.
* @since 2.0
*/
<T> void deleteWithVersion(Object id, Class<T> domainType, Number previousVersion);
Expand Down Expand Up @@ -211,4 +218,24 @@ default Iterable<Object> findAllByPath(Identifier identifier,
* @return {@code true} if a matching row exists, otherwise {@code false}.
*/
<T> boolean existsById(Object id, Class<T> domainType);

/**
* Loads all entities of the given type, sorted.
*
* @param domainType the type of entities to load. Must not be {@code null}.
* @param <T> the type of entities to load.
* @param sort the sorting information. Must not be {@code null}.
* @return Guaranteed to be not {@code null}.
*/
<T> Iterable<T> findAll(Class<T> domainType, Sort sort);

/**
* Loads all entities of the given type, paged and sorted.
*
* @param domainType the type of entities to load. Must not be {@code null}.
* @param <T> the type of entities to load.
* @param pageable the pagination information. Must not be {@code null}.
* @return Guaranteed to be not {@code null}.
*/
<T> Iterable<T> findAll(Class<T> domainType, Pageable pageable);
}
Loading