@Override public Object getCompositeIdAttributeValue(Object id, String idAttribute) { Assert.isTrue(hasCompositeId(), "Model must have a composite Id!"); return new DirectFieldAccessFallbackBeanWrapper(id).getPropertyValue(idAttribute); }
super.setPropertyValue(propertyName, value); return; Object nestedIdPropertyValue = new DirectFieldAccessFallbackBeanWrapper(value) .getPropertyValue(nestedEntityInformation.getRequiredIdAttribute().getName()); super.setPropertyValue(propertyName, nestedIdPropertyValue); return; BeanWrapper sourceIdValueWrapper = new DirectFieldAccessFallbackBeanWrapper(value); BeanWrapper targetIdClassTypeWrapper = new BeanWrapperImpl(nestedEntityInformation.getIdType()); super.setPropertyValue(propertyName, targetIdClassTypeWrapper.getWrappedInstance());
@Override public boolean isNew(T entity) { if (!versionAttribute.isPresent() || versionAttribute.map(Attribute::getJavaType).map(Class::isPrimitive).orElse(false)) { return super.isNew(entity); } BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(entity); return versionAttribute.map(it -> wrapper.getPropertyValue(it.getName()) == null).orElse(true); }
@Override @Nullable public Object getPropertyValue(String propertyName) { try { return super.getPropertyValue(propertyName); } catch (NotReadablePropertyException e) { Field field = findField(getWrappedClass(), propertyName); if (field == null) { throw new NotReadablePropertyException(getWrappedClass(), propertyName, "Could not find field for property during fallback access!"); } makeAccessible(field); return getField(field, getWrappedInstance()); } }
/** * Creates new {@link JedisClusterNodeResourceProvider}. * * @param cluster must not be {@literal null}. * @param topologyProvider must not be {@literal null}. */ JedisClusterNodeResourceProvider(JedisCluster cluster, ClusterTopologyProvider topologyProvider) { this.cluster = cluster; this.topologyProvider = topologyProvider; if (cluster != null) { PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster); this.connectionHandler = accessor.isReadableProperty("connectionHandler") ? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null; } else { this.connectionHandler = null; } }
@Override public void setPropertyValue(String propertyName, @Nullable Object value) { try { super.setPropertyValue(propertyName, value); } catch (NotWritablePropertyException e) { Field field = findField(getWrappedClass(), propertyName); if (field == null) { throw new NotWritablePropertyException(getWrappedClass(), propertyName, "Could not find field for property during fallback access!", e); } makeAccessible(field); setField(field, getWrappedInstance(), value); } } }
@Nullable private Object extractActualIdPropertyValue(BeanWrapper sourceIdValueWrapper, String idAttributeName) { Object idPropertyValue = sourceIdValueWrapper.getPropertyValue(idAttributeName); if (idPropertyValue != null) { Class<? extends Object> idPropertyValueType = idPropertyValue.getClass(); if (!jpaMetamodel.isJpaManaged(idPropertyValueType)) { return idPropertyValue; } return new DirectFieldAccessFallbackBeanWrapper(idPropertyValue) .getPropertyValue(tryFindSingularIdAttributeNameOrUseFallback(idPropertyValueType, idAttributeName)); } return null; }
@Override @Nullable @SuppressWarnings("unchecked") public ID getId(T entity) { BeanWrapper entityWrapper = new DirectFieldAccessFallbackBeanWrapper(entity); if (idMetadata.hasSimpleId()) { return (ID) entityWrapper.getPropertyValue(idMetadata.getSimpleIdAttribute().getName()); } BeanWrapper idWrapper = new IdentifierDerivingDirectFieldAccessFallbackBeanWrapper(idMetadata.getType(), metamodel); boolean partialIdValueFound = false; for (SingularAttribute<? super T, ?> attribute : idMetadata) { Object propertyValue = entityWrapper.getPropertyValue(attribute.getName()); if (propertyValue != null) { partialIdValueFound = true; } idWrapper.setPropertyValue(attribute.getName(), propertyValue); } return partialIdValueFound ? (ID) idWrapper.getWrappedInstance() : null; }
super.setPropertyValue(propertyName, value); return; Object nestedIdPropertyValue = new DirectFieldAccessFallbackBeanWrapper(value) .getPropertyValue(nestedEntityInformation.getRequiredIdAttribute().getName()); super.setPropertyValue(propertyName, nestedIdPropertyValue); return; BeanWrapper sourceIdValueWrapper = new DirectFieldAccessFallbackBeanWrapper(value); BeanWrapper targetIdClassTypeWrapper = new BeanWrapperImpl(nestedEntityInformation.getIdType()); super.setPropertyValue(propertyName, targetIdClassTypeWrapper.getWrappedInstance());
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) { if (!(source instanceof JsonNode)) { resultMap.put(propertyPrefix, source); return; } JsonNode element = (JsonNode) source; if (element.isArray()) { Iterator<JsonNode> nodes = element.elements(); while (nodes.hasNext()) { JsonNode cur = nodes.next(); if (cur.isArray()) { this.falttenCollection(propertyPrefix, cur.elements(), resultMap); } } } else if (element.isContainerNode()) { this.doFlatten(propertyPrefix, element.fields(), resultMap); } else { resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value")); } }
/** * Creates a new {@link PropertyAccessingMethodInterceptor} for the given target object. * * @param target must not be {@literal null}. */ public PropertyAccessingMethodInterceptor(Object target) { Assert.notNull(target, "Proxy target must not be null!"); this.target = new DirectFieldAccessFallbackBeanWrapper(target); }
DirectFieldAccessFallbackBeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(value); .apply(Optional.ofNullable(beanWrapper.getPropertyValue(attribute.getName())));
@Override public boolean isNew(T entity) { if (!versionAttribute.isPresent() || versionAttribute.map(Attribute::getJavaType).map(Class::isPrimitive).orElse(false)) { return super.isNew(entity); } BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(entity); return versionAttribute.map(it -> wrapper.getPropertyValue(it.getName()) == null).orElse(true); }
public Object getCompositeIdAttributeValue(Object id, String idAttribute) { Assert.isTrue(hasCompositeId(), "Model must have a composite Id!"); return new DirectFieldAccessFallbackBeanWrapper(id).getPropertyValue(idAttribute); }
/** * Creates new {@link JedisClusterNodeResourceProvider}. * * @param cluster must not be {@literal null}. * @param topologyProvider must not be {@literal null}. */ JedisClusterNodeResourceProvider(JedisCluster cluster, ClusterTopologyProvider topologyProvider) { this.cluster = cluster; this.topologyProvider = topologyProvider; if (cluster != null) { PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster); this.connectionHandler = accessor.isReadableProperty("connectionHandler") ? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null; } else { this.connectionHandler = null; } }
@Nullable private Object extractActualIdPropertyValue(BeanWrapper sourceIdValueWrapper, String idAttributeName) { Object idPropertyValue = sourceIdValueWrapper.getPropertyValue(idAttributeName); if (idPropertyValue != null) { Class<? extends Object> idPropertyValueType = idPropertyValue.getClass(); if (!jpaMetamodel.isJpaManaged(idPropertyValueType)) { return idPropertyValue; } return new DirectFieldAccessFallbackBeanWrapper(idPropertyValue) .getPropertyValue(tryFindSingularIdAttributeNameOrUseFallback(idPropertyValueType, idAttributeName)); } return null; }
/** * Creates new {@link JedisClusterNodeResourceProvider}. * * @param cluster must not be {@literal null}. * @param topologyProvider must not be {@literal null}. */ JedisClusterNodeResourceProvider(JedisCluster cluster, ClusterTopologyProvider topologyProvider) { this.cluster = cluster; this.topologyProvider = topologyProvider; if (cluster != null) { PropertyAccessor accessor = new DirectFieldAccessFallbackBeanWrapper(cluster); this.connectionHandler = accessor.isReadableProperty("connectionHandler") ? (JedisClusterConnectionHandler) accessor.getPropertyValue("connectionHandler") : null; } else { this.connectionHandler = null; } }
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) { if (!(source instanceof JsonNode)) { resultMap.put(propertyPrefix, source); return; } JsonNode element = (JsonNode) source; if (element.isArray()) { Iterator<JsonNode> nodes = element.elements(); while (nodes.hasNext()) { JsonNode cur = nodes.next(); if (cur.isArray()) { this.falttenCollection(propertyPrefix, cur.elements(), resultMap); } } } else if (element.isContainerNode()) { this.doFlatten(propertyPrefix, element.fields(), resultMap); } else { resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value")); } }
@Nullable @SuppressWarnings("unchecked") public ID getId(T entity) { BeanWrapper entityWrapper = new DirectFieldAccessFallbackBeanWrapper(entity); if (idMetadata.hasSimpleId()) { return (ID) entityWrapper.getPropertyValue(idMetadata.getSimpleIdAttribute().getName()); } BeanWrapper idWrapper = new IdentifierDerivingDirectFieldAccessFallbackBeanWrapper(idMetadata.getType(), metamodel); boolean partialIdValueFound = false; for (SingularAttribute<? super T, ?> attribute : idMetadata) { Object propertyValue = entityWrapper.getPropertyValue(attribute.getName()); if (propertyValue != null) { partialIdValueFound = true; } idWrapper.setPropertyValue(attribute.getName(), propertyValue); } return partialIdValueFound ? (ID) idWrapper.getWrappedInstance() : null; }
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) { if (!(source instanceof JsonNode)) { resultMap.put(propertyPrefix, source); return; } JsonNode element = (JsonNode) source; if (element.isArray()) { Iterator<JsonNode> nodes = element.elements(); while (nodes.hasNext()) { JsonNode cur = nodes.next(); if (cur.isArray()) { this.falttenCollection(propertyPrefix, cur.elements(), resultMap); } } } else if (element.isContainerNode()) { this.doFlatten(propertyPrefix, element.fields(), resultMap); } else { resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value")); } }