Search in sources :

Example 1 with PersistentProperty

use of org.springframework.data.mapping.PersistentProperty in project spring-cloud-gcp by spring-cloud.

the class SpannerMutationFactoryImpl method delete.

@Override
public <T> Mutation delete(Class<T> entityClass, Iterable<? extends T> entities) {
    SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext.getPersistentEntity(entityClass);
    KeySet.Builder builder = KeySet.newBuilder();
    for (T entity : entities) {
        PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(entity);
        PersistentProperty idProperty = persistentEntity.getIdProperty();
        Key value = (Key) accessor.getProperty(idProperty);
        builder.addKey(value);
    }
    return delete(entityClass, builder.build());
}
Also used : KeySet(com.google.cloud.spanner.KeySet) PersistentPropertyAccessor(org.springframework.data.mapping.PersistentPropertyAccessor) PersistentProperty(org.springframework.data.mapping.PersistentProperty) Key(com.google.cloud.spanner.Key)

Example 2 with PersistentProperty

use of org.springframework.data.mapping.PersistentProperty in project spring-data-commons by spring-projects.

the class AnnotationBasedPersistentPropertyUnitTests method getRequiredAnnotationReturnsAnnotation.

// DATACMNS-1141
@Test
public void getRequiredAnnotationReturnsAnnotation() {
    PersistentProperty property = getProperty(Sample.class, "id");
    assertThat(property.getRequiredAnnotation(Id.class)).isNotNull();
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) PersistentProperty(org.springframework.data.mapping.PersistentProperty) Test(org.junit.Test)

Example 3 with PersistentProperty

use of org.springframework.data.mapping.PersistentProperty in project spring-data-commons by spring-projects.

the class AnnotationBasedPersistentPropertyUnitTests method getRequiredAnnotationThrowsException.

// DATACMNS-1141
@Test
public void getRequiredAnnotationThrowsException() {
    PersistentProperty property = getProperty(Sample.class, "id");
    assertThatThrownBy(() -> property.getRequiredAnnotation(Transient.class)).isInstanceOf(IllegalStateException.class);
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) PersistentProperty(org.springframework.data.mapping.PersistentProperty) Test(org.junit.Test)

Example 4 with PersistentProperty

use of org.springframework.data.mapping.PersistentProperty in project spring-data-commons by spring-projects.

the class AbstractPersistentPropertyUnitTests method doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven.

// DATACMNS-206
@Test
public void doesNotDiscoverGetterAndSetterIfNoPropertyDescriptorGiven() {
    Field field = ReflectionUtils.findField(AccessorTestClass.class, "id");
    Property property = Property.of(ClassTypeInformation.from(AccessorTestClass.class), field);
    PersistentProperty<SamplePersistentProperty> persistentProperty = new SamplePersistentProperty(property, getEntity(AccessorTestClass.class), typeHolder);
    assertThat(persistentProperty.getGetter()).isNull();
    assertThat(persistentProperty.getSetter()).isNull();
}
Also used : Field(java.lang.reflect.Field) PersistentProperty(org.springframework.data.mapping.PersistentProperty) Test(org.junit.Test)

Aggregations

PersistentProperty (org.springframework.data.mapping.PersistentProperty)4 Test (org.junit.Test)3 SamplePersistentProperty (org.springframework.data.mapping.context.SamplePersistentProperty)2 Key (com.google.cloud.spanner.Key)1 KeySet (com.google.cloud.spanner.KeySet)1 Field (java.lang.reflect.Field)1 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)1