use of jodd.db.oom.tst.BadBoy in project jodd by oblac.
the class DbSqlTemplateTest method testMatch.
@Test
public void testMatch() {
DbSqlBuilder st;
Boy boy = new Boy();
boy.id = 1;
boy.girlId = 3;
st = sql("$T{boy boy} where $M{boy=boy}").use("boy", boy);
assertEquals("BOY boy where (boy.GIRL_ID=:boy.girlId and boy.ID=:boy.id)", st.generateQuery());
Map<String, ParameterValue> map = st.getQueryParameters();
assertEquals(2, map.size());
assertEquals(Integer.valueOf(1), map.get("boy.id").getValue());
assertEquals(Integer.valueOf(3), map.get("boy.girlId").getValue());
boy.id = 4;
boy.girlId = 1;
st = sql("$T{boy b} where $M{b=boy}").use("boy", boy);
assertEquals("BOY b where (b.GIRL_ID=:boy.girlId and b.ID=:boy.id)", st.generateQuery());
map = st.getQueryParameters();
assertEquals(2, map.size());
assertEquals(Integer.valueOf(4), map.get("boy.id").getValue());
assertEquals(Integer.valueOf(1), map.get("boy.girlId").getValue());
BadBoy badBoy = new BadBoy();
st = sql("$T{boy b} where $M{b=boy}").use("boy", badBoy);
assertEquals("BOY b where (1=1)", st.generateQuery());
map = st.getQueryParameters();
assertNull(map);
st = sql("$T{boy b} where $M{b=boy}").use("boy", badBoy);
assertEquals("BOY b where (1=1)", st.generateQuery());
map = st.getQueryParameters();
assertNull(map);
badBoy.ajdi = Integer.valueOf(4);
badBoy.girlId = Integer.valueOf(1);
st = sql("$T{boy b} where $M{b=boy}").use("boy", badBoy);
assertEquals("BOY b where (b.ID=:boy.ajdi and b.GIRL_ID=:boy.girlId)", st.generateQuery());
map = st.getQueryParameters();
assertEquals(2, map.size());
assertEquals(Integer.valueOf(4), map.get("boy.ajdi").getValue());
assertEquals(Integer.valueOf(1), map.get("boy.girlId").getValue());
badBoy.ajdi = null;
st = sql("$T{boy b} where $M{b=boy.*}").use("boy", badBoy);
assertEquals("BOY b where (b.ID=:boy.ajdi and b.GIRL_ID=:boy.girlId and b.NAME=:boy.nejm)", st.generateQuery());
map = st.getQueryParameters();
assertEquals(3, map.size());
assertEquals(Integer.valueOf(1), map.get("boy.girlId").getValue());
}
use of jodd.db.oom.tst.BadBoy in project jodd by oblac.
the class DbSqlTemplateTest method testColumns1.
@Test
public void testColumns1() {
DbSqlBuilder st;
// 1
st = sql("$T{Boy} | $C{Boy.id} | $C{Boy.*}");
assertEquals("BOY | BOY.ID | BOY.GIRL_ID, BOY.ID, BOY.NAME", st.generateQuery());
st = sql("$T{BadBoy} | $C{BadBoy.ajdi} | $C{BadBoy.*} | $C{BadBoy.+}");
assertEquals("BOY | BOY.ID | BOY.ID, BOY.GIRL_ID, BOY.NAME | BOY.ID", st.generateQuery());
// 2
st = sql("$T{b b} | $C{b.id}").use("b", new Boy());
assertEquals("BOY b | b.ID", st.generateQuery());
st = sql("$T{b bb} | $C{bb.id} | $C{bb.*}").use("b", new Boy());
assertEquals("BOY bb | bb.ID | bb.GIRL_ID, bb.ID, bb.NAME", st.generateQuery());
st = sql("$T{b bb} | $C{bb.ajdi} | $C{bb.*} | $C{bb.+}").use("b", new BadBoy());
assertEquals("BOY bb | bb.ID | bb.ID, bb.GIRL_ID, bb.NAME | bb.ID", st.generateQuery());
// 3
st = sql("$T{b b} | $C{b.id}").use("b", Boy.class);
assertEquals("BOY b | b.ID", st.generateQuery());
st = sql("$T{b bb} | $C{bb.id} | $C{bb.*}").use("b", Boy.class);
assertEquals("BOY bb | bb.ID | bb.GIRL_ID, bb.ID, bb.NAME", st.generateQuery());
st = sql("$T{b bb} | $C{bb.ajdi} | $C{bb.*}").use("b", BadBoy.class);
assertEquals("BOY bb | bb.ID | bb.ID, bb.GIRL_ID, bb.NAME", st.generateQuery());
st = sql("$T{b bb} | $C{bb.ajdi} | $C{bb.*} | $C{bb.+}").use("b", BadBoy.class);
assertEquals("BOY bb | bb.ID | bb.ID, bb.GIRL_ID, bb.NAME | bb.ID", st.generateQuery());
}
use of jodd.db.oom.tst.BadBoy 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());
}
use of jodd.db.oom.tst.BadBoy in project jodd by oblac.
the class DbSqlBuilderTest method testUpdateSet.
@Test
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());
}
use of jodd.db.oom.tst.BadBoy in project jodd by oblac.
the class DbSqlBuilderTest method testTable.
@Test
public void testTable() {
DbSqlBuilder s;
// [1]
s = sql().table("Boy");
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("Boy"));
s = sql().table("Boy", null);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("Boy"));
s = sql().table("Boy", "bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
// [2]
s = sql().table("BadBoy");
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("BadBoy"));
s = sql().table("BadBoy", null);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("BadBoy"));
s = sql().table("BadBoy", "bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
// [3]
s = sql().table(Boy.class);
assertEquals("BOY Boy", s.generateQuery());
assertNotNull(s.getTableDescriptor("Boy"));
s = sql().table(Boy.class, null);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("Boy"));
s = sql().table(Boy.class, "bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
// [4]
s = sql().table(BadBoy.class);
assertEquals("BOY BadBoy", s.generateQuery());
assertNotNull(s.getTableDescriptor("BadBoy"));
s = sql().table(BadBoy.class, null);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("BadBoy"));
s = sql().table(BadBoy.class, "bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
// [5]
s = sql().table("bbb").use("bbb", Boy.class);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
s = sql().table("bbb", null).use("bbb", Boy.class);
assertEquals("BOY", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
s = sql().table("bbb", "x").use("bbb", Boy.class);
assertEquals("BOY x", s.generateQuery());
assertNotNull(s.getTableDescriptor("x"));
// [6]
s = sql().table("Boy bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
s = sql().table("BadBoy bbb");
assertEquals("BOY bbb", s.generateQuery());
assertNotNull(s.getTableDescriptor("bbb"));
}
Aggregations