List of usage examples for org.springframework.data.mapping Association getInverse
public P getInverse()
From source file:org.develspot.data.orientdb.convert.MappingOrientConverter.java
@SuppressWarnings("unchecked") private <S extends Object> S read(final OrientPersistentEntity<S> entity, final OrientElement dbObject, boolean lazy) { OrientMappingInstance mappingInstance = MappingInstanceHolder.getMappingInstance(); //check if entity is already loaded if (mappingInstance.instanceLoaded(dbObject.getId())) { return (S) mappingInstance.get(dbObject.getId()); }/* w w w .j av a 2 s. c om*/ EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final DefaultOrientPropertyValueProvider objectResolver = new DefaultOrientPropertyValueProvider(dbObject, this, spELContext, lazy); PersistentEntityParameterValueProvider<OrientPersistentProperty> parameterProvider = new PersistentEntityParameterValueProvider<OrientPersistentProperty>( entity, objectResolver, null); S instance = instantiator.createInstance(entity, parameterProvider); final BeanWrapper<OrientPersistentEntity<S>, S> wrapper = BeanWrapper.create(instance, conversionService); final S result = wrapper.getBean(); mappingInstance.addInstance(dbObject.getId(), result); // Set properties not already set in the constructor entity.doWithProperties(new PropertyHandler<OrientPersistentProperty>() { public void doWithPersistentProperty(OrientPersistentProperty prop) { if (!prop.isIdProperty() && (dbObject.getProperty(prop.getField().getName()) == null || entity.isConstructorArgument(prop))) { return; } Object obj = objectResolver.getPropertyValue(prop); wrapper.setProperty(prop, obj, fieldAccessOnly); } }); entity.doWithAssociations(new AssociationHandler<OrientPersistentProperty>() { public void doWithAssociation(Association<OrientPersistentProperty> association) { OrientPersistentProperty inverse = association.getInverse(); Object resolved = objectResolver.getPropertyValue(inverse); wrapper.setProperty(inverse, resolved); } }); return result; }
From source file:com.expedia.seiso.web.assembler.ItemAssociationHandler.java
@Override public void doWithAssociation(Association<? extends PersistentProperty<?>> assoc) { val item = wrapper.getBean(); // val doesn't work here for some reason. PersistentProperty<?> prop = assoc.getInverse(); val propName = prop.getName(); val propType = prop.getType(); val child = projection.getChild(propName); // Link/*from www.j a v a 2s.com*/ if (topLevel) { val restResource = prop.findAnnotation(RestResource.class); val path = (restResource == null ? propName : restResource.path()); resource.addLink(itemLinks.itemPropertyLink(item, path)); } // Property if (child != null) { if (Item.class.isAssignableFrom(propType)) { val propEntity = (Item) wrapper.getProperty(prop); val propResource = assembler.toResource(apiVersion, propEntity, child, false); resource.setAssociation(propName, propResource); } else if (List.class.isAssignableFrom(propType)) { val propEntityList = (List<?>) wrapper.getProperty(prop); val propResourceList = assembler.toResourceList(apiVersion, propEntityList, child); resource.setAssociation(propName, propResourceList); } else { log.warn("Don't know how to handle association type {}", propType); } } }
From source file:org.oasis.datacore.sdk.data.spring.DatacoreMappingMongoConverter.java
protected void writeInternal(Object obj, final DBObject dbo, MongoPersistentEntity<?> entity) { if (obj == null) { return;/*from w w w . j av a 2 s . c om*/ } if (null == entity) { throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName()); } final BeanWrapper<MongoPersistentEntity<Object>, Object> wrapper = BeanWrapper.create(obj, conversionService); final MongoPersistentProperty idProperty = entity.getIdProperty(); if (!dbo.containsField("_id") && null != idProperty) { boolean fieldAccessOnly = idProperty.usePropertyAccess() ? false : useFieldAccessOnly; try { Object id = wrapper.getProperty(idProperty, Object.class, fieldAccessOnly); dbo.put("_id", idMapper.convertId(id)); } catch (ConversionException ignored) { } } // Write the properties entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() { public void doWithPersistentProperty(MongoPersistentProperty prop) { if (prop.equals(idProperty)) { return; } boolean fieldAccessOnly = prop.usePropertyAccess() ? false : useFieldAccessOnly; Object propertyObj = wrapper.getProperty(prop, prop.getType(), fieldAccessOnly); //if (null != propertyObj) { // [Ozwillo] HACK to allow unset / set to null at save if (/*[Ozwillo] HACK*/null != propertyObj && /*[Ozwillo] END*/!conversions.isSimpleType(propertyObj.getClass())) { writePropertyInternal(propertyObj, dbo, prop); } else { writeSimpleInternal(propertyObj, dbo, prop.getFieldName()); } //} // [Ozwillo] HACK } }); entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() { public void doWithAssociation(Association<MongoPersistentProperty> association) { MongoPersistentProperty inverseProp = association.getInverse(); Class<?> type = inverseProp.getType(); Object propertyObj = wrapper.getProperty(inverseProp, type, useFieldAccessOnly); //if (null != propertyObj) { // [Ozwillo] HACK to allow unset / set to null at save writePropertyInternal(propertyObj, dbo, inverseProp); //} // [Ozwillo] HACK } }); // [Ozwillo] HACK to persist Datacore model fields at root level NOT FOR NOW /*if ("DCEntity".equals(entity.getName())) { DCEntity dcEntity = (DCEntity) object; DCModel dcModel = dcModelService.getModel(dcEntity.getType()); for (DCField dcField : dcModel.getAllFields()) { } }*/ }
From source file:org.lightadmin.core.config.bootstrap.GlobalAdministrationConfigurationFactoryBean.java
private void registerAssociationDomainTypeConfigurations( DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration, final GlobalAdministrationConfiguration globalAdministrationConfiguration) { PersistentEntity persistentEntity = domainTypeAdministrationConfiguration.getPersistentEntity(); persistentEntity.doWithAssociations(new SimpleAssociationHandler() { @Override/*www. j av a 2 s. co m*/ public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { Class<?> associationDomainType = association.getInverse().getActualType(); if (!isManagedEntity(associationDomainType) && repositories.hasRepositoryFor(associationDomainType)) { DomainTypeBasicConfiguration associationTypeConfiguration = domainTypeAdministrationConfigurationFactory .createNonManagedDomainTypeConfiguration(associationDomainType); globalAdministrationConfiguration .registerNonDomainTypeConfiguration(associationTypeConfiguration); } } }); }
From source file:org.lightadmin.core.web.json.JsonConfigurationMetadata.java
public JsonConfigurationMetadata addAssociationProperty(Association association, Link restTemplateLink) { PersistentProperty persistentProperty = association.getInverse(); addProperty(persistentProperty.getName(), newAssociationProperty(persistentProperty, persistentProperty.getName(), restTemplateLink)); return this; }
From source file:org.lightadmin.core.web.json.DomainTypeToJsonMetadataConverter.java
@Override public JsonConfigurationMetadata convert(PersistentEntity persistentEntity) { final JsonConfigurationMetadata jsonConfigurationMetadata = new JsonConfigurationMetadata( persistentEntity.getName(),/*from www .j a v a2 s .c o m*/ globalAdministrationConfiguration.isManagedDomainType(persistentEntity.getType())); persistentEntity.doWithProperties(new SimplePropertyHandler() { @Override public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) { jsonConfigurationMetadata.addPersistentProperty(persistentProperty); } }); persistentEntity.doWithAssociations(new SimpleAssociationHandler() { @Override public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { jsonConfigurationMetadata.addAssociationProperty(association, associationRestLinkTemplate(association.getInverse())); } }); if (!globalAdministrationConfiguration.isManagedDomainType(persistentEntity.getType())) { return jsonConfigurationMetadata; } DomainTypeAdministrationConfiguration configuration = globalAdministrationConfiguration .forManagedDomainType(persistentEntity.getType()); List<DomainConfigurationUnitType> unitTypes = newArrayList(LIST_VIEW, FORM_VIEW, SHOW_VIEW, QUICK_VIEW); for (DomainConfigurationUnitType unitType : unitTypes) { Set<FieldMetadata> fieldForUnit = configuration.fieldsForUnit(unitType); for (FieldMetadata field : fieldForUnit) { if (persistentFieldMetadataPredicate().apply(field)) { addPersistentProperty((PersistentFieldMetadata) field, unitType.toString(), jsonConfigurationMetadata); } if (customFieldMetadataPredicate().apply(field)) { jsonConfigurationMetadata.addDynamicProperty((CustomFieldMetadata) field, unitType.toString()); } if (transientFieldMetadataPredicate().apply(field)) { jsonConfigurationMetadata.addDynamicProperty((TransientFieldMetadata) field, unitType.toString()); } } } return jsonConfigurationMetadata; }
From source file:org.lightadmin.core.web.json.JsonConfigurationMetadata.java
public JsonConfigurationMetadata addAssociationProperty(Association association, Link restTemplateLink, DomainConfigurationUnitType unitType) { PersistentProperty persistentProperty = association.getInverse(); String persistentPropertyName = persistentProperty.getName(); addDynamicProperty(persistentPropertyName, newAssociationProperty(persistentProperty, persistentPropertyName, restTemplateLink), unitType); return this; }
From source file:org.lightadmin.core.persistence.support.DynamicDomainObjectMerger.java
/** * Merges the given target object into the source one. * * @param from can be {@literal null}. * @param target can be {@literal null}. * @param nullPolicy how to handle {@literal null} values in the source object. *//* ww w .j a va 2 s . co m*/ @Override public void merge(final Object from, final Object target, final NullHandlingPolicy nullPolicy) { if (from == null || target == null) { return; } final BeanWrapper fromWrapper = beanWrapper(from); final BeanWrapper targetWrapper = beanWrapper(target); final DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration = configuration .forManagedDomainType(target.getClass()); final PersistentEntity<?, ?> entity = domainTypeAdministrationConfiguration.getPersistentEntity(); entity.doWithProperties(new SimplePropertyHandler() { @Override public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) { Object sourceValue = fromWrapper.getPropertyValue(persistentProperty.getName()); Object targetValue = targetWrapper.getPropertyValue(persistentProperty.getName()); if (entity.isIdProperty(persistentProperty)) { return; } if (nullSafeEquals(sourceValue, targetValue)) { return; } if (propertyIsHiddenInFormView(persistentProperty, domainTypeAdministrationConfiguration)) { return; } if (nullPolicy == APPLY_NULLS || sourceValue != null) { targetWrapper.setPropertyValue(persistentProperty.getName(), sourceValue); } } }); entity.doWithAssociations(new SimpleAssociationHandler() { @Override @SuppressWarnings("unchecked") public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { PersistentProperty<?> persistentProperty = association.getInverse(); Object fromValue = fromWrapper.getPropertyValue(persistentProperty.getName()); Object targetValue = targetWrapper.getPropertyValue(persistentProperty.getName()); if (propertyIsHiddenInFormView(persistentProperty, domainTypeAdministrationConfiguration)) { return; } if ((fromValue == null && nullPolicy == APPLY_NULLS)) { targetWrapper.setPropertyValue(persistentProperty.getName(), fromValue); } if (persistentProperty.isCollectionLike()) { Collection<Object> sourceCollection = (Collection) fromValue; Collection<Object> targetCollection = (Collection) targetValue; Collection<Object> candidatesForAddition = candidatesForAddition(sourceCollection, targetCollection, persistentProperty); Collection<Object> candidatesForRemoval = candidatesForRemoval(sourceCollection, targetCollection, persistentProperty); removeReferencedItems(targetCollection, candidatesForRemoval); addReferencedItems(targetCollection, candidatesForAddition); return; } if (!nullSafeEquals(fromValue, targetWrapper.getPropertyValue(persistentProperty.getName()))) { targetWrapper.setPropertyValue(persistentProperty.getName(), fromValue); } } }); }
From source file:org.lightadmin.core.web.support.DynamicPersistentEntityResourceProcessor.java
private Object associationPropertyValue(Association association, Object instance) { PersistentProperty persistentProperty = association.getInverse(); PersistentEntity persistentEntity = persistentProperty.getOwner(); if (persistentProperty.isMap()) { return null; }//from w ww . ja v a 2 s.co m if (persistentProperty.isCollectionLike()) { return associatedPersistentEntities(association, instance); } Object associationValue = beanWrapper(instance).getPropertyValue(persistentProperty.getName()); return associatedPersistentEntity(persistentProperty, associationValue); }