/** * Adds the plural attribute. * * @param attributeName * the attribute name * @param attribute * the attribute */ public void addPluralAttribute(String attributeName, PluralAttribute<X, ?, ?> attribute) { if (declaredPluralAttributes == null) { declaredPluralAttributes = new HashMap<String, PluralAttribute<X, ?, ?>>(); } declaredPluralAttributes.put(attributeName, attribute); onValidateAttributeConstraints((Field) attribute.getJavaMember()); onEmbeddableAttribute((Field) attribute.getJavaMember()); }
Member javaMember = pluralAttrib.getJavaMember(); String name = javaMember.getName(); if (javaMember instanceof Field)
/** * Assert on owner type attributes. * * @param managedType * the managed type * @param fieldName * the field name * @param fieldClazz * the field clazz * @param javaClazz * the java clazz */ private void assertOnOwnerTypeAttributes(AbstractManagedType managedType, String fieldName, Class fieldClazz, Class javaClazz) { Assert.assertNotNull(managedType); Assert.assertNotNull(managedType.getPluralAttributes()); Assert.assertEquals(4, managedType.getPluralAttributes().size()); Assert.assertNotNull(managedType.getAttribute(fieldName)); Assert.assertEquals(javaClazz, managedType.getAttribute(fieldName).getJavaType()); Assert.assertEquals(fieldClazz, ((PluralAttribute) managedType.getAttribute(fieldName)).getElementType() .getJavaType()); Assert.assertEquals(BindableType.PLURAL_ATTRIBUTE, ((PluralAttribute) managedType.getAttribute(fieldName)).getBindableType()); Assert.assertNotNull(((PluralAttribute) managedType.getAttribute(fieldName)).getJavaMember()); Assert.assertNotNull(fieldName, ((PluralAttribute) managedType.getAttribute(fieldName)).getJavaMember() .getName()); }
public boolean isOrphanRemoval(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return oneToMany.orphanRemoval(); } } return true; } }
public boolean isOrphanRemoval(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return oneToMany.orphanRemoval(); } } return true; } }
/** * Fetches the value of the given SingularAttribute on the given * entity. * * @see http://stackoverflow.com/questions/7077464/how-to-get-singularattribute-mapped-value-of-a-persistent-object */ @SuppressWarnings("unchecked") public <EntityType, FieldType> FieldType getAttributeValue(EntityType entity, PluralAttribute<EntityType, ?, FieldType> field) { try { Member member = field.getJavaMember(); if (member instanceof Method) { // this should be a getter method: return (FieldType) ((Method)member).invoke(entity); } else if (member instanceof java.lang.reflect.Field) { return (FieldType) ((java.lang.reflect.Field)member).get(entity); } else { throw new IllegalArgumentException("Unexpected java member type. Expecting method or field, found: " + member); } } catch (Exception e) { throw new RuntimeException(e); } }
/** * Retrieves cascade from metamodel attribute * * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }
/** * Retrieves cascade from metamodel attribute * * @param attribute given pluaral attribute * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }