Package org.apache.oozie.util.db

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


     *     required parameter
     * @param targetHref
     *     required parameter
     */
    public Update createAndSetUpdate(final String targetHref, final List<Object> createOrDeleteOrChange) {
        Update newValue = new Update(targetHref, createOrDeleteOrChange);
        this.setUpdate(newValue);
        return newValue;
    }
View Full Code Here


     *     required parameter
     * @param targetHref
     *     required parameter
     */
    public Update createAndSetUpdate(final String targetHref, final List<Object> createOrDeleteOrChange) {
        Update newValue = new Update(targetHref, createOrDeleteOrChange);
        this.setUpdate(newValue);
        return newValue;
    }
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

    }

    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

        return q.first();
    }

    private Object handleDML(String s, Method method, Object[] args)
    {
        Update u = handle.createStatement(s);
        if (args != null) bindArguments(method.isAnnotationPresent(BindBy.class) ?
                                        method.getAnnotation(BindBy.class).value() :
                                        BindType.Position, u, args);
        Class rt = method.getReturnType();
        int changed = u.execute();
        if (method.getReturnType() == null)
        {
            return null;
        }
        else if (Integer.class.equals(rt) || int.class.equals(rt))
View Full Code Here

TOP

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

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.