use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.
the class TableAgileMart method dropTable.
@Override
public boolean dropTable() {
TableOutputMeta meta = getMeta();
TableOutputData data = getData();
String schema = meta.getSchemaName();
String table = meta.getTableName();
if (schema != null && !schema.equals("")) {
table = schema + "." + table;
}
String sql = "drop table " + table + ";";
try {
Result result = data.db.execStatement(sql);
int status = result.getExitStatus();
if (status == 0) {
util.updateMetadata(meta, -1);
}
return status == 0;
} catch (KettleDatabaseException e) {
message = "Could not drop table: " + table;
logError(message, e);
}
return false;
}
use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.
the class TableAgileMart method truncateTable.
@Override
public boolean truncateTable() {
TableOutputMeta meta = getMeta();
TableOutputData data = getData();
try {
data.db.truncateTable(environmentSubstitute(meta.getSchemaName()), environmentSubstitute(meta.getTableName()));
util.updateMetadata(meta, -1);
return true;
} catch (KettleDatabaseException e) {
message = "Could not truncate table: " + meta.getTableName();
logError(message, e);
}
return false;
}
use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.
the class TableAgileMart method processRow.
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
if (rowLimit != -1 && rowsWritten >= rowLimit) {
// we are done, ignore any new rows
TableOutputMeta meta = (TableOutputMeta) smi;
util.updateMetadata(meta, rowsWritten);
throw new KettleException("Row limit exceeded");
}
boolean result = super.processRow(smi, sdi);
if (result) {
rowsWritten++;
} else {
TableOutputMeta meta = (TableOutputMeta) smi;
util.updateMetadata(meta, rowsWritten);
}
return result;
}
use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta 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.trans.steps.tableoutput.TableOutputMeta in project pentaho-kettle by pentaho.
the class JobGenerator method generateDateTransformation.
private TransMeta generateDateTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
// We actually load the transformation from a template and then slightly modify it.
//
String filename = "/org/pentaho/di/resources/Generate date dimension.ktr";
InputStream inputStream = getClass().getResourceAsStream(filename);
TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);
// Find the table output step and inject the target table name and database...
//
StepMeta stepMeta = transMeta.findStep("TARGET");
if (stepMeta != null) {
TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
meta.setDatabaseMeta(databaseMeta);
String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
meta.setTableName(phTable);
}
return transMeta;
}
Aggregations