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

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


        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

        AppInfo appInfo = config.configureApplication(app);
        assembler.createApplication(appInfo);
View Full Code Here


        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

        AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");

        Persistence persistence = new Persistence(new org.apache.openejb.jee.jpa.unit.PersistenceUnit("foo-unit"));
        app.getPersistenceModules().add(new PersistenceModule("root", persistence));

        EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
        app.getEjbModules().add(new EjbModule(ejbJar));
View Full Code Here

        PersistenceUnit unit = new PersistenceUnit("router");
        unit.addClass(Person.class);
        unit.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
        unit.setTransactionType(TransactionType.JTA);
        unit.setJtaDataSource("Routed Datasource");
        appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));
        for (int i = 1; i <= 3; i++) {
            PersistenceUnit u = new PersistenceUnit("db" + i);
            u.addClass(Person.class);
            u.getProperties().put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
            u.setTransactionType(TransactionType.JTA);
            u.setJtaDataSource("database" + i);
            appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(u)));
        }

        assembler.createApplication(config.configureApplication(appModule));

        // context
View Full Code Here

    }

    public void addPersistenceModule(final PersistenceModule root) {
        persistenceModules.add(root);

        final Persistence persistence = root.getPersistence();
        for (final PersistenceUnit unit : persistence.getPersistenceUnit()) {
            txTypeByUnit.put(unit.getName(), unit.getTransactionType());
        }
    }
View Full Code Here

        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

    }

    private void buildPersistenceModules(AppModule appModule, AppInfo appInfo) {
        for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
            String rootUrl = persistenceModule.getRootUrl();
            Persistence persistence = persistenceModule.getPersistence();
            for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
                PersistenceUnitInfo info = new PersistenceUnitInfo();
                info.id = persistenceUnit.getName() + " " + rootUrl.hashCode();
                info.name = persistenceUnit.getName();
                info.watchedResources.addAll(persistenceModule.getWatchedResources());
                info.persistenceUnitRootUrl = rootUrl;
View Full Code Here

    private void deploy(PersistenceModule persistenceModule) throws OpenEJBException {
        if (!autoCreateResources) {
            return;
        }

        Persistence persistence = persistenceModule.getPersistence();
        for (PersistenceUnit persistenceUnit : persistence.getPersistenceUnit()) {
            Properties required = new Properties();

            required.put("JtaManaged", "true");
            String jtaDataSourceId = getResourceId(persistenceUnit.getName(), persistenceUnit.getJtaDataSource(), DataSource.class.getName(), null, required);
            if (jtaDataSourceId != null) {
View Full Code Here

        if (!hasCmpEntities(appModule)) return appModule;

        // 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");
View Full Code Here

        URL resource = this.getClass().getClassLoader().getResource("persistence-example.xml");
        InputStream in = resource.openStream();
        java.lang.String expected = readContent(in);

        Persistence element =  (Persistence) unmarshaller.unmarshal(new ByteArrayInputStream(expected.getBytes()));
        unmarshaller.setEventHandler(new TestValidationEventHandler());
        System.out.println("unmarshalled");

        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty("jaxb.formatted.output", true);
View Full Code Here

                moduleName = moduleName.replaceFirst("/?META-INF/persistence.xml$", "/");
                if (moduleName.startsWith("jar:")) moduleName = moduleName.substring("jar:".length());
                if (moduleName.startsWith("file:")) moduleName = moduleName.substring("file:".length());
//                if (moduleName1.endsWith("/")) moduleName1 = moduleName1.substring(0, moduleName1.length() - 1);
                try {
                    Persistence persistence = JaxbPersistenceFactory.getPersistence(persistenceUrl);
                    PersistenceModule persistenceModule = new PersistenceModule(moduleName, persistence);
                    persistenceModule.getWatchedResources().add(moduleName);
                    if ("file".equals(persistenceUrl.getProtocol())) {
                        persistenceModule.getWatchedResources().add(persistenceUrl.getPath());
                    }
View Full Code Here

TOP

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

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.