@Test public void testInsert() { UserNotifyPO poa = new UserNotifyPO(); poa.setUserId(1L); poa.setType(1); int i = dao.insert(poa); System.out.println("size:" + i); ActiveDevicePO po = new ActiveDevicePO(); po.setAgent("test0"); po.setChannel("test0"); po.setCreateTime(new Date()); po.setImei("1230"); po.setPlatform("test0"); po.setVendor("test0"); po.setVersion("10"); ActiveDevicePO po1 = new ActiveDevicePO(); po1.setId(1L); po1.setAgent("test1"); po1.setChannel("test1"); po1.setCreateTime(new Date()); po1.setImei("1231"); po1.setPlatform("test1"); po1.setVendor("test1"); po1.setVersion("11"); dao.insert(po, po1); System.out.println(po1.getId()); System.out.println(po.getId()); UserPO user = new UserPO(); user.setId(123455L); dao.insert(user); }
@Override public int insert(Object... pojos) throws DataAccessException { int r = 0; Map<String, List<Object[]>> sqlAndArgsList = new HashMap<String, List<Object[]>>(); Map<String, List<Object>> sqlPojosMapping = new HashMap<String, List<Object>>(); try { for (Object obj : pojos) { SqlInsGenerator sqlGenerator = new SqlInsGenerator(obj); String sql = sqlGenerator.getSql(); if (sqlAndArgsList.containsKey(sql)) { sqlAndArgsList.get(sql).add(sqlGenerator.getArgs()); sqlPojosMapping.get(sql).add(obj); } else { List<Object[]> argsList = new ArrayList<Object[]>(); argsList.add(sqlGenerator.getArgs()); sqlAndArgsList.put(sql, argsList); List<Object> objsList = new ArrayList<Object>(); objsList.add(obj); sqlPojosMapping.put(sql, objsList); } } } catch (IllegalArgumentException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (IllegalAccessException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (NoSuchFieldException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (SecurityException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } Connection conn; try { conn = getConnection(); } catch (SQLException e) { logger.error("Get connection from datasource error", e); throw new DataAccessException("Get connection from datasource error!", e); } try { for (String sql : sqlAndArgsList.keySet()) { int[] ii = batchUpdate(conn, sql, sqlAndArgsList.get(sql)); SelectKey selectKey = SqlRepairer.getSelectKey(dbType); if (selectKey != null) { List<Object> objs = sqlPojosMapping.get(sql); if (objs != null && !objs.isEmpty()) { IdentityFinder identityFinder = new IdentityFinder(conn, selectKey); try { identityFinder.find(objs.toArray()); } catch (IllegalArgumentException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (IllegalAccessException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (SQLException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } } } for (int i : ii) { if (DBType.MYSQL.equals(this.dbType)) { r += (i == -2 ? 1 : 0); } else { r += i; } } } } finally { try { close(conn); } catch (SQLException e) { throw new DataAccessException("close connection error!", e); } } return r; }
DefaultCommonDao implements ICommonDao { @Override public int insert(Object... pojos) throws DataAccessException { int r = 0; Map<String, List<Object[]>> sqlAndArgsList = new HashMap<String, List<Object[]>>(); Map<String, List<Object>> sqlPojosMapping = new HashMap<String, List<Object>>(); try { for (Object obj : pojos) { SqlInsGenerator sqlGenerator = new SqlInsGenerator(obj); String sql = sqlGenerator.getSql(); if (sqlAndArgsList.containsKey(sql)) { sqlAndArgsList.get(sql).add(sqlGenerator.getArgs()); sqlPojosMapping.get(sql).add(obj); } else { List<Object[]> argsList = new ArrayList<Object[]>(); argsList.add(sqlGenerator.getArgs()); sqlAndArgsList.put(sql, argsList); List<Object> objsList = new ArrayList<Object>(); objsList.add(obj); sqlPojosMapping.put(sql, objsList); } } } catch (IllegalArgumentException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (IllegalAccessException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (NoSuchFieldException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (SecurityException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } Connection conn; try { conn = getConnection(); } catch (SQLException e) { logger.error("Get connection from datasource error", e); throw new DataAccessException("Get connection from datasource error!", e); } try { for (String sql : sqlAndArgsList.keySet()) { int[] ii = batchUpdate(conn, sql, sqlAndArgsList.get(sql)); SelectKey selectKey = SqlRepairer.getSelectKey(dbType); if (selectKey != null) { List<Object> objs = sqlPojosMapping.get(sql); if (objs != null && !objs.isEmpty()) { IdentityFinder identityFinder = new IdentityFinder(conn, selectKey); try { identityFinder.find(objs.toArray()); } catch (IllegalArgumentException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (IllegalAccessException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (SQLException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } } } for (int i : ii) { if (DBType.MYSQL.equals(this.dbType)) { r += (i == -2 ? 1 : 0); } else { r += i; } } } } finally { try { close(conn); } catch (SQLException e) { throw new DataAccessException("close connection error!", e); } } return r; } }
DefaultCommonDao implements ICommonDao { @Override public int insert(Object... pojos) throws DataAccessException { int r = 0; Map<String, List<Object[]>> sqlAndArgsList = new HashMap<String, List<Object[]>>(); Map<String, List<Object>> sqlPojosMapping = new HashMap<String, List<Object>>(); try { for (Object obj : pojos) { SqlInsGenerator sqlGenerator = new SqlInsGenerator(obj); String sql = sqlGenerator.getSql(); if (sqlAndArgsList.containsKey(sql)) { sqlAndArgsList.get(sql).add(sqlGenerator.getArgs()); sqlPojosMapping.get(sql).add(obj); } else { List<Object[]> argsList = new ArrayList<Object[]>(); argsList.add(sqlGenerator.getArgs()); sqlAndArgsList.put(sql, argsList); List<Object> objsList = new ArrayList<Object>(); objsList.add(obj); sqlPojosMapping.put(sql, objsList); } } } catch (IllegalArgumentException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (IllegalAccessException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (NoSuchFieldException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (SecurityException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } Connection conn; try { conn = getConnection(); } catch (SQLException e) { logger.error("Get connection from datasource error", e); throw new DataAccessException("Get connection from datasource error!", e); } try { for (String sql : sqlAndArgsList.keySet()) { int[] ii = batchUpdate(conn, sql, sqlAndArgsList.get(sql)); SelectKey selectKey = SqlRepairer.getSelectKey(dbType); if (selectKey != null) { List<Object> objs = sqlPojosMapping.get(sql); if (objs != null && !objs.isEmpty()) { IdentityFinder identityFinder = new IdentityFinder(conn, selectKey); try { identityFinder.find(objs.toArray()); } catch (IllegalArgumentException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (IllegalAccessException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (SQLException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } } } for (int i : ii) { if (DBType.MYSQL.equals(this.dbType)) { r += (i == -2 ? 1 : 0); } else { r += i; } } } } finally { try { close(conn); } catch (SQLException e) { throw new DataAccessException("close connection error!", e); } } return r; } DefaultCommonDao(); }
DefaultCommonDao implements ICommonDao { @Override public int insert(Object... pojos) throws DataAccessException { int r = 0; Map<String, List<Object[]>> sqlAndArgsList = new HashMap<String, List<Object[]>>(); Map<String, List<Object>> sqlPojosMapping = new HashMap<String, List<Object>>(); try { for (Object obj : pojos) { SqlInsGenerator sqlGenerator = new SqlInsGenerator(obj); String sql = sqlGenerator.getSql(); if (sqlAndArgsList.containsKey(sql)) { sqlAndArgsList.get(sql).add(sqlGenerator.getArgs()); sqlPojosMapping.get(sql).add(obj); } else { List<Object[]> argsList = new ArrayList<Object[]>(); argsList.add(sqlGenerator.getArgs()); sqlAndArgsList.put(sql, argsList); List<Object> objsList = new ArrayList<Object>(); objsList.add(obj); sqlPojosMapping.put(sql, objsList); } } } catch (IllegalArgumentException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (IllegalAccessException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (NoSuchFieldException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (SecurityException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } Connection conn; try { conn = getConnection(); } catch (SQLException e) { logger.error("Get connection from datasource error", e); throw new DataAccessException("Get connection from datasource error!", e); } try { for (String sql : sqlAndArgsList.keySet()) { int[] ii = batchUpdate(conn, sql, sqlAndArgsList.get(sql)); SelectKey selectKey = SqlRepairer.getSelectKey(dbType); if (selectKey != null) { List<Object> objs = sqlPojosMapping.get(sql); if (objs != null && !objs.isEmpty()) { IdentityFinder identityFinder = new IdentityFinder(conn, selectKey); try { identityFinder.find(objs.toArray()); } catch (IllegalArgumentException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (IllegalAccessException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (SQLException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } } } for (int i : ii) { if (DBType.MYSQL.equals(this.dbType)) { r += (i == -2 ? 1 : 0); } else { r += i; } } } } finally { try { close(conn); } catch (SQLException e) { throw new DataAccessException("close connection error!", e); } } return r; } DefaultCommonDao(); @Override PaginationSupport<T> queryForPaginatedPojoList(String sql,
			Object[] args, Class<T> pojoType, RowSelection rowSelection); @Override PaginationSupport<T> queryForPaginatedPojoList(
			Class<T> pojoType, Map<String, Object> args,
			RowSelection rowSelection); @Override List<Map<String, Object>> queryForMapList(String sql, Object... args); @Override List<Map<String, Object>> queryForMapList(String sql, Map<String, Object> params); @Override List<T> queryForPojoList(String sql, Object[] args,
			Class<T> pojoType); @Override List<T> queryForPojoList(String sql, Map<String, Object> params,
			Class<T> pojoType); @Override List<T> queryForPojoList(Class<T> pojoType, Map<String, Object> args); @Override List<T> queryForPojoList(Class<T> pojoType, String col, Object... args); @SuppressWarnings("unchecked") @Override T queryForSimpObject(String sql, Object[] args, Class<T> requiredType); @Override List<T> queryForSimpObjectList(String sql, Object[] args,
			Class<T> requiredType); @Override T queryForPojoOne(Class<T> pojoType, Map<String, Object> args); @Override T queryCallback(String sql, Object[] args, ResultSetExtractor<T> resultSetExtractor); @Override int update(String sql, Object... args); @Override int updateByLogic(Object... pojos); @Override int updateByPhysical(Object... pojos); @Override int deleteByLogic(Object... pojos); @Override int deleteByPhysical(Object... pojos); @Override int delete(Class<T> pojoType, Map<String, Object> args); @Override int deleteByLogic(Class<T> pojoType, Object... args); @Override int deleteByPhysical(Class<T> pojoType, Object... args); @Override int insert(Object... pojos); @Override int[] batchUpdate(String sql, List<Object[]> argsList); @Override int[] batchUpdateByLogic(Class<T> pojoType, T... pojos); @Override int[] batchUpdateByPhysical(Class<T> pojoType, T... pojos); void setDataSource(DataSource dataSource); void setDbType(DBType dbType); }
DefaultCommonDao implements ICommonDao { @Override public int insert(Object... pojos) throws DataAccessException { int r = 0; Map<String, List<Object[]>> sqlAndArgsList = new HashMap<String, List<Object[]>>(); Map<String, List<Object>> sqlPojosMapping = new HashMap<String, List<Object>>(); try { for (Object obj : pojos) { SqlInsGenerator sqlGenerator = new SqlInsGenerator(obj); String sql = sqlGenerator.getSql(); if (sqlAndArgsList.containsKey(sql)) { sqlAndArgsList.get(sql).add(sqlGenerator.getArgs()); sqlPojosMapping.get(sql).add(obj); } else { List<Object[]> argsList = new ArrayList<Object[]>(); argsList.add(sqlGenerator.getArgs()); sqlAndArgsList.put(sql, argsList); List<Object> objsList = new ArrayList<Object>(); objsList.add(obj); sqlPojosMapping.put(sql, objsList); } } } catch (IllegalArgumentException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (IllegalAccessException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (NoSuchFieldException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } catch (SecurityException e) { logger.error("init insert sql error! exec number : {}", r, e); throw new DataAccessException("init insert sql error!", e); } Connection conn; try { conn = getConnection(); } catch (SQLException e) { logger.error("Get connection from datasource error", e); throw new DataAccessException("Get connection from datasource error!", e); } try { for (String sql : sqlAndArgsList.keySet()) { int[] ii = batchUpdate(conn, sql, sqlAndArgsList.get(sql)); SelectKey selectKey = SqlRepairer.getSelectKey(dbType); if (selectKey != null) { List<Object> objs = sqlPojosMapping.get(sql); if (objs != null && !objs.isEmpty()) { IdentityFinder identityFinder = new IdentityFinder(conn, selectKey); try { identityFinder.find(objs.toArray()); } catch (IllegalArgumentException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (IllegalAccessException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } catch (SQLException e) { logger.error("find identity!", e); throw new DataAccessException("find identity error!", e); } } } for (int i : ii) { if (DBType.MYSQL.equals(this.dbType)) { r += (i == -2 ? 1 : 0); } else { r += i; } } } } finally { try { close(conn); } catch (SQLException e) { throw new DataAccessException("close connection error!", e); } } return r; } DefaultCommonDao(); @Override PaginationSupport<T> queryForPaginatedPojoList(String sql,
			Object[] args, Class<T> pojoType, RowSelection rowSelection); @Override PaginationSupport<T> queryForPaginatedPojoList(
			Class<T> pojoType, Map<String, Object> args,
			RowSelection rowSelection); @Override List<Map<String, Object>> queryForMapList(String sql, Object... args); @Override List<Map<String, Object>> queryForMapList(String sql, Map<String, Object> params); @Override List<T> queryForPojoList(String sql, Object[] args,
			Class<T> pojoType); @Override List<T> queryForPojoList(String sql, Map<String, Object> params,
			Class<T> pojoType); @Override List<T> queryForPojoList(Class<T> pojoType, Map<String, Object> args); @Override List<T> queryForPojoList(Class<T> pojoType, String col, Object... args); @SuppressWarnings("unchecked") @Override T queryForSimpObject(String sql, Object[] args, Class<T> requiredType); @Override List<T> queryForSimpObjectList(String sql, Object[] args,
			Class<T> requiredType); @Override T queryForPojoOne(Class<T> pojoType, Map<String, Object> args); @Override T queryCallback(String sql, Object[] args, ResultSetExtractor<T> resultSetExtractor); @Override int update(String sql, Object... args); @Override int updateByLogic(Object... pojos); @Override int updateByPhysical(Object... pojos); @Override int deleteByLogic(Object... pojos); @Override int deleteByPhysical(Object... pojos); @Override int delete(Class<T> pojoType, Map<String, Object> args); @Override int deleteByLogic(Class<T> pojoType, Object... args); @Override int deleteByPhysical(Class<T> pojoType, Object... args); @Override int insert(Object... pojos); @Override int[] batchUpdate(String sql, List<Object[]> argsList); @Override int[] batchUpdateByLogic(Class<T> pojoType, T... pojos); @Override int[] batchUpdateByPhysical(Class<T> pojoType, T... pojos); void setDataSource(DataSource dataSource); void setDbType(DBType dbType);  }