Examples of PersistenceSession


Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

        servicesInjector.setContainer(container);
        servicesInjector.setServices(serviceList);
        persistenceSessionFactory.getSpecificationLoader().injectInto(runtimeContext);

        PersistenceSession persistenceSession = createPersistenceSession(persistenceSessionFactory, adapterManager, adapterFactory, objectFactory, oidGenerator, servicesInjector);

        if (getConfiguration().getBoolean(LOGGING_PROPERTY, false)) {
            final String level = getConfiguration().getString(LOGGING_PROPERTY + ".level", "debug");
            persistenceSession = new PersistenceSessionLogger(persistenceSession, level);
        }
View Full Code Here

Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

            LOG.info("error " + errorRef);
            LOG.debug(e.getMessage(), e);

            prepareErrorDetails(e, context, errorRef, servletPath);

            final PersistenceSession checkSession = IsisContext.getPersistenceSession();
            final IsisTransactionManager transactionManager = checkSession.getTransactionManager();
            if (transactionManager.getTransaction() != null && transactionManager.getTransaction().getState().canAbort()) {
                transactionManager.abortTransaction();
                transactionManager.startTransaction();
            }
View Full Code Here

Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

        userProfileLoader.shutdown();
    }

    @Override
    public IsisSession openSession(final AuthenticationSession authenticationSession) {
        final PersistenceSession persistenceSession = persistenceSessionFactory.createPersistenceSession();
        ensureThatArg(persistenceSession, is(not(nullValue())));

        final UserProfile userProfile = userProfileLoader.getProfile(authenticationSession);
        ensureThatArg(userProfile, is(not(nullValue())));
View Full Code Here

Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

        servicesInjector.setContainer(container);
        servicesInjector.setServices(serviceList);
        persistenceSessionFactory.getSpecificationLoader().injectInto(runtimeContext);

        PersistenceSession persistenceSession =
            createPersistenceSession(persistenceSessionFactory, adapterManager, adapterFactory, objectFactory,
                oidGenerator, servicesInjector);

        if (getConfiguration().getBoolean(LOGGING_PROPERTY, false)) {
            final String level = getConfiguration().getString(LOGGING_PROPERTY + ".level", "debug");
View Full Code Here

Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

        return persistedObjects;
    }

    @Override
    public PersistenceSession createPersistenceSession() {
        final PersistenceSession persistenceSession = super.createPersistenceSession();
        if (persistedObjects != null) {
            final OidGenerator oidGenerator = persistenceSession.getOidGenerator();
            if (oidGenerator instanceof SimpleOidGenerator) {
                final SimpleOidGenerator simpleOidGenerator = (SimpleOidGenerator) oidGenerator;
                simpleOidGenerator.resetTo(persistedObjects.getOidGeneratorMemento());
            }
        }
View Full Code Here

Examples of org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession

            LOG.info("error " + errorRef);
            LOG.debug(e.getMessage(), e);

            prepareErrorDetails(e, context, errorRef, servletPath);

            final PersistenceSession checkSession = IsisContext.getPersistenceSession();
            final IsisTransactionManager transactionManager = checkSession.getTransactionManager();
            if (transactionManager.getTransaction() != null
                && transactionManager.getTransaction().getState().canAbort()) {
                transactionManager.abortTransaction();
                transactionManager.startTransaction();
            }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

            System.out.println("Wait until all schema objects are available...");
            System.out.println();
            persistenceManager.refreshSchema(); // This is necessary until schema changes are propagated from the Java Driver to Caffinitas Mappe automatically!
            schemaGenerator.forSchemaObjectsAvailable().awaitUninterruptibly();

            PersistenceSession session = persistenceManager.createSession();
            try
            {

                // create a user object and persist it

                UserEntity snazy = new UserEntity();
                snazy.setUsername("snazy");
                AddressType mainAddress = new AddressType(null, null, "Koeln", "Germany");
                snazy.setMainAddress(mainAddress);
                snazy.getOtherAddresses().put(AddressKind.HOME, mainAddress);
                session.insert(snazy);

                // now load the user object

                UserEntity loaded = session.loadOne(UserEntity.class, "snazy");
                System.out.printf("got user record for %s %n", loaded.getUsername());

                //
                //
                //

                // Setup a project...

                ProjectEntity project = new ProjectEntity();
                project.setId(UUID.randomUUID());
                project.setName("caffinitas");
                project.setLicense(License.APACHE_V2);
                project.getAuthors().add("snazy");
                project.getContributors().add("snazy");
                project.setProjectURL(new URL("http://caffinitas.org/"));

                AggregatorModuleEntity parentModule = new AggregatorModuleEntity();
                parentModule.setProjectId(project.getId());
                parentModule.setName("caffinitas-parent");

                CodeModuleEntity moduleCore = new CodeModuleEntity();
                moduleCore.setProjectId(project.getId());
                moduleCore.setName("caffinitas-core");
                moduleCore.setLanguage(Language.JAVA);

                CodeModuleEntity moduleDemo = new CodeModuleEntity();
                moduleDemo.setProjectId(project.getId());
                moduleDemo.setName("caffinitas-demo");
                moduleDemo.setLanguage(Language.JAVA);

                CodeModuleEntity moduleTest = new CodeModuleEntity();
                moduleTest.setProjectId(project.getId());
                moduleTest.setName("caffinitas-test");
                moduleTest.setLanguage(Language.JAVA);

                parentModule.getModules().add("caffinitas-core");
                parentModule.getModules().add("caffinitas-demo");
                parentModule.getModules().add("caffinitas-test");

                ModifyFuture<ProjectEntity> projectPersistFuture = session.insertAsync(project);
                ModifyFuture<AggregatorModuleEntity> parentModulePersistFuture = session.insertAsync(parentModule);
                ModifyFuture<CodeModuleEntity> moduleCorePersistFuture = session.insertAsync(moduleCore);
                ModifyFuture<CodeModuleEntity> moduleDemoPersistFuture = session.insertAsync(moduleDemo);
                ModifyFuture<CodeModuleEntity> moduleTestPersistFuture = session.insertAsync(moduleTest);

                ListenableFuture<List<Object>> combinedFuture =
                    Futures.allAsList(projectPersistFuture, parentModulePersistFuture,
                        moduleCorePersistFuture, moduleDemoPersistFuture, moduleTestPersistFuture);
                Uninterruptibles.getUninterruptibly(combinedFuture);

                //

                project = session.loadOne(ProjectEntity.class, project.getId());

                // load all modules (since projectId is the partition key in ModuleEntity we can load it with one SELECT)
                List<ModuleEntity> modules = session.loadMultiple(ModuleEntity.class, project.getId());

                for (ModuleEntity module : modules)
                {
                    System.out.println("  " + module.getName());
                }
            }
            finally
            {
                session.close();
            }

        }
        finally
        {
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void tablePerClass_atB_differentConditions() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            Map<Class<? extends TpcInheritB>, String> conditionMap = new HashMap<Class<? extends TpcInheritB>, String>();
            conditionMap.put(TpcInheritB.class, "id = :id3");
            conditionMap.put(TpcInheritB2.class, "id = :id4");
            QueryBinder<TpcInheritB> queryBinder = session.createQueryBinder(TpcInheritB.class, null, null, conditionMap);
            queryBinder.setInt("id1", 41);
            queryBinder.setInt("id2", 42);
            queryBinder.setInt("id3", 43);
            queryBinder.setInt("id4", 44);
            queryBinder.setInt("id5", 45);
            List<TpcInheritB> result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // as named query

            queryBinder = session.createNamedQueryBinder(TpcInheritB.class, null, "byOther");
            queryBinder.setInt("id1", 41);
            queryBinder.setInt("id2", 42);
            queryBinder.setInt("id3", 43);
            queryBinder.setInt("id4", 44);
            queryBinder.setInt("id5", 45);
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // insert data

            TpcBaseEntity inst = new TpcBaseEntity();
            inst.setId(41);
            inst.setVal("one");
            session.insert(inst);
            inst = new TpcInheritA();
            inst.setId(42);
            inst.setVal("two");
            session.insert(inst);
            inst = new TpcInheritB();
            inst.setId(43);
            inst.setVal("three");
            session.insert(inst);
            inst = new TpcInheritB2();
            inst.setId(44);
            inst.setVal("three");
            session.insert(inst);
            inst = new TpcInheritC();
            inst.setId(45);
            inst.setVal("three");
            session.insert(inst);

            // again

            queryBinder = session.createQueryBinder(TpcInheritB.class, null, null, conditionMap);
            queryBinder.setInt("id1", 41);
            queryBinder.setInt("id2", 42);
            queryBinder.setInt("id3", 43);
            queryBinder.setInt("id4", 44);
            queryBinder.setInt("id5", 45);
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 2);

            // as named query

            queryBinder = session.createNamedQueryBinder(TpcInheritB.class, null, "byOther");
            queryBinder.setInt("id1", 41);
            queryBinder.setInt("id2", 42);
            queryBinder.setInt("id3", 43);
            queryBinder.setInt("id4", 44);
            queryBinder.setInt("id5", 45);
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 2);
        } finally {session.close();}
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "createSchema")
    public void singleTable_root() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            QueryBinder<StBaseEntity> queryBinder = session.createQueryBinder(StBaseEntity.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            List<StBaseEntity> result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // as named query

            queryBinder = session.createNamedQueryBinder(StBaseEntity.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // insert data

            StBaseEntity inst = new StBaseEntity();
            inst.setId(11);
            inst.setVal("one");
            session.insert(inst);
            inst.setId(12);
            inst.setVal("two");
            session.insert(inst);
            inst.setId(13);
            inst.setVal("three");
            session.insert(inst);

            // again

            queryBinder = session.createQueryBinder(StBaseEntity.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(11, 12, 13));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);

            // as named query

            queryBinder = session.createNamedQueryBinder(StBaseEntity.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(11, 12, 13));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);
        } finally {session.close();}
    }
