Skip to content

Commit

Permalink
Introduce JpaEntityInformation.getVersionAttribute()
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Mar 19, 2024
1 parent ac3f819 commit 3ce4af2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import org.springframework.data.jpa.repository.query.JpaEntityMetadata;
import org.springframework.data.repository.core.EntityInformation;
Expand All @@ -30,6 +31,7 @@
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
* @author Yanming Zhou
*/
public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, JpaEntityMetadata<T> {

Expand All @@ -39,6 +41,11 @@ public interface JpaEntityInformation<T, ID> extends EntityInformation<T, ID>, J
@Nullable
SingularAttribute<? super T, ?> getIdAttribute();

/**
* Returns the version attribute of the entity.
*/
Optional<SingularAttribute<? super T, ?>> getVersionAttribute();

/**
* Returns the required identifier type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@

/**
* Implementation of {@link org.springframework.data.repository.core.EntityInformation} that uses JPA {@link Metamodel}
* to find the domain class' id field.
* to find the domain class' id and version field.
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Christoph Strobl
* @author Mark Paluch
* @author Jens Schauder
* @author Greg Turnquist
* @author Yanming Zhou
*/
public class JpaMetamodelEntityInformation<T, ID> extends JpaEntityInformationSupport<T, ID> {

Expand Down Expand Up @@ -191,6 +192,11 @@ public Class<ID> getIdType() {
return idMetadata.getSimpleIdAttribute();
}

@Override
public Optional<SingularAttribute<? super T, ?>> getVersionAttribute() {
return versionAttribute;
}

@Override
public boolean hasCompositeId() {
return !idMetadata.hasSimpleId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -42,6 +43,7 @@
*
* @author Oliver Gierke
* @author Jens Schauder
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
Expand Down Expand Up @@ -88,6 +90,11 @@ static class DummyJpaEntityInformation<T, ID> extends JpaEntityInformationSuppor
return null;
}

@Override
public Optional<SingularAttribute<? super T, ?>> getVersionAttribute() {
return Optional.empty();
}

@Override
public ID getId(T entity) {
return null;
Expand Down

0 comments on commit 3ce4af2

Please sign in to comment.