Examples of PersistenceUnit


Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

                        final Persistence persistence = (Persistence) modules;
                        appModule.getPersistenceModules().add(new PersistenceModule("", persistence));

                    } else if (modules instanceof PersistenceUnit) {

                        final PersistenceUnit unit = (PersistenceUnit) modules;
                        appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));

                    } else if (modules instanceof Beans) {

                        final Beans beans = (Beans) modules;
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

        if (ref.getMappedName() != null && ref.getMappedName().startsWith("jndi:")){
            return null;
        }

        PersistenceUnit unit = persistenceUnits.resolveLink(ref.getPersistenceUnitName(), moduleURI);

        // Explicitly check if we messed up the "if there's only one,
        // that's what you get" rule by adding our "cmp" unit.
        Collection<PersistenceUnit> cmpUnits = persistenceUnits.values("cmp");
        if (unit == null && cmpUnits.size() > 0 && persistenceUnits.values().size() - cmpUnits.size() == 1) {
            // We did, there is exactly one non-cmp unit.  Let's find it.
            for (PersistenceUnit persistenceUnit : persistenceUnits.values()) {
                if (!persistenceUnit.getName().equals("cmp")){
                    // Found it
                    unit = persistenceUnit;
                    break;
                }
            }
        }


        // try again using the ref name
        if (unit == null){
            unit = persistenceUnits.resolveLink(ref.getName(), moduleURI);
        }

        // try again using the ref name with any prefix removed
        if (unit == null){
            String shortName = ref.getName().replaceFirst(".*/", "");
            unit = persistenceUnits.resolveLink(shortName, moduleURI);
        }

        if (unit != null){
            ref.setMappedName(unit.getId());
        } else {

            // ----------------------------------------------
            //  Nothing was found.  Let's try and figure out
            //  what went wrong and log a validation message
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

    private void addGeronimmoOpenEJBPersistenceUnit(EjbModule ejbModule) {
        GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");

        // search for the cmp persistence unit
        PersistenceUnit persistenceUnit = null;
        for (Persistence persistence : geronimoEjbJarType.getPersistence()) {
            for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
                if ("cmp".equals(unit.getName())) {
                    persistenceUnit = unit;
                    break;
                }
            }
        }

        // if not found create one
        if (persistenceUnit == null) {
            String jtaDataSource = null;
            // todo Persistence Unit Data Sources need to be global JNDI names
            Object altDD = ejbModule.getEjbModule().getAltDDs().get("openejb-jar.xml");
            if (altDD instanceof OpenejbJarType) {
                ResourceLocatorType cmpConnectionFactory = ((OpenejbJarType) altDD).getCmpConnectionFactory();
                if (cmpConnectionFactory != null) {
                    String datasourceName = cmpConnectionFactory.getResourceLink();
                    if (datasourceName != null) {
                        jtaDataSource = "?name=" + datasourceName;
                    }
                }
            }

            persistenceUnit = new PersistenceUnit();
            persistenceUnit.setName("cmp");
            persistenceUnit.setTransactionType(TransactionType.JTA);
            if (jtaDataSource != null) {
                persistenceUnit.setJtaDataSource(jtaDataSource);
            } else {
                persistenceUnit.setJtaDataSource("?name=SystemDatasource");
            }
            persistenceUnit.setNonJtaDataSource("?name=NoTxDatasource");

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

            geronimoEjbJarType.getPersistence().add(persistence);
        }
        persistenceUnit.getMappingFile().add("META-INF/openejb-cmp-generated-orm.xml");
    }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

    private void addGeronimmoOpenEJBPersistenceUnit(EjbModule ejbModule) {
        GeronimoEjbJarType geronimoEjbJarType = (GeronimoEjbJarType) ejbModule.getEjbModule().getAltDDs().get("geronimo-openejb.xml");

        // search for the cmp persistence unit
        PersistenceUnit persistenceUnit = null;
        for (Persistence persistence : geronimoEjbJarType.getPersistence()) {
            for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
                if ("cmp".equals(unit.getName())) {
                    persistenceUnit = unit;
                    break;
                }
            }
        }

        // if not found create one
        if (persistenceUnit == null) {
            String jtaDataSource = null;
            // todo Persistence Unit Data Sources need to be global JNDI names
            Object altDD = ejbModule.getEjbModule().getAltDDs().get("openejb-jar.xml");
            if (altDD instanceof OpenejbJarType) {
                ResourceLocatorType cmpConnectionFactory = ((OpenejbJarType) altDD).getCmpConnectionFactory();
                if (cmpConnectionFactory != null) {
                    String datasourceName = cmpConnectionFactory.getResourceLink();
                    if (datasourceName != null) {
                        jtaDataSource = datasourceName.trim();
                    }
                }
            }

            persistenceUnit = new PersistenceUnit();
            persistenceUnit.setName("cmp");
            persistenceUnit.setTransactionType(TransactionType.JTA);
            if (jtaDataSource != null) {
                persistenceUnit.setJtaDataSource(jtaDataSource);
            } else {
                persistenceUnit.setJtaDataSource(defaultCmpJTADataSource);
            }
            persistenceUnit.setNonJtaDataSource(defaultCmpNonJTADataSource);
            persistenceUnit.setExcludeUnlistedClasses(true);

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

            geronimoEjbJarType.getPersistence().add(persistence);
        }
        persistenceUnit.getMappingFile().add("META-INF/openejb-cmp-generated-orm.xml");
    }
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

        assertSame(orangeJta, resources.get(0));
        assertSame(orangeNonJta, resources.get(1));
        assertSame(limeJta, resources.get(2));
        assertSame(limeNonJta, resources.get(3));

        PersistenceUnit unit1 = new PersistenceUnit("orange-unit");
        unit1.setJtaDataSource("Orange");
        unit1.setNonJtaDataSource("OrangeUnmanaged");

        PersistenceUnit unit2 = new PersistenceUnit("lime-unit");
        unit2.setJtaDataSource("Lime");
        unit2.setNonJtaDataSource("LimeUnmanaged");

        AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit1, unit2)));

        // Create app
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

    // --------------------------------------------------------------------------------------------
    //  Convenience methods
    // --------------------------------------------------------------------------------------------

    private PersistenceUnitInfo addPersistenceUnit(String unitName, String jtaDataSource, String nonJtaDataSource) throws OpenEJBException, IOException, NamingException {
        PersistenceUnit unit = new PersistenceUnit(unitName);
        unit.setJtaDataSource(jtaDataSource);
        unit.setNonJtaDataSource(nonJtaDataSource);

        AppModule app = new AppModule(this.getClass().getClassLoader(), unitName + "-app");
        app.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));

        // Create app
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

        // Add the ejb-jar.xml to the ear
        appModule.getEjbModules().add(ejbModule);

        // Create a persistence-unit for this app
        PersistenceUnit unit = new PersistenceUnit("testUnit");
        unit.getClazz().add(Color.class.getName());
        unit.setProperties(new org.apache.openejb.jee.jpa.unit.Properties());
        unit.getProperties().setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");

        // Add the persistence.xml to the "ear"
        appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));

        // Configure and assemble the ear -- aka. deploy it
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

            "serialVersionUID"
    )));

    public AppModule deploy(AppModule appModule) throws OpenEJBException {
        // search for the cmp persistence unit
        PersistenceUnit persistenceUnit = null;
        for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
            Persistence persistence = persistenceModule.getPersistence();
            for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
                if (CMP_PERSISTENCE_UNIT_NAME.equals(unit.getName())) {
                    persistenceUnit = unit;
                    break;
                }

            }
        }

        // 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.unit.PersistenceUnit

                    final Persistence persistence = (Persistence) obj;
                    appModule.getPersistenceModules().add(new PersistenceModule("", persistence));

                } else if (obj instanceof PersistenceUnit) {

                    final PersistenceUnit unit = (PersistenceUnit) obj;
                    appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));

                } else if (obj instanceof Beans) {

                    final Beans beans = (Beans) obj;
View Full Code Here

Examples of org.apache.openejb.jee.jpa.unit.PersistenceUnit

        bean.setLocalBean(new Empty());
        return bean;
    }

    @Module public Persistence persistence() {
        PersistenceUnit unit = new PersistenceUnit("foo-unit");
        unit.addClass(EntityToValidate.class);
        unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
        unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
        unit.setExcludeUnlistedClasses(true);

        Persistence persistence = new Persistence(unit);
        persistence.setVersion("2.0");
        return persistence;
    }
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.