|
6 | 6 | import com.mongodb.MongoException;
|
7 | 7 | import org.apache.commons.logging.Log;
|
8 | 8 | import org.apache.commons.logging.LogFactory;
|
9 |
| -import org.springframework.beans.factory.annotation.Autowired; |
10 | 9 | import org.springframework.dao.DataAccessException;
|
11 | 10 | import org.springframework.dao.DataIntegrityViolationException;
|
12 | 11 | import org.springframework.data.document.mongodb.CollectionCallback;
|
@@ -43,27 +42,32 @@ public void getPersistentState(Class<? extends ChangeSetBacked> entityClass,
|
43 | 42 | final DBObject dbk = new BasicDBObject();
|
44 | 43 | dbk.put(ENTITY_ID, id);
|
45 | 44 | dbk.put(ENTITY_CLASS, entityClass.getName());
|
| 45 | + if (log.isDebugEnabled()) { |
| 46 | + log.debug("Loading MongoDB data for " + dbk); |
| 47 | + } |
46 | 48 | mongoTemplate.execute(collName, new CollectionCallback<Object>() {
|
47 | 49 | @Override
|
48 | 50 | public Object doInCollection(DBCollection collection)
|
49 | 51 | throws MongoException, DataAccessException {
|
50 | 52 | for (DBObject dbo : collection.find(dbk)) {
|
51 | 53 | String key = (String) dbo.get(ENTITY_FIELD_NAME);
|
52 |
| - String className = (String) dbo.get(ENTITY_FIELD_CLASS); |
53 |
| - if (className == null) { |
54 |
| - throw new DataIntegrityViolationException( |
55 |
| - "Unble to convert property " + key |
56 |
| - + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); |
| 54 | + if (log.isDebugEnabled()) { |
| 55 | + log.debug("Processing key: " + key); |
57 | 56 | }
|
58 |
| - Class<?> clazz = null; |
59 |
| - try { |
60 |
| - clazz = Class.forName(className); |
61 |
| - } catch (ClassNotFoundException e) { |
62 |
| - throw new DataIntegrityViolationException( |
63 |
| - "Unble to convert property " + key + " of type " + className, e); |
| 57 | + if (!changeSet.getValues().containsKey(key)) { |
| 58 | + String className = (String) dbo.get(ENTITY_FIELD_CLASS); |
| 59 | + if (className == null) { |
| 60 | + throw new DataIntegrityViolationException( |
| 61 | + "Unble to convert property " + key |
| 62 | + + ": Invalid metadata, " + ENTITY_FIELD_CLASS + " not available"); |
| 63 | + } |
| 64 | + Class<?> clazz = ClassUtils.resolveClassName(className, ClassUtils.getDefaultClassLoader()); |
| 65 | + Object value = mongoTemplate.getConverter().read(clazz, dbo); |
| 66 | + if (log.isDebugEnabled()) { |
| 67 | + log.debug("Adding to ChangeSet: " + key); |
| 68 | + } |
| 69 | + changeSet.set(key, value); |
64 | 70 | }
|
65 |
| - Object value = mongoTemplate.getConverter().read(clazz, dbo); |
66 |
| - changeSet.set(key, value); |
67 | 71 | }
|
68 | 72 | return null;
|
69 | 73 | }
|
|
0 commit comments