Package org.apache.openejb.jee.jpa.unit

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.
        final 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 (final 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) {
            final String shortName = ref.getName().replaceFirst(".*/", "");
            unit = persistenceUnits.resolveLink(shortName, moduleURI);
        }

        if (unit != null) {
            ref.setPersistenceUnitName(unit.getName());
            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


                    final Persistence persistence = (Persistence) obj;
                    appModule.addPersistenceModule(new PersistenceModule(appModule, implicitRootUrl(), persistence));

                } else if (obj instanceof PersistenceUnit) {

                    final PersistenceUnit unit = (PersistenceUnit) obj;
                    appModule.addPersistenceModule(new PersistenceModule(appModule, implicitRootUrl(), new Persistence(unit)));

                } else if (obj instanceof Beans) {

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

        return bean;
    }

    @Module
    public Persistence persistence() {
        final 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);

        final Persistence persistence = new Persistence(unit);
        persistence.setVersion("2.0");
        return persistence;
    }
View Full Code Here

        return bean;
    }

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

        final Persistence persistence = new Persistence(unit);
        persistence.setVersion("2.0");
        return persistence;
    }
View Full Code Here

        return bean;
    }

    @Module
    public Persistence persistence() {
        final PersistenceUnit unit = new PersistenceUnit("ImportSqlScriptTest");
        unit.addClass(Something.class);
        unit.setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
        unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
        unit.setProperty("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
        unit.setExcludeUnlistedClasses(true);

        final Persistence persistence = new Persistence(unit);
        persistence.setVersion("2.0");
        return persistence;
    }
View Full Code Here

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

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

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

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

        // Create app
View Full Code Here

    public void testFromWebAppIdThirdParty() throws Exception {

        final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
        assertSame(supplied, resources.get(0));

        final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");

        final ClassLoader cl = this.getClass().getClassLoader();
        final AppModule app = new AppModule(cl, "orange-app");
        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
        final WebApp webApp = new WebApp();
View Full Code Here

    public void testFromWebAppIdJta() throws Exception {

        final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", true);
        assertSame(supplied, resources.get(0));

        final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");

        final ClassLoader cl = this.getClass().getClassLoader();
        final AppModule app = new AppModule(cl, "orange-app");
        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
        final WebApp webApp = new WebApp();
View Full Code Here

    public void testFromWebAppIdNonJta() throws Exception {

        final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", false);
        assertSame(supplied, resources.get(0));

        final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");

        final ClassLoader cl = this.getClass().getClassLoader();
        final AppModule app = new AppModule(cl, "orange-app");
        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
        final WebApp webApp = new WebApp();
View Full Code Here

    public void testFromWebAppContextThirdParty() throws Exception {

        final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
        assertSame(supplied, resources.get(0));

        final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");

        final ClassLoader cl = this.getClass().getClassLoader();
        final AppModule app = new AppModule(cl, "orange-app");
        app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
        final WebApp webApp = new WebApp();
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.jpa.unit.PersistenceUnit

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.