use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.
the class BasicRelationalConverterAggregateReferenceUnitTests method convertsFromAggregateReference.
// DATAJDBC-221
@Test
public void convertsFromAggregateReference() {
final RelationalPersistentProperty property = entity.getRequiredPersistentProperty("reference");
AggregateReference<Object, Integer> reference = AggregateReference.to(23);
Object writeValue = converter.writeValue(reference, ClassTypeInformation.from(converter.getColumnType(property)));
Assertions.assertThat(writeValue).isEqualTo(23L);
}
use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.
the class RelationalEntityVersionUtils method setVersionNumberOnEntity.
/**
* Set the version property on an instance of a relational persistent entity. This method returns an instance of the
* same type with the updated version property and will correctly handle the case where the version is immutable.
*
* @param instance must not be {@literal null}.
* @param version The value to be set on the version property.
* @param persistentEntity must not be {@literal null}.
* @param converter must not be {@literal null}.
* @return An instance of the entity with an updated version property.
* @throws IllegalArgumentException if the entity does not have a version property.
*/
public static <S> S setVersionNumberOnEntity(S instance, @Nullable Number version, RelationalPersistentEntity<S> persistentEntity, RelationalConverter converter) {
if (!persistentEntity.hasVersionProperty()) {
throw new IllegalArgumentException("The entity does not have a version property.");
}
PersistentPropertyAccessor<S> propertyAccessor = converter.getPropertyAccessor(persistentEntity, instance);
RelationalPersistentProperty versionProperty = persistentEntity.getRequiredVersionProperty();
propertyAccessor.setProperty(versionProperty, version);
return propertyAccessor.getBean();
}
use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.
the class BasicJdbcConverterUnitTests method classificationOfCollectionLikeProperties.
// DATAJDBC-259
@Test
public void classificationOfCollectionLikeProperties() {
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
RelationalPersistentProperty listOfString = entity.getRequiredPersistentProperty("listOfString");
RelationalPersistentProperty arrayOfString = entity.getRequiredPersistentProperty("arrayOfString");
SoftAssertions softly = new SoftAssertions();
softly.assertThat(converter.getColumnType(arrayOfString)).isEqualTo(String[].class);
softly.assertThat(converter.getColumnType(listOfString)).isEqualTo(String[].class);
softly.assertAll();
}
use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.
the class BasicJdbcConverterUnitTests method checkTargetType.
private void checkTargetType(SoftAssertions softly, RelationalPersistentEntity<?> persistentEntity, String propertyName, Class<?> expected) {
RelationalPersistentProperty property = persistentEntity.getRequiredPersistentProperty(propertyName);
softly.assertThat(converter.getColumnType(property)).describedAs(propertyName).isEqualTo(expected);
}
use of org.springframework.data.relational.core.mapping.RelationalPersistentProperty in project spring-data-jdbc by spring-projects.
the class BasicJdbcConverterUnitTests method referencesAreNotEntitiesAndGetStoredAsTheirId.
// DATAJDBC-221
@Test
public void referencesAreNotEntitiesAndGetStoredAsTheirId() {
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
SoftAssertions softly = new SoftAssertions();
RelationalPersistentProperty reference = entity.getRequiredPersistentProperty("reference");
softly.assertThat(reference.isEntity()).isFalse();
softly.assertThat(converter.getColumnType(reference)).isEqualTo(Long.class);
softly.assertAll();
}
Aggregations