Skip to content

Commit ae1a873

Browse files
committed
DATASOLR-250 - Switched to PersistentEntityInformation to avoid reference to BeanWrapper.
MappingElasticsearchEntityInformation now extends PersistentEntityInformation over AbstractInformation to be able to use the default implementations of getId(…) and getIdType(). Related ticket: DATACMNS-738.
1 parent 9524b2c commit ae1a873

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,8 +21,7 @@
2121
import org.slf4j.LoggerFactory;
2222
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
2323
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
24-
import org.springframework.data.mapping.model.BeanWrapper;
25-
import org.springframework.data.repository.core.support.AbstractEntityInformation;
24+
import org.springframework.data.repository.core.support.PersistentEntityInformation;
2625
import org.springframework.util.Assert;
2726

2827
/**
@@ -34,44 +33,27 @@
3433
* @author Rizwan Idrees
3534
* @author Mohsin Husen
3635
* @author Ryan Henszey
36+
* @author Oliver Gierke
3737
*/
38-
public class MappingElasticsearchEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID>
38+
public class MappingElasticsearchEntityInformation<T, ID extends Serializable> extends PersistentEntityInformation<T, ID>
3939
implements ElasticsearchEntityInformation<T, ID> {
4040

4141
private static final Logger logger = LoggerFactory.getLogger(MappingElasticsearchEntityInformation.class);
4242
private final ElasticsearchPersistentEntity<T> entityMetadata;
4343
private final String indexName;
4444
private final String type;
45-
private Class<?> idClass;
4645

4746
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) {
4847
this(entity, null, null);
4948
}
5049

5150
public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) {
52-
super(entity.getType());
51+
super(entity);
5352
this.entityMetadata = entity;
5453
this.indexName = indexName;
5554
this.type = type;
56-
this.idClass = entity.getIdProperty().getType();
5755
}
5856

59-
@SuppressWarnings("unchecked")
60-
@Override
61-
public ID getId(T entity) {
62-
ElasticsearchPersistentProperty id = entityMetadata.getIdProperty();
63-
try {
64-
return (ID) BeanWrapper.create(entity, null).getProperty(id);
65-
} catch (Exception e) {
66-
throw new IllegalStateException("ID could not be resolved", e);
67-
}
68-
}
69-
70-
@SuppressWarnings("unchecked")
71-
@Override
72-
public Class<ID> getIdType() {
73-
return (Class<ID>) idClass;
74-
}
7557

7658
@Override
7759
public String getIdAttribute() {
@@ -96,7 +78,7 @@ public Long getVersion(T entity) {
9678
ElasticsearchPersistentProperty versionProperty = entityMetadata.getVersionProperty();
9779
try {
9880
if (versionProperty != null) {
99-
return (Long) BeanWrapper.create(entity, null).getProperty(versionProperty);
81+
return (Long) entityMetadata.getPropertyAccessor(entity).getProperty(versionProperty);
10082
}
10183
} catch (Exception e) {
10284
throw new IllegalStateException("failed to load version field", e);
@@ -109,7 +91,7 @@ public String getParentId(T entity) {
10991
ElasticsearchPersistentProperty parentProperty = entityMetadata.getParentIdProperty();
11092
try {
11193
if (parentProperty != null) {
112-
return (String) BeanWrapper.create(entity, null).getProperty(parentProperty);
94+
return (String) entityMetadata.getPropertyAccessor(entity).getProperty(parentProperty);
11395
}
11496
} catch (Exception e) {
11597
throw new IllegalStateException("failed to load parent ID: " + e, e);

0 commit comments

Comments
 (0)