Exemplo n.º 1
0
  @Test
  public void testUpdateWithParameter() throws Exception {
    Map[] friends =
        new Map[] {
          new HashMap<String, Object>() {
            {
              put("name", "Slartibartfast");
            }
          },
          new HashMap<String, Object>() {
            {
              put("name", "Marvin");
            }
          }
        };
    UpdateAnalyzedStatement.NestedAnalyzedStatement analysis =
        analyze(
                "update users set name=?, other_id=?, friends=? where id=?",
                new Object[] {"Jeltz", 0, friends, "9"})
            .nestedStatements()
            .get(0);
    assertThat(analysis.assignments().size(), is(3));
    assertThat(
        analysis
            .assignments()
            .get(new Reference(USER_TABLE_INFO.getReferenceInfo(new ColumnIdent("name")))),
        isLiteral("Jeltz"));
    assertThat(
        analysis
            .assignments()
            .get(new Reference(USER_TABLE_INFO.getReferenceInfo(new ColumnIdent("friends")))),
        isLiteral(friends, new ArrayType(DataTypes.OBJECT)));
    assertThat(
        analysis
            .assignments()
            .get(new Reference(USER_TABLE_INFO.getReferenceInfo(new ColumnIdent("other_id")))),
        isLiteral(0L));

    assertThat(((Function) analysis.whereClause().query()).arguments().get(1), isLiteral(9L));
  }
Exemplo n.º 2
0
  @Test
  public void testUpdateWithEmptyObjectArray() throws Exception {
    UpdateAnalyzedStatement.NestedAnalyzedStatement analysis =
        analyze("update users set friends=? where other_id=0", new Object[] {new Map[0], 0})
            .nestedStatements()
            .get(0);

    Literal friendsLiteral =
        (Literal)
            analysis
                .assignments()
                .get(new Reference(USER_TABLE_INFO.getReferenceInfo(new ColumnIdent("friends"))));
    assertThat(friendsLiteral.valueType().id(), is(ArrayType.ID));
    assertEquals(DataTypes.OBJECT, ((ArrayType) friendsLiteral.valueType()).innerType());
    assertThat(((Object[]) friendsLiteral.value()).length, is(0));
  }