public final void setValue(X target, Y value) { initialize(); try { Object leafObj = getLeafObject(target, false); final Method setter = leafSetter == null && leafObj != null ? ReflectionUtils .getSetter( leafObj.getClass(), explodedPropertyPath[explodedPropertyPath.length - 1]) : leafSetter; setter.invoke(leafObj, value); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
private void setAttribute(Object instance, SingularAttribute<?, ?> jpaAttribute, Object value) throws Exception { if (jpaAttribute.getJavaMember() instanceof Method) { Method setter = ReflectionUtils.getSetter(instance.getClass(), jpaAttribute.getName()); setter.setAccessible(true); setter.invoke(instance, value); } else if (jpaAttribute.getJavaMember() instanceof Field) { Field field = (Field) jpaAttribute.getJavaMember(); field.setAccessible(true); field.set(instance, value); } else { throw new IllegalArgumentException("Unsupported JPA member type: " + jpaAttribute.getJavaMember()); } }
private AssociationFromIdParameterTransformer(Class<?> associationType, Attribute<?, ?> idAttribute) { try { Constructor<Object> constructor = (Constructor<Object>) associationType.getDeclaredConstructor(); constructor.setAccessible(true); Member idMember = idAttribute.getJavaMember(); if (idMember instanceof Method) { Method setter = ReflectionUtils.getSetter(associationType, idAttribute.getName()); setter.setAccessible(true); this.idField = null; this.idSetter = setter; } else if (idMember instanceof Field) { Field field = (Field) idMember; field.setAccessible(true); this.idField = field; this.idSetter = null; } else { throw new IllegalArgumentException("Unsupported attribute member type [" + idMember + "] for attribute [" + idAttribute.getName() + "] of class [" + associationType.getName() + "]"); } this.entityConstructor = constructor; } catch (Exception e) { throw new IllegalArgumentException("The entity type [" + associationType.getName() + "] does not have a default constructor or id field/setter!", e); } }
leafSetter = ReflectionUtils.getSetter(current, properties[getterChainLength]);
sb.append("\t\tcase ").append(attribute.getDirtyStateIndex()).append(": "); if (ReflectionUtils.getSetter(attribute.getDeclaringType().getJavaType(), attribute.getName()) != null) { sb.append("$0.set").append(Character.toUpperCase(attribute.getName().charAt(0))).append(attribute.getName(), 1, attribute.getName().length()); sb.append('(');
} else { attributeName = getAttributeName(m); Method setter = ReflectionUtils.getSetter(viewType, attributeName);
private boolean determineUpdatable(Type<?> elementType) { // Subquery and Parameter mappings are never considered updatable if (getMappingType() != MappingType.BASIC && getMappingType() != MappingType.CORRELATED) { return false; } Method setter = ReflectionUtils.getSetter(getDeclaringType().getJavaType(), getName()); boolean hasSetter = setter != null && (setter.getModifiers() & Modifier.ABSTRACT) != 0; // Note that the same logic is implemented for subtype discovery in MethodAttributeMapping.initializeViewMappings() // For a plural attribute being considered updatable, there must be a setter or the view type must be creatable if (elementType instanceof ManagedViewType<?>) { ManagedViewType<?> t = (ManagedViewType<?>) elementType; return hasSetter || t.isCreatable(); } // We exclude entity types from this since there is no clear intent return hasSetter; }
private static AttributeAccessor forEntityAttribute(EntityViewManagerImpl evm, Class<?> entityClass, Attribute<?, ?> attribute, Class<?> targetType) { Member member = attribute.getJavaMember(); if (member instanceof Field) { return new EntityFieldAttributeAccessor(evm.getJpaProvider(), (Field) member, targetType); } else if (member instanceof Method) { Method getter = ReflectionUtils.getGetter(entityClass, attribute.getName()); Method setter = ReflectionUtils.getSetter(entityClass, attribute.getName()); return new EntityMethodAttributeAccessor(getter, setter, targetType); } else { throw new IllegalArgumentException("Unsupported java member for id attribute: " + member); } } }
private boolean determineUpdatable(Type<?> elementType) { // Subquery and Parameter mappings are never considered updatable if (getMappingType() != MappingType.BASIC && getMappingType() != MappingType.CORRELATED) { return false; } Method setter = ReflectionUtils.getSetter(getDeclaringType().getJavaType(), getName()); boolean hasSetter = setter != null && (setter.getModifiers() & Modifier.ABSTRACT) != 0; // For a singular attribute being considered updatable, there must be a setter // If the type is a flat view, it must be updatable or creatable and have a setter if (elementType instanceof FlatViewType<?>) { FlatViewType<?> t = (FlatViewType<?>) elementType; return t.isUpdatable() || hasSetter && t.isCreatable(); } // We exclude entity types from this since there is no clear intent return hasSetter; }
Method setter = ReflectionUtils.getSetter(getDeclaringView().getEntityViewClass(), getName()); boolean hasSetter = setter != null && (setter.getModifiers() & Modifier.ABSTRACT) != 0; boolean isCollection = false;
private CtField addMembersForAttribute(AbstractMethodAttribute<?, ?> attribute, Class<?> clazz, CtClass cc, CtField mutableStateField, boolean dirtyChecking, boolean isId, boolean forceMutable) throws CannotCompileException, NotFoundException { Method getter = attribute.getJavaMethod(); Method setter = ReflectionUtils.getSetter(clazz, attribute.getName()); // Create the field from the attribute CtField attributeField = new CtField(getType(attribute), attribute.getName(), cc); attributeField.setModifiers(getModifiers(forceMutable || setter != null)); String genericSignature = getGenericSignature(attribute, attributeField); if (genericSignature != null) { setGenericSignature(attributeField, genericSignature); } cc.addField(attributeField); createGettersAndSetters(attribute, clazz, cc, getter, setter, mutableStateField, attributeField, dirtyChecking, isId); return attributeField; }