/** 부분 커밋하면서 입력한다. ex) batchInsert(dataSource,"QQ", params, 1000); */ public static void batchInsert( DataSource dataSource, String tableName, List<Object[]> params, int commitInterval) { Connection conn = null; try { conn = dataSource.getConnection(); conn.setAutoCommit(false); QueryRunner runner = new QueryRunner(); StringAppender appender = new StringAppender(); appender.appendLine( "SELECT a.TABLE_NAME,a.COLUMN_NAME,COMMENTS,DATA_TYPE,DATA_LENGTH,DATA_PRECISION,DATA_SCALE"); appender.appendLine("FROM user_tab_columns a JOIN USER_COL_COMMENTS b"); appender.appendLine("ON a.COLUMN_NAME = b.COLUMN_NAME AND a.TABLE_NAME = b.TABLE_NAME"); appender.appendLine("WHERE a.TABLE_NAME = ? "); appender.appendLine("ORDER BY a.TABLE_NAME, COLUMN_ID "); List<String> columnNames = Lists.newArrayList(); // 걍 한번 쓸거라 일케 함 List<Map<String, Object>> result = runner.query(conn, appender.toString(), LIST_MAP_HANDLER, tableName); for (Map<String, Object> value : result) { columnNames.add(value.get("COLUMN_NAME").toString()); } String sql = "INSERT INTO " + tableName + " (" + StringUtil.join(columnNames, ",") + ") values (" + StringUtil.iterateStr("?", ",", columnNames.size()) + ")"; List<List<Object[]>> splited = CollectionUtil.splitBySize(params, commitInterval); for (List<Object[]> inputList : splited) { Object[][] convertedList = new Object[inputList.size()][]; for (int i = 0; i < convertedList.length; i++) { Object[] input = inputList.get(i); Object[] converted = new Object[input.length]; for (int j = 0; j < input.length; j++) { converted[j] = CONVERTER.convert(input[j]); } convertedList[i] = converted; } runner.batch(conn, sql, convertedList); conn.commit(); } } catch (SQLException e) { throw new SQLRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
@Override public IPoint3D convert(String source) { // Handle Tuple of floats {lat, lon}. Need a better strategy, such as fallback converters if (source.startsWith("{")) { return fromLatLon(source); } GeoInformation geo = stringToGeo.convert(source); return EcefVector.fromDegs(0, geo.getLatitude(), geo.getLongitude()); }
/** {@inheritDoc} */ @Override public T next() { return converter.convert(iterator.next()); }