Examples of AttributeOverride


Examples of org.apache.openejb.jee.jpa.AttributeOverride

            MappedSuperclass superclass = superclassByField.get(fieldName);
            if (superclass == null) {
                throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
            }
            superclass.addField(new Id(fieldName));
            mapping.addField(new AttributeOverride(fieldName));
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            String fieldName = "OpenEJB_pk";
            Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
        } else if (bean.getPrimKeyClass() != null) {
            Class<?> pkClass = null;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass superclass = null;
                for (java.lang.reflect.Field pkField : pkClass.getFields()) {
                    String fieldName = pkField.getName();
                    int modifiers = pkField.getModifiers();
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
                        superclass = superclassByField.get(fieldName);
                        if (superclass == null) {
                            throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                        }
                        superclass.addField(new Id(fieldName));
                        mapping.addField(new AttributeOverride(fieldName));
                        primaryKeyFields.add(fieldName);
                    }
                }
                if (superclass != null) {
                    superclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (ClassNotFoundException e) {
                // todo throw exception
            }
        }

        //
        // basic: cmp-fields
        //
        for (CmpField cmpField : bean.getCmpField()) {
            String fieldName = cmpField.getFieldName();
            if (!primaryKeyFields.contains(fieldName)) {
                MappedSuperclass superclass = superclassByField.get(fieldName);
                if (superclass == null) {
                    throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                }
                superclass.addField(new Basic(fieldName));
                mapping.addField(new AttributeOverride(fieldName));
            }
        }

        return new HashSet<MappedSuperclass>(superclassByField.values());
    }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.AttributeOverride

            MappedSuperclass superclass = superclassByField.get(fieldName);
            if (superclass == null) {
                throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
            }
            superclass.addField(new Id(fieldName));
            mapping.addField(new AttributeOverride(fieldName));
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            String fieldName = "OpenEJB_pk";
            Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
        } else if (bean.getPrimKeyClass() != null) {
            Class<?> pkClass = null;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass superclass = null;
                for (java.lang.reflect.Field pkField : pkClass.getFields()) {
                    String fieldName = pkField.getName();
                    int modifiers = pkField.getModifiers();
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
                        superclass = superclassByField.get(fieldName);
                        if (superclass == null) {
                            throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                        }
                        superclass.addField(new Id(fieldName));
                        mapping.addField(new AttributeOverride(fieldName));
                        primaryKeyFields.add(fieldName);
                    }
                }
                if (superclass != null) {
                    superclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (ClassNotFoundException e) {
                // todo throw exception
            }
        }

        //
        // basic: cmp-fields
        //
        for (CmpField cmpField : bean.getCmpField()) {
            String fieldName = cmpField.getFieldName();
            if (!primaryKeyFields.contains(fieldName)) {
                MappedSuperclass superclass = superclassByField.get(fieldName);
                if (superclass == null) {
                    throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                }
                superclass.addField(new Basic(fieldName));
                mapping.addField(new AttributeOverride(fieldName));
            }
        }

        return new HashSet<MappedSuperclass>(superclassByField.values());
    }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.AttributeOverride

            // this need not be here...for CMP 2.x, these are generally autogenerated fields.
            if (superclass != null) {
                // ok, add this field to the superclass mapping
                superclass.addField(new Id(fieldName));
                // the direct mapping is an over ride
                mapping.addField(new AttributeOverride(fieldName));
            } else {
                // this is a normal generated field, it will be in the main class mapping.
                mapping.addField(new Id(fieldName));
            }
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            // the automatically generated keys use a special property name
            // and will always be in the generated superclass.
            final String fieldName = "OpenEJB_pk";
            final Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
            primaryKeyFields.add(fieldName);
        } else if (bean.getPrimKeyClass() != null) {
            final Class<?> pkClass;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass idclass = null;
                // now validate the primary class fields against the bean cmp fields
                // to make sure everything maps correctly.
                for (final Field pkField : pkClass.getFields()) {
                    final String pkFieldName = pkField.getName();
                    final int modifiers = pkField.getModifiers();
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(pkFieldName)) {
                        // see if the bean field is concretely defined in one of the superclasses
                        final MappedSuperclass superclass = superclassByField.get(pkFieldName);
                        if (superclass != null) {
                            // ok, we have an override that needs to be specified at the main class level.
                            superclass.addField(new Id(pkFieldName));
                            mapping.addField(new AttributeOverride(pkFieldName));
                            idclass = resolveIdClass(idclass, superclass, beanClass);
                        } else {
                            // this field will be autogenerated
                            mapping.addField(new Id(pkFieldName));
                        }
                        primaryKeyFields.add(pkFieldName);
                    }
                }
                // if we've located an ID class, set it as such
                if (idclass != null) {
                    idclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                } else {
                    // do this for the toplevel mapping
                    mapping.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (final ClassNotFoundException e) {
                throw (IllegalStateException) new IllegalStateException("Could not find entity primary key class " + bean.getPrimKeyClass()).initCause(e);
            }
        }

        //
        // basic: cmp-fields
        // This again, adds all of the additional cmp-fields to the mapping
        //
        for (final CmpField cmpField : bean.getCmpField()) {
            // only add entries for cmp fields that are not part of the primary key
            if (!primaryKeyFields.contains(cmpField.getFieldName())) {
                final String fieldName = cmpField.getFieldName();
                // this will be here if we've already processed this
                final MappedSuperclass superclass = superclassByField.get(fieldName);
                // if this field is defined by one of the superclasses, then
                // we need to provide a mapping for this.
                if (superclass != null) {
                    // we need to mark this as being in one of the superclasses
                    superclass.addField(new Basic(fieldName));
                    mapping.addField(new AttributeOverride(fieldName));
                } else {
                    // directly generated.
                    mapping.addField(new Basic(fieldName));
                }
            }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.AttributeOverride

            final MappedSuperclass superclass = superclassByField.get(fieldName);
            if (superclass == null) {
                throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
            }
            superclass.addField(new Id(fieldName));
            mapping.addField(new AttributeOverride(fieldName));
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            // a primary field type of Object is an automatically generated
            // pk field.  Mark it as such and add it to the mapping. 
            final String fieldName = "OpenEJB_pk";
            final Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
        } else if (bean.getPrimKeyClass() != null) {
            // we have a primary key class.  We need to define the mappings between the key class fields
            // and the bean's managed fields.

            final Class<?> pkClass;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass superclass;
                MappedSuperclass idclass = null;
                for (final Field pkField : pkClass.getFields()) {
                    final String fieldName = pkField.getName();
                    final int modifiers = pkField.getModifiers();
                    // the primary key fields must be public, non-static, must be defined as a CMP field,
                    // AND must also exist in the class hierarchy (not enforced by mapFields());
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
                        superclass = superclassByField.get(fieldName);
                        if (superclass == null) {
                            throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                        }
                        // these are defined ast ID fields because they are part of the primary key
                        superclass.addField(new Id(fieldName));
                        mapping.addField(new AttributeOverride(fieldName));
                        primaryKeyFields.add(fieldName);
                        idclass = resolveIdClass(idclass, superclass, ejbClass);
                    }
                }

                // if we've located an ID class, set it as such
                if (idclass != null) {
                    idclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (final ClassNotFoundException e) {
                throw (IllegalStateException) new IllegalStateException("Could not find entity primary key class " + bean.getPrimKeyClass()).initCause(e);
            }
        }

        //
        // basic: cmp-fields
        //
        for (final CmpField cmpField : bean.getCmpField()) {
            final String fieldName = cmpField.getFieldName();
            // all of the primary key fields have been processed, so only handle whatever is left over
            if (!primaryKeyFields.contains(fieldName)) {
                final MappedSuperclass superclass = superclassByField.get(fieldName);
                if (superclass == null) {
                    throw new IllegalStateException("CMP field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                }
                superclass.addField(new Basic(fieldName));
                mapping.addField(new AttributeOverride(fieldName));
            }
        }

        // all of the fields should now be identified by type, so return a set of
        // the field mappings
View Full Code Here

Examples of org.apache.openejb.jee.jpa.AttributeOverride

            // this need not be here...for CMP 2.x, these are generally autogenerated fields.
            if (superclass != null) {
                // ok, add this field to the superclass mapping
                superclass.addField(new Id(fieldName));
                // the direct mapping is an over ride
                mapping.addField(new AttributeOverride(fieldName));
            } else {
                // this is a normal generated field, it will be in the main class mapping.
                mapping.addField(new Id(fieldName));
            }
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            // the automatically generated keys use a special property name
            // and will always be in the generated superclass.
            final String fieldName = "OpenEJB_pk";
            final Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
            primaryKeyFields.add(fieldName);
        } else if (bean.getPrimKeyClass() != null) {
            Class<?> pkClass = null;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass idclass = null;
                // now validate the primary class fields against the bean cmp fields
                // to make sure everything maps correctly.
                for (final Field pkField : pkClass.getFields()) {
                    final String pkFieldName = pkField.getName();
                    final int modifiers = pkField.getModifiers();
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(pkFieldName)) {
                        // see if the bean field is concretely defined in one of the superclasses
                        final MappedSuperclass superclass = superclassByField.get(pkFieldName);
                        if (superclass != null) {
                            // ok, we have an override that needs to be specified at the main class level.
                            superclass.addField(new Id(pkFieldName));
                            mapping.addField(new AttributeOverride(pkFieldName));
                            idclass = resolveIdClass(idclass, superclass, beanClass);
                        } else {
                            // this field will be autogenerated
                            mapping.addField(new Id(pkFieldName));
                        }
                        primaryKeyFields.add(pkFieldName);
                    }
                }
                // if we've located an ID class, set it as such
                if (idclass != null) {
                    idclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                } else {
                    // do this for the toplevel mapping
                    mapping.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (final ClassNotFoundException e) {
                throw (IllegalStateException) new IllegalStateException("Could not find entity primary key class " + bean.getPrimKeyClass()).initCause(e);
            }
        }

        //
        // basic: cmp-fields
        // This again, adds all of the additional cmp-fields to the mapping
        //
        for (final CmpField cmpField : bean.getCmpField()) {
            // only add entries for cmp fields that are not part of the primary key
            if (!primaryKeyFields.contains(cmpField.getFieldName())) {
                final String fieldName = cmpField.getFieldName();
                // this will be here if we've already processed this
                final MappedSuperclass superclass = superclassByField.get(fieldName);
                // if this field is defined by one of the superclasses, then
                // we need to provide a mapping for this.
                if (superclass != null) {
                    // we need to mark this as being in one of the superclasses
                    superclass.addField(new Basic(fieldName));
                    mapping.addField(new AttributeOverride(fieldName));
                } else {
                    // directly generated.
                    mapping.addField(new Basic(fieldName));
                }
            }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.AttributeOverride

            final MappedSuperclass superclass = superclassByField.get(fieldName);
            if (superclass == null) {
                throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
            }
            superclass.addField(new Id(fieldName));
            mapping.addField(new AttributeOverride(fieldName));
            primaryKeyFields.add(fieldName);
        } else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
            // a primary field type of Object is an automatically generated
            // pk field.  Mark it as such and add it to the mapping. 
            final String fieldName = "OpenEJB_pk";
            final Id field = new Id(fieldName);
            field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
            mapping.addField(field);
        } else if (bean.getPrimKeyClass() != null) {
            // we have a primary key class.  We need to define the mappings between the key class fields
            // and the bean's managed fields.

            Class<?> pkClass = null;
            try {
                pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                MappedSuperclass superclass = null;
                MappedSuperclass idclass = null;
                for (final Field pkField : pkClass.getFields()) {
                    final String fieldName = pkField.getName();
                    final int modifiers = pkField.getModifiers();
                    // the primary key fields must be public, non-static, must be defined as a CMP field,
                    // AND must also exist in the class hierarchy (not enforced by mapFields());
                    if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
                        superclass = superclassByField.get(fieldName);
                        if (superclass == null) {
                            throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                        }
                        // these are defined ast ID fields because they are part of the primary key
                        superclass.addField(new Id(fieldName));
                        mapping.addField(new AttributeOverride(fieldName));
                        primaryKeyFields.add(fieldName);
                        idclass = resolveIdClass(idclass, superclass, ejbClass);
                    }
                }

                // if we've located an ID class, set it as such
                if (idclass != null) {
                    idclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
                }
            } catch (final ClassNotFoundException e) {
                throw (IllegalStateException) new IllegalStateException("Could not find entity primary key class " + bean.getPrimKeyClass()).initCause(e);
            }
        }

        //
        // basic: cmp-fields
        //
        for (final CmpField cmpField : bean.getCmpField()) {
            final String fieldName = cmpField.getFieldName();
            // all of the primary key fields have been processed, so only handle whatever is left over
            if (!primaryKeyFields.contains(fieldName)) {
                final MappedSuperclass superclass = superclassByField.get(fieldName);
                if (superclass == null) {
                    throw new IllegalStateException("CMP field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
                }
                superclass.addField(new Basic(fieldName));
                mapping.addField(new AttributeOverride(fieldName));
            }
        }

        // all of the fields should now be identified by type, so return a set of
        // the field mappings
View Full Code Here

Examples of org.hibernate.metamodel.source.annotations.attribute.AttributeOverride

        classInfo,
        JPADotNames.ATTRIBUTE_OVERRIDE
    );
    if ( attributeOverrideAnnotation != null ) {
      String prefix = createPathPrefix( attributeOverrideAnnotation.target() );
      AttributeOverride override = new AttributeOverride( prefix, attributeOverrideAnnotation );
      attributeOverrideList.put( override.getAttributePath(), override );
    }

    AnnotationInstance attributeOverridesAnnotation = JandexHelper.getSingleAnnotation(
        classInfo,
        JPADotNames.ATTRIBUTE_OVERRIDES
    );
    if ( attributeOverridesAnnotation != null ) {
      AnnotationInstance[] annotationInstances = attributeOverridesAnnotation.value().asNestedArray();
      for ( AnnotationInstance annotationInstance : annotationInstances ) {
        String prefix = createPathPrefix( attributeOverridesAnnotation.target() );
        AttributeOverride override = new AttributeOverride( prefix, annotationInstance );
        attributeOverrideList.put( override.getAttributePath(), override );
      }
    }
    return attributeOverrideList;
  }
