Package org.eclipse.persistence.internal.jpa.metadata.accessors.objects

Examples of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod


                        String getMethodName = accessor.getAccessMethods().getGetMethodName();
                        Method getMethod = MetadataHelper.getMethod(getMethodName, getJavaClass(), new Class[]{});
                        String setMethodName = accessor.getAccessMethods().getSetMethodName();
                        Method setMethod = MetadataHelper.getMethod(setMethodName, getJavaClass(), new Class[]{getMethod.getReturnType()});
                       
                        accessibleObject = new MetadataMethod(getMethod, setMethod, accessor.getName(), getEntityMappings());
                    } else {
                        Method method = MetadataHelper.getMethodForPropertyName(accessor.getName(), getJavaClass());
                       
                        if (method == null) {
                            throw ValidationException.invalidPropertyForClass(accessor.getName(), getJavaClass());
                        } else {
                            MetadataMethod metadataMethod = new MetadataMethod(method, getEntityMappings());
                           
                            // True will force an exception to be thrown if it
                            // is not a valid method. However, if it is a
                            // transient accessor, don't validate it and just
                            // let it through.
                            if (accessor.isTransient() || metadataMethod.isValidPersistenceMethod(getDescriptor(), true)) {   
                                accessibleObject = metadataMethod;
                            }
                        } 
                    }
                } else {
View Full Code Here


    /**
     * INTERNAL:
     */
    protected boolean havePersistenceAnnotationsDefined(Method[] methods) {
        for (Method method : methods) {
            MetadataMethod metadataMethod = new MetadataMethod(method, getLogger());
           
            if (metadataMethod.hasDeclaredAnnotations(getDescriptor())) {
                return true;
            }
        }
       
        return false;
View Full Code Here

     * setting and for a field to be processed it must have a Access(PROPERTY)
     * setting.
     */
    protected void processAccessorMethods(boolean processingInverse) {
        for (Method method : MetadataHelper.getDeclaredMethods(getJavaClass())) {
            MetadataMethod metadataMethod = new MetadataMethod(method, getLogger());
           
            if (metadataMethod.isAnnotationPresent(Transient.class)) {   
                if (metadataMethod.hasMoreThanOneDeclaredAnnotation(getDescriptor())) {
                    throw ValidationException.mappingAnnotationsAppliedToTransientAttribute(method);
                }
            } else {
                // The is valid check will throw an exception if needed.
                if (metadataMethod.isValidPersistenceMethod(processingInverse, getDescriptor())) {
                    // If the accessor already exists, it may have come from XML
                    // or because of an explicit access type setting. E.G.
                    // Access type is field however the user indicated the we
                    // should use its access methods. We must therefore
                    // overwrite the previous accessor with this explicit one.
                    if (! getDescriptor().hasAccessorFor(metadataMethod.getAttributeName()) || (getDescriptor().hasAccessorFor(metadataMethod.getAttributeName()) && processingInverse)) {
                        getDescriptor().addAccessor(buildAccessor(metadataMethod));
                    }
                }
            }
        }
View Full Code Here

     * is performed on the existence of the method by property name or by
     * the access methods if specified.
     */
    protected MetadataMethod getAccessibleMethod(MappingAccessor accessor) {
        if (accessor.hasAccessMethods()) {
            MetadataMethod getMethod = getJavaClass().getMethod(accessor.getGetMethodName(), new String[]{});
            MetadataMethod setMethod = getJavaClass().getMethod(accessor.getSetMethodName(), Arrays.asList(new String[]{getMethod.getReturnType()}));
            getMethod.setSetMethod(setMethod);
            return getMethod;
        } else {
            MetadataMethod method = getJavaClass().getMethodForPropertyName(accessor.getName());

            if (method == null) {
                throw ValidationException.invalidPropertyForClass(accessor.getName(), getJavaClass());
            } else {
                // True will force an exception to be thrown if it is not a
                // valid method. However, if it is a transient accessor, don't
                // validate it and return.
                if (accessor.isTransient() || method.isValidPersistenceMethod(this, true)) {
                    return method;
                }
               
                return null;
           
View Full Code Here

        // set the default access methods.
        if (! accessor.hasAccessMethods()) {
            accessor.setAccessMethods(getDescriptor().getDefaultAccessMethods());
        }

        MetadataMethod getMethod = new MetadataMethod(getMetadataFactory(), getJavaClass());
        MetadataMethod setMethod = new MetadataMethod(getMetadataFactory(), getJavaClass());
       
        // Set the set method on the getMethod and return it.
        getMethod.setSetMethod(setMethod);

        // Make sure we set the attribute name on the getMethod.
        getMethod.setAttributeName(accessor.getName());
       
        // Set the get and set method names.
        getMethod.setName(accessor.getGetMethodName());
        setMethod.setName(accessor.getSetMethodName());

        return getMethod;
    }
View Full Code Here

        classDetails.setSuperClassName(superClassName);
        classDetails.setShouldWeaveValueHolders(weaveValueHolders);
        classDetails.setShouldWeaveChangeTracking(weaveChangeTracking);
        classDetails.setShouldWeaveFetchGroups(weaveFetchGroups);
        classDetails.setShouldWeaveInternal(weaveInternal);
        MetadataMethod method = metadataClass.getMethod("clone", new ArrayList(), false);
        classDetails.setImplementsCloneMethod(method != null);
        return classDetails;
    }
View Full Code Here

    private MetadataClass getAttributeTypeFromClass(MetadataClass metadataClass, String attributeName, DatabaseMapping mapping, boolean checkSuperclass){      
        String getterMethod = mapping.getGetMethodName();
        if (mapping.isAbstractDirectMapping() && mapping.getAttributeAccessor().isVirtualAttributeAccessor()){
            return metadataClass.getMetadataClass(((AbstractDirectMapping)mapping).getAttributeClassificationName());
        } else if (mapping != null && getterMethod != null) {
            MetadataMethod method = metadataClass.getMethod(getterMethod, new ArrayList(), checkSuperclass);
            if (method == null) {
                return null;
            }
            return method.getMetadataClass(method.getReturnType());
        } else {
            MetadataField field = metadataClass.getField(attributeName, checkSuperclass);
            if (field == null) {
                return null;
            }
View Full Code Here

     * Visit a method.
     */
    @Override
    public MetadataAnnotatedElement visitExecutable(ExecutableType executableType, MetadataAnnotatedElement annotatedElement) {
        MetadataMirrorFactory factory = ((MetadataMirrorFactory) annotatedElement.getMetadataFactory());
        MetadataMethod method = (MetadataMethod) annotatedElement;
       
        // Set the parameters.
        for (TypeMirror parameter : executableType.getParameterTypes()) {
            method.addParameter(factory.getMetadataClass(parameter).getType());
        }
       
        // Visit the return type (will set the type and generic types).
        executableType.getReturnType().accept(this, method);
        method.setReturnType(method.getType());
       
        return method;
    }
View Full Code Here

     * INTERNAL:
     * Visit an executable and create a MetadataMethod object.
     */
    @Override
    public MetadataMethod visitExecutable(ExecutableElement executableElement, MetadataClass metadataClass) {
        MetadataMethod method = new MetadataMethod(metadataClass.getMetadataFactory(), metadataClass);
       
        // Set the name.
        method.setName(executableElement.getSimpleName().toString());
       
        // Set the attribute name.
        method.setAttributeName(Helper.getAttributeNameFromMethodName(method.getName()));
       
        // Set the modifiers.
        method.setModifiers(getModifiers(executableElement.getModifiers()));

        // Visit executable element for the parameters, return type and generic type.
        executableElement.asType().accept(typeVisitor, method);
       
        // Set the annotations.
        buildMetadataAnnotations(method, executableElement.getAnnotationMirrors());

        // Handle multiple methods with the same name.
        MetadataMethod existing = metadataClass.getMethods().get(method.getName());
        if (existing == null) {
            metadataClass.addMethod(method);
        } else {
            while (existing.getNext() != null) {
                existing = existing.getNext();
            }
            existing.setNext(method);
        }
       
        return method;
    }
View Full Code Here

        }
       
        // 2 - Set any annotation defined methods second. We should only add
        // add them if they were not overridden in XML.
        for (Method method : methods) {
            MetadataMethod metadataMethod = getMetadataClass(method.getDeclaringClass().getName(), false).getMethod(method.getName(), method.getParameterTypes());
            // Metadata method can be null when dealing with jdk methods: equals, notify, toString, wait etc..
            if (metadataMethod != null) {
                if (metadataMethod.isAnnotationPresent(JPA_POST_LOAD, classAccessor) && m_postLoad == null) {
                    setPostLoad(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_POST_PERSIST, classAccessor) && m_postPersist == null) {
                    setPostPersist(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_POST_REMOVE, classAccessor) && m_postRemove == null) {
                    setPostRemove(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_POST_UPDATE, classAccessor) && m_postUpdate == null) {
                    setPostUpdate(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_PRE_PERSIST, classAccessor) && m_prePersist == null) {
                    setPrePersist(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_PRE_REMOVE, classAccessor) && m_preRemove == null) {
                    setPreRemove(method);
                }
               
                if (metadataMethod.isAnnotationPresent(JPA_PRE_UPDATE, classAccessor) && m_preUpdate == null) {
                    setPreUpdate(method);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.