use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class AddSequenceMeta method getSQLStatements.
@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), database, null);
if (useDatabase) {
// Otherwise, don't bother!
if (database != null) {
Database db = new Database(loggingObject, database);
db.shareVariablesWith(transMeta);
try {
db.connect();
if (!db.checkSequenceExists(schemaName, sequenceName)) {
String cr_table = db.getCreateSequenceStatement(sequenceName, startAt, incrementBy, maxValue, true);
retval.setSQL(cr_table);
} else {
// Empty string means: nothing to do: set it to null...
retval.setSQL(null);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "AddSequenceMeta.ErrorMessage.UnableToConnectDB") + Const.CR + e.getMessage());
} finally {
db.disconnect();
}
} else {
retval.setError(BaseMessages.getString(PKG, "AddSequenceMeta.ErrorMessage.NoConnectionDefined"));
}
}
return retval;
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class DeleteMeta method getSQLStatements.
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName);
String cr_table = db.getDDL(schemaTable, prev, null, false, null, true);
String cr_index = "";
String[] idx_fields = null;
if (keyLookup != null && keyLookup.length > 0) {
idx_fields = new String[keyLookup.length];
for (int i = 0; i < keyLookup.length; i++) {
idx_fields[i] = keyLookup[i];
}
} else {
retval.setError(BaseMessages.getString(PKG, "DeleteMeta.CheckResult.KeyFieldsRequired"));
}
// Key lookup dimensions...
if (idx_fields != null && idx_fields.length > 0 && !db.checkIndexExists(schemaTable, idx_fields)) {
String indexname = "idx_" + tableName + "_lookup";
cr_index = db.getCreateIndexStatement(schemaName, tableName, indexname, idx_fields, false, false, false, true);
}
String sql = cr_table + cr_index;
if (sql.length() == 0) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "DeleteMeta.Returnvalue.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "DeleteMeta.Returnvalue.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "DeleteMeta.Returnvalue.NoReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "DeleteMeta.Returnvalue.NoConnectionDefined"));
}
return retval;
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class GPBulkLoaderMeta method getSQLStatements.
@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
// Copy the row
RowMetaInterface tableFields = new RowMeta();
// Now change the field names
for (int i = 0; i < fieldTable.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
if (v != null) {
ValueMetaInterface tableField = v.clone();
tableField.setName(fieldTable[i]);
tableFields.addValueMeta(tableField);
} else {
throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
}
}
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
if (sql.length() == 0) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined"));
}
return retval;
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class GPLoadMeta method getSQLStatements.
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
// default: nothing to do!
SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
if (databaseMeta != null) {
if (prev != null && prev.size() > 0) {
// Copy the row
RowMetaInterface tableFields = new RowMeta();
// Now change the field names
for (int i = 0; i < fieldTable.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
if (v != null) {
ValueMetaInterface tableField = v.clone();
tableField.setName(fieldTable[i]);
tableFields.addValueMeta(tableField);
} else {
throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
}
}
if (!Utils.isEmpty(tableName)) {
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
try {
db.connect();
String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
if (sql.length() == 0) {
retval.setSQL(null);
} else {
retval.setSQL(sql);
}
} catch (KettleException e) {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.ErrorOccurred") + e.getMessage());
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoTableDefinedOnConnection"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NotReceivingAnyFields"));
}
} else {
retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoConnectionDefined"));
}
return retval;
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class LucidDBBulkLoaderDialog method create.
// Generate code for create table...
// Conversions done by Database
private void create() {
try {
LucidDBBulkLoaderMeta info = new LucidDBBulkLoaderMeta();
getInfo(info);
// new name might not yet be linked to other steps!
String name = stepname;
StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.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, "LucidDBBulkLoaderDialog.NoSQLNeeds.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.NoSQLNeeds.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(sql.getError());
mb.setText(BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.SQLError.DialogTitle"));
mb.open();
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "LucidDBBulkLoaderDialog.CouldNotBuildSQL.DialogMessage"), ke);
}
}
Aggregations