Package org.eclipse.persistence.descriptors

Examples of org.eclipse.persistence.descriptors.CMPPolicy


     *  Return the type that represents the type of the id.
     *  @return type of id
     */
    public Type<?> getIdType() {
        // NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor
        CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy();
        if (null == cmpPolicy) {
            // Composite key support (IE: @EmbeddedId)           
            List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings();
            // Check the primaryKeyFields on the descriptor - for MappedSuperclass pseudo-Descriptors
            if(pkMappings.isEmpty()) {
                // Search the mappings for Id mappings
                for(DatabaseMapping aMapping : getDescriptor().getMappings()) {                   
                    if(aMapping.isJPAId()) {
                        // get the attribute Id (declared or not)
                        Attribute anAttribute = this.getAttribute(aMapping.getAttributeName());
                        if(anAttribute != null) {
                            return this.getMetamodel().getType(anAttribute.getJavaType());
                        }                       
                    }
                }
            }
           
            if (pkMappings.size() == 1) {
                Class aClass = pkMappings.get(0).getAttributeClassification(); // null for OneToOneMapping
                // lookup class in our types map
                return this.metamodel.getType(aClass);
            }
        }
       
        // Single Key support using any Java class - built in or user defined
        // There already is an instance of the PKclass on the policy
        if (cmpPolicy.isCMP3Policy()) {
            // BasicType, EntityType or IdentifiableType are handled here, lookup the class in the types map and create a wrapper if it does not exist yet
            return this.metamodel.getType(((CMP3Policy) cmpPolicy).getPKClass());
        }
        // Non-specification mandated exception       
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
View Full Code Here


     *  Return the type that represents the type of the id.
     *  @return type of id
     */
    public Type<?> getIdType() {
        // NOTE: This code is another good reason to abstract out a PKPolicy on the descriptor
        CMPPolicy cmpPolicy = getDescriptor().getCMPPolicy();
        if (null == cmpPolicy) {
            // Composite key support (IE: @EmbeddedId)           
            List<DatabaseMapping> pkMappings = getDescriptor().getObjectBuilder().getPrimaryKeyMappings();
            // Check the primaryKeyFields on the descriptor - for MappedSuperclass pseudo-Descriptors
            if(pkMappings.isEmpty()) {
                // Search the mappings for Id mappings
                for(DatabaseMapping aMapping : getDescriptor().getMappings()) {                   
                    if(aMapping.isJPAId()) {
                        // get the attribute Id (declared or not)
                        Attribute anAttribute = this.getAttribute(aMapping.getAttributeName());
                        if(anAttribute != null) {
                            return this.getMetamodel().getType(anAttribute.getJavaType());
                        }                       
                    }
                }
            }
           
            if (pkMappings.size() == 1) {
                Class aClass = pkMappings.get(0).getAttributeClassification(); // null for OneToOneMapping
                // lookup class in our types map
                return this.metamodel.getType(aClass);
            }
        }
       
        // Single Key support using any Java class - built in or user defined
        // There already is an instance of the PKclass on the policy
        if (cmpPolicy.isCMP3Policy()) {
            // BasicType, EntityType or IdentifiableType are handled here, lookup the class in the types map and create a wrapper if it does not exist yet
            return this.metamodel.getType(((CMP3Policy) cmpPolicy).getPKClass());
        }
        // Non-specification mandated exception       
        throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
View Full Code Here

        Iterator iterator = (Iterator)this.containerPolicy.iteratorFor(collection);
        int index = 0;
        while(iterator.hasNext()){
            Object target = iterator.next();
            if (target != null){
                CMPPolicy policy = referenceDescriptor.getCMPPolicy();
                if (policy != null && policy.isCMP3Policy()){
                    result[index] = policy.createPrimaryKeyInstance(target, session);
                }else{
                    result[index] = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session);
                }
                ++index;
            }
View Full Code Here

    /**
     * INTERNAL:
     * Creates the Array of simple types used to recreate this map. 
     */
    public Object createSerializableMapKeyInfo(Object key, AbstractSession session){
            CMPPolicy policy = referenceDescriptor.getCMPPolicy();
            if (policy != null && policy.isCMP3Policy()){
                return policy.createPrimaryKeyInstance(key, session);
            }else{
                return referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(key, session);
            }
    }
View Full Code Here

    public Object[] buildReferencesPKList(Object entity, Object attribute, AbstractSession session) {
        ClassDescriptor referenceDescriptor = getReferenceDescriptor();
        Object target = this.indirectionPolicy.getRealAttributeValueFromObject(entity, attribute);
        Object[] result = new Object[1];
        if (target != null){
            CMPPolicy policy = referenceDescriptor.getCMPPolicy();
            if (policy != null && policy.isCMP3Policy()) {
                result[0] = policy.createPrimaryKeyInstance(target, session);
            } else {
                result[0] = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session);
            }
        }
        return result;
View Full Code Here

        Iterator iterator = (Iterator)this.iteratorFor(container);
        int index = 0;
        while(iterator.hasNext()){
            Object target = iterator.next();
            if (target != null){
                CMPPolicy policy = elementDescriptor.getCMPPolicy();
                if (policy != null && policy.isCMP3Policy()){
                    result[index] = policy.createPrimaryKeyInstance(target, session);
                }else{
                    result[index] = elementDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session);
                }
                ++index;
            }
View Full Code Here

        int index = 0;
        while(iterator.hasNext()){
            Map.Entry entry = (Entry) iterator.next();
            result[index] = entry.getKey();
            ++index;
            CMPPolicy policy = elementDescriptor.getCMPPolicy();
            if (policy != null && policy.isCMP3Policy()){
                result[index] = policy.createPrimaryKeyInstance(entry.getValue(), session);
            }else{
                result[index] = elementDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(entry.getValue(), session);
            }
            ++index;
        }
View Full Code Here

        int index = 0;
        while(iterator.hasNext()){
            Object target = iterator.next();
            if (target != null){
                Vector pks = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session);
                CMPPolicy policy = referenceDescriptor.getCMPPolicy();
                if (policy != null && policy.isCMP3Policy()){
                    result[index] = policy.createPrimaryKeyInstance(pks);
                }else{
                    result[index] = pks;
                }
                ++index;
            }
View Full Code Here

        ClassDescriptor referenceDescriptor = getReferenceDescriptor();
        Object target = getIndirectionPolicy().getRealAttributeValueFromObject(entity, attribute);
        Object[] result = new Object[1];
        if (target != null){
            Vector pks = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session);
            CMPPolicy policy = referenceDescriptor.getCMPPolicy();
            if (policy != null && policy.isCMP3Policy()) {
                result[0] = policy.createPrimaryKeyInstance(pks);
            } else {
                result[0] = pks;
            }
        }
        return result;
View Full Code Here

       
        List primaryKeyValues;
        if (primaryKey instanceof List) {
            primaryKeyValues = (List)primaryKey;
        } else {
            CMPPolicy policy = descriptor.getCMPPolicy();
            Class pkClass = policy.getPKClass();
            if ((pkClass != null) && (pkClass != primaryKey.getClass()) && (!pkClass.isAssignableFrom(primaryKey.getClass()))) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] { descriptor.getCMPPolicy().getPKClass(), primaryKey.getClass() }));
            }
            primaryKeyValues = policy.createPkVectorFromKey(primaryKey, session);
        }
       
        // Get the read object query and apply the properties to it.
        // PERF: use descriptor defined query to avoid extra query creation.
        ReadObjectQuery query = descriptor.getQueryManager().getReadObjectQuery();
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.descriptors.CMPPolicy

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.