DATAJDBC-137 - Improve EntityInformation usage.
Moved to both the usage of the newly introduced PersistentEntity.isNew(…) and identifier lookups via PersistentEntity instead of using a custom EntityInformation implementation. JdbcRepositoryFactory now creates a PersistentEntityInformation, SimpleJdbcRepository simply works with a PersistentEntity. Removed references to EntityInformation (a repository subsystem concept) from the template implementation. Removed BasicJdbcPersistentEntity and its tests entirely. JdbcAuditingEventListener is now using an IsNewAwareAuditingHandler. Related tickets: DATACMNS-1333.
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jdbc.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.Persistable;
|
||||
import org.springframework.data.jdbc.core.mapping.BasicJdbcPersistentEntityInformation;
|
||||
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BasicJdbcPersistentEntityInformation}.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class BasicJdbcPersistentEntityInformationUnitTests {
|
||||
|
||||
JdbcMappingContext context = new JdbcMappingContext();
|
||||
private DummyEntity dummyEntity = new DummyEntity();
|
||||
private PersistableDummyEntity persistableDummyEntity = new PersistableDummyEntity();
|
||||
|
||||
@Test // DATAJDBC-158
|
||||
public void idIsBasedOnIdAnnotatedProperty() {
|
||||
|
||||
dummyEntity.id = 42L;
|
||||
assertThat(context.getRequiredPersistentEntityInformation(DummyEntity.class).getRequiredId(dummyEntity))
|
||||
.isEqualTo(42L);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-158
|
||||
public void idIsBasedOnPersistableGetId() {
|
||||
|
||||
assertThat( //
|
||||
context.getRequiredPersistentEntityInformation(PersistableDummyEntity.class)
|
||||
.getRequiredId(persistableDummyEntity) //
|
||||
).isEqualTo(23L);
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-158
|
||||
public void isNewIsBasedOnIdAnnotatedPropertyBeingNull() {
|
||||
|
||||
assertThat(context.getRequiredPersistentEntityInformation(DummyEntity.class).isNew(dummyEntity)).isTrue();
|
||||
dummyEntity.id = 42L;
|
||||
assertThat(context.getRequiredPersistentEntityInformation(DummyEntity.class).isNew(dummyEntity)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAJDBC-158
|
||||
public void isNewIsBasedOnPersistableIsNew() {
|
||||
|
||||
persistableDummyEntity.isNewFlag = true;
|
||||
assertThat(
|
||||
context.getRequiredPersistentEntityInformation(PersistableDummyEntity.class).isNew(persistableDummyEntity))
|
||||
.isTrue();
|
||||
|
||||
persistableDummyEntity.isNewFlag = false;
|
||||
assertThat(
|
||||
context.getRequiredPersistentEntityInformation(PersistableDummyEntity.class).isNew(persistableDummyEntity))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
private static class DummyEntity {
|
||||
@Id Long id;
|
||||
}
|
||||
|
||||
private static class PersistableDummyEntity implements Persistable<Long> {
|
||||
boolean isNewFlag;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Long getId() {
|
||||
return 23L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew() {
|
||||
return isNewFlag;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user