@Test public void updateQueries() { TestQueryBuilderImpl queryBuilder = new TestQueryBuilderImpl(); queryBuilder.update("table_name").set(r -> r.put("int_column", 2).put("boolean_column", true).build()).all(); assertEquals("UPDATE table_name SET int_column = ?, boolean_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 2, true }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(r -> r.put("int_column", 2).put("boolean_column", true).build()).limit(1); assertEquals("UPDATE table_name SET int_column = ?, boolean_column = ? LIMIT 1", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 2, true }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(r -> r.put("boolean_column", true).put("int_column", 2).build()).all(); assertEquals("UPDATE table_name SET boolean_column = ?, int_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { true, 2 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(r -> r.put("boolean_column", true).put("null_column", null).build()).all(); assertEquals("UPDATE table_name SET boolean_column = ?, null_column = NULL", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { true }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 2, "boolean_column", true)).all(); assertEquals("UPDATE table_name SET int_column = ?, boolean_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 2, true }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); HashMap<String, Object> values = new LinkedHashMap<>(); values.put("int_column", 2); values.put("boolean_column", null); queryBuilder.update("table_name").set(values).all(); assertEquals("UPDATE table_name SET int_column = ?, boolean_column = NULL", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 2 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.eq("int_column", 2)).all(); assertEquals("UPDATE table_name SET int_column = ? WHERE int_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, 2 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.eq("int_column", 2)).limit(1); assertEquals("UPDATE table_name SET int_column = ? WHERE int_column = ? LIMIT 1", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, 2 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.in("int_column", Arrays.asList(2, 3))).all(); assertEquals("UPDATE table_name SET int_column = ? WHERE int_column IN (?,?)", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, 2, 3 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.in("int_column", Collections.singletonList(2))).all(); assertEquals("UPDATE table_name SET int_column = ? WHERE int_column IN (?)", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, 2 }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.eq("boolean_column", true)).all(); assertEquals("UPDATE table_name SET int_column = ? WHERE boolean_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, true }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); queryBuilder.update("table_name").set(ImmutableMap.of("int_column", 1)).where(c -> c.eq("string_column", "value")).all(); assertEquals("UPDATE table_name SET int_column = ? WHERE string_column = ?", queryBuilder.getLastQuery()); assertArrayEquals(new Object[] { 1, "value" }, queryBuilder.getLastParameters()); assertTrue(queryBuilder.getLastWasUpdate()); }
protected abstract UpdateQueryExecution update(String query, Object... parameters);
QueryBuilderImpl implements QueryBuilder { protected abstract UpdateQueryExecution update(String query, Object... parameters); }
QueryBuilderImpl implements QueryBuilder { protected abstract UpdateQueryExecution update(String query, Object... parameters);  }
QueryBuilderImpl implements QueryBuilder { protected abstract UpdateQueryExecution update(String query, Object... parameters);  @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFrom(
            String table); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFrom(
            Outline<?> outline); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFromNamed(
            String table); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFromNamed(
            Outline<?> outline); @Override InsertBuilder insertInto(String table); @Override InsertBuilder insertInto(Outline<?> outline); @Override SelectBuilder select(String column); @Override SelectBuilder select(Member member); @Override SelectBuilder select(String... columns); @Override SelectBuilder select(Member... members); @Override SelectBuilder select(Iterable<String> columns); @Override SelectBuilder selectQualified(String table, String column); @Override SelectBuilder selectQualified(String table, String... columns); @Override SelectBuilder selectQualified(String table, Iterable<String> columns); @Override SelectBuilder selectAll(); @Override SelectBuilder selectAllIn(Outline<?> outline); @Override UpdateBuilder update(String table); @Override UpdateBuilder update(Outline<?> outline); }
QueryBuilderImpl implements QueryBuilder { protected abstract UpdateQueryExecution update(String query, Object... parameters);  @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFrom(
            String table); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFrom(
            Outline<?> outline); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFromNamed(
            String table); @Override WhereBuilder<UpdateQueryExecution, ? extends LimitBuilder<? extends UpdateQueryExecution>> deleteFromNamed(
            Outline<?> outline); @Override InsertBuilder insertInto(String table); @Override InsertBuilder insertInto(Outline<?> outline); @Override SelectBuilder select(String column); @Override SelectBuilder select(Member member); @Override SelectBuilder select(String... columns); @Override SelectBuilder select(Member... members); @Override SelectBuilder select(Iterable<String> columns); @Override SelectBuilder selectQualified(String table, String column); @Override SelectBuilder selectQualified(String table, String... columns); @Override SelectBuilder selectQualified(String table, Iterable<String> columns); @Override SelectBuilder selectAll(); @Override SelectBuilder selectAllIn(Outline<?> outline); @Override UpdateBuilder update(String table); @Override UpdateBuilder update(Outline<?> outline);  }