List of usage examples for org.springframework.data.mapping PersistentProperty isCollectionLike
boolean isCollectionLike();
From source file:org.lightadmin.core.persistence.metamodel.PersistentPropertyType.java
public static PersistentPropertyType forPersistentProperty(PersistentProperty persistentProperty) { final Class<?> attrType = persistentProperty.getType(); if (persistentProperty.isAnnotationPresent(Embedded.class) || persistentProperty.isAnnotationPresent(EmbeddedId.class)) { return PersistentPropertyType.EMBEDDED; }// w w w. jav a 2 s .c om if (persistentProperty.isAssociation()) { if (persistentProperty.isCollectionLike()) { return PersistentPropertyType.ASSOC_MULTI; } return PersistentPropertyType.ASSOC; } if (persistentProperty.isMap()) { return PersistentPropertyType.MAP; } if (ClassUtils.isAssignable(Enum.class, attrType)) { return ENUM; } if (forType(attrType) == STRING && persistentProperty.isAnnotationPresent(FileReference.class)) { return PersistentPropertyType.FILE; } if (isOfDateType(persistentProperty)) { return DATE; } if (isOfTimeType(persistentProperty)) { return TIME; } if (isOfDateTimeType(persistentProperty)) { return DATE_TIME; } return forType(attrType); }
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 va 2 s .co m if (persistentProperty.isCollectionLike()) { return associatedPersistentEntities(association, instance); } Object associationValue = beanWrapper(instance).getPropertyValue(persistentProperty.getName()); return associatedPersistentEntity(persistentProperty, associationValue); }
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. *///w ww .j av a 2s. c om @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); } } }); }