private HashMap<String, HashMap<String, Object>> updateProc( HashMap<String, Object> params, HttpServletRequest request, Session session, Login login) throws Exception { @SuppressWarnings("unused") String screen = request.getParameter("screen"); Map<String, Object> updateInput = preProc(params); UserTable upd = null; try { upd = BeanUtil.copyMapToNewBean(updateInput, UserTable.class); } catch (Exception e) { ServiceUtil.mapToNewBeanExceptionAnalyze(e); } UserTable dbUserTable = em.find(UserTable.class, upd.getId()); if (dbUserTable == null) { throw new SystemException("id:" + upd.getId().toString() + " が見つかりません"); } if (!(upd.getTableName().equals(dbUserTable.getTableName()) && upd.getKey1().equals(dbUserTable.getKey1()) && upd.getKey2().equals(dbUserTable.getKey2())) && userTableCodeDupCheck(upd)) { return DBFluteUtil.setErrorMessage("このDataは既に使用されています。", params); } BeanUtil.copyBeanToBean(upd, dbUserTable, CopyOptionsUtil.excludeNull()); em.merge(dbUserTable); Map<String, Object> map = null; map = entityToMap(upd); return DBFluteUtil.setFetchResult(map, params); }
private Map<String, Object> entityToMap(UserTable newEntity) { Map<String, Object> map = BeanUtil.copyBeanToNewMap( newEntity, include( "id", "tableName", "key1", "key2", "s1Data", "s2Data", "s3Data", "n1Data", "n2Data", "n3Data", "versionNo")); return map; }
private HashMap<String, HashMap<String, Object>> insertProc( HashMap<String, Object> params, HttpServletRequest request, Session session, Login login) throws Exception { @SuppressWarnings("unused") String screen = request.getParameter("screen"); Map<String, Object> newin = preProc(params); UserTable newEntity = null; try { newEntity = BeanUtil.copyMapToNewBean(newin, UserTable.class); } catch (Exception e) { ServiceUtil.mapToNewBeanExceptionAnalyze(e); } if (userTableCodeDupCheck(newEntity)) { return DBFluteUtil.setErrorMessage("このDataは既に使用されています。", params); } HashMap<String, HashMap<String, Object>> res; em.persist(newEntity); Map<String, Object> map = null; map = entityToMap(newEntity); res = DBFluteUtil.setFetchResult(map, params); return res; }