public DocumentCollectionMapping(PersistentEntity entity, MappingContext context) { super(entity, context); if(entity.isExternal()) { this.mappedForm = null; } else { this.mappedForm = (Collection) context.getMappingFactory().createMappedForm(DocumentPersistentEntity.this); } } @Override
/** * Tries to obtain or create an associated entity. Note that if #canExpandMappingContext is set to false then this method may return null * * @param entity The main entity * @param context The context * @param propType The associated property type * @return The associated entity or null */ protected PersistentEntity getOrCreateAssociatedEntity(PersistentEntity entity, MappingContext context, Class propType) { PersistentEntity associatedEntity = context.getPersistentEntity(propType.getName()); if (associatedEntity == null) { if(canExpandMappingContext) { if (entity.isExternal()) { associatedEntity = context.addExternalPersistentEntity(propType); } else { associatedEntity = context.addPersistentEntity(propType); } } } else { if(!associatedEntity.isInitialized()) { associatedEntity.initialize(); } } return associatedEntity; }
/** * @see org.grails.datastore.mapping.model.MappingConfigurationStrategy#getIdentity(Class, org.grails.datastore.mapping.model.MappingContext) */ public PersistentProperty getIdentity(Class javaClass, MappingContext context) { ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); PersistentEntity entity = context.getPersistentEntity(javaClass.getName()); ClassMapping mapping = entity.getMapping(); IdentityMapping id = mapping.getIdentifier(); final String[] names = id.getIdentifierName(); if (names.length == 1) { final PropertyDescriptor pd = cpf.getPropertyDescriptor(names[0]); if (pd != null) { return propertyFactory.createIdentity(entity, context, pd); } if (!entity.isExternal() && isAbstract(entity)) { throw new IllegalMappingException("Mapped identifier [" + names[0] + "] for class [" + javaClass.getName() + "] is not a valid property"); } return null; } return null; }
if (entity.isExternal()) { return null; PropertyDescriptor pd = findProperty(descriptors, classPropertyName); if (pd == null) { if (entity.isExternal()) { return null;
if (entity.isExternal()) { associatedEntity = context.addExternalPersistentEntity(type); associatedEntity.initialize();