Package com.alibaba.cobar.client.entities

Examples of com.alibaba.cobar.client.entities.Offer


    }

    @SuppressWarnings("unchecked")
    private void verifyOffersOrderBySubject(List lst) {
        for (int i = 0; i < lst.size(); i++) {
            Offer offer = (Offer) lst.get(i);
            if (i == 0 || i == 1) {
                assertEquals(2, offer.getMemberId().longValue());
            } else {
                assertEquals(1, offer.getMemberId().longValue());
            }
            switch (i) {
                case 0:
                    assertEquals("A", offer.getSubject());
                    break;
                case 1:
                    assertEquals("D", offer.getSubject());
                    break;
                case 2:
                    assertEquals("S", offer.getSubject());
                    break;
                case 3:
                    assertEquals("X", offer.getSubject());
                    break;
                case 4:
                    assertEquals("Z", offer.getSubject());
                    break;
                default:
                    throw new IllegalArgumentException("unexpected condition.");
            }
        }
View Full Code Here


    private void batchInsertOffersAsFixture() {
        BatchInsertTask task = new BatchInsertTask();

        List<Offer> offers = new ArrayList<Offer>();
        Offer offer = new Offer();
        offer.setMemberId(1L);
        offer.setSubject("Z");
        offer.setGmtUpdated(new Date());
        offers.add(offer);

        offer = new Offer();
        offer.setMemberId(1L);
        offer.setSubject("X");
        offer.setGmtUpdated(new Date());
        offers.add(offer);

        offer = new Offer();
        offer.setMemberId(1L);
        offer.setSubject("S");
        offer.setGmtUpdated(new Date());
        offers.add(offer);

        offer = new Offer();
        offer.setMemberId(2L);
        offer.setSubject("D");
        offer.setGmtUpdated(new Date());
        offers.add(offer);

        offer = new Offer();
        offer.setMemberId(2L);
        offer.setSubject("A");
        offer.setGmtUpdated(new Date());
        offers.add(offer);

        task.setEntities(offers);

        getSqlMapClientTemplate().insert("com.alibaba.cobar.client.entities.Offer.batchInsert",
View Full Code Here

                "META-INF/spring/datasources-appctx.xml",
                "META-INF/spring/namespace-sqlaction-composed-router-appctx.xml" });
    }

    public void testInsertOnCobarSqlMapClientTemplate() {
        Offer offer = new Offer();
        offer.setGmtUpdated(new Date());
        offer.setMemberId(129L);
        offer.setSubject("some offer");
        Object pk = getSqlMapClientTemplate().insert(OFFER_CREATION_SQL, offer);
        assertNotNull(pk);

        String confirmSQL = "SELECT memberId FROM offers where id=" + pk;
        verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt1m);
        verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
        verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2m);
        verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);

        offer = new Offer();
        offer.setGmtUpdated(new Date());
        offer.setMemberId(130L);
        offer.setSubject("some offer");
        pk = null;
        pk = getSqlMapClientTemplate().insert(OFFER_CREATION_SQL, offer);
        assertNotNull(pk);
       
        confirmSQL = "SELECT memberId FROM offers where id=" + pk;
View Full Code Here

        verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt2m);
        verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);
    }

    public void testInsertOnCobarSqlMapClientTemplateWithoutFoundRule() {
        Offer offer = new Offer();
        offer.setGmtUpdated(new Date());
        offer.setMemberId(128L);
        offer.setSubject("some offer");
        Object pk = getSqlMapClientTemplate().insert(OFFER_CREATION_SQL, offer);
        assertNotNull(pk);

        String confirmSQL = "SELECT memberId FROM offers where id=" + pk;
        verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt1m);
View Full Code Here

    public void testDeleteOnCobarSqlMapClientTemplateNormally() {
        Long[] memberIds = new Long[] { 1L, 129L, 257L, 2L, 130L, 258L, 386L };
        // 1. empty data bases
        String sqlAction = "com.alibaba.cobar.client.entities.Offer.deleteByMemberId";
        for (Long mid : memberIds) {
            Offer offer = new Offer();
            offer.setMemberId(mid);
            int affectedRows = getSqlMapClientTemplate().delete(sqlAction, offer);
            assertEquals(0, affectedRows);
        }
        // 2. insert data fixtures
        batchInsertOffersAsFixtureForLaterUse(memberIds);
        for (int i = 0; i < memberIds.length; i++) {
            String confirmSQL = "select subject from offers where memberId=" + memberIds[i];
            if (i < 3) {
                verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt1m);
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2m);
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);
            } else {
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1m);
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
                verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt2m);
                verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);
            }
        }
        // 3. perform deletion and assertion
        for (Long mid : memberIds) {
            Offer offer = new Offer();
            offer.setMemberId(mid);
            int affectedRows = getSqlMapClientTemplate().delete(sqlAction, offer);
            assertEquals(1, affectedRows);
        }
    }
