@@ -64,8 +64,8 @@ public static int countRecord(String table, String schema) throws SQLException,
6464 public static void createSourceTable (String sourceTable , String schema ) throws SQLException ,
6565 ClassNotFoundException {
6666 try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
67- String createSourceTableQuery = "CREATE TABLE " + schema + "." + sourceTable +
68- "(ID varchar(100), LASTNAME varchar(100))" ;
67+ String createSourceTableQuery = createTableQuery ( sourceTable , schema ,
68+ "(ID varchar(100), LASTNAME varchar(100))" ) ;
6969 statement .executeUpdate (createSourceTableQuery );
7070
7171 // Insert dummy data.
@@ -79,12 +79,82 @@ public static void createSourceTable(String sourceTable, String schema) throws S
7979 public static void createTargetTable (String targetTable , String schema ) throws SQLException ,
8080 ClassNotFoundException {
8181 try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
82- String createTargetTableQuery = "CREATE TABLE " + schema + "." + targetTable +
83- "(ID varchar(100), LASTNAME varchar(100))" ;
82+ String createTargetTableQuery = createTableQuery ( targetTable , schema ,
83+ "(ID varchar(100), LASTNAME varchar(100))" ) ;
8484 statement .executeUpdate (createTargetTableQuery );
8585 }
8686 }
8787
88+ public static void createSourceDatatypesTable (String sourceTable , String schema ) throws SQLException ,
89+ ClassNotFoundException {
90+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
91+ String datatypeColumns = PluginPropertyUtils .pluginProp ("datatypeColumns" );
92+ String createSourceTableQuery2 = createTableQuery (sourceTable , schema , datatypeColumns );
93+ statement .executeUpdate (createSourceTableQuery2 );
94+
95+ // Insert dummy data.
96+ String datatypeValues = PluginPropertyUtils .pluginProp ("datatypeValues" );
97+ String datatypeColumnsList = PluginPropertyUtils .pluginProp ("datatypeColumnsList" );
98+ statement .executeUpdate (insertQuery (sourceTable , schema , datatypeColumnsList , datatypeValues ));
99+ }
100+ }
101+
102+ public static void createTargetDatatypesTable (String targetTable , String schema ) throws SQLException ,
103+ ClassNotFoundException {
104+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
105+ String datatypeColumns = PluginPropertyUtils .pluginProp ("datatypeColumns" );
106+ String createTargetTableQuery2 = createTableQuery (targetTable , schema , datatypeColumns );
107+ statement .executeUpdate (createTargetTableQuery2 );
108+ }
109+ }
110+
111+ public static void createSourceImageTable (String sourceTable , String schema ) throws SQLException ,
112+ ClassNotFoundException {
113+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
114+ String imageColumns = PluginPropertyUtils .pluginProp ("imageColumns" );
115+ String createSourceTableQuery3 = createTableQuery (sourceTable , schema , imageColumns );
116+ statement .executeUpdate (createSourceTableQuery3 );
117+
118+ // Insert dummy data.
119+ String imageValues = PluginPropertyUtils .pluginProp ("imageValues" );
120+ String imageColumnsList = PluginPropertyUtils .pluginProp ("imageColumnsList" );
121+ statement .executeUpdate (insertQuery (sourceTable , schema , imageColumnsList , imageValues ));
122+ }
123+ }
124+
125+ public static void createTargetImageTable (String targetTable , String schema ) throws SQLException ,
126+ ClassNotFoundException {
127+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
128+ String imageColumns = PluginPropertyUtils .pluginProp ("imageColumns" );
129+ String createTargetTableQuery3 = createTableQuery (targetTable , schema , imageColumns );
130+ statement .executeUpdate (createTargetTableQuery3 );
131+ }
132+ }
133+
134+ public static void createSourceUniqueIdentifierTable (String sourceTable , String schema ) throws SQLException ,
135+ ClassNotFoundException {
136+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
137+ String uniqueIdentifierColumns = PluginPropertyUtils .pluginProp ("uniqueIdentifierColumns" );
138+ String createSourceTableQuery3 = createTableQuery (sourceTable , schema , uniqueIdentifierColumns );
139+ statement .executeUpdate (createSourceTableQuery3 );
140+
141+ // Insert dummy data.
142+ String uniqueIdentifierValues = PluginPropertyUtils .pluginProp ("uniqueIdentifierValues" );
143+ String uniqueIdentifierColumnsList = PluginPropertyUtils .pluginProp ("uniqueIdentifierColumnsList" );
144+ statement .executeUpdate (insertQuery (sourceTable , schema , uniqueIdentifierColumnsList ,
145+ uniqueIdentifierValues ));
146+ }
147+ }
148+
149+ public static void createTargetUniqueIdentifierTable (String targetTable , String schema ) throws SQLException ,
150+ ClassNotFoundException {
151+ try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
152+ String uniqueIdentifierColumns = PluginPropertyUtils .pluginProp ("uniqueIdentifierColumns" );
153+ String createTargetTableQuery3 = createTableQuery (targetTable , schema , uniqueIdentifierColumns );
154+ statement .executeUpdate (createTargetTableQuery3 );
155+ }
156+ }
157+
88158 public static void deleteTables (String schema , String [] tables )
89159 throws SQLException , ClassNotFoundException {
90160 try (Connection connect = getMssqlConnection (); Statement statement = connect .createStatement ()) {
@@ -111,6 +181,15 @@ public static boolean validateRecordValues(String schema, String sourceTable, St
111181 }
112182 }
113183
184+ private static String createTableQuery (String table , String schema , String columns ) {
185+ return String .format ("CREATE TABLE %s.%s %s" , schema , table , columns );
186+ }
187+
188+ private static String insertQuery (String table , String schema , String columnList , String columnValues ) {
189+ return String .format ("INSERT INTO %s.%s %s %s" , schema , table ,
190+ columnList , columnValues );
191+ }
192+
114193 private static boolean compareResultSetData (ResultSet rsSource , ResultSet rsTarget ) throws SQLException {
115194 ResultSetMetaData mdSource = rsSource .getMetaData ();
116195 ResultSetMetaData mdTarget = rsTarget .getMetaData ();
@@ -124,13 +203,19 @@ private static boolean compareResultSetData(ResultSet rsSource, ResultSet rsTarg
124203 String columnTypeName = mdSource .getColumnTypeName (currentColumnCount );
125204 int columnType = mdSource .getColumnType (currentColumnCount );
126205 String columnName = mdSource .getColumnName (currentColumnCount );
127- switch (columnType ) {
206+ if (columnType == Types .TIMESTAMP ) {
207+ GregorianCalendar gc = new GregorianCalendar (TimeZone .getTimeZone ("UTC" ));
208+ gc .setGregorianChange (new Date (Long .MIN_VALUE ));
209+ Timestamp sourceTS = rsSource .getTimestamp (currentColumnCount , gc );
210+ Timestamp targetTS = rsTarget .getTimestamp (currentColumnCount , gc );
211+ Assert .assertEquals (String .format ("Different values found for column : %s" , columnName ),
212+ sourceTS , targetTS );
128213
129- default :
130- String sourceString = rsSource .getString (currentColumnCount );
131- String targetString = rsTarget .getString (currentColumnCount );
132- Assert .assertTrue (String .format ("Different values found for column : %s" , columnName ),
133- sourceString . equals ( targetString ) );
214+ } else {
215+ String sourceString = rsSource .getString (currentColumnCount );
216+ String targetString = rsTarget .getString (currentColumnCount );
217+ Assert .assertEquals (String .format ("Different values found for column : %s" , columnName ),
218+ sourceString , targetString );
134219 }
135220 currentColumnCount ++;
136221 }
0 commit comments