use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class GPLoadDialog 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
}
}
}
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class GPLoadDialog method getTableName.
private void getTableName(TextVar schema, TextVar tableName) {
DatabaseMeta inf = null;
// New class: SelectTableDialog
int connr = wConnection.getSelectionIndex();
if (connr >= 0) {
inf = transMeta.getDatabase(connr);
}
if (inf != null) {
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "GPLoadDialog.Log.LookingAtConnection") + inf.toString());
}
DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
if (std.open()) {
schema.setText(Const.NVL(std.getSchemaName(), ""));
tableName.setText(Const.NVL(std.getTableName(), ""));
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "GPLoadDialog.InvalidConnection.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "GPLoadDialog.InvalidConnection.DialogTitle"));
mb.open();
}
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class GPBulkLoader method getControlFileContents.
/**
* Get the contents of the control file as specified in the meta object
*
* @param meta
* the meta object to model the control file after
*
* @return a string containing the control file contents
*/
public String getControlFileContents(GPBulkLoaderMeta meta, RowMetaInterface rm, Object[] r) throws KettleException {
DatabaseMeta dm = meta.getDatabaseMeta();
String inputName = "'" + environmentSubstitute(meta.getDataFile()) + "'";
// if ( GPBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals(meta.getLoadMethod()) )
// {
// // if loading is concurrent, the filename has to be a * as sqlldr will
// // read from stdin.
// inputName = "*";
// }
String loadAction = meta.getLoadAction();
StringBuffer contents = new StringBuffer(500);
String tableName = dm.getQuotedSchemaTableCombination(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
// Create a Postgres / Greenplum COPY string for use with a psql client
if (loadAction.equalsIgnoreCase("truncate")) {
contents.append(loadAction + " ");
contents.append(tableName + ";");
contents.append(Const.CR);
}
contents.append("\\COPY ");
// Table name
contents.append(tableName);
// Names of columns
contents.append(" ( ");
String[] streamFields = meta.getFieldStream();
String[] tableFields = meta.getFieldTable();
if (streamFields == null || streamFields.length == 0) {
throw new KettleException("No fields defined to load to database");
}
for (int i = 0; i < streamFields.length; i++) {
if (i != 0) {
contents.append(", ");
}
contents.append(dm.quoteField(tableFields[i]));
}
contents.append(" ) ");
// The "FROM" filename
contents.append(" FROM ");
contents.append(inputName);
// The "FORMAT" clause
contents.append(" WITH CSV ");
// The single row error handling
contents.append("LOG ERRORS INTO ");
contents.append(tableName + "_errors ");
contents.append(" SEGMENT REJECT LIMIT ");
contents.append(meta.getMaxErrors());
return contents.toString();
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class GPBulkLoaderDialog 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
}
}
}
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.
the class GPBulkLoaderDialog method getTableName.
private void getTableName() {
DatabaseMeta inf = null;
// New class: SelectTableDialog
int connr = wConnection.getSelectionIndex();
if (connr >= 0) {
inf = transMeta.getDatabase(connr);
}
if (inf != null) {
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "GPBulkLoaderDialog.Log.LookingAtConnection") + inf.toString());
}
DatabaseExplorerDialog std = new DatabaseExplorerDialog(shell, SWT.NONE, inf, transMeta.getDatabases());
std.setSelectedSchemaAndTable(wSchema.getText(), wTable.getText());
if (std.open()) {
wSchema.setText(Const.NVL(std.getSchemaName(), ""));
wTable.setText(Const.NVL(std.getTableName(), ""));
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "GPBulkLoaderDialog.InvalidConnection.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.InvalidConnection.DialogTitle"));
mb.open();
}
}
Aggregations