View Full Code Here

Examples of org.caffinitas.mapper.core.PersistenceSession

        } finally {session.close();}
    }

    @Test(dependsOnMethods = "singleTable_root")
    public void singleTable_atB() throws Exception {
        PersistenceSession session = persistenceManager.createSession();
        try {
            QueryBinder<StInheritB> queryBinder = session.createQueryBinder(StInheritB.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            List<StInheritB> result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // as named query

            queryBinder = session.createNamedQueryBinder(StInheritB.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(1, 2, 3));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertTrue(result.isEmpty());

            // insert data

            StInheritB inst = new StInheritB();
            inst.setId(21);
            inst.setVal("one");
            session.insert(inst);
            inst.setId(22);
            inst.setVal("two");
            session.insert(inst);
            inst.setId(23);
            inst.setVal("three");
            session.insert(inst);

            // again

            queryBinder = session.createQueryBinder(StInheritB.class, null, "id in :id", null);
            queryBinder.setList("id", Arrays.asList(11, 12, 13, 21, 22, 23));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);

            // as named query

            queryBinder = session.createNamedQueryBinder(StInheritB.class, null, "byIds");
            queryBinder.setList("id", Arrays.asList(11, 12, 13, 21, 22, 23));
            result = session.executeQuery(queryBinder);

            Assert.assertNotNull(result);
            Assert.assertEquals(result.size(), 3);
        } finally {session.close();}
    }
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.