Package com.taobao.tdhs.client.statement

Examples of com.taobao.tdhs.client.statement.BatchStatement


    public boolean isValid(int timeout) throws SQLException {
        if (isClosed()) {
            return false;
        }
        TDHSClient client = getClient();
        BatchStatement batchStatement = client.createBatchStatement();
        batchStatement.setTimeOut(timeout);
        try {
            batchStatement.commit();
            return true;
        } catch (TDHSException e) {
            logger.warn("valid failed", e);
            return false;
        }
View Full Code Here


        batchStatement = null;
    }

    public int[] executeBatch() throws SQLException {
        checkclose();
        BatchStatement b = batchStatement;
        reset();

        TDHSResponse[] responses = null;
        try {
            responses = b.commit();
        } catch (TDHSException e) {
            throw new SQLException(e);
        }
        int[] result = new int[responses.length];
        StringBuilder expString = new StringBuilder();
View Full Code Here

        client.query().use(db).from(table).where().greaterEqual("-1").delete();
    }

    @Test
    public void testBatchDone() throws TDHSException {
        BatchStatement batchStatement = client.createBatchStatement();
        batchStatement.insert().use(db).from(table)
                .value("id", "1")
                .value("name", "a")
                .value("level", "1").insert();
        batchStatement.insert().use(db).from(table)
                .value("id", "2")
                .value("name", "b")
                .value("level", "2").insert();
        batchStatement.insert().use(db).from(table)
                .value("id", "3")
                .value("name", "c")
                .value("level", "3").insert();
        TDHSResponse[] responses = batchStatement.commit();
        Assert.assertEquals(3, responses.length);
        for (TDHSResponse r : responses) {
            Assert.assertEquals(TDHSResponseEnum.ClientStatus.OK, r.getStatus());
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testBatchFailed() throws TDHSException {
        BatchStatement batchStatement = client.createBatchStatement();
        batchStatement.insert().use(db).from(table)
                .value("id", "1")
                .value("name", "a")
                .value("level", "1").insert();
        batchStatement.insert().use(db).from(table)
                .value("id", "2")
                .value("name", "b")
                .value("level", "2").insert();
        batchStatement.insert().use(db).from(table)
                .value("id", "1")
                .value("name", "c")
                .value("level", "1").insert();
        TDHSResponse[] responses = batchStatement.commit();
        Assert.assertEquals(3, responses.length);
        Assert.assertEquals(responses[0].getStatus(), TDHSResponseEnum.ClientStatus.SERVER_ERROR);
        Assert.assertEquals(responses[0].getErrorCode(), TDHSResponseEnum.ErrorCode.CLIENT_ERROR_CODE_FAILED_TO_COMMIT);
        Assert.assertEquals(responses[1].getStatus(), TDHSResponseEnum.ClientStatus.SERVER_ERROR);
        Assert.assertEquals(responses[1].getErrorCode(), TDHSResponseEnum.ErrorCode.CLIENT_ERROR_CODE_FAILED_TO_COMMIT);
View Full Code Here

TOP

Related Classes of com.taobao.tdhs.client.statement.BatchStatement

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.