protected PropertyMapping<T> createPropertyMapping(final PersistentProperty<T> property, final PersistentEntity owner) { return new PropertyMapping<T>() { private T mappedForm = createMappedForm(property); public ClassMapping getClassMapping() { return owner.getMapping(); } public T getMappedForm() { return mappedForm; } }; }
@Override public String toString() { return associationtoString("embedded: ", this); } };
public Basic createBasicCollection(PersistentEntity entity, MappingContext context, PropertyDescriptor property) { return createBasicCollection(entity, context, property, null); }
return propertyFactory.createBasicCollection(entity, context, property); if (propertyFactory.isSimpleType(relatedClassType)) { return propertyFactory.createBasicCollection(entity, context, property, relatedClassType); EmbeddedCollection association = propertyFactory.createEmbeddedCollection(entity, context, property); PersistentEntity associatedEntity = getOrCreateEmbeddedEntity(entity, context, relatedClassType); association.setAssociatedEntity(associatedEntity); return propertyFactory.createBasicCollection(entity, context, property, relatedClassType); association = propertyFactory.createManyToMany(entity, context, property); ManyToMany manyToMany = getAnnotation(readMethod, field, ManyToMany.class); if (!manyToMany.mappedBy().equals("")) { association = propertyFactory.createOneToMany(entity, context, property); OneToMany oneToMany = getAnnotation(readMethod, field, OneToMany.class); if (!oneToMany.mappedBy().equals("")) {
PropertyDescriptor propertyDescriptor = propertyFactory.createPropertyDescriptor(entity.getJavaClass(), metaProperty); if(propertyDescriptor == null) { continue; else if(propertyFactory.isTenantId(entity, context, propertyDescriptor)) { persistentProperties.add(propertyFactory.createTenantId(entity, context, propertyDescriptor)); else if (propertyFactory.isSimpleType(propertyType)) { persistentProperties.add(propertyFactory.createSimple(entity, context, propertyDescriptor)); persistentProperties.add(propertyFactory.createCustom(entity, context, propertyDescriptor));
PropertyDescriptor descriptor = propertyFactory.createPropertyDescriptor(entityClass, metaProperty); persistentProperties.add( propertyFactory.createIdentity(entity, context, descriptor)); persistentProperties.add( propertyFactory.createIdentity(entity, context, descriptor)); else if (propertyFactory.isSimpleType(propertyType)) { Simple simpleProperty = propertyFactory.createSimple(entity, context, descriptor); if(hasAnnotation(readMethod, field, GeneratedValue.class)) { simpleProperty.getMapping().getMappedForm().setDerived(true); persistentProperties.add(propertyFactory.createCustom(entity, context, descriptor));
association = propertyFactory.createEmbedded(entity, context, property); association.setAssociatedEntity(associatedEntity); return association; association = embedded ? propertyFactory.createEmbedded(entity, context, property) : propertyFactory.createOneToOne(entity, context, property); association = propertyFactory.createManyToOne(entity, context, property);
/** * Creates a custom prpoerty type * * @param owner The owner * @param context The context * @param pd The PropertyDescriptor * @return A custom property type */ public Custom<T> createCustom(PersistentEntity owner, MappingContext context, PropertyDescriptor pd) { final Class<?> propertyType = pd.getPropertyType(); CustomTypeMarshaller customTypeMarshaller = findCustomType(context, propertyType); if (customTypeMarshaller == null && propertyType.isEnum()) { // If there is no custom type marshaller for current enum, lookup marshaller for enum itself. customTypeMarshaller = findCustomType(context, Enum.class); } if (customTypeMarshaller == null && !allowArbitraryCustomTypes()) { throw new IllegalStateException("Cannot create a custom type without a type converter for type " + propertyType); } return new Custom<T>(owner, context, pd, customTypeMarshaller) { PropertyMapping<T> propertyMapping = createPropertyMapping(this, owner); public PropertyMapping<T> getMapping() { return propertyMapping; } }; }
/** * Obtains the identity mapping for the specified class mapping * * @param classMapping The class mapping * @return The identity mapping */ public IdentityMapping getIdentityMapping(ClassMapping classMapping) { return propertyFactory.createIdentityMapping(classMapping); }
public IdentityMapping getDefaultIdentityMapping(final ClassMapping classMapping) { return propertyFactory.createDefaultIdentityMapping(classMapping); } }
@Override public PersistentProperty[] getCompositeIdentity(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(); PersistentProperty[] identifiers = new PersistentProperty[names.length]; for (int i = 0; i < names.length; i++) { String name = names[i]; final PersistentProperty p = entity.getPropertyByName(name); if(p != null) { identifiers[i] = p; } else { final PropertyDescriptor pd = cpf.getPropertyDescriptor(name); if (pd != null) { identifiers[i] = propertyFactory.createIdentity(entity, context, pd); } else { throw new IllegalMappingException("Invalid composite id mapping. Could not resolve property ["+name+"] for entity ["+javaClass.getName()+"]"); } } } return identifiers; }
return propertyFactory.createBasicCollection(entity, context, property); if (propertyFactory.isSimpleType(relatedClassType)) { return propertyFactory.createBasicCollection(entity, context, property, relatedClassType); EmbeddedCollection association = propertyFactory.createEmbeddedCollection(entity, context, property); PersistentEntity associatedEntity = getOrCreateEmbeddedEntity(entity, context, relatedClassType); association.setAssociatedEntity(associatedEntity); return propertyFactory.createBasicCollection(entity, context, property, relatedClassType); boolean many = false; if (embedded) { association = propertyFactory.createEmbeddedCollection(entity, context, property); association = propertyFactory.createOneToMany(entity, context, property); association = propertyFactory.createManyToMany(entity, context, property); ((ManyToMany)association).setInversePropertyName(relatedClassPropertyName); many = true; association = propertyFactory.createOneToMany(entity, context, property);
association = propertyFactory.createEmbedded(entity, context, property); association.setAssociatedEntity(associatedEntity); return association; association = propertyFactory.createManyToOne(entity, context, property); relatedClassPropertyName = oneToOne.mappedBy(); association = propertyFactory.createOneToOne(entity, context, property); association.setForeignKeyInChild(true); List<PropertyDescriptor> descriptors = relatedCpf.getPropertiesOfType(entity.getJavaClass());
@Override public IdentityMapping getIdentifier() { if (identityMapping == null) { identityMapping = context.getMappingFactory().createIdentityMapping(this); } return identityMapping; } }
public IdentityMapping createIdentityMapping(final ClassMapping classMapping) { return createDefaultIdentityMapping(classMapping); }
/** * @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; }
private PropertyMapping<T> createDerivedPropertyMapping(final PersistentProperty<T> property, final PersistentEntity owner) { final T mappedFormObject = createMappedForm(property); mappedFormObject.setDerived(true); return new PropertyMapping<T>() { private T mappedForm = mappedFormObject; public ClassMapping getClassMapping() { return owner.getMapping(); } public T getMappedForm() { return mappedForm; } }; }
@Override public String toString() { return associationtoString("embedded: ", this); } };
@Override public IdentityMapping createIdentityMapping(ClassMapping classMapping) { Map<String, T> props = entityToPropertyMap.get(classMapping.getEntity()); if (props != null) { T property = props.get(IDENTITY_PROPERTY); IdentityMapping customIdentityMapping = getIdentityMappedForm(classMapping,property); if (customIdentityMapping != null) { return customIdentityMapping; } } return super.createIdentityMapping(classMapping); }
public HibernatePersistentEntity(Class javaClass, final MappingContext context) { super(javaClass, context); this.classMapping = new AbstractClassMapping<Mapping>(this, context) { Mapping mappedForm = (Mapping) context.getMappingFactory().createMappedForm(HibernatePersistentEntity.this); @Override public PersistentEntity getEntity() { return HibernatePersistentEntity.this; } @Override public Mapping getMappedForm() { return mappedForm; } }; }