Skip to content

Commit

Permalink
Connection is not visible in Snowflake bulk loader apache#3244
Browse files Browse the repository at this point in the history
Remove resource leak
  • Loading branch information
nadment committed Sep 21, 2023
1 parent d51e395 commit a961fa5
Showing 1 changed file with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public String open() {
Shell parent = getParent();
display = parent.getDisplay();

int margin = props.getMargin();
int margin = PropsUi.getMargin();

shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
PropsUi.setLook(shell);
Expand Down Expand Up @@ -342,7 +342,7 @@ public void widgetSelected(SelectionEvent e) {
wLoaderComp.setLayout(loaderLayout);

// Connection line
wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod);
wConnection = addConnectionLine(wLoaderComp, wTransformName, input.getConnection(), lsMod);
if (input.getConnection() == null && pipelineMeta.nrDatabases() == 1) {
wConnection.select(0);
}
Expand Down Expand Up @@ -481,8 +481,7 @@ public void focusGained(FocusEvent focusEvent) {

DatabaseMeta databaseMeta = pipelineMeta.findDatabase(wConnection.getText(), variables);
if (databaseMeta != null) {
Database db = new Database(loggingObject, variables, databaseMeta);
try {
try (Database db = new Database(loggingObject, variables, databaseMeta)) {
db.connect();
String sql = "show stages";
if (!StringUtils.isEmpty(variables.resolve(wSchema.getText()))) {
Expand Down Expand Up @@ -510,13 +509,6 @@ public void focusGained(FocusEvent focusEvent) {

} catch (Exception ex) {
logDebug("Error getting stages", ex);
} finally {
try {

db.disconnect();
} catch (Exception ex) {
// Nothing more we can do
}
}
}
}
Expand Down Expand Up @@ -1291,7 +1283,7 @@ private void getInfo(SnowflakeBulkLoaderMeta sbl) {

int nrfields = wFields.nrNonEmpty();

List<SnowflakeBulkLoaderField> fields = new ArrayList();
List<SnowflakeBulkLoaderField> fields = new ArrayList<>();

for (int i = 0; i < nrfields; i++) {
SnowflakeBulkLoaderField field = new SnowflakeBulkLoaderField();
Expand Down Expand Up @@ -1488,8 +1480,7 @@ private void generateMappings() {
private void getSchemaNames() {
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(wConnection.getText(), variables);
if (databaseMeta != null) {
Database database = new Database(loggingObject, variables, databaseMeta);
try {
try (Database database = new Database(loggingObject, variables, databaseMeta)) {
database.connect();
String[] schemas = database.getSchemas();

Expand Down Expand Up @@ -1525,8 +1516,6 @@ private void getSchemaNames() {
BaseMessages.getString(PKG, "System.Dialog.Error.Title"),
BaseMessages.getString(PKG, "SnowflakeBulkLoader.Dialog.ErrorGettingSchemas"),
e);
} finally {
database.disconnect();
}
}
}
Expand Down Expand Up @@ -1575,14 +1564,14 @@ private void setTableFieldCombo() {
tableField.setComboValues(new String[] {});
}
if (!StringUtils.isEmpty(tableName)) {
DatabaseMeta ci = pipelineMeta.findDatabase(connectionName, variables);
if (ci != null) {
Database db = new Database(loggingObject, variables, ci);
try {
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(connectionName, variables);
if (databaseMeta != null) {
;
try ( Database db = new Database(loggingObject, variables, databaseMeta)) {
db.connect();

String schemaTable =
ci.getQuotedSchemaTableCombination(
databaseMeta.getQuotedSchemaTableCombination(
variables, variables.resolve(schemaName), variables.resolve(tableName));
IRowMeta r = db.getTableFields(schemaTable);
if (null != r) {
Expand All @@ -1597,20 +1586,6 @@ private void setTableFieldCombo() {
for (ColumnInfo tableField : tableFieldColumns) {
tableField.setComboValues(new String[] {});
}
// ignore any errors here. drop downs will not be
// filled, but no problem for the user
} finally {
try {
//noinspection ConstantConditions
if (db != null) {
db.disconnect();
}
} catch (Exception ignored) {
// ignore any errors here. Nothing we can do if
// connection fails to close properly
//noinspection UnusedAssignment
db = null;
}
}
}
}
Expand Down

0 comments on commit a961fa5

Please sign in to comment.