use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.
the class TransDialog method sql.
/**
* Generates code for create table... Conversions done by Database
*/
private void sql() {
getLogInfo();
try {
boolean allOK = true;
for (LogTableInterface logTable : new LogTableInterface[] { transLogTable, performanceLogTable, channelLogTable, stepLogTable, metricsLogTable }) {
if (logTable.getDatabaseMeta() != null && !Utils.isEmpty(logTable.getTableName())) {
// OK, we have something to work with!
//
Database db = null;
try {
db = new Database(transMeta, logTable.getDatabaseMeta());
db.shareVariablesWith(transMeta);
db.connect();
StringBuilder ddl = new StringBuilder();
RowMetaInterface fields = logTable.getLogRecord(LogStatus.START, null, null).getRowMeta();
String tableName = db.environmentSubstitute(logTable.getTableName());
String schemaTable = logTable.getDatabaseMeta().getQuotedSchemaTableCombination(db.environmentSubstitute(logTable.getSchemaName()), tableName);
String createTable = db.getDDL(schemaTable, fields);
if (!Utils.isEmpty(createTable)) {
ddl.append("-- ").append(logTable.getLogTableType()).append(Const.CR);
ddl.append("--").append(Const.CR).append(Const.CR);
ddl.append(createTable).append(Const.CR);
}
java.util.List<RowMetaInterface> indexes = logTable.getRecommendedIndexes();
for (int i = 0; i < indexes.size(); i++) {
RowMetaInterface index = indexes.get(i);
if (!index.isEmpty()) {
String createIndex = db.getCreateIndexStatement(schemaTable, "IDX_" + tableName + "_" + (i + 1), index.getFieldNames(), false, false, false, true);
if (!Utils.isEmpty(createIndex)) {
ddl.append(createIndex);
}
}
}
if (ddl.length() > 0) {
allOK = false;
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, logTable.getDatabaseMeta(), transMeta.getDbCache(), ddl.toString());
sqledit.open();
}
} finally {
if (db != null) {
db.disconnect();
}
}
}
}
if (allOK) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setText(BaseMessages.getString(PKG, "TransDialog.NoSqlNedds.DialogTitle"));
mb.setMessage(BaseMessages.getString(PKG, "TransDialog.NoSqlNedds.DialogMessage"));
mb.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TransDialog.ErrorOccurred.DialogTitle"), BaseMessages.getString(PKG, "TransDialog.ErrorOccurred.DialogMessage"), e);
}
}
use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.
the class SynchronizeAfterMergeDialog method create.
// Generate code for create table...
// Conversions done by Database
private void create() {
try {
SynchronizeAfterMergeMeta info = new SynchronizeAfterMergeMeta();
getInfo(info);
// new name might not yet be linked to other steps!
String name = stepname;
StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.StepMeta.Title"), name, info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(sql.getError());
mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.SQLError.DialogTitle"));
mb.open();
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.CouldNotBuildSQL.DialogMessage"), ke);
}
}
use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.
the class TableOutputDialog method sql.
// Generate code for create table...
// Conversions done by Database
//
private void sql() {
try {
TableOutputMeta info = new TableOutputMeta();
getInfo(info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
if (info.isTableNameInField() && !info.isTableNameInTable() && info.getTableNameField().length() > 0) {
int idx = prev.indexOfValue(info.getTableNameField());
if (idx >= 0) {
prev.removeValueMeta(idx);
}
}
StepMeta stepMeta = transMeta.findStep(stepname);
if (info.specifyFields()) {
// Only use the fields that were specified.
RowMetaInterface prevNew = new RowMeta();
for (int i = 0; i < info.getFieldDatabase().length; i++) {
ValueMetaInterface insValue = prev.searchValueMeta(info.getFieldStream()[i]);
if (insValue != null) {
ValueMetaInterface insertValue = insValue.clone();
insertValue.setName(info.getFieldDatabase()[i]);
prevNew.addValueMeta(insertValue);
} else {
throw new KettleStepException(BaseMessages.getString(PKG, "TableOutputDialog.FailedToFindField.Message", info.getFieldStream()[i]));
}
}
prev = prevNew;
}
boolean autoInc = false;
String pk = null;
//
if (info.isReturningGeneratedKeys() && !Utils.isEmpty(info.getGeneratedKeyField())) {
ValueMetaInterface valueMeta = new ValueMetaInteger(info.getGeneratedKeyField());
valueMeta.setLength(15);
prev.addValueMeta(0, valueMeta);
autoInc = true;
pk = info.getGeneratedKeyField();
}
if (isValidRowMeta(prev)) {
SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, pk, autoInc, pk);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
String message = getBaseMessage("TableOutputDialog.NoSQL.DialogMessage");
String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
showMessage(shell, SWT.OK | SWT.ICON_INFORMATION, message, text);
}
} else {
String text = getBaseMessage("System.Dialog.Error.Title");
showMessage(shell, SWT.OK | SWT.ICON_ERROR, sql.getError(), text);
}
} else {
String message = getBaseMessage("TableOutputDialog.NoSQL.EmptyCSVFields");
String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
showMessage(shell, SWT.OK | SWT.ICON_ERROR, message, text);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogTitle"), BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogMessage"), ke);
}
}
use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.
the class DimensionLookupDialog method create.
// Generate code for create table...
// Conversions done by Database
// For Sybase ASE: don't keep everything in lowercase!
private void create() {
try {
DimensionLookupMeta info = new DimensionLookupMeta();
getInfo(info);
// new name might not yet be linked to other
String name = stepname;
// steps!
StepMeta stepinfo = new StepMeta(BaseMessages.getString(PKG, "DimensionLookupDialog.Stepinfo.Title"), name, info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
String message = null;
if (Utils.isEmpty(info.getKeyField())) {
message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTechnicalKeySpecified");
}
if (Utils.isEmpty(info.getTableName())) {
message = BaseMessages.getString(PKG, "DimensionLookupDialog.Error.NoTableNameSpecified");
}
if (message == null) {
SQLStatement sql = info.getSQLStatements(transMeta, stepinfo, prev, repository, metaStore);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.NoSQLNeeds.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(sql.getError());
mb.setText(BaseMessages.getString(PKG, "DimensionLookupDialog.SQLError.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(message);
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogMessage"), BaseMessages.getString(PKG, "DimensionLookupDialog.UnableToBuildSQLError.DialogTitle"), ke);
}
}
use of org.pentaho.di.ui.core.database.dialog.SQLEditor in project pentaho-kettle by pentaho.
the class GPBulkLoaderDialog method create.
// Generate code for create table...
// Conversions done by Database
private void create() {
try {
GPBulkLoaderMeta info = new GPBulkLoaderMeta();
getInfo(info);
// new name might not yet be linked to other steps!
String name = stepname;
StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "GPBulkLoaderDialog.StepMeta.Title"), name, info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "GPBulkLoaderDialog.NoSQLNeeds.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.NoSQLNeeds.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(sql.getError());
mb.setText(BaseMessages.getString(PKG, "GPBulkLoaderDialog.SQLError.DialogTitle"));
mb.open();
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "GPBulkLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "GPBulkLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
}
}
Aggregations