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) {
            URL url = (URL) data;
            try {
                EntityMappings entitymappings = (EntityMappings) JaxbJavaee.unmarshalJavaee(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

    return result;
  }

  @SuppressWarnings("unchecked") //$NON-NLS-1$
  public void convert(AppModule appModule) {
    EntityMappings entityMappings = appModule.getCmpMappings();
    List<EntityBean> entityBeans = getEntityBeans(appModule);

    addRelationshipAnnotations(appModule);
   
    for (EntityBean entityBean : entityBeans) {
View Full Code Here

    super();
    this.facade = facade;
  }

  public void convert(AppModule module) {
    EntityMappings cmpMappings = module.getCmpMappings();

    List<EjbModule> ejbModules = module.getEjbModules();
    for (EjbModule ejbModule : ejbModules) {
      EjbJar ejbJar = ejbModule.getEjbJar();
      EnterpriseBean[] enterpriseBeans = ejbJar.getEnterpriseBeans();
View Full Code Here

  @SuppressWarnings("unchecked") //$NON-NLS-1$
  public boolean convert(InputSource ejbJarSrc, InputSource openEjbJarSrc) throws ConversionException {
    AppModule appModule = getAppModule(ejbJarSrc, openEjbJarSrc);

    if (appModule.getCmpMappings() == null) {
      appModule.setCmpMappings(new EntityMappings());
    }
   
    for (Converter converter : converters) {
      converter.convert(appModule);
    }
View Full Code Here

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


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

        for (EjbModule ejbModule : appModule.getEjbModules()) {
            generateEntityMappings(ejbModule, cmpMappings);
        }

        if (!cmpMappings.getEntity().isEmpty()) {
            // if not found create one
            if (persistenceUnit == null) {
                persistenceUnit = new PersistenceUnit();
                persistenceUnit.setName(CMP_PERSISTENCE_UNIT_NAME);
                persistenceUnit.setTransactionType(TransactionType.JTA);
                persistenceUnit.setJtaDataSource("java:openejb/Resource/Default JDBC Database");
                persistenceUnit.setNonJtaDataSource("java:openejb/Resource/Default Unmanaged JDBC Database");
                // todo paramterize this
                Properties properties = new Properties();
                properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)");
                // properties.setProperty("openjpa.DataCache", "false");
                // properties.setProperty("openjpa.Log", "DefaultLevel=TRACE");
                persistenceUnit.setProperties(properties);

                Persistence persistence = new Persistence();
                persistence.setVersion("1.0");
                persistence.getPersistenceUnit().add(persistenceUnit);

                PersistenceModule persistenceModule = new PersistenceModule(appModule.getModuleId(), persistence);
                appModule.getPersistenceModules().add(persistenceModule);
            }
            persistenceUnit.getMappingFile().add("META-INF/openejb-cmp-generated-orm.xml");
            for (Entity entity : cmpMappings.getEntity()) {
                persistenceUnit.getClazz().add(entity.getClazz());
            }
        }

        return appModule;
View Full Code Here

    public EntityMappings generateEntityMappings(EjbModule ejbModule) throws OpenEJBException {
        AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
        appModule.getEjbModules().add(ejbModule);

        EntityMappings entityMappings = new EntityMappings();
        generateEntityMappings(ejbModule, entityMappings);
        return entityMappings;
    }
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

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.