use of org.springframework.data.mapping.PersistentPropertyAccessor 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());
}
use of org.springframework.data.mapping.PersistentPropertyAccessor in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method getIdValue.
private <T> Value<?> getIdValue(Example<T> example, DatastorePersistentEntity<?> persistentEntity, DatastorePersistentProperty persistentProperty) {
// ID properties are not stored as regular fields in Datastore.
Value<?> value;
PersistentPropertyAccessor accessor = persistentEntity.getPropertyAccessor(example.getProbe());
Object property = accessor.getProperty(persistentProperty);
value = property != null ? KeyValue.of(createKey(persistentEntity.kindName(), property)) : NullValue.of();
return value;
}
use of org.springframework.data.mapping.PersistentPropertyAccessor in project spring-cloud-gcp by spring-cloud.
the class SpannerPersistentEntityImplTests method testIgnoredProperty.
@Test
public void testIgnoredProperty() {
TestEntity t = new TestEntity();
t.id = "a";
t.something = "a";
t.notMapped = "b";
SpannerPersistentEntity p = new SpannerMappingContext().getPersistentEntity(TestEntity.class);
PersistentPropertyAccessor accessor = p.getPropertyAccessor(t);
p.doWithProperties((SimplePropertyHandler) (property) -> assertThat(accessor.getProperty(property)).isNotEqualTo("b"));
}
use of org.springframework.data.mapping.PersistentPropertyAccessor in project spring-data-mongodb by spring-projects.
the class DefaultDbRefProxyHandler method populateId.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.convert.DbRefProxyHandler#populateId(com.mongodb.DBRef, java.lang.Object)
*/
@Override
public Object populateId(MongoPersistentProperty property, @Nullable DBRef source, Object proxy) {
if (source == null) {
return proxy;
}
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(property);
MongoPersistentProperty idProperty = entity.getRequiredIdProperty();
if (idProperty.usePropertyAccess()) {
return proxy;
}
SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(proxy, spELContext);
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(proxy);
Document object = new Document(idProperty.getFieldName(), source.getId());
ObjectPath objectPath = ObjectPath.ROOT.push(proxy, entity, null);
accessor.setProperty(idProperty, resolver.getValueInternal(idProperty, object, evaluator, objectPath));
return proxy;
}
use of org.springframework.data.mapping.PersistentPropertyAccessor in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method shouldEagerlyResolveIdPropertyWithFieldAccess.
// DATAMONGO-1012
@Test
void shouldEagerlyResolveIdPropertyWithFieldAccess() {
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(ClassWithLazyDbRefs.class);
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteType");
MongoPersistentEntity<?> propertyEntity = mappingContext.getRequiredPersistentEntity(property);
String idValue = new ObjectId().toString();
DBRef dbRef = converter.toDBRef(new LazyDbRefTarget(idValue), property);
Document object = new Document("dbRefToConcreteType", dbRef);
ClassWithLazyDbRefs result = converter.read(ClassWithLazyDbRefs.class, object);
PersistentPropertyAccessor accessor = propertyEntity.getPropertyAccessor(result.dbRefToConcreteType);
MongoPersistentProperty idProperty = mappingContext.getRequiredPersistentEntity(LazyDbRefTarget.class).getIdProperty();
assertThat(accessor.getProperty(idProperty)).isNotNull();
assertProxyIsResolved(result.dbRefToConcreteType, false);
}
Aggregations