View Full Code Here

        String selectSqlActionOne = "com.alibaba.cobar.client.entities.Offer.load";
        for (int i = 0; i < memberIds.length; i++) {
            String confirmSQL = "select id from offers where memberId=" + memberIds[i];
            if (i < 3) {
                Long id = jt1m.queryForLong(confirmSQL);
                Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionOne,
                        id);
                assertNotNull(offer);
                assertEquals(memberIds[i], offer.getMemberId());
            } else {
                Long id = jt2m.queryForLong(confirmSQL);
                Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionOne,
                        id);
                assertNull(offer);
            }
        }
        // scenario 2: fallback sharding rules can be found for current sql action, so all requested records are returned normally.
        String selectSqlActionTwo = "com.alibaba.cobar.client.entities.Offer.findByMemberId";
        for (Long mid : memberIds) {
            Offer parameter = new Offer();
            parameter.setMemberId(mid);
            Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo,
                    parameter);
            assertNotNull(offer);
            assertEquals(mid, offer.getMemberId());
        }
    }
View Full Code Here

        String selectSqlActionTwo = "com.alibaba.cobar.client.entities.Offer.findByMemberId";
        String offerSubject = "_SUBEJCT_";
        for (Long mid : memberIds) {
            // 1. assertion before update
            Offer parameter = new Offer();
            parameter.setMemberId(mid);
            Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo,
                    parameter);
            assertNotNull(offer);
            assertEquals("fake offer", offer.getSubject());
            // 2. assertion on update
            offer.setSubject(offerSubject);
            int affectedRows = getSqlMapClientTemplate().update(
                    "com.alibaba.cobar.client.entities.Offer.update", offer);
            assertEquals(1, affectedRows);
            // 3. assertion after update
            offer = null;
            offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo, parameter);
            assertNotNull(offer);
            assertEquals(offerSubject, offer.getSubject());
        }

    }
View Full Code Here

    }

    private Object batchInsertOffersAsFixtureForLaterUse(Long[] memberIds) {
        List<Offer> offers = new ArrayList<Offer>();
        for (Long mid : memberIds) {
            Offer offer = new Offer();
            offer.setGmtUpdated(new Date());
            offer.setMemberId(mid);
            offer.setSubject("fake offer");
            offers.add(offer);
        }

        Object pk = getSqlMapClientTemplate().insert(
                "com.alibaba.cobar.client.entities.Offer.batchInsert", new BatchInsertTask(offers));
View Full Code Here

    }

    private List<Offer> createOffersWithMemberIds(Long[] memberIds) {
        List<Offer> offers = new ArrayList<Offer>();
        for (Long mid : memberIds) {
            Offer offer = new Offer();
            offer.setGmtUpdated(new Date());
            offer.setMemberId(mid);
            offer.setSubject("fake offer");
            offers.add(offer);
        }
        return offers;
    }
View Full Code Here

                .getBean("transactionManager"))).execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {

                try {
                    Offer offer = new Offer();
                    offer.setMemberId(1L);
                    offer.setGmtUpdated(new Date());
                    offer.setSubject("o1");
                    getSqlMapClientTemplate().insert(
                            "com.alibaba.cobar.client.entities.Offer.create", offer);

                    offer = new Offer();
                    offer.setMemberId(2L);
                    offer.setGmtUpdated(new Date());
                    offer.setSubject("o2");
                    getSqlMapClientTemplate().insert(
                            "com.alibaba.cobar.client.entities.Offer.create", offer);

                } finally {
                    status.setRollbackOnly();
                }

            }
        });

        Long[] mids = new Long[] { 1L, 2L };
        for (Long mid : mids) {
            Offer parameter = new Offer();
            parameter.setMemberId(mid);
            assertNull(getSqlMapClientTemplate().queryForObject(selectSqlActionTwo, parameter));
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.cobar.client.entities.Offer

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.