Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add Mongo-specific simple types.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Mack committed Mar 29, 2012
1 parent b25bf60 commit 7cb2cb8
Showing 1 changed file with 25 additions and 1 deletion.
Expand Up @@ -20,14 +20,28 @@
import org.grails.datastore.mapping.document.config.DocumentPersistentEntity;
import org.grails.datastore.mapping.model.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* Models a {@link org.grails.datastore.mapping.model.MappingContext} for Mongo.
*
* @author Graeme Rocher
*/
public class MongoMappingContext extends DocumentMappingContext {

private final class MongoDocumentMappingFactory extends
public static final Set<String> MONGO_SIMPLE_TYPES;

static {
MONGO_SIMPLE_TYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
org.bson.types.ObjectId.class.getName(),
com.mongodb.DBObject.class.getName()
)));
}

private final class MongoDocumentMappingFactory extends
AbstractGormMappingFactory<MongoCollection, MongoAttribute> {
@Override
protected Class<MongoAttribute> getPropertyMappedFormType() {
Expand Down Expand Up @@ -63,6 +77,16 @@ public Object getMappedForm() {
}
return super.getIdentityMappedForm(classMapping, property);
}

@Override
public boolean isSimpleType(Class propType) {
if (propType == null) return false;
if (propType.isArray()) {
return isSimpleType(propType.getComponentType()) || super.isSimpleType(propType);
}
final String typeName = propType.getName();
return MONGO_SIMPLE_TYPES.contains(typeName) || super.isSimpleType(propType);
}
}

public MongoMappingContext(String defaultDatabaseName) {
Expand Down

0 comments on commit 7cb2cb8

Please sign in to comment.