Package jodd.db.oom.sqlgen

Examples of jodd.db.oom.sqlgen.DbSqlBuilder


  public void testUpdateSet() {
    Boy b = new Boy();
    b.id = 1;
    b.girlId = 2;

    DbSqlBuilder dbc = sql().set("b", b).table("Boy", "b");
    assertEquals("set GIRL_ID=:boy.girlId, ID=:boy.id BOY b", dbc.generateQuery());
    assertEquals(2, dbc.getQueryParameters().size());

    dbc = sql().set("Boy", b).table("Boy", null);
    assertEquals("set GIRL_ID=:boy.girlId, ID=:boy.id BOY", dbc.generateQuery());
    assertEquals(2, dbc.getQueryParameters().size());


    dbc = sql().setAll("b", b).table("Boy", "b");
    assertEquals("set GIRL_ID=:boy.girlId, ID=:boy.id, NAME=:boy.name BOY b", dbc.generateQuery());
    assertEquals(3, dbc.getQueryParameters().size());

    BadBoy bb = new BadBoy();

    dbc = sql().set("b", bb).table("BadBoy", "b");
    assertEquals("set BOY b", dbc.generateQuery());

    dbc = sql().set("BadBoy", bb).table("BadBoy", null);
    assertEquals("set BOY", dbc.generateQuery());

    dbc = sql().setAll("b", bb).table("BadBoy", "b");
    assertEquals("set ID=:badBoy.ajdi, GIRL_ID=:badBoy.girlId, NAME=:badBoy.nejm BOY b", dbc.generateQuery());
  }
View Full Code Here


    assertEquals("set ID=:badBoy.ajdi, GIRL_ID=:badBoy.girlId, NAME=:badBoy.nejm BOY b", dbc.generateQuery());
  }

  @Test
  public void testStrings() {
    DbSqlBuilder dbc = sql()._("123")._("xxx");
    assertEquals("123xxx", dbc.generateQuery());
  }
View Full Code Here

  public void testWhere() {
    {
      Boy b = new Boy();
      b.id = 1;
      b.girlId = 2;
      DbSqlBuilder dbc = sql().match("Boy", b)._(" ").table(b, null);
      assertEquals("(BOY.GIRL_ID=:boy.girlId and BOY.ID=:boy.id) BOY", dbc.generateQuery());
      dbc = sql().match("b", b)._(" ").table(b, "b");
      assertEquals("(b.GIRL_ID=:boy.girlId and b.ID=:boy.id) BOY b", dbc.generateQuery());
    }
    {
      BadBoy bb = new BadBoy();
      DbSqlBuilder dbc = sql().match("BadBoy", bb).table(bb, null);
      assertEquals("(1=1) BOY", dbc.generateQuery());
      dbc = sql().match("b", bb).table(bb, "b");
      assertEquals("(1=1) BOY b", dbc.generateQuery());
    }
    {
      BadBoy bb = new BadBoy();
      DbSqlBuilder dbc = sql()._("where ").match("BadBoy", bb)._(" ").table(bb, null);
      assertEquals("where (1=1) BOY", dbc.generateQuery());
      dbc = sql()._("where")._().match("b", bb)._(" ").table(bb, "b");
      assertEquals("where (1=1) BOY b", dbc.generateQuery());

      dbc = sql()._("where")._().match("BadBoy", bb).table(bb, null);
      assertEquals("where (1=1) BOY", dbc.generateQuery());
      dbc = sql()._("where ").match("b", bb).table(bb, "b");
      assertEquals("where (1=1) BOY b", dbc.generateQuery());

      bb.ajdi = Integer.valueOf(3);
      dbc = sql()._("where ").match("BadBoy", bb)._(" ").table(bb, null);
      assertEquals("where (BOY.ID=:badBoy.ajdi) BOY", dbc.generateQuery());
      dbc = sql()._("where ").match("b", bb)._(" ").table(bb, "b");
      assertEquals("where (b.ID=:badBoy.ajdi) BOY b", dbc.generateQuery());

      bb.ajdi = null;
      bb.nejm = "";
      dbc = sql()._("where ").match("BadBoy", bb)._(" ").table(bb, null);
      assertEquals("where (1=1) BOY", dbc.generateQuery());
      dbc = sql()._("where ").match("b", bb)._(" ").table(bb, "b");
      assertEquals("where (1=1) BOY b", dbc.generateQuery());

      bb.ajdi = null;
      bb.nejm = "foo";
      dbc = sql()._("where ").match("BadBoy", bb)._(" ").table(bb, null);
      assertEquals("where (BOY.NAME=:badBoy.nejm) BOY", dbc.generateQuery());
      dbc = sql()._("where ").match("b", bb)._(" ").table(bb, "b");
      assertEquals("where (b.NAME=:badBoy.nejm) BOY b", dbc.generateQuery());
    }
  }
View Full Code Here

  @Test
  public void testCriteria() {
    BadBoy bb = new BadBoy();
    BadGirl bg = new BadGirl();

    DbSqlBuilder dbc = sql()._("select").
        columnsAll("bb").columnsIds("bg")._(" from").
        table(bb, "bb").table(bg, "bg")._().
        match("bb", bb)._().match("bg", bg);

    assertEquals("select bb.ID, bb.GIRL_ID, bb.NAME, bg.ID from BOY bb, GIRL bg (1=1) (1=1)", dbc.generateQuery());

    dbc = sql()._("select").
        columnsAll("bb").columnsIds("bg")._(" from").
        table(bb, "bb").table(bg, "bg")._(" where ").
        match("bb", bb)._().match("bg", bg)._(" or ").refId("bb")._("=").value(Long.valueOf(5L));


    assertEquals("select bb.ID, bb.GIRL_ID, bb.NAME, bg.ID from BOY bb, GIRL bg where (1=1) (1=1) or bb.ID=:p0", dbc.generateQuery());

    dbc.reset();
    bb.ajdi = bg.fooid = Integer.valueOf(1);
    assertEquals("select bb.ID, bb.GIRL_ID, bb.NAME, bg.ID from BOY bb, GIRL bg where (bb.ID=:badBoy.ajdi) (bg.ID=:badGirl.fooid) or bb.ID=:p0", dbc.generateQuery());
  }
View Full Code Here

TOP

Related Classes of jodd.db.oom.sqlgen.DbSqlBuilder

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.