From 6ed1d2b22699a2f8249f7dc38a12ba38f708daa9 Mon Sep 17 00:00:00 2001 From: Thomas Risberg Date: Mon, 16 May 2011 12:11:55 -0400 Subject: [PATCH] DATADOC-110 removed 'substituteMappedIdIfNecessary' since this is now handled by QueryMapper --- .../data/document/mongodb/MongoTemplate.java | 82 ------------------- 1 file changed, 82 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java index f2b79d2aa..48233bc72 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java @@ -1074,88 +1074,6 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } } - /** - * Substitutes the id key if it is found in he query. Any 'id' keys will be replaced with '_id' and the value - * converted to an ObjectId if possible. This conversion should match the way that the id fields are converted during - * read operations. - * - * @param query - * @param targetClass - * @param reader - */ - protected void substituteMappedIdIfNecessary(DBObject query, Class targetClass, MongoReader reader) { - MongoConverter converter = null; - if (reader instanceof SimpleMongoConverter) { - converter = (MongoConverter) reader; - } else if (reader instanceof MappingMongoConverter) { - converter = (MappingMongoConverter) reader; - } else { - return; - } - String idKey = null; - if (query.containsField("id")) { - idKey = "id"; - } - if (query.containsField("_id")) { - idKey = "_id"; - } - if (idKey == null) { - // no ids in this query - return; - } - MongoPropertyDescriptor descriptor; - try { - MongoPropertyDescriptor mpd = new MongoPropertyDescriptor(new PropertyDescriptor(idKey, targetClass), targetClass); - descriptor = mpd; - } catch (IntrospectionException e) { - // no property descriptor for this key - try the other - try { - String theOtherIdKey = "id".equals(idKey) ? "_id" : "id"; - MongoPropertyDescriptor mpd2 = new MongoPropertyDescriptor(new PropertyDescriptor(theOtherIdKey, targetClass), - targetClass); - descriptor = mpd2; - } catch (IntrospectionException e2) { - // no property descriptor for this key either - bail - return; - } - } - if (descriptor.isIdProperty() && descriptor.isOfIdType()) { - Object value = query.get(idKey); - if (value instanceof DBObject) { - DBObject dbo = (DBObject) value; - if (dbo.containsField("$in")) { - List ids = new ArrayList(); - int count = 0; - for (Object o : (Object[]) dbo.get("$in")) { - count++; - ObjectId newValue = convertIdValue(converter, o); - if (newValue != null) { - ids.add(newValue); - } - } - if (ids.size() > 0 && ids.size() != count) { - throw new InvalidDataAccessApiUsageException("Inconsistent set of id values provided " - + Arrays.asList((Object[]) dbo.get("$in"))); - } - if (ids.size() > 0) { - dbo.removeField("$in"); - dbo.put("$in", ids.toArray()); - } - } - query.removeField(idKey); - query.put(MongoPropertyDescriptor.ID_KEY, value); - } else { - ObjectId newValue = convertIdValue(converter, value); - query.removeField(idKey); - if (newValue != null) { - query.put(MongoPropertyDescriptor.ID_KEY, newValue); - } else { - query.put(MongoPropertyDescriptor.ID_KEY, value); - } - } - } - } - private MongoPersistentEntity getPersistentEntity(Class type) { return type == null ? null : mappingContext.getPersistentEntity(type); }