Example #1
0
  @Test
  public void testInsertOptimized() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    List<Person> list = sqlEngine.query(session, Person.class);
    assertEquals(2, list.size());

    Person p = new Person();
    p.setId(3L);
    p.setSsn(new Ssn());
    p.getSsn().setNumber("345678");
    p.getSsn().setCountry(Country.UNITED_STATES);
    p.setName(new PersonName());
    p.getName().setFirst("Toby");
    p.getName().setLast("Stephens");
    p.setAge(1969, 4, 21);
    p.setSex(Gender.MALE);
    p.setCreatedDate(new Date());
    p.setCreatedBy("wlado");
    p.setVersion(1L);
    p.setClothesSize(Size.MIDDLE);

    SqlCrudEngine crudEngine = getCrudEngine("INSERT_PERSON_OPT");

    String sql = crudEngine.getInsertSql(p, null);
    logger.info(sql);

    int count = crudEngine.insert(session, p);
    assertEquals(1, count);
    logger.info("new id: " + p.getId());
    assertNotNull(p.getId());

    list = sqlEngine.query(session, Person.class);
    assertEquals(3, list.size());
  }
Example #2
0
  @Test
  public void testDelete() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    Person p = new Person();
    p.setId(2L);

    List<Person> list = sqlEngine.query(session, Person.class, p);
    assertEquals(1, list.size());
    assertEquals("Halle", list.get(0).getName().getFirst());
    assertNotSame(null, list.get(0).getCreatedDate());

    SqlCrudEngine crudEngine = getCrudEngine("DELETE_PERSON");

    String sql = crudEngine.getDeleteSql(p, null);
    logger.info(sql);
    assertContains(sql, "delete from PERSON");
    assertContains(sql, "WHERE ID = :id", "WHERE ID = ?");

    int count = crudEngine.delete(session, p);
    assertEquals(1, count);

    list = sqlEngine.query(session, Person.class, p);
    assertEquals(0, list.size());
  }
Example #3
0
  @Test
  public void testDelete6() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    Person p = new Person();

    List<Person> list = sqlEngine.query(session, Person.class, p);
    assertEquals(2, list.size());

    SqlCrudEngine crudEngine = getCrudEngine("DELETE_PERSON_6");

    p.setId(list.get(0).getId());
    String sql = crudEngine.getDeleteSql(p, p);
    logger.info(sql);
    assertContains(sql, "delete from PERSON");
    assertContains(sql, "WHERE ID = :id", "WHERE ID = ?");
    assertContains(sql, "AND LASTUPDATEDBY is null");

    int count = crudEngine.delete(session, p);
    assertEquals(1, count);

    list = sqlEngine.query(session, Person.class);
    assertEquals(1, list.size());

    try {
      count = crudEngine.delete(session, null);
      fail();
    } catch (IllegalArgumentException e) {
      assertContains(e.getMessage(), "notempty");
    }
  }
 public int count(
     final SqlSession sqlSession, final PersonLibrary personLibrary, SqlControl sqlControl) {
   if (logger.isTraceEnabled()) {
     logger.trace("count personLibrary: " + personLibrary + " " + sqlControl);
   }
   org.sqlproc.engine.SqlQueryEngine sqlEnginePersonLibrary =
       sqlEngineFactory.getCheckedQueryEngine("SELECT_PERSON_LIBRARY");
   // sqlControl = getMoreResultClasses(personLibrary, sqlControl);
   int count = sqlEnginePersonLibrary.queryCount(sqlSession, personLibrary, sqlControl);
   if (logger.isTraceEnabled()) {
     logger.trace("count: " + count);
   }
   return count;
 }
 public List<PersonLibrary> list(
     final SqlSession sqlSession, final PersonLibrary personLibrary, SqlControl sqlControl) {
   if (logger.isTraceEnabled()) {
     logger.trace("sql list personLibrary: " + personLibrary + " " + sqlControl);
   }
   org.sqlproc.engine.SqlQueryEngine sqlEnginePersonLibrary =
       sqlEngineFactory.getCheckedQueryEngine("SELECT_PERSON_LIBRARY");
   // sqlControl = getMoreResultClasses(personLibrary, sqlControl);
   List<PersonLibrary> personLibraryList =
       sqlEnginePersonLibrary.query(sqlSession, PersonLibrary.class, personLibrary, sqlControl);
   if (logger.isTraceEnabled()) {
     logger.trace(
         "sql list personLibrary size: "
             + ((personLibraryList != null) ? personLibraryList.size() : "null"));
   }
   return personLibraryList;
 }
 public int query(
     final SqlSession sqlSession,
     final PersonLibrary personLibrary,
     SqlControl sqlControl,
     final SqlRowProcessor<PersonLibrary> sqlRowProcessor) {
   if (logger.isTraceEnabled()) {
     logger.trace("sql query personLibrary: " + personLibrary + " " + sqlControl);
   }
   org.sqlproc.engine.SqlQueryEngine sqlEnginePersonLibrary =
       sqlEngineFactory.getCheckedQueryEngine("SELECT_PERSON_LIBRARY");
   // sqlControl = getMoreResultClasses(personLibrary, sqlControl);
   int rownums =
       sqlEnginePersonLibrary.query(
           sqlSession, PersonLibrary.class, personLibrary, sqlControl, sqlRowProcessor);
   if (logger.isTraceEnabled()) {
     logger.trace("sql query personLibrary size: " + rownums);
   }
   return rownums;
 }
Example #7
0
  @Test
  public void testDelete7() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    Person p = new Person();

    List<Person> list = sqlEngine.query(session, Person.class, p);
    assertEquals(2, list.size());

    SqlCrudEngine crudEngine = getCrudEngine("DELETE_PERSON_7");

    p.setSsn(new Ssn());
    p.getSsn().setNumber("123456");
    p.setSex(Gender.MALE);
    String sql = crudEngine.getDeleteSql(p, p);
    logger.info(sql);
    assertContains(sql, "delete from PERSON");
    assertContains(sql, "WHERE SSN_NUMBER = :ssn.number", "WHERE SSN_NUMBER = ?");
    assertContains(sql, "SEX = :sex", "SEX = ?");

    int count = crudEngine.delete(session, p);
    assertEquals(1, count);

    list = sqlEngine.query(session, Person.class);
    assertEquals(1, list.size());

    try {
      count = crudEngine.delete(session, null);
      fail();
    } catch (IllegalArgumentException e) {
      assertContains(e.getMessage(), "notempty");
    }

    try {
      p = new Person();
      p.setSsn(new Ssn());
      p.getSsn().setNumber("123456");
      count = crudEngine.delete(session, p);
      fail();
    } catch (IllegalArgumentException e) {
      assertContains(e.getMessage(), "notempty");
    }
  }
Example #8
0
  @Test
  public void testInsert3() {
    if ("MYSQL".equalsIgnoreCase(dbType) || "MSSQL".equalsIgnoreCase(dbType)) return;

    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    List<Person> list = sqlEngine.query(session, Person.class);
    assertEquals(2, list.size());

    Person p = new Person();
    // p.setId(3L);
    p.setSsn(new Ssn());
    p.getSsn().setNumber("345678");
    p.getSsn().setCountry(Country.UNITED_STATES);
    p.setName(new PersonName());
    p.getName().setFirst("Toby");
    p.getName().setLast("Stephens");
    p.setAge(1969, 4, 21);
    p.setSex(Gender.MALE);
    // p.setCreatedDate(new Date());
    p.setCreatedBy("wlado");
    p.setVersion(1L);
    p.setClothesSize(Size.MIDDLE);

    SqlCrudEngine crudEngine = getCrudEngine("INSERT_PERSON_3");

    String sql = crudEngine.getInsertSql(p, null);
    logger.info(sql);
    assertContains(sql, "VALUES");
    assertContains(
        sql,
        ":ssn_number, :ssn_country, :name_first, :name_last, :birthDate, :sex, :createdDate, :createdBy, :version, :clothesSize)",
        "?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

    int count = crudEngine.insert(session, p);
    assertEquals(1, count);
    logger.info("new id: " + p.getId());
    assertNotNull(p.getId());

    list = sqlEngine.query(session, Person.class);
    assertEquals(3, list.size());
  }
Example #9
0
  @Test
  public void testInsertEmpty() {
    if ("oracle".equalsIgnoreCase(dbType)) return;

    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    List<Person> list = sqlEngine.query(session, Person.class);
    assertEquals(2, list.size());

    Person p = new Person();
    p.setId(3L);
    p.setSsn(new Ssn());
    p.getSsn().setNumber("");
    p.getSsn().setCountry(Country.UNITED_STATES);
    p.setName(new PersonName());
    p.getName().setFirst("");
    p.getName().setLast("Stephens");
    p.setAge(1969, 4, 21);
    p.setSex(Gender.MALE);
    p.setCreatedDate(new Date());
    p.setCreatedBy("wlado");
    p.setVersion(1L);
    p.setClothesSize(Size.MIDDLE);

    SqlCrudEngine crudEngine = getCrudEngine("INSERT_PERSON");

    String sql = crudEngine.getInsertSql(p, null);
    logger.info(sql);

    int count = crudEngine.insert(session, p);
    assertEquals(1, count);
    logger.info("new id: " + p.getId());
    assertNotNull(p.getId());

    Person p2 = new Person();
    p2.setId(p.getId());
    list = sqlEngine.query(session, Person.class, p2);
    assertEquals(1, list.size());
    Person p3 = list.get(0);
    assertEquals("", p3.getName().getFirst());
    assertEquals("Stephens", p3.getName().getLast());
  }
Example #10
0
  @Test
  public void testDelete2() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    Person p = new Person();

    List<Person> list = sqlEngine.query(session, Person.class, p);
    assertEquals(2, list.size());

    SqlCrudEngine crudEngine = getCrudEngine("DELETE_PERSON_2");

    String sql = crudEngine.getDeleteSql(p, null);
    logger.info(sql);
    assertContains(sql, "delete from PERSON");
    assertContains(sql, "WHERE LASTUPDATEDBY is null");

    int count = crudEngine.delete(session, p);
    assertEquals(2, count);

    list = sqlEngine.query(session, Person.class, p);
    assertEquals(0, list.size());
  }
Example #11
0
  @Test
  public void testUpdate1() {
    SqlQueryEngine sqlEngine = getQueryEngine("CRUD_PERSON_SELECT");

    Person p = new Person();
    p.setId(2L);

    List<Person> list = sqlEngine.query(session, Person.class, p);
    assertEquals(1, list.size());
    assertEquals("Halle", list.get(0).getName().getFirst());
    assertNotSame(null, list.get(0).getCreatedDate());

    p.setName(new PersonName());
    p.getName().setFirst("Toby");
    p.setCreatedDate(null);

    SqlCrudEngine crudEngine = getCrudEngine("UPDATE_PERSON");

    String sql = crudEngine.getUpdateSql(p, null);
    logger.info(sql);
    assertContains(sql, "update PERSON");
    assertContains(sql, "SET");
    assertContains(sql, "NAME_FIRST = :name_first", "NAME_FIRST = ?");
    assertContains(sql, "CREATEDDATE = :createdDate", "CREATEDDATE = ?");
    assertContains(sql, "WHERE");
    assertContains(sql, "ID = :id", "ID = ?");

    int count = crudEngine.update(session, p);
    assertEquals(1, count);

    list = sqlEngine.query(session, Person.class, p);
    assertEquals(1, list.size());
    assertEquals("Toby", list.get(0).getName().getFirst());
    if ("MYSQL".equalsIgnoreCase(dbType)) assertNotNull(list.get(0).getCreatedDate());
    else assertEquals(null, list.get(0).getCreatedDate());
  }