/** * 功能描述: <br> * 〈功能详细描述〉 * * @param entity * @return * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ public int merge(Object entity) { EntityParser sqlParser = EntityParser.getEntityParser(entity.getClass()); String updateSql = sqlParser.getUpdate(); Map<String, Object> paramMap = sqlParser.parser(entity); logMessage("merge", updateSql, paramMap); return getValidateJdbcTemplate(paramMap).update(updateSql, paramMap); }
/** * 功能描述: <br> * 〈功能详细描述〉 * * @param entity * @return * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ public int remove(Object entity) { EntityParser sqlParser = EntityParser.getEntityParser(entity.getClass()); String removeSql = sqlParser.getDelete(); Map<String, Object> paramMap = sqlParser.parser(entity); logMessage("remove", removeSql, paramMap); return getValidateJdbcTemplate(paramMap).update(removeSql, paramMap); }
/** * 功能描述: <br> * 〈功能详细描述〉 * * @param entityClass * @param entity * @return * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ public <T> T find(Class<T> entityClass, Object entity) { EntityParser sqlParser = EntityParser.getEntityParser(entity.getClass()); String findSql = sqlParser.getSelect(); Map<String, Object> paramMap = sqlParser.parser(entity); logMessage("find", findSql, paramMap); List<T> resultList = getJdbcTemplate(paramMap) .query(findSql, paramMap, new BeanPropertyRowMapper<T>(entityClass)); return singleResult(resultList); }
/** * 功能描述: <br> * 〈功能详细描述〉 * * @param entity * @param requiredType * @return * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ @SuppressWarnings("unchecked") public <T> T persist(Object entity) { EntityParser sqlParser = EntityParser.getEntityParser(entity.getClass()); String insertSQL = sqlParser.getInsert(); Map<String, Object> paramMap = sqlParser.parser(entity); logMessage("persist", insertSQL, paramMap); KeyHolder keyHolder = new GeneratedKeyHolder(); try { getValidateJdbcTemplate(paramMap) .update(insertSQL, new MapSqlParameterSource(paramMap), keyHolder); } catch (Exception e) { logger.error(paramMap.toString()); } Object key = paramMap.get(sqlParser.getId()); if (key == null) { return (T) keyHolder.getKey(); } return (T) key; }