Search in sources :

Example 6 with Girl

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);
}
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 7 with Girl

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);
}
Also used : BadBoy(jodd.db.oom.tst.BadBoy) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Example 8 with Girl

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());
}
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 9 with Girl

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());
}
Also used : BadGirl(jodd.db.oom.tst.BadGirl) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Example 10 with Girl

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);
}
Also used : BadGirl(jodd.db.oom.tst.BadGirl) Girl(jodd.db.oom.tst.Girl) Test(org.junit.Test)

Aggregations

Girl (jodd.db.oom.tst.Girl)12 Test (org.junit.Test)12 BadGirl (jodd.db.oom.tst.BadGirl)8 DbSession (jodd.db.DbSession)3 DbThreadSession (jodd.db.DbThreadSession)3 DbSqlBuilder (jodd.db.oom.sqlgen.DbSqlBuilder)2 BadBoy (jodd.db.oom.tst.BadBoy)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DbQuery (jodd.db.DbQuery)1 ParameterValue (jodd.db.oom.sqlgen.ParameterValue)1 Boy2 (jodd.db.oom.tst.Boy2)1 Girl2 (jodd.db.oom.tst.Girl2)1 IdName (jodd.db.oom.tst.IdName)1