/** * 测试级联的更新操作 * * @throws SQLException */ @Test public void testRefUpdate() throws SQLException { System.out.println("=========== testRefUpdate Begin =========="); Transaction db = this.db.startTransaction(); Person p = new Person(); p.setId(2); p = db.load(p); // p.setSchoolId(0); p.setSchool(new School("华南大学")); p.setAge(123); db.updateCascade(p); db.rollback(true); System.out.println("=========== testRefUpdate End =========="); }
/** * 测试级联对象的插入操作 * * @throws SQLException */ @Test public void testRefInsert() throws SQLException { System.out.println("=========== testRefInsert Begin =========="); Person p = new Person(); p.setName("张三"); p.setGender("M"); p.setSchool(new School("浙江大学")); p.setAge(22); db.insertCascade(p); System.out.println(p.getId()); Person query = new Person(); query.setId(p.getId()); query = db.load(query); assertEquals("浙江大学", query.getSchoolName()); System.out.println("=========== testRefInsert End =========="); }
@Test public void testUpdateNormal() throws SQLException { Transaction db = this.db.startTransaction(); List<School> schools = db.selectAll(School.class); School s = schools.get(0); Person p = new Person(); p.setId(2); p = db.load(p); System.out.println(p); System.out.println(p.getSchoolId()); System.out.println(p.getSchool()); p.setSchool(s); db.update(p); db.rollback(true); }
@Test public void testInsertCascade() throws SQLException { Transaction db = this.db.startTransaction(); List<School> schools = db.selectAll(School.class); School s = schools.get(0); Person p = new Person(); p.setAge(12); p.setBirthDay(new Date()); p.setCell("123433454"); p.setFriendComment(new String[] {"AA"}); p.setGender("M"); p.setLastModified(new Date()); p.setParentId(1); p.setSchool(s); p.setName("刘备"); p.setSchoolId(3); db.insertCascade(p); System.out.println(p.getSchoolId()); db.rollback(true); }