private void uploadFlow( Connection connection, Project project, int version, Flow flow, EncodingType encType) throws ProjectManagerException, IOException { QueryRunner runner = new QueryRunner(); String json = JSONUtils.toJSON(flow.toObject()); byte[] stringData = json.getBytes("UTF-8"); byte[] data = stringData; logger.info("UTF-8 size:" + data.length); if (encType == EncodingType.GZIP) { data = GZIPUtils.gzipBytes(stringData); } logger.info("Flow upload " + flow.getId() + " is byte size " + data.length); final String INSERT_FLOW = "INSERT INTO project_flows (project_id, version, flow_id, modified_time, encoding_type, json) values (?,?,?,?,?,?)"; try { runner.update( connection, INSERT_FLOW, project.getId(), version, flow.getId(), System.currentTimeMillis(), encType.getNumVal(), data); } catch (SQLException e) { throw new ProjectManagerException("Error inserting flow " + flow.getId(), e); } }
@Override public void updateFlow(Project project, int version, Flow flow) throws ProjectManagerException { logger.info("Uploading flows"); Connection connection = getConnection(); try { QueryRunner runner = new QueryRunner(); String json = JSONUtils.toJSON(flow.toObject()); byte[] stringData = json.getBytes("UTF-8"); byte[] data = stringData; logger.info("UTF-8 size:" + data.length); if (defaultEncodingType == EncodingType.GZIP) { data = GZIPUtils.gzipBytes(stringData); } logger.info("Flow upload " + flow.getId() + " is byte size " + data.length); final String UPDATE_FLOW = "UPDATE project_flows SET encoding_type=?,json=? WHERE project_id=? AND version=? AND flow_id=?"; try { runner.update( connection, UPDATE_FLOW, defaultEncodingType.getNumVal(), data, project.getId(), version, flow.getId()); } catch (SQLException e) { e.printStackTrace(); throw new ProjectManagerException("Error inserting flow " + flow.getId(), e); } connection.commit(); } catch (IOException e) { throw new ProjectManagerException("Flow Upload failed.", e); } catch (SQLException e) { throw new ProjectManagerException("Flow Upload failed commit.", e); } finally { DbUtils.closeQuietly(connection); } }