use of jodd.db.oom.tst.Girl 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);
}
use of jodd.db.oom.tst.Girl in project jodd by oblac.
the class JointHintResolverTest method testHints.
@Test
public void testHints() {
Girl girl = new Girl();
BadBoy badBoy = new BadBoy();
Object[] data = new Object[] { girl, badBoy };
JoinHintResolver jhr = new JoinHintResolver();
Object[] result = jhr.join(data, "girl, boy");
assertEquals(2, result.length);
assertTrue(result[0] instanceof Girl);
assertTrue(result[1] instanceof BadBoy);
badBoy = (BadBoy) result[1];
assertNull(badBoy.girl);
jhr = new JoinHintResolver();
result = jhr.join(data, "boy.girl, boy");
assertEquals(1, result.length);
assertTrue(result[0] instanceof BadBoy);
badBoy = (BadBoy) result[0];
assertEquals(girl, badBoy.girl);
girl = new Girl();
badBoy = new BadBoy();
data = new Object[] { girl, badBoy, Integer.valueOf(7) };
jhr = new JoinHintResolver();
result = jhr.join(data, "boy.girl, boy, boy.girlId");
assertEquals(1, result.length);
assertTrue(result[0] instanceof BadBoy);
badBoy = (BadBoy) result[0];
assertEquals(girl, badBoy.girl);
assertEquals(7, badBoy.girlId.intValue());
girl = new Girl();
badBoy = new BadBoy();
data = new Object[] { girl, badBoy, Integer.valueOf(7) };
jhr = new JoinHintResolver();
result = jhr.join(data, "boy.girl, boy, girlId");
assertEquals(2, result.length);
assertTrue(result[0] instanceof BadBoy);
badBoy = (BadBoy) result[0];
assertEquals(girl, badBoy.girl);
assertNull(badBoy.girlId);
assertTrue(result[1] instanceof Integer);
}
use of jodd.db.oom.tst.Girl 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());
}
use of jodd.db.oom.tst.Girl in project jodd by oblac.
the class DbEntitySqlTest method testFrom.
@Test
public void testFrom() {
Girl g = new Girl(1, "sanja", "c++");
assertEquals("select Girl_.ID, Girl_.NAME, Girl_.SPECIALITY from GIRL Girl_ ", DbEntitySql.from(g).generateQuery());
assertEquals("select BadGirl_.ID, BadGirl_.NAME, BadGirl_.SPECIALITY from GIRL BadGirl_ ", DbEntitySql.from(BadGirl.class).generateQuery());
assertEquals("select ggg.ID, ggg.NAME, ggg.SPECIALITY from GIRL ggg ", DbEntitySql.from(BadGirl.class, "ggg").generateQuery());
}
use of jodd.db.oom.tst.Girl in project jodd by oblac.
the class DbEntitySqlTest method testInsert.
@Test
public void testInsert() {
Girl g = new Girl(1, "sanja", "c++");
DbSqlBuilder b = DbEntitySql.insert(g);
assertEquals("insert into GIRL (ID, NAME, SPECIALITY) values (:girl.id, :girl.name, :girl.speciality)", b.generateQuery());
checkGirl(b);
}
Aggregations