use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class PGBulkLoaderDialog method setTableFieldCombo.
private void setTableFieldCombo() {
Runnable fieldLoader = new Runnable() {
public void run() {
if (!wTable.isDisposed() && !wConnection.isDisposed() && !wSchema.isDisposed()) {
final String tableName = wTable.getText(), connectionName = wConnection.getText(), schemaName = wSchema.getText();
// clear
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
if (!Utils.isEmpty(tableName)) {
DatabaseMeta ci = transMeta.findDatabase(connectionName);
if (ci != null) {
Database db = new Database(loggingObject, ci);
try {
db.connect();
String schemaTable = ci.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
RowMetaInterface r = db.getTableFields(schemaTable);
if (null != r) {
String[] fieldNames = r.getFieldNames();
if (null != fieldNames) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(fieldNames);
}
}
}
} catch (Exception e) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
// ignore any errors here. drop downs will not be
// filled, but no problem for the user
} finally {
try {
if (db != null) {
db.disconnect();
}
} catch (Exception ignored) {
// ignore any errors here.
db = null;
}
}
}
}
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class JobEntryEvalTableContentDialog method getSQL.
private void getSQL() {
DatabaseMeta inf = jobMeta.findDatabase(wConnection.getText());
if (inf != null) {
DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, jobMeta.getDatabases());
if (std.open()) {
String sql = "SELECT *" + Const.CR + "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
wSQL.setText(sql);
MessageBox yn = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
yn.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.IncludeFieldNamesInSQL"));
yn.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionQuestion"));
int id = yn.open();
switch(id) {
case SWT.CANCEL:
break;
case SWT.NO:
wSQL.setText(sql);
break;
case SWT.YES:
Database db = new Database(loggingObject, inf);
try {
db.connect();
RowMetaInterface fields = db.getQueryFields(sql, false);
if (fields != null) {
sql = "SELECT" + Const.CR;
for (int i = 0; i < fields.size(); i++) {
ValueMetaInterface field = fields.getValueMeta(i);
if (i == 0) {
sql += " ";
} else {
sql += ", ";
}
sql += inf.quoteField(field.getName()) + Const.CR;
}
sql += "FROM " + inf.getQuotedSchemaTableCombination(std.getSchemaName(), std.getTableName()) + Const.CR;
wSQL.setText(sql);
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ERROR_CouldNotRetrieveFields") + Const.CR + BaseMessages.getString(PKG, "JobEntryEvalTableContent.PerhapsNoPermissions"));
mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError2"));
mb.open();
}
} catch (KettleException e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError3"));
mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.AnErrorOccurred") + Const.CR + e.getMessage());
mb.open();
} finally {
db.disconnect();
}
break;
default:
break;
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "JobEntryEvalTableContent.ConnectionNoLongerAvailable"));
mb.setText(BaseMessages.getString(PKG, "JobEntryEvalTableContent.DialogCaptionError4"));
mb.open();
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class JobEntryColumnsExistDialog method getSchemaNames.
private void getSchemaNames() {
if (wSchemaname.isDisposed()) {
return;
}
DatabaseMeta databaseMeta = jobMeta.findDatabase(wConnection.getText());
if (databaseMeta != null) {
Database database = new Database(loggingObject, databaseMeta);
database.shareVariablesWith(jobMeta);
try {
database.connect();
String[] schemas = database.getSchemas();
if (null != schemas && schemas.length > 0) {
schemas = Const.sortStrings(schemas);
EnterSelectionDialog dialog = new EnterSelectionDialog(shell, schemas, BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Message"));
String d = dialog.open();
if (d != null) {
wSchemaname.setText(Const.NVL(d.toString(), ""));
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Message"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.Empty.Title"));
mb.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "System.Dialog.AvailableSchemas.ConnectionError"), e);
} finally {
if (database != null) {
database.disconnect();
database = null;
}
}
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class MySQLBulkLoaderDialog method setTableFieldCombo.
private void setTableFieldCombo() {
Runnable fieldLoader = new Runnable() {
public void run() {
if (!wTable.isDisposed() && !wConnection.isDisposed() && !wSchema.isDisposed()) {
final String tableName = wTable.getText(), connectionName = wConnection.getText(), schemaName = wSchema.getText();
// clear
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
if (!Utils.isEmpty(tableName)) {
DatabaseMeta ci = transMeta.findDatabase(connectionName);
if (ci != null) {
Database db = new Database(loggingObject, ci);
try {
db.connect();
String schemaTable = ci.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
RowMetaInterface r = db.getTableFields(schemaTable);
if (null != r) {
String[] fieldNames = r.getFieldNames();
if (null != fieldNames) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(fieldNames);
}
}
}
} catch (Exception e) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
// ignore any errors here. drop downs will not be
// filled, but no problem for the user
} finally {
try {
if (db != null) {
db.disconnect();
}
} catch (Exception ignored) {
// ignore any errors here.
db = null;
}
}
}
}
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class MonetDBBulkLoaderDialog method setTableFieldCombo.
protected void setTableFieldCombo() {
Runnable fieldLoader = new Runnable() {
public void run() {
if (!wTable.isDisposed() && !wConnection.isDisposed() && !wSchema.isDisposed()) {
final String tableName = wTable.getText(), connectionName = wConnection.getText(), schemaName = wSchema.getText();
// clear
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
if (!Utils.isEmpty(tableName)) {
DatabaseMeta ci = transMeta.findDatabase(connectionName);
if (ci != null) {
Database db = new Database(loggingObject, ci);
try {
db.connect();
String schemaTable = ci.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
RowMetaInterface r = db.getTableFields(schemaTable);
if (null != r) {
String[] fieldNames = r.getFieldNames();
if (null != fieldNames) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(fieldNames);
}
}
}
} catch (Exception e) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(new String[] {});
}
// ignore any errors here. drop downs will not be
// filled, but no problem for the user
} finally {
try {
if (db != null) {
db.disconnect();
}
} catch (Exception ignored) {
// ignore any errors here.
db = null;
}
}
}
}
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
Aggregations