Search in sources :

Example 1 with RelationalPersistentProperty

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);
}
Also used : RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Example 2 with RelationalPersistentProperty

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();
}
Also used : RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty)

Example 3 with RelationalPersistentProperty

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();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Example 4 with RelationalPersistentProperty

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);
}
Also used : RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty)

Example 5 with RelationalPersistentProperty

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();
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) RelationalPersistentProperty(org.springframework.data.relational.core.mapping.RelationalPersistentProperty) Test(org.junit.jupiter.api.Test)

Aggregations

RelationalPersistentProperty (org.springframework.data.relational.core.mapping.RelationalPersistentProperty)22 Test (org.junit.jupiter.api.Test)9 PersistentPropertyPathExtension (org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension)5 BasicRelationalPersistentProperty (org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty)3 SQLType (java.sql.SQLType)2 ArrayList (java.util.ArrayList)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 RelationalPersistentEntity (org.springframework.data.relational.core.mapping.RelationalPersistentEntity)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 SqlSession (org.apache.ibatis.session.SqlSession)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 Mockito (org.mockito.Mockito)1 Example (org.springframework.data.domain.Example)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1