View Full Code Here

Examples of org.hibernate.metamodel.source.annotations.attribute.AttributeOverride

  @Override
  public Iterable<AttributeSource> attributeSources() {
    List<AttributeSource> attributeList = new ArrayList<AttributeSource>();
    for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
      AttributeOverride attributeOverride = null;
      String tmp = getPath() + PATH_SEPERATOR + attribute.getName();
      if ( attributeOverrides.containsKey( tmp ) ) {
        attributeOverride = attributeOverrides.get( tmp );
      }
      attributeList.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
View Full Code Here

Examples of org.hibernate.metamodel.source.annotations.attribute.AttributeOverride

        classInfo,
        JPADotNames.ATTRIBUTE_OVERRIDE
    );
    if ( attributeOverrideAnnotation != null ) {
      String prefix = createPathPrefix( attributeOverrideAnnotation.target() );
      AttributeOverride override = new AttributeOverride( prefix, attributeOverrideAnnotation );
      attributeOverrideList.put( override.getAttributePath(), override );
    }

    AnnotationInstance attributeOverridesAnnotation = JandexHelper.getSingleAnnotation(
        classInfo,
        JPADotNames.ATTRIBUTE_OVERRIDES
    );
    if ( attributeOverridesAnnotation != null ) {
      AnnotationInstance[] annotationInstances = attributeOverridesAnnotation.value().asNestedArray();
      for ( AnnotationInstance annotationInstance : annotationInstances ) {
        String prefix = createPathPrefix( attributeOverridesAnnotation.target() );
        AttributeOverride override = new AttributeOverride( prefix, annotationInstance );
        attributeOverrideList.put( override.getAttributePath(), override );
      }
    }
    return attributeOverrideList;
  }
View Full Code Here

Examples of org.hibernate.metamodel.source.annotations.attribute.AttributeOverride

  @Override
  public Iterable<AttributeSource> attributeSources() {
    List<AttributeSource> attributeList = new ArrayList<AttributeSource>();
    for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
      AttributeOverride attributeOverride = null;
      String tmp = getPath() + PATH_SEPERATOR + attribute.getName();
      if ( attributeOverrides.containsKey( tmp ) ) {
        attributeOverride = attributeOverrides.get( tmp );
      }
      attributeList.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.