Package org.apache.openejb.jee.jpa

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


        if (data == null || data instanceof EntityMappings) {
            return;
        } else if (data instanceof URL) {
            final URL url = (URL) data;
            try {
                final EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshalJavaee(EntityMappings.class, IO.read(url));
                ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
            } catch (final SAXException e) {
                throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
            } catch (final JAXBException e) {
                throw new OpenEJBException("Cannot unmarshall the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
View Full Code Here


            in = getClass().getClassLoader().getResourceAsStream(expectedFileName);
            final String expected = readContent(in);

            // Sun doen't really support generated primary keys, so we need to add them by hand here
            final Set<String> generatedPks = new HashSet<String>(Arrays.asList("BasicCmp2", "AOBasicCmp2", "EncCmp2", "Cmp2RmiIiop"));
            final EntityMappings cmpMappings = appModule.getCmpMappings();
            for (final Entity entity : cmpMappings.getEntity()) {
                if (generatedPks.contains(entity.getName())) {
                    entity.getAttributes().getId().get(0).setGeneratedValue(new GeneratedValue(GenerationType.IDENTITY));
                }
            }
            final String actual = toString(cmpMappings);
View Full Code Here

            in = getClass().getClassLoader().getResourceAsStream(expectedFileName);
            String expected = readContent(in);

            // Sun doen't really support generated primary keys, so we need to add them by hand here
            Set<String> generatedPks = new HashSet<String>(Arrays.asList("BasicCmp2", "AOBasicCmp2", "EncCmp2", "Cmp2RmiIiop"));
            EntityMappings cmpMappings = appModule.getCmpMappings();
            for (Entity entity : cmpMappings.getEntity()) {
                if (generatedPks.contains(entity.getName())) {
                    entity.getAttributes().getId().get(0).setGeneratedValue(new GeneratedValue(GenerationType.IDENTITY));
                }
            }
            String actual = toString(cmpMappings);
View Full Code Here

        if (data == null || data instanceof EntityMappings) {
            return;
        } else if (data instanceof URL) {
            URL url = (URL) data;
            try {
                EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshal(EntityMappings.class, url.openStream());
                ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
            } catch (SAXException e) {
                throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
            } catch (JAXBException e) {
                throw new OpenEJBException("Cannot unmarshall the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
View Full Code Here

        }

        // todo scan existing persistence module for all entity mappings and don't generate mappings for them

        // create mappings if no mappings currently exist
        EntityMappings cmpMappings = appModule.getCmpMappings();
        if (cmpMappings == null) {
            cmpMappings = new EntityMappings();
            cmpMappings.setVersion("1.0");
            appModule.setCmpMappings(cmpMappings);
        }

        // we process this one jar-file at a time...each contributing to the
        // app mapping data
        for (final EjbModule ejbModule : appModule.getEjbModules()) {
            final EjbJar ejbJar = ejbModule.getEjbJar();

            // scan for CMP entity beans and merge the data into the collective set
            for (final EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
                if (isCmpEntity(enterpriseBean)) {
                    processEntityBean(ejbModule, cmpMappings, (EntityBean) enterpriseBean);
                }
            }

            // if there are relationships defined in this jar, get a list of the defined
            // entities and process the relationship maps.
            final Relationships relationships = ejbJar.getRelationships();
            if (relationships != null) {

                final Map<String, Entity> entitiesByEjbName = new TreeMap<String, Entity>();
                for (final Entity entity : cmpMappings.getEntity()) {
                    entitiesByEjbName.put(entity.getEjbName(), entity);
                }

                for (final EjbRelation relation : relationships.getEjbRelation()) {
                    processRelationship(entitiesByEjbName, relation);
                }
            }

            // Let's warn the user about any declarations we didn't end up using
            // so there can be no misunderstandings.
            final EntityMappings userMappings = getUserEntityMappings(ejbModule);
            for (final Entity mapping : userMappings.getEntity()) {
                logger.warning("openejb-cmp-orm.xml mapping ignored: module=" + ejbModule.getModuleId() + ":  <entity class=\"" + mapping.getClazz() + "\">");
            }

            for (final MappedSuperclass mapping : userMappings.getMappedSuperclass()) {
                logger.warning("openejb-cmp-orm.xml mapping ignored: module=" + ejbModule.getModuleId() + ":  <mapped-superclass class=\"" + mapping.getClazz() + "\">");
            }

        }
View Full Code Here

        // exactly correct.  i.e. users should be able to write mappings completely
        // ignorant of the fact that we subclass.  The fact that we subclass means
        // these user supplied mappings might need to be adjusted as the jpa orm.xml
        // file is extremely subclass/supperclass aware and mappings specified in it
        // need to be spot on.
        final EntityMappings userMappings = getUserEntityMappings(ejbModule);

        // Look for any existing mapped superclass mappings.  We check the entire inheritance
        // chain of the bean looking for any that have user defined mappings.
        for (Class clazz = ejbClass; clazz != null; clazz = clazz.getSuperclass()) {
View Full Code Here

    private EntityMappings getUserEntityMappings(final EjbModule ejbModule) {
        final Object o = ejbModule.getAltDDs().get("openejb-cmp-orm.xml");
        if (o instanceof EntityMappings) {
            return (EntityMappings) o;
        }
        return new EntityMappings();
    }
View Full Code Here

        if (data == null || data instanceof EntityMappings) {
            return;
        } else if (data instanceof URL) {
            final URL url = (URL) data;
            try {
                final EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshalJavaee(EntityMappings.class, IO.read(url));
                ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
            } catch (final SAXException e) {
                throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
            } catch (final JAXBException e) {
                throw new OpenEJBException("Cannot unmarshall the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
View Full Code Here

        if (data == null || data instanceof EntityMappings) {
            return;
        } else if (data instanceof URL) {
            URL url = (URL) data;
            try {
                EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshal(EntityMappings.class, url.openStream());
                ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entitymappings);
            } catch (SAXException e) {
                throw new OpenEJBException("Cannot parse the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
            } catch (JAXBException e) {
                throw new OpenEJBException("Cannot unmarshall the openejb-cmp-orm.xml file: " + url.toExternalForm(), e);
View Full Code Here

            in = getClass().getClassLoader().getResourceAsStream(expectedFileName);
            String expected = readContent(in);

            // Sun doen't really support generated primary keys, so we need to add them by hand here
            Set<String> generatedPks = new HashSet<String>(Arrays.asList("BasicCmp2", "AOBasicCmp2", "EncCmp2", "Cmp2RmiIiop"));
            EntityMappings cmpMappings = appModule.getCmpMappings();
            for (Entity entity : cmpMappings.getEntity()) {
                if (generatedPks.contains(entity.getName())) {
                    entity.getAttributes().getId().get(0).setGeneratedValue(new GeneratedValue(GenerationType.IDENTITY));
                }
            }
            String actual = toString(cmpMappings);
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.jpa.EntityMappings

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.