Search in sources :

Example 1 with BadGirl

use of jodd.db.oom.tst.BadGirl in project jodd by oblac.

the class DbEntitySqlTest method testUpdate.

@Test
public void testUpdate() {
    Girl g = new Girl(1, "sanja", "c++");
    DbSqlBuilder b = DbEntitySql.update(g);
    assertEquals("update GIRL Girl_ set ID=:girl.id, NAME=:girl.name, SPECIALITY=:girl.speciality  where (1=1)", b.generateQuery());
    checkGirl(b);
    BadGirl bg = new BadGirl(Integer.valueOf(2), null, ".net");
    b = DbEntitySql.update(bg);
    assertEquals("update GIRL BadGirl_ set ID=:badGirl.fooid, SPECIALITY=:badGirl.foospeciality  where (BadGirl_.ID=:badGirl.fooid)", b.generateQuery());
    checkBadGirl1(b);
    b = DbEntitySql.updateAll(bg);
    assertEquals("update GIRL BadGirl_ set ID=:badGirl.fooid, NAME=:badGirl.fooname, SPECIALITY=:badGirl.foospeciality  where (BadGirl_.ID=:badGirl.fooid)", b.generateQuery());
    checkBadGirl2(b);
}
Also used : BadGirl(jodd.db.oom.tst.BadGirl) BadGirl(jodd.db.oom.tst.BadGirl) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Example 2 with BadGirl

use of jodd.db.oom.tst.BadGirl in project jodd by oblac.

the class DbSqlBuilderTest method testCriteria.

@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());
    // test double call
    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());
}
Also used : BadBoy(jodd.db.oom.tst.BadBoy) BadGirl(jodd.db.oom.tst.BadGirl) DbSqlBuilder(jodd.db.oom.sqlgen.DbSqlBuilder) Test(org.junit.Test)

Example 3 with BadGirl

use of jodd.db.oom.tst.BadGirl in project jodd by oblac.

the class DbEntitySqlTest method testFind.

@Test
public void testFind() {
    Girl g = new Girl(1, "sanja", "c++");
    DbSqlBuilder b = DbEntitySql.find(g);
    assertEquals("select Girl_.ID, Girl_.NAME, Girl_.SPECIALITY from GIRL Girl_ where (Girl_.ID=:girl.id and Girl_.NAME=:girl.name and Girl_.SPECIALITY=:girl.speciality)", b.generateQuery());
    checkGirl(b);
    b = DbEntitySql.findByAll(g);
    assertEquals("select Girl_.ID, Girl_.NAME, Girl_.SPECIALITY from GIRL Girl_ where (Girl_.ID=:girl.id and Girl_.NAME=:girl.name and Girl_.SPECIALITY=:girl.speciality)", b.generateQuery());
    checkGirl(b);
    BadGirl bg = new BadGirl(Integer.valueOf(2), null, ".net");
    b = DbEntitySql.find(bg);
    assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ where (BadGirl_.ID=:badGirl.fooid and BadGirl_.SPECIALITY=:badGirl.foospeciality)", b.generateQuery());
    checkBadGirl1(b);
    b = DbEntitySql.findByAll(bg);
    assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ where (BadGirl_.ID=:badGirl.fooid and BadGirl_.NAME=:badGirl.fooname and BadGirl_.SPECIALITY=:badGirl.foospeciality)", b.generateQuery());
    checkBadGirl2(b);
    b = DbEntitySql.findByColumn(Girl.class, "name", "sanja");
    assertEquals("select Girl_.ID, Girl_.NAME, Girl_.SPECIALITY from GIRL Girl_ where Girl_.NAME=:p0", b.generateQuery());
    checkGirl1(b);
    b = DbEntitySql.findByColumn(BadGirl.class, "fooname", "sanja");
    assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ where BadGirl_.NAME=:p0", b.generateQuery());
    checkGirl1(b);
    b = DbEntitySql.findForeign(BadBoy.class, bg);
    assertEquals("select BadBoy_.ID, BadBoy_.GIRL_ID, BadBoy_.NAME from BOY BadBoy_ where BadBoy_.GIRL_ID=:p0", b.generateQuery());
    checkBadGirl4(b);
    b = DbEntitySql.findById(bg);
    assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ where (BadGirl_.ID=:badGirl.fooid)", b.generateQuery());
    checkBadGirl3(b);
    b = DbEntitySql.findById(bg, 2);
    assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ where BadGirl_.ID=:p0", b.generateQuery());
    checkBadGirl4(b);
}
Also used : BadBoy(jodd.db.oom.tst.BadBoy) BadGirl(jodd.db.oom.tst.BadGirl) BadGirl(jodd.db.oom.tst.BadGirl) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Example 4 with BadGirl

use of jodd.db.oom.tst.BadGirl in project jodd by oblac.

the class DbEntitySqlTest method testCount.

@Test
public void testCount() {
    Girl g = new Girl(1, "sanja", "c++");
    DbSqlBuilder b = DbEntitySql.count(g);
    assertEquals("select count(*) from GIRL Girl_ where (Girl_.ID=:girl.id and Girl_.NAME=:girl.name and Girl_.SPECIALITY=:girl.speciality)", b.generateQuery());
    checkGirl(b);
    BadGirl bg = new BadGirl();
    b = DbEntitySql.count(bg);
    assertEquals("select count(*) from GIRL BadGirl_ where (1=1)", b.generateQuery());
    bg = new BadGirl(Integer.valueOf(2), null, ".net");
    b = DbEntitySql.count(bg);
    assertEquals("select count(*) from GIRL BadGirl_ where (BadGirl_.ID=:badGirl.fooid and BadGirl_.SPECIALITY=:badGirl.foospeciality)", b.generateQuery());
    checkBadGirl1(b);
    b = DbEntitySql.countAll(bg);
    assertEquals("select count(*) from GIRL BadGirl_ where (BadGirl_.ID=:badGirl.fooid and BadGirl_.NAME=:badGirl.fooname and BadGirl_.SPECIALITY=:badGirl.foospeciality)", b.generateQuery());
    checkBadGirl2(b);
    b = DbEntitySql.count(BadGirl.class);
    assertEquals("select count(*) from GIRL BadGirl_", b.generateQuery());
}
Also used : BadGirl(jodd.db.oom.tst.BadGirl) BadGirl(jodd.db.oom.tst.BadGirl) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Example 5 with BadGirl

use of jodd.db.oom.tst.BadGirl in project jodd by oblac.

the class DbEntitySqlTest method testUpdateColumn.

@Test
public void testUpdateColumn() {
    BadGirl bg = new BadGirl(Integer.valueOf(1), "sanja", "c++");
    DbSqlBuilder b = DbEntitySql.updateColumn(bg, "fooname", "Anja");
    assertEquals("update GIRL BadGirl_ set NAME=:p0 where (BadGirl_.ID=:badGirl.fooid)", b.generateQuery());
    Map<String, ParameterValue> params = b.getQueryParameters();
    assertEquals(2, params.entrySet().size());
    assertEquals(Integer.valueOf(1), params.get("badGirl.fooid").getValue());
    assertEquals("Anja", params.get("p0").getValue());
}
Also used : BadGirl(jodd.db.oom.tst.BadGirl) Test(org.junit.Test)

Aggregations

BadGirl (jodd.db.oom.tst.BadGirl)6 Test (org.junit.Test)6 Girl (jodd.db.oom.tst.Girl)4 BadBoy (jodd.db.oom.tst.BadBoy)2 DbSqlBuilder (jodd.db.oom.sqlgen.DbSqlBuilder)1