Examples of EntityMappings


Examples of net.sourceforge.jpaxjc.ns.persistence.orm.EntityMappings

        this.log( Level.INFO, "title" );

        try
        {
            final EntityMappings orm = new EntityMappings();
            orm.setVersion( ORM_VERSION );

            this.mappedClasses.clear();

            for ( ClassOutline c : model.getClasses() )
            {
                this.toMappedSuperclass( model, c, orm );
            }
            for ( ClassOutline c : model.getClasses() )
            {
                this.toEmbeddable( c, orm );
            }
            for ( ClassOutline c : model.getClasses() )
            {
                this.toEntity( model, c, orm );
            }

            this.customizeOrm( model.getModel().getCustomizations(), orm );
            for ( PackageOutline p : model.getAllPackageContexts() )
            {
                this.generateAdapterMethods( model.getCodeModel(), p );
            }

            for ( Entity e : orm.getEntity() )
            {
                if ( e.getAttributes() == null )
                {
                    e.setAttributes( new Attributes() );
                }

                this.addMandatoryAttributes( orm, e.getAttributes(), this.getClassOutline( model, e.getClazz() ) );
            }

            final Persistence p = new Persistence();
            final Persistence.PersistenceUnit u = new Persistence.PersistenceUnit();
            u.setName( this.persistenceUnitName );
            p.setVersion( PERSISTENCE_VERSION );
            p.getPersistenceUnit().add( u );

            this.customizePersistenceUnit( model.getModel().getCustomizations(), u );

            for ( Entity e : orm.getEntity() )
            {
                if ( !u.getClazz().contains( e.getClazz() ) )
                {
                    u.getClazz().add( e.getClazz() );
                }
            }
            for ( Embeddable e : orm.getEmbeddable() )
            {
                if ( !u.getClazz().contains( e.getClazz() ) )
                {
                    u.getClazz().add( e.getClazz() );
                }
            }
            for ( MappedSuperclass m : orm.getMappedSuperclass() )
            {
                if ( !u.getClazz().contains( m.getClazz() ) )
                {
                    u.getClazz().add( m.getClazz() );
                }
            }

            this.annotate( model, orm );
            orm.getEmbeddable().clear();
            orm.getEntity().clear();
            orm.getMappedSuperclass().clear();

            final SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
            final Schema persistenceSchema =
                schemaFactory.newSchema( this.getClass().getResource( PERSISTENCE_SCHEMA_CLASSPATH_LOCATION ) );

            final Schema ormSchema =
                schemaFactory.newSchema( this.getClass().getResource( ORM_SCHEMA_CLASSPATH_LOCATION ) );

            final JAXBContext persistenceCtx = JAXBContext.newInstance( "net.sourceforge.jpaxjc.ns.persistence" );
            final JAXBContext ormCtx = JAXBContext.newInstance( "net.sourceforge.jpaxjc.ns.persistence.orm" );
            final Marshaller persistenceMarshaller = persistenceCtx.createMarshaller();
            final Marshaller ormMarshaller = ormCtx.createMarshaller();
            persistenceMarshaller.setSchema( persistenceSchema );
            persistenceMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
            persistenceMarshaller.setProperty( Marshaller.JAXB_SCHEMA_LOCATION,
                                               PERSISTENCE_NS + ' ' + this.persistenceSystemId );

            ormMarshaller.setSchema( ormSchema );
            ormMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
            ormMarshaller.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, ORM_NS + ' ' + this.ormSystemId );

            final File metaInf = new File( this.persistenceUnitRoot, "META-INF" );
            if ( !metaInf.exists() )
            {
                success = metaInf.mkdirs();
            }

            if ( orm.getAccess() != null
                 || orm.getCatalog() != null
                 || orm.getDescription() != null
                 || !orm.getNamedNativeQuery().isEmpty()
                 || !orm.getNamedQuery().isEmpty()
                 || orm.getPackage() != null
                 || orm.getPersistenceUnitMetadata() != null
                 || orm.getSchema() != null
                 || !orm.getSequenceGenerator().isEmpty()
                 || !orm.getSqlResultSetMapping().isEmpty()
                 || !orm.getTableGenerator().isEmpty()
                 || !orm.getEmbeddable().isEmpty()
                 || !orm.getEntity().isEmpty()
                 || !orm.getMappedSuperclass().isEmpty() )
            {
                final File ormFile = new File( metaInf, this.persistenceUnitName + ".xml" );
                this.log( Level.INFO, "writing", ormFile.getAbsolutePath() );

                ormMarshaller.marshal( orm, ormFile );
View Full Code Here

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

            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

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.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

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, IO.read(url));
                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

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.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

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

            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

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

        }

        // 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

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

    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

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

            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

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
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.