@@ -80,9 +80,8 @@ public final class CliRunner implements Closeable {
80
80
private final boolean _closeOut ;
81
81
82
82
/**
83
- * Alternative constructor that will specifically specifies the output
84
- * writer. Should be used only for testing, since normally the CliArguments
85
- * should be used to decide which outputwriter to use
83
+ * Alternative constructor that will specifically specifies the output writer. Should be used only for testing,
84
+ * since normally the CliArguments should be used to decide which outputwriter to use
86
85
*
87
86
* @param arguments
88
87
* @param writer
@@ -234,29 +233,32 @@ private void printColumns(final DataCleanerConfiguration configuration) {
234
233
System .err .println ("No such datastore: " + datastoreName );
235
234
} else {
236
235
final DatastoreConnection con = ds .openConnection ();
237
- final DataContext dc = con .getDataContext ();
238
- final Schema schema ;
239
- if (schemaName == null ) {
240
- schema = dc .getDefaultSchema ();
241
- } else {
242
- schema = dc .getSchemaByName (schemaName );
243
- }
244
- if (schema == null ) {
245
- System .err .println ("No such schema: " + schemaName );
246
- } else {
247
- final Table table = schema .getTableByName (tableName );
248
- if (table == null ) {
249
- write ("No such table: " + tableName );
236
+ try {
237
+ final DataContext dc = con .getDataContext ();
238
+ final Schema schema ;
239
+ if (schemaName == null ) {
240
+ schema = dc .getDefaultSchema ();
250
241
} else {
251
- final List <String > columnNames = table .getColumnNames ();
252
- write ("Columns:" );
253
- write ("--------" );
254
- for (final String columnName : columnNames ) {
255
- write (columnName );
242
+ schema = dc .getSchemaByName (schemaName );
243
+ }
244
+ if (schema == null ) {
245
+ System .err .println ("No such schema: " + schemaName );
246
+ } else {
247
+ final Table table = schema .getTableByName (tableName );
248
+ if (table == null ) {
249
+ write ("No such table: " + tableName );
250
+ } else {
251
+ final List <String > columnNames = table .getColumnNames ();
252
+ write ("Columns:" );
253
+ write ("--------" );
254
+ for (final String columnName : columnNames ) {
255
+ write (columnName );
256
+ }
256
257
}
257
258
}
259
+ } finally {
260
+ con .close ();
258
261
}
259
- con .close ();
260
262
}
261
263
}
262
264
}
@@ -273,28 +275,31 @@ private void printTables(final DataCleanerConfiguration configuration) {
273
275
System .err .println ("No such datastore: " + datastoreName );
274
276
} else {
275
277
final DatastoreConnection con = ds .openConnection ();
276
- final DataContext dc = con .getDataContext ();
277
- final Schema schema ;
278
- if (schemaName == null ) {
279
- schema = dc .getDefaultSchema ();
280
- } else {
281
- schema = dc .getSchemaByName (schemaName );
282
- }
283
- if (schema == null ) {
284
- System .err .println ("No such schema: " + schemaName );
285
- } else {
286
- final List <String > tableNames = schema .getTableNames ();
287
- if (tableNames == null || tableNames .isEmpty ()) {
288
- System .err .println ("No tables in schema!" );
278
+ try {
279
+ final DataContext dc = con .getDataContext ();
280
+ final Schema schema ;
281
+ if (schemaName == null ) {
282
+ schema = dc .getDefaultSchema ();
289
283
} else {
290
- write ("Tables:" );
291
- write ("-------" );
292
- for (final String tableName : tableNames ) {
293
- write (tableName );
284
+ schema = dc .getSchemaByName (schemaName );
285
+ }
286
+ if (schema == null ) {
287
+ System .err .println ("No such schema: " + schemaName );
288
+ } else {
289
+ final List <String > tableNames = schema .getTableNames ();
290
+ if (tableNames == null || tableNames .isEmpty ()) {
291
+ System .err .println ("No tables in schema!" );
292
+ } else {
293
+ write ("Tables:" );
294
+ write ("-------" );
295
+ for (final String tableName : tableNames ) {
296
+ write (tableName );
297
+ }
294
298
}
295
299
}
300
+ } finally {
301
+ con .close ();
296
302
}
297
- con .close ();
298
303
}
299
304
}
300
305
}
@@ -310,17 +315,20 @@ private void printSchemas(final DataCleanerConfiguration configuration) {
310
315
System .err .println ("No such datastore: " + datastoreName );
311
316
} else {
312
317
final DatastoreConnection con = ds .openConnection ();
313
- final List <String > schemaNames = con .getDataContext ().getSchemaNames ();
314
- if (schemaNames == null || schemaNames .isEmpty ()) {
315
- write ("No schemas in datastore!" );
316
- } else {
317
- write ("Schemas:" );
318
- write ("--------" );
319
- for (final String schemaName : schemaNames ) {
320
- write (schemaName );
318
+ try {
319
+ final List <String > schemaNames = con .getDataContext ().getSchemaNames ();
320
+ if (schemaNames == null || schemaNames .isEmpty ()) {
321
+ write ("No schemas in datastore!" );
322
+ } else {
323
+ write ("Schemas:" );
324
+ write ("--------" );
325
+ for (final String schemaName : schemaNames ) {
326
+ write (schemaName );
327
+ }
321
328
}
329
+ } finally {
330
+ con .close ();
322
331
}
323
- con .close ();
324
332
}
325
333
}
326
334
}
@@ -367,30 +375,34 @@ protected void runJob(final DataCleanerConfiguration configuration) throws Throw
367
375
FileHelper .safeClose (inputStream );
368
376
}
369
377
370
- final AnalysisRunner runner = new AnalysisRunnerImpl (configuration , new CliProgressAnalysisListener ());
371
- final AnalysisResultFuture resultFuture = runner .run (analysisJobBuilder .toAnalysisJob ());
378
+ try {
379
+ final AnalysisRunner runner = new AnalysisRunnerImpl (configuration , new CliProgressAnalysisListener ());
380
+ final AnalysisResultFuture resultFuture = runner .run (analysisJobBuilder .toAnalysisJob ());
372
381
373
- resultFuture .await ();
382
+ resultFuture .await ();
374
383
375
- if (resultFuture .isSuccessful ()) {
376
- final CliOutputType outputType = _arguments .getOutputType ();
377
- final AnalysisResultWriter writer = outputType .createWriter ();
378
- writer .write (resultFuture , configuration , _writerRef , _outputStreamRef );
379
- } else {
380
- write ("ERROR!" );
381
- write ("------" );
384
+ if (resultFuture .isSuccessful ()) {
385
+ final CliOutputType outputType = _arguments .getOutputType ();
386
+ final AnalysisResultWriter writer = outputType .createWriter ();
387
+ writer .write (resultFuture , configuration , _writerRef , _outputStreamRef );
388
+ } else {
389
+ write ("ERROR!" );
390
+ write ("------" );
382
391
383
- final List <Throwable > errors = resultFuture .getErrors ();
384
- write (errors .size () + " error(s) occurred while executing the job:" );
392
+ final List <Throwable > errors = resultFuture .getErrors ();
393
+ write (errors .size () + " error(s) occurred while executing the job:" );
385
394
386
- for (final Throwable throwable : errors ) {
387
- write ("------" );
388
- final StringWriter stringWriter = new StringWriter ();
389
- throwable .printStackTrace (new PrintWriter (stringWriter ));
390
- write (stringWriter .toString ());
391
- }
395
+ for (final Throwable throwable : errors ) {
396
+ write ("------" );
397
+ final StringWriter stringWriter = new StringWriter ();
398
+ throwable .printStackTrace (new PrintWriter (stringWriter ));
399
+ write (stringWriter .toString ());
400
+ }
392
401
393
- throw errors .get (0 );
402
+ throw errors .get (0 );
403
+ }
404
+ } finally {
405
+ analysisJobBuilder .close ();
394
406
}
395
407
}
396
408
}
@@ -441,22 +453,22 @@ protected void printBeanDescriptors(final Collection<? extends ComponentDescript
441
453
final ConfiguredPropertyDescriptor propertyForInput = propertiesForInput .iterator ().next ();
442
454
if (propertyForInput != null ) {
443
455
if (propertyForInput .isArray ()) {
444
- write (" - Consumes multiple input columns (type: " + propertyForInput . getTypeArgument ( 0 )
445
- .getSimpleName () + ")" );
456
+ write (" - Consumes multiple input columns (type: "
457
+ + propertyForInput . getTypeArgument ( 0 ) .getSimpleName () + ")" );
446
458
} else {
447
- write (" - Consumes a single input column (type: " + propertyForInput . getTypeArgument ( 0 )
448
- .getSimpleName () + ")" );
459
+ write (" - Consumes a single input column (type: "
460
+ + propertyForInput . getTypeArgument ( 0 ) .getSimpleName () + ")" );
449
461
}
450
462
}
451
463
} else {
452
464
write (" - Consumes " + propertiesForInput .size () + " named inputs" );
453
465
for (final ConfiguredPropertyDescriptor propertyForInput : propertiesForInput ) {
454
466
if (propertyForInput .isArray ()) {
455
- write (" Input columns: " + propertyForInput .getName () + " (type: " + propertyForInput
456
- .getTypeArgument (0 ).getSimpleName () + ")" );
467
+ write (" Input columns: " + propertyForInput .getName () + " (type: "
468
+ + propertyForInput .getTypeArgument (0 ).getSimpleName () + ")" );
457
469
} else {
458
- write (" Input column: " + propertyForInput .getName () + " (type: " + propertyForInput
459
- .getTypeArgument (0 ).getSimpleName () + ")" );
470
+ write (" Input column: " + propertyForInput .getName () + " (type: "
471
+ + propertyForInput .getTypeArgument (0 ).getSimpleName () + ")" );
460
472
}
461
473
}
462
474
}
0 commit comments