Package org.apache.oozie.util.db

Examples of org.apache.oozie.util.db.SqlStatement$Between


    }

    private void _testInsertAndGetCountAndprepare() throws SQLException {
        int i;
        List<Map<Object, Object>> maps = new ArrayList<Map<Object, Object>>();
        SqlStatement insert = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                         true);
        SqlStatement update = update(TEST_TABLE).set(TEST_BOOLEAN, false).where(
                and(isEqual(TEST_LONG, "1"), isEqual(TEST_STRING, "2")));
        PreparedStatement pUpdate = update.prepare(conn);
        PreparedStatement pInsert = insert.prepare(conn);
        for (i = 0; i < 4; i++) {
            Map<Object, Object> values = new HashMap<Object, Object>();
            values.put("1", i);
            values.put("2", names[i]);
            insert.getNewStatementWithValues(values).prepare(pInsert).execute();
            maps.add(values);
        }

        ResultSet rs = getCount(TEST_TABLE).prepareAndSetValues(conn).executeQuery();
        rs.next();
        int cnt = myGetCount(TEST_TABLE);
        assertEquals(4, cnt);
        assertEquals(rs.getInt(1), cnt);

        ResultSetReader rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, true)).orderBy(
                TEST_LONG, true).prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        update.prepareForBatch(conn, maps, pUpdate).executeBatch();
        rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, false)).orderBy(TEST_LONG, true)
                .prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        currTime = new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis());
        SqlStatement stmt = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                       "3").value(TEST_TIMESTAMP, "4").value(TEST_BLOB, "5");
        Map<Object, Object> values = new HashMap<Object, Object>();
        values.put("1", i);
        values.put("2", names[i]);
        values.put("3", true);
        values.put("4", currTime);
        values.put("5", names[i].getBytes());
        PreparedStatement pstmt = stmt.prepare(conn);
        stmt.getNewStatementWithValues(values).prepare(pstmt).executeUpdate();
        assertEquals(5, myGetCount(TEST_TABLE));
    }
View Full Code Here


    }

    private void _testInsertAndGetCountAndprepare() throws SQLException {
        int i;
        List<Map<Object, Object>> maps = new ArrayList<Map<Object, Object>>();
        SqlStatement insert = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                         true);
        SqlStatement update = update(TEST_TABLE).set(TEST_BOOLEAN, false).where(
                and(isEqual(TEST_LONG, "1"), isEqual(TEST_STRING, "2")));
        PreparedStatement pUpdate = update.prepare(conn);
        PreparedStatement pInsert = insert.prepare(conn);
        for (i = 0; i < 4; i++) {
            Map<Object, Object> values = new HashMap<Object, Object>();
            values.put("1", i);
            values.put("2", names[i]);
            insert.getNewStatementWithValues(values).prepare(pInsert).execute();
            maps.add(values);
        }

        ResultSet rs = getCount(TEST_TABLE).prepareAndSetValues(conn).executeQuery();
        rs.next();
        int cnt = myGetCount(TEST_TABLE);
        assertEquals(4, cnt);
        assertEquals(rs.getInt(1), cnt);

        ResultSetReader rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, true)).orderBy(
                TEST_LONG, true).prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        update.prepareForBatch(conn, maps, pUpdate).executeBatch();
        rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, false)).orderBy(TEST_LONG, true)
                .prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        currTime = new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis());
        SqlStatement stmt = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                       "3").value(TEST_TIMESTAMP, "4").value(TEST_BLOB, "5");
        Map<Object, Object> values = new HashMap<Object, Object>();
        values.put("1", i);
        values.put("2", names[i]);
        values.put("3", true);
        values.put("4", currTime);
        values.put("5", names[i].getBytes());
        PreparedStatement pstmt = stmt.prepare(conn);
        stmt.getNewStatementWithValues(values).prepare(pstmt).executeUpdate();
        assertEquals(5, myGetCount(TEST_TABLE));
    }
