Package jodd.db.oom.tst

Examples of jodd.db.oom.tst.Girl


  @Test
  public void testMappingNoTable() {
    DbSession session = new DbThreadSession(cp);

    assertEquals(1, DbEntitySql.insert(new Girl(1, "Anna", "swim")).query().autoClose().executeUpdate());
    assertEquals(0, session.getTotalQueries());

    // one
    DbOomQuery q = new DbOomQuery(DbSqlBuilder.sql("select $C{g.id} + 10, UCASE($C{g.name}) from $T{Girl g}"));
    Object[] row = q.find(Integer.class, String.class);

    assertEquals(Integer.valueOf(11), row[0]);
    assertEquals("ANNA", row[1]);


    // two
    DbSqlBuilder dbSqlBuilder = DbSqlBuilder
        .sql("select $g.id + 10 as $C{Bean1.sum}, UCASE($g.name) as $C{Bean1.bigName}, $C{g.*} from $T{Girl g} where $g.id=1")
        .aliasColumnsAs(ColumnAliasType.COLUMN_CODE);

    assertEquals(
        "select g.ID + 10 as col_0_, UCASE(g.NAME) as col_1_, g.ID as col_2_, g.NAME as col_3_, g.SPECIALITY as col_4_ from GIRL g where g.ID=1",
        dbSqlBuilder.generateQuery());

    dbSqlBuilder.reset();

    assertEquals(
        "select g.ID + 10 as Bean1$SUM, UCASE(g.NAME) as Bean1$BIG_NAME, g.ID, g.NAME, g.SPECIALITY from GIRL g where g.ID=1",
        dbSqlBuilder.generateQuery());

    dbSqlBuilder.reset();

    q = new DbOomQuery(dbSqlBuilder);
    row = q.find(Bean1.class, Girl.class);

    Bean1 bean1 = (Bean1) row[0];
    Girl girl = (Girl) row[1];

    assertNotNull(bean1);
    assertEquals(11, bean1.getSum().intValue());
    assertEquals("ANNA", bean1.getBigName());

View Full Code Here


public class JointHintResolverTest {

  @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);
View Full Code Here

TOP

Related Classes of jodd.db.oom.tst.Girl

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.