Package org.apache.cayenne.access

Examples of org.apache.cayenne.access.DataContext


        }

    }
   
    public void testUpdate() throws Exception {
        final DataContext context = createDataContext();
        final DbEntity entity = context.getEntityResolver().lookupObjEntity(
                SoftTest.class).getDbEntity();
       
        try {
            context.getParentDataDomain().setQueryBuilderFactory(new SoftDeleteQueryBuilderFactory());
           
            final SoftTest test = context.newObject(SoftTest.class);
            test.setName("SoftDeleteBatchQueryBuilderTest");
            context.commitChanges();
           
            final SelectQuery query = new SelectQuery(SoftTest.class);
           
            new ThreadedTestHelper() {
                @Override
                protected void assertResult() throws Exception {
                    query.setQualifier(ExpressionFactory.matchExp("name", test.getName()));
                    assertEquals(1, context.performQuery(query).size());
                   
                    query.andQualifier(ExpressionFactory.matchDbExp("DELETED", true));
                    assertEquals(0, context.performQuery(query).size());
                }
            }.assertWithTimeout(200);
           
            context.deleteObject(test);
            assertEquals(test.getPersistenceState(), PersistenceState.DELETED);
            context.commitChanges();
           
            new ThreadedTestHelper() {
                @Override
                protected void assertResult() throws Exception {
                    query.setQualifier(ExpressionFactory.matchExp("name", test.getName()));
                    assertEquals(0, context.performQuery(query).size());
                   
                    SQLTemplate template = new SQLTemplate(entity, "SELECT * FROM SOFT_TEST");
                    template.setFetchingDataRows(true);
                    assertEquals(1, context.performQuery(template).size());
                }
            }.assertWithTimeout(200);
        }
        finally {
            context.performQuery(new SQLTemplate(entity, "DELETE FROM SOFT_TEST"));
            context.getParentDataDomain().setQueryBuilderFactory(null);
        }
    }
View Full Code Here


     * Load data files into the database
     *
     * @throws IOException if an I/O error occurs
     */
    private void loadDatabase() throws IOException {
        final DataContext dataContext = DataContext.createDataContext();

        // Load users data file
        loadUsers(dataContext);

        // Load customers data file
        loadCustomers(dataContext);

        // Load customers data file
        loadSystemCodes(dataContext);

        // Load post codes data file
        loadPostCodes(dataContext);

        // Load course data file
        loadCourses(dataContext);

        // Load student houses data file
        loadStudentHouses(dataContext);

        dataContext.commitChanges();
    }
View Full Code Here

            this.schedulerService = schedulerService;
        }

        @SuppressWarnings("unchecked")
        public void run() {
            DataContext dataContext = null;
            try {
                dataContext = DataContext.createDataContext();

                SelectQuery query = new SelectQuery(Customer.class);
                List<Customer> list = dataContext.performQuery(query);

                if (list.size() < 60) {
                    dataContext.deleteObjects(list);

                    loadCustomers(dataContext);

                    dataContext.commitChanges();
                }

                loadQuartzJobs(schedulerService);

            } catch (Throwable t) {
                t.printStackTrace();

                if (dataContext != null) {
                    dataContext.rollbackChanges();
                }
            }
        }
View Full Code Here

        Injector injector = DIBootstrap.createInjector(testModule);

        DataContextFactory factory = new DataContextFactory();
        injector.injectMembers(factory);

        DataContext c3 = (DataContext) factory.createContext();
        assertNotNull(c3.getObjectStore().getDataRowCache());
        assertNull(domain.getSharedSnapshotCache());
        assertNotSame(c3.getObjectStore().getDataRowCache(), domain
                .getSharedSnapshotCache());
    }
View Full Code Here

        Injector injector = DIBootstrap.createInjector(testModule);

        DataContextFactory factory = new DataContextFactory();
        injector.injectMembers(factory);

        DataContext c1 = (DataContext) factory.createContext();
        assertTrue(c1.isValidatingObjectsOnCommit());

        domain.setValidatingObjectsOnCommit(false);

        DataContext c2 = (DataContext) factory.createContext();
        assertFalse(c2.isValidatingObjectsOnCommit());
    }
View Full Code Here

        ServerRuntime runtime = new ServerRuntime("Yuis", module);
        assertSame(channel, runtime.getChannel());
    }

    public void testGetObjectContext_CustomModule() {
        final ObjectContext context = new DataContext();
        final ObjectContextFactory factory = new ObjectContextFactory() {

            public ObjectContext createContext(DataChannel parent) {
                return context;
            }
View Full Code Here

             ConfigService configService = ClickUtils.getConfigService(servletContext);
             logger = configService.getLogService();
        }

        // Obtain the users DataContext
        DataContext dataContext = getDataContext((HttpServletRequest) request);

        if (dataContext == null) {
            throw new RuntimeException("DataContext could not be obtained");
        }

        // Bind DataContext to the request thread
        BaseContext.bindThreadObjectContext(dataContext);

        try {
            chain.doFilter(request, response);

        } finally {
            BaseContext.bindThreadObjectContext(null);

            if (logger.isDebugEnabled() && dataContext.hasChanges()) {
                logger.debug("Uncommitted data objects:");

                for (Object uncommitted : dataContext.uncommittedObjects()) {
                    logger.debug("   " + uncommitted);
                }
            }

            if (autoRollback) {
                dataContext.rollbackChanges();
            }
        }
    }
View Full Code Here

    protected DataContext getDataContext(HttpServletRequest request) {

        if (sessionScope) {
            HttpSession session = request.getSession(true);

            DataContext dataContext = (DataContext)
                session.getAttribute(ServletUtil.DATA_CONTEXT_KEY);

            if (dataContext == null) {
                synchronized (session) {
                    dataContext = createDataContext();
View Full Code Here

     *
     * @return the DataContext object
     */
    protected DataContext createDataContext() {

        DataContext dataContext = null;
        if (sharedCache != null) {
            dataContext = dataDomain.createDataContext(sharedCache);

        } else {
            dataContext = dataDomain.createDataContext();
View Full Code Here

        } else if (getOptionList().size() > 1) {
            // Don't load list
            return;
        }

        DataContext dataContext = DataContext.getThreadDataContext();

        List list = Collections.EMPTY_LIST;

        if (getSelectQuery() != null) {
            list = dataContext.performQuery(getSelectQuery());

        } else if (getNamedQuery() != null) {
            list = dataContext.performQuery(getNamedQuery());

        } else if (getQueryName() != null) {
            list = dataContext.performQuery(getQueryName(), getExpireCache());
        }

        if (isRequired() && getOptionList().isEmpty() || isOptional()) {
            getOptionList().add(Option.EMPTY_OPTION);
        }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.access.DataContext

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.