From 351fee60e134bec0d4e1019acad4c9bb3259952b Mon Sep 17 00:00:00 2001 From: AnkitCLI Date: Mon, 5 Jun 2023 15:20:10 +0530 Subject: [PATCH] commit changes --- .../cloudsqlpostgresql/BQValidation.java | 34 +-- .../CloudSqlPostgreSqlClient.java | 236 +++++++++--------- .../stepsdesign/CloudSqlPostgreSql.java | 2 +- .../resources/pluginParameters.properties | 17 +- 4 files changed, 141 insertions(+), 148 deletions(-) diff --git a/cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/BQValidation.java b/cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/BQValidation.java index 86214b9bc..18520a84b 100644 --- a/cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/BQValidation.java +++ b/cloudsql-postgresql-plugin/src/e2e-test/java/io/cdap/plugin/cloudsqlpostgresql/BQValidation.java @@ -28,6 +28,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.*; +import java.text.SimpleDateFormat; import java.time.*; import java.util.Date; import java.text.ParseException; @@ -40,51 +41,52 @@ public class BQValidation { static List BigQueryResponse = new ArrayList<>(); static List bigQueryRows = new ArrayList<>(); + static JsonObject json; /** * Extracts entire data from source and target tables. - * * @param sourceTable table at the source side * @param targetTable table at the sink side * @return true if the values in source and target side are equal */ public static boolean validateDBToBQRecordValues(String schema, String sourceTable, String targetTable) - throws SQLException, ClassNotFoundException, IOException, InterruptedException { + throws SQLException, ClassNotFoundException, IOException, InterruptedException, ParseException { getBigQueryTableData(targetTable, bigQueryRows); for (Object rows : bigQueryRows) { - JsonObject json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); + json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); BigQueryResponse.add(json); } String getSourceQuery = "SELECT * FROM " + schema + "." + sourceTable; - try (Connection connect = CloudSqlPostgreSqlClient.getCloudSqlConnection()) { - connect.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - Statement statement1 = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + try (Connection connection = CloudSqlPostgreSqlClient.getCloudSqlConnection()) { + connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + Statement statement1 = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT); ResultSet rsSource = statement1.executeQuery(getSourceQuery); return compareResultSetandJsonData(rsSource, BigQueryResponse); } } + public static boolean validateBQToDBRecordValues(String schema, String sourceTable, String targetTable) - throws SQLException, ClassNotFoundException, IOException, InterruptedException { + throws SQLException, ClassNotFoundException, IOException, InterruptedException, ParseException { getBigQueryTableData(sourceTable, bigQueryRows); for (Object rows : bigQueryRows) { - JsonObject json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); + json = new Gson().fromJson(String.valueOf(rows), JsonObject.class); BigQueryResponse.add(json); } String getTargetQuery = "SELECT * FROM " + schema + "." + targetTable; - try (Connection connect = CloudSqlPostgreSqlClient.getCloudSqlConnection()) { - connect.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - Statement statement1 = connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + try (Connection connection = CloudSqlPostgreSqlClient.getCloudSqlConnection()) { + connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + Statement statement1 = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT); ResultSet rsTarget = statement1.executeQuery(getTargetQuery); return compareResultSetandJsonData(rsTarget, BigQueryResponse); } } + /** * Retrieves the data from a specified BigQuery table and populates it into the provided list of objects. - * * @param table The name of the BigQuery table to fetch data from. * @param bigQueryRows The list to store the fetched BigQuery data. */ @@ -100,7 +102,6 @@ private static void getBigQueryTableData(String table, List bigQueryRows /** * Compares the data in the result set obtained from the Oracle database with the provided BigQuery JSON objects. - * * @param rsSource The result set obtained from the Oracle database. * @param bigQueryData The list of BigQuery JSON objects to compare with the result set data. * @return True if the result set data matches the BigQuery data, false otherwise. @@ -108,7 +109,7 @@ private static void getBigQueryTableData(String table, List bigQueryRows * @throws ParseException If an error occurs while parsing the data. */ public static boolean compareResultSetandJsonData(ResultSet rsSource, List bigQueryData) - throws SQLException { + throws SQLException, ParseException { ResultSetMetaData mdSource = rsSource.getMetaData(); boolean result = false; int columnCountSource = mdSource.getColumnCount(); @@ -161,6 +162,11 @@ public static boolean compareResultSetandJsonData(ResultSet rsSource, List