use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DeleteDialog method getSchemaNames.
private void getSchemaNames() {
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta != null) {
Database database = new Database(loggingObject, databaseMeta);
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, "DeleteDialog.AvailableSchemas.Title", wConnection.getText()), BaseMessages.getString(PKG, "DeleteDialog.AvailableSchemas.Message", wConnection.getText()));
String d = dialog.open();
if (d != null) {
wSchema.setText(Const.NVL(d, ""));
setTableFieldCombo();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "DeleteDialog.NoSchema.Error"));
mb.setText(BaseMessages.getString(PKG, "DeleteDialog.GetSchemas.Error"));
mb.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "DeleteDialog.ErrorGettingSchemas"), e);
} finally {
database.disconnect();
}
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DimensionLookupDialog method getFieldsFromTable.
private void getFieldsFromTable() {
if (!gotTableFields) {
if (!Utils.isEmpty(wTable.getText())) {
DatabaseMeta ci = transMeta.findDatabase(wConnection.getText());
if (ci != null) {
Database db = new Database(loggingObject, ci);
try {
db.connect();
RowMetaInterface r = db.getTableFieldsMeta(transMeta.environmentSubstitute(wSchema.getText()), transMeta.environmentSubstitute(wTable.getText()));
if (null != r) {
String[] fieldNames = r.getFieldNames();
if (null != fieldNames) {
// Version
String version = wVersion.getText();
wVersion.setItems(fieldNames);
if (version != null) {
wVersion.setText(version);
}
// from date
String fromdate = wFromdate.getText();
wFromdate.setItems(fieldNames);
if (fromdate != null) {
wFromdate.setText(fromdate);
}
// to date
String todate = wTodate.getText();
wTodate.setItems(fieldNames);
if (todate != null) {
wTodate.setText(todate);
}
// tk
String tk = wTk.getText();
wTk.setItems(fieldNames);
if (tk != null) {
wTk.setText(tk);
}
// AltStartDateField
String sd = wAltStartDateField.getText();
wAltStartDateField.setItems(fieldNames);
if (sd != null) {
wAltStartDateField.setText(sd);
}
}
}
} catch (Exception e) {
// ignore any errors here. drop downs will not be
// filled, but no problem for the user
}
}
}
gotTableFields = true;
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DimensionLookupDialog method getLookup.
/**
* Get the fields from the table in the database and use them as lookup keys. Only get the the fields which are not
* yet in use as key, or in the field table. Also ignore technical key, version, fromdate, todate.
*/
private void getLookup() {
DatabaseMeta databaseMeta = transMeta.findDatabase(wConnection.getText());
if (databaseMeta != null) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
RowMetaInterface r = db.getTableFieldsMeta(wSchema.getText(), wTable.getText());
if (r != null && !r.isEmpty()) {
BaseStepDialog.getFieldsFromPrevious(r, wUpIns, 2, new int[] { 1, 2 }, new int[] { 3 }, -1, -1, new TableItemInsertListener() {
public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
int idx = wKey.indexOfString(v.getName(), 2);
return idx < 0 && !v.getName().equalsIgnoreCase(wTk.getText()) && !v.getName().equalsIgnoreCase(wVersion.getText()) && !v.getName().equalsIgnoreCase(wFromdate.getText()) && !v.getName().equalsIgnoreCase(wTodate.getText());
}
});
}
} catch (KettleException e) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.ErrorOccurred.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.ErrorOccurred.DialogMessage") + Const.CR + e.getMessage());
mb.open();
} finally {
db.disconnect();
}
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DimensionLookupDialog method setTableFieldCombo.
// Set table "dimension field" and "technical key" drop downs
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[] {});
}
// Ensure other table field dropdowns are refreshed fields when they
// next get focus
gotTableFields = false;
if (!Utils.isEmpty(tableName)) {
DatabaseMeta ci = transMeta.findDatabase(connectionName);
if (ci != null) {
Database db = new Database(loggingObject, ci);
try {
db.connect();
RowMetaInterface r = db.getTableFieldsMeta(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
if (null != r) {
String[] fieldNames = r.getFieldNames();
if (null != fieldNames) {
for (ColumnInfo colInfo : tableFieldColumns) {
colInfo.setComboValues(fieldNames);
}
wTk.setItems(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 LucidDBStreamingLoaderMeta method getRequiredFields.
public RowMetaInterface getRequiredFields(VariableSpace space) throws KettleException {
String realTableName = space.environmentSubstitute(tableName);
String realSchemaName = space.environmentSubstitute(schemaName);
if (databaseMeta != null) {
Database db = new Database(loggingObject, databaseMeta);
try {
db.connect();
if (!Utils.isEmpty(realTableName)) {
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(realSchemaName, realTableName);
// Check if this table exists...
if (db.checkTableExists(schemaTable)) {
return db.getTableFields(schemaTable);
} else {
throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotFound"));
}
} else {
throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.TableNotSpecified"));
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.ErrorGettingFields"), e);
} finally {
db.disconnect();
}
} else {
throw new KettleException(BaseMessages.getString(PKG, "LucidDBStreamingLoaderMeta.Exception.ConnectionNotDefined"));
}
}
Aggregations