EmpireUserDao extends EmpireDao implements UserDao { @Override public void update(UserProfile user) { DBRecord dbr = new DBRecord(); try { if (user.getId() == null) { dbr.create(table); Timestamp now = new Timestamp(System.currentTimeMillis()); if (user.getCreated() == null) { user.setCreated(now); } user.setTimestamp(now); dbr.setValue(table.timestamp, now); dbr.setBeanValues(user); } else { dbr.read(table, new Object[] {user.getId()}, getConnection()); Collection<Column> ignore = user.getUserPasswordDigest() == null ? Arrays.<Column>asList(table.passwd) : null; dbr.setBeanValues(user, ignore); } try { dbr.update(getConnection()); } catch (RecordUpdateInvalidException ex) { throw new ConcurrentModificationException(ex); } dbr.getBeanProperties(user); } finally { dbr.close(); } } EmpireUserDao(ProarcDatabase db); @Override UserProfile create(); @Override void update(UserProfile user); @Override UserProfile find(int userId); @Override List<UserProfile> find(String userName, String passwd, String remoteName, String remoteType);  }
@Test public void testUpdate() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "group.xml"), support.loadFlatXmlDataStream(getClass(), "user.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); UserProfile user = dao.find(1); String userName = user.getUserName(); assertNotNull(userName); user.setDefaultGroup(1); user.setEmail("email2"); user.setForename("forename2"); user.setRemoteName("remotename2"); user.setRemoteType("remotetype2"); user.setSurname("surname2"); user.setUserGroup(1); user.setUserHome("home2"); user.setUserPasswordDigest("digest2"); dao.update(user); assertNotNull(user.getCreated()); assertEquals((Integer) 1, user.getDefaultGroup()); assertEquals("email2", user.getEmail()); assertEquals("forename2", user.getForename()); assertEquals((Integer) 1, user.getId()); assertEquals("remotename2", user.getRemoteName()); assertEquals("remotetype2", user.getRemoteType()); assertEquals("surname2", user.getSurname()); assertEquals((Integer) 1, user.getUserGroup()); assertEquals(userName, user.getUserName()); assertEquals("home2", user.getUserHome()); assertEquals("digest2", user.getUserPasswordDigest()); UserProfile result = dao.find(1); assertNotNull(result.getCreated()); assertEquals((Integer) 1, result.getDefaultGroup()); assertEquals("email2", result.getEmail()); assertEquals("forename2", result.getForename()); assertEquals((Integer) 1, result.getId()); assertEquals("remotename2", result.getRemoteName()); assertEquals("remotetype2", result.getRemoteType()); assertEquals("surname2", result.getSurname()); assertEquals((Integer) 1, result.getUserGroup()); assertEquals(userName, result.getUserName()); assertEquals("home2", result.getUserHome()); assertEquals("digest2", result.getUserPasswordDigest()); user.setForename(null); user.setUserPasswordDigest(null); dao.update(user); assertNull(user.getForename()); assertEquals("digest2", user.getUserPasswordDigest()); result = dao.find(1); assertNull(result.getForename()); assertEquals("digest2", result.getUserPasswordDigest()); user.setUserPasswordDigest(""); dao.update(user); assertNull(user.getUserPasswordDigest()); }