use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DimensionLookup method init.
@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (DimensionLookupMeta) smi;
data = (DimensionLookupData) sdi;
if (super.init(smi, sdi)) {
meta.actualizeWithInjectedValues();
data.min_date = meta.getMinDate();
data.max_date = meta.getMaxDate();
data.realSchemaName = environmentSubstitute(meta.getSchemaName());
data.realTableName = environmentSubstitute(meta.getTableName());
data.startDateChoice = DimensionLookupMeta.START_DATE_ALTERNATIVE_NONE;
if (meta.isUsingStartDateAlternative()) {
data.startDateChoice = meta.getStartDateAlternative();
}
if (meta.getDatabaseMeta() == null) {
logError(BaseMessages.getString(PKG, "DimensionLookup.Init.ConnectionMissing", getStepname()));
return false;
}
data.db = new Database(this, meta.getDatabaseMeta());
data.db.shareVariablesWith(this);
try {
if (getTransMeta().isUsingUniqueConnections()) {
synchronized (getTrans()) {
data.db.connect(getTrans().getTransactionId(), getPartitionID());
}
} else {
data.db.connect(getPartitionID());
}
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "DimensionLookup.Log.ConnectedToDB"));
}
data.db.setCommit(meta.getCommitSize());
return true;
} catch (KettleException ke) {
logError(BaseMessages.getString(PKG, "DimensionLookup.Log.ErrorOccurredInProcessing") + ke.getMessage());
}
}
return false;
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DatabaseJoinMeta method getTableFields.
@Override
public RowMetaInterface getTableFields() {
// Build a dummy parameter row...
//
RowMetaInterface param = new RowMeta();
for (int i = 0; i < parameterField.length; i++) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(parameterField[i], parameterType[i]);
} catch (KettlePluginException e) {
v = new ValueMetaNone(parameterField[i]);
}
param.addValueMeta(v);
}
RowMetaInterface fields = null;
if (databaseMeta != null) {
Database db = new Database(loggingObject, databaseMeta);
// Keep track of this one for cancelQuery
databases = new Database[] { db };
try {
db.connect();
fields = db.getQueryFields(databaseMeta.environmentSubstitute(sql), true, param, new Object[param.size()]);
} catch (KettleDatabaseException dbe) {
logError(BaseMessages.getString(PKG, "DatabaseJoinMeta.Log.DatabaseErrorOccurred") + dbe.getMessage());
} finally {
db.disconnect();
}
}
return fields;
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DBProcMeta method check.
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
CheckResult cr;
String error_message = "";
if (database != null) {
Database db = new Database(transMeta, database);
try {
db.connect();
// Look up fields in the input stream <prev>
if (prev != null && prev.size() > 0) {
boolean first = true;
error_message = "";
boolean error_found = false;
for (int i = 0; i < argument.length; i++) {
ValueMetaInterface v = prev.searchValueMeta(argument[i]);
if (v == null) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "DBProcMeta.CheckResult.MissingArguments") + Const.CR;
}
error_found = true;
error_message += "\t\t" + argument[i] + Const.CR;
} else {
if (v.getType() != argumentType[i] && !(v.isNumeric() && ValueMetaBase.isNumeric(argumentType[i]))) {
error_found = true;
error_message += "\t\t" + argument[i] + BaseMessages.getString(PKG, "DBProcMeta.CheckResult.WrongTypeArguments", v.getTypeDesc(), ValueMetaFactory.getValueMetaName(argumentType[i])) + Const.CR;
}
}
}
if (error_found) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "DBProcMeta.CheckResult.AllArgumentsOK"), stepMeta);
}
remarks.add(cr);
} else {
error_message = BaseMessages.getString(PKG, "DBProcMeta.CheckResult.CouldNotReadFields") + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
remarks.add(cr);
}
} catch (KettleException e) {
error_message = BaseMessages.getString(PKG, "DBProcMeta.CheckResult.ErrorOccurred") + e.getMessage();
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
remarks.add(cr);
}
} else {
error_message = BaseMessages.getString(PKG, "DBProcMeta.CheckResult.InvalidConnection");
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
remarks.add(cr);
}
// See if we have input streams leading to this step!
if (input.length > 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "DBProcMeta.CheckResult.ReceivingInfoFromOtherSteps"), stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "DBProcMeta.CheckResult.NoInpuReceived"), stepMeta);
remarks.add(cr);
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DimensionLookupMeta method checkLookup.
private void checkLookup(List<CheckResultInterface> remarks, StepMeta stepinfo, RowMetaInterface prev) {
int i;
boolean error_found = false;
String error_message = "";
boolean first;
CheckResult cr;
if (databaseMeta != null) {
Database db = createDatabaseObject();
// TODO SB: share variable space
try {
db.connect();
if (!Utils.isEmpty(tableName)) {
RowMetaInterface tableFields = db.getTableFieldsMeta(schemaName, tableName);
if (tableFields != null) {
if (prev != null && prev.size() > 0) {
// Start at the top, see if the key fields exist:
first = true;
boolean warning_found = false;
for (i = 0; i < keyStream.length; i++) {
// Does the field exist in the input stream?
String strfield = keyStream[i];
//
ValueMetaInterface strvalue = prev.searchValueMeta(strfield);
if (strvalue == null) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyhasProblem") + Const.CR;
}
error_found = true;
error_message += "\t\t" + keyField + BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyNotPresentInStream") + Const.CR;
} else {
// does the field exist in the dimension table?
String dimfield = keyLookup[i];
ValueMetaInterface dimvalue = tableFields.searchValueMeta(dimfield);
if (dimvalue == null) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyhasProblem2") + Const.CR;
}
error_found = true;
error_message += "\t\t" + dimfield + BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyNotPresentInDimensiontable") + databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName) + ")" + Const.CR;
} else {
// Is the streamvalue of the same type as the dimension value?
if (strvalue.getType() != dimvalue.getType()) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyhasProblem3") + Const.CR;
}
warning_found = true;
error_message += "\t\t" + strfield + " (" + strvalue.getOrigin() + BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.KeyNotTheSameTypeAs") + dimfield + " (" + databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName) + ")" + Const.CR;
error_message += BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.WarningInfoInDBConversion");
}
}
}
}
if (error_found) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else if (warning_found) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_WARNING, error_message, stepinfo);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.AllKeysFieldsFound"), stepinfo);
}
remarks.add(cr);
// In case of lookup, the first column of the UpIns dialog table contains the table field
error_found = false;
for (i = 0; i < fieldLookup.length; i++) {
String lufield = fieldLookup[i];
if (lufield != null && lufield.length() > 0) {
// Checking compare field: lufield
ValueMetaInterface v = tableFields.searchValueMeta(lufield);
if (v == null) {
if (first) {
first = false;
error_message += BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.FieldsToRetrieveNotExistInDimension") + Const.CR;
}
error_found = true;
error_message += "\t\t" + lufield + Const.CR;
}
}
}
if (error_found) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.AllFieldsToRetrieveFound"), stepinfo);
}
remarks.add(cr);
/* Also, check the fields: tk, version, from-to, ... */
if (tableFields.indexOfValue(keyField) < 0) {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.TechnicalKeyNotFound", keyField) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.TechnicalKeyFound", keyField) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepinfo);
}
remarks.add(cr);
if (tableFields.indexOfValue(versionField) < 0) {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.VersionFieldNotFound", versionField) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.VersionFieldFound", versionField) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepinfo);
}
remarks.add(cr);
if (tableFields.indexOfValue(dateFrom) < 0) {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.StartOfDaterangeFieldNotFound", dateFrom) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.StartOfDaterangeFieldFound", dateFrom) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepinfo);
}
remarks.add(cr);
if (tableFields.indexOfValue(dateTo) < 0) {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.EndOfDaterangeFieldNotFound", dateTo) + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.EndOfDaterangeFieldFound", dateTo);
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, error_message, stepinfo);
}
remarks.add(cr);
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.CouldNotReadFieldsFromPreviousStep") + Const.CR;
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
}
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.CouldNotReadTableInfo");
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
}
}
} catch (KettleException e) {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.CouldNotConnectDB") + e.getMessage();
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
}
} else {
error_message = BaseMessages.getString(PKG, "DimensionLookupMeta.CheckResult.InvalidConnection");
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepinfo);
remarks.add(cr);
}
}
use of org.pentaho.di.core.database.Database in project pentaho-kettle by pentaho.
the class DynamicSQLRow method init.
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (DynamicSQLRowMeta) smi;
data = (DynamicSQLRowData) sdi;
if (super.init(smi, sdi)) {
if (meta.getDatabaseMeta() == null) {
logError(BaseMessages.getString(PKG, "DynmaicSQLRow.Init.ConnectionMissing", getStepname()));
return false;
}
data.db = new Database(this, meta.getDatabaseMeta());
data.db.shareVariablesWith(this);
try {
if (getTransMeta().isUsingUniqueConnections()) {
synchronized (getTrans()) {
data.db.connect(getTrans().getTransactionId(), getPartitionID());
}
} else {
data.db.connect(getPartitionID());
}
// we never get a commit, but it just turns off auto-commit.
data.db.setCommit(100);
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "DynamicSQLRow.Log.ConnectedToDB"));
}
data.db.setQueryLimit(meta.getRowLimit());
return true;
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "DynamicSQLRow.Log.DatabaseError") + e.getMessage());
if (data.db != null) {
data.db.disconnect();
}
}
}
return false;
}
Aggregations