View Full Code Here

    }

    private void _testInsertAndGetCountAndprepare() throws SQLException {
        int i;
        List<Map<Object, Object>> maps = new ArrayList<Map<Object, Object>>();
        SqlStatement insert = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                         true);
        SqlStatement update = update(TEST_TABLE).set(TEST_BOOLEAN, false).where(
                and(isEqual(TEST_LONG, "1"), isEqual(TEST_STRING, "2")));
        PreparedStatement pUpdate = update.prepare(conn);
        PreparedStatement pInsert = insert.prepare(conn);
        for (i = 0; i < 4; i++) {
            Map<Object, Object> values = new HashMap<Object, Object>();
            values.put("1", i);
            values.put("2", names[i]);
            insert.getNewStatementWithValues(values).prepare(pInsert).execute();
            maps.add(values);
        }

        ResultSet rs = getCount(TEST_TABLE).prepareAndSetValues(conn).executeQuery();
        rs.next();
        int cnt = myGetCount(TEST_TABLE);
        assertEquals(4, cnt);
        assertEquals(rs.getInt(1), cnt);

        ResultSetReader rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, true)).orderBy(
                TEST_LONG, true).prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        update.prepareForBatch(conn, maps, pUpdate).executeBatch();
        rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, false)).orderBy(TEST_LONG, true)
                .prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        currTime = new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis());
        SqlStatement stmt = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                       "3").value(TEST_TIMESTAMP, "4").value(TEST_BLOB, "5");
        Map<Object, Object> values = new HashMap<Object, Object>();
        values.put("1", i);
        values.put("2", names[i]);
        values.put("3", true);
        values.put("4", currTime);
        values.put("5", names[i].getBytes());
        PreparedStatement pstmt = stmt.prepare(conn);
        stmt.getNewStatementWithValues(values).prepare(pstmt).executeUpdate();
        assertEquals(5, myGetCount(TEST_TABLE));
    }
View Full Code Here

    }

    private void _testInsertAndGetCountAndprepare() throws SQLException {
        int i;
        List<Map<Object, Object>> maps = new ArrayList<Map<Object, Object>>();
        SqlStatement insert = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                         true);
        SqlStatement update = update(TEST_TABLE).set(TEST_BOOLEAN, false).where(
                and(isEqual(TEST_LONG, "1"), isEqual(TEST_STRING, "2")));
        PreparedStatement pUpdate = update.prepare(conn);
        PreparedStatement pInsert = insert.prepare(conn);
        for (i = 0; i < 4; i++) {
            Map<Object, Object> values = new HashMap<Object, Object>();
            values.put("1", i);
            values.put("2", names[i]);
            insert.getNewStatementWithValues(values).prepare(pInsert).execute();
            maps.add(values);
        }

        ResultSet rs = getCount(TEST_TABLE).prepareAndSetValues(conn).executeQuery();
        rs.next();
        int cnt = myGetCount(TEST_TABLE);
        assertEquals(4, cnt);
        assertEquals(rs.getInt(1), cnt);

        ResultSetReader rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, true)).orderBy(
                TEST_LONG, true).prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        update.prepareForBatch(conn, maps, pUpdate).executeBatch();
        rsReader = parse(selectAllFrom(TEST_TABLE).where(isEqual(TEST_BOOLEAN, false)).orderBy(TEST_LONG, true)
                .prepareAndSetValues(conn).executeQuery());
        assertEquals(4, checkIdAndName(rsReader));

        currTime = new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis());
        SqlStatement stmt = insertInto(TEST_TABLE).value(TEST_LONG, "1").value(TEST_STRING, "2").value(TEST_BOOLEAN,
                                                                                                       "3").value(TEST_TIMESTAMP, "4").value(TEST_BLOB, "5");
        Map<Object, Object> values = new HashMap<Object, Object>();
        values.put("1", i);
        values.put("2", names[i]);
        values.put("3", true);
        values.put("4", currTime);
        values.put("5", names[i].getBytes());
        PreparedStatement pstmt = stmt.prepare(conn);
        stmt.getNewStatementWithValues(values).prepare(pstmt).executeUpdate();
        assertEquals(5, myGetCount(TEST_TABLE));
    }
View Full Code Here

TOP

Related Classes of org.apache.oozie.util.db.SqlStatement$Between

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.