@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()); }
@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()); }
@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()); }