Search in sources :

Example 6 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConditionDelegate method lookupValue.

public synchronized ObjectId lookupValue(String name, String type, String value_str, boolean isnull) throws KettleException {
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_NAME), name);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE), type);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_VALUE_STR), value_str);
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_VALUE_IS_NULL), Boolean.valueOf(isnull));
    String sql = "SELECT " + quote(KettleDatabaseRepository.FIELD_VALUE_ID_VALUE) + " FROM " + quoteTable(KettleDatabaseRepository.TABLE_R_VALUE) + " ";
    sql += "WHERE " + quote(KettleDatabaseRepository.FIELD_VALUE_NAME) + "       = ? ";
    sql += "AND   " + quote(KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE) + " = ? ";
    sql += "AND   " + quote(KettleDatabaseRepository.FIELD_VALUE_VALUE_STR) + "  = ? ";
    sql += "AND   " + quote(KettleDatabaseRepository.FIELD_VALUE_IS_NULL) + "    = ? ";
    RowMetaAndData result = repository.connectionDelegate.getOneRow(sql, table.getRowMeta(), table.getData());
    if (result != null && result.getData() != null && result.isNumeric(0)) {
        return new LongObjectId(result.getInteger(0, 0L));
    } else {
        return null;
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 7 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryJobDelegate method insertJobHop.

public synchronized ObjectId insertJobHop(ObjectId id_job, ObjectId id_jobentry_copy_from, ObjectId id_jobentry_copy_to, boolean enabled, boolean evaluation, boolean unconditional) throws KettleException {
    ObjectId id = repository.connectionDelegate.getNextJobHopID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_HOP_ID_JOB_HOP), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_HOP_ID_JOB), id_job);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_HOP_ID_JOBENTRY_COPY_FROM), id_jobentry_copy_from);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_HOP_ID_JOBENTRY_COPY_TO), id_jobentry_copy_to);
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_HOP_ENABLED), Boolean.valueOf(enabled));
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_HOP_EVALUATION), Boolean.valueOf(evaluation));
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_HOP_UNCONDITIONAL), Boolean.valueOf(unconditional));
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_JOB_HOP);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean)

Example 8 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryJobDelegate method insertJob.

private synchronized void insertJob(JobMeta jobMeta) throws KettleException {
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ID_JOB), jobMeta.getObjectId());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ID_DIRECTORY), jobMeta.getRepositoryDirectory().getObjectId());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_NAME), jobMeta.getName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_DESCRIPTION), jobMeta.getDescription());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_EXTENDED_DESCRIPTION), jobMeta.getExtendedDescription());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_JOB_VERSION), jobMeta.getJobversion());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_JOB_STATUS), new Long(jobMeta.getJobstatus() < 0 ? -1L : jobMeta.getJobstatus()));
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOB_ID_DATABASE_LOG), jobMeta.getJobLogTable().getDatabaseMeta() != null ? jobMeta.getJobLogTable().getDatabaseMeta().getObjectId() : -1L);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_TABLE_NAME_LOG), jobMeta.getJobLogTable().getTableName());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_USE_BATCH_ID), jobMeta.getJobLogTable().isBatchIdUsed());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_USE_LOGFIELD), jobMeta.getJobLogTable().isLogFieldUsed());
    repository.connectionDelegate.insertJobAttribute(jobMeta.getObjectId(), 0, KettleDatabaseRepository.JOB_ATTRIBUTE_LOG_SIZE_LIMIT, 0, jobMeta.getJobLogTable().getLogSizeLimit());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_CREATED_USER), jobMeta.getCreatedUser());
    table.addValue(new ValueMetaDate(KettleDatabaseRepository.FIELD_JOB_CREATED_DATE), jobMeta.getCreatedDate());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_MODIFIED_USER), jobMeta.getModifiedUser());
    table.addValue(new ValueMetaDate(KettleDatabaseRepository.FIELD_JOB_MODIFIED_DATE), jobMeta.getModifiedDate());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_JOB_PASS_BATCH_ID), jobMeta.isBatchIdPassed());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOB_SHARED_FILE), jobMeta.getSharedObjectsFile());
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_JOB);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    if (log.isDebug()) {
        log.logDebug("Inserted new record into table " + quoteTable(KettleDatabaseRepository.TABLE_R_JOB) + " with data : " + table);
    }
    repository.connectionDelegate.getDatabase().closeInsert();
    // Save the logging connection link...
    if (jobMeta.getJobLogTable().getDatabaseMeta() != null) {
        repository.insertJobEntryDatabase(jobMeta.getObjectId(), null, jobMeta.getJobLogTable().getDatabaseMeta().getObjectId());
    }
    // Save the logging tables too..
    // 
    RepositoryAttributeInterface attributeInterface = new KettleDatabaseRepositoryJobAttribute(repository.connectionDelegate, jobMeta.getObjectId());
    for (LogTableInterface logTable : jobMeta.getLogTables()) {
        logTable.saveToRepository(attributeInterface);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) RepositoryAttributeInterface(org.pentaho.di.repository.RepositoryAttributeInterface)

Example 9 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.

the class StringEvaluator method populateConversionMetaList.

private void populateConversionMetaList() {
    int[] trimTypes;
    if (tryTrimming) {
        trimTypes = new int[] { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_BOTH };
    } else {
        trimTypes = new int[] { ValueMetaInterface.TRIM_TYPE_NONE };
    }
    for (int trimType : trimTypes) {
        for (String format : getDateFormats()) {
            ValueMetaInterface conversionMeta = new ValueMetaDate("date");
            conversionMeta.setConversionMask(format);
            conversionMeta.setTrimType(trimType);
            conversionMeta.setDateFormatLenient(false);
            evaluationResults.add(new StringEvaluationResult(conversionMeta));
        }
        EvalResultBuilder numberUsBuilder = new EvalResultBuilder("number-us", ValueMetaInterface.TYPE_NUMBER, 15, trimType, ".", ",");
        EvalResultBuilder numberEuBuilder = new EvalResultBuilder("number-eu", ValueMetaInterface.TYPE_NUMBER, 15, trimType, ",", ".");
        for (String format : getNumberFormats()) {
            if (format.equals("#") || format.equals("0")) {
                // skip the integer ones. we'll get those later
                continue;
            }
            int precision = determinePrecision(format);
            evaluationResults.add(numberUsBuilder.format(format, precision).build());
            evaluationResults.add(numberEuBuilder.format(format, precision).build());
        }
        // Try the locale's Currency
        DecimalFormat currencyFormat = ((DecimalFormat) NumberFormat.getCurrencyInstance());
        ValueMetaInterface conversionMeta = new ValueMetaNumber("number-currency");
        // replace the universal currency symbol with the locale's currency symbol for user recognition
        String currencyMask = currencyFormat.toLocalizedPattern().replace("\u00A4", currencyFormat.getCurrency().getSymbol());
        conversionMeta.setConversionMask(currencyMask);
        conversionMeta.setTrimType(trimType);
        conversionMeta.setDecimalSymbol(String.valueOf(currencyFormat.getDecimalFormatSymbols().getDecimalSeparator()));
        conversionMeta.setGroupingSymbol(String.valueOf(currencyFormat.getDecimalFormatSymbols().getGroupingSeparator()));
        conversionMeta.setCurrencySymbol(currencyFormat.getCurrency().getSymbol());
        conversionMeta.setLength(15);
        int currencyPrecision = currencyFormat.getCurrency().getDefaultFractionDigits();
        conversionMeta.setPrecision(currencyPrecision);
        evaluationResults.add(new StringEvaluationResult(conversionMeta));
        // add same mask w/o currency symbol
        String currencyMaskAsNumeric = currencyMask.replaceAll(Pattern.quote(currencyFormat.getCurrency().getSymbol()), "");
        evaluationResults.add(numberUsBuilder.format(currencyMaskAsNumeric, currencyPrecision).build());
        evaluationResults.add(numberEuBuilder.format(currencyMaskAsNumeric, currencyPrecision).build());
        // Integer
        // 
        conversionMeta = new ValueMetaInteger("integer");
        conversionMeta.setConversionMask("#");
        conversionMeta.setLength(15);
        evaluationResults.add(new StringEvaluationResult(conversionMeta));
        conversionMeta = new ValueMetaInteger("integer");
        conversionMeta.setConversionMask(" #");
        conversionMeta.setLength(15);
        evaluationResults.add(new StringEvaluationResult(conversionMeta));
        // 
        for (int i = 1; i <= 15; i++) {
            String mask = " ";
            for (int x = 0; x < i; x++) {
                mask += "0";
            }
            mask += ";-";
            for (int x = 0; x < i; x++) {
                mask += "0";
            }
            conversionMeta = new ValueMetaInteger("integer-zero-padded-" + i);
            conversionMeta.setConversionMask(mask);
            conversionMeta.setLength(i);
            evaluationResults.add(new StringEvaluationResult(conversionMeta));
        }
        // Boolean
        // 
        conversionMeta = new ValueMetaBoolean("boolean");
        evaluationResults.add(new StringEvaluationResult(conversionMeta));
    }
}
Also used : ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) DecimalFormat(java.text.DecimalFormat) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 10 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.

the class MSSQLServerDatabaseMetaTest method testSQLStatements.

@Test
public void testSQLStatements() {
    assertEquals("SELECT TOP 1 * FROM FOO", nativeMeta.getSQLQueryFields("FOO"));
    String lineSep = System.getProperty("line.separator");
    assertEquals("SELECT top 0 * FROM FOO WITH (UPDLOCK, HOLDLOCK);" + lineSep + "SELECT top 0 * FROM BAR WITH (UPDLOCK, HOLDLOCK);" + lineSep, nativeMeta.getSQLLockTables(new String[] { "FOO", "BAR" }));
    assertEquals("ALTER TABLE FOO ADD BAR DATETIME", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD BAR DATETIME", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
    assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(15)", nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
    assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(100)", nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR"), "", false, "", true));
    // some subclass of the MSSQL meta probably ...
    odbcMeta.setSupportsBooleanDataType(true);
    assertEquals("ALTER TABLE FOO ADD BAR BIT", odbcMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
    odbcMeta.setSupportsBooleanDataType(false);
    assertEquals("select o.name from sysobjects o, sysusers u where  xtype in ( 'FN', 'P' ) and o.uid = u.uid order by o.name", nativeMeta.getSQLListOfProcedures("FOO"));
    assertEquals("select name from sys.schemas", nativeMeta.getSQLListOfSchemas());
    assertEquals("insert into FOO(FOOVERSION) values (1)", nativeMeta.getSQLInsertAutoIncUnknownDimensionRow("FOO", "FOOKEY", "FOOVERSION"));
    assertEquals("SELECT NEXT VALUE FOR FOO", nativeMeta.getSQLNextSequenceValue("FOO"));
    assertEquals("SELECT current_value FROM sys.sequences WHERE name = 'FOO'", nativeMeta.getSQLCurrentSequenceValue("FOO"));
    assertEquals("SELECT 1 FROM sys.sequences WHERE name = 'FOO'", nativeMeta.getSQLSequenceExists("FOO"));
    assertEquals("SELECT name FROM sys.sequences", nativeMeta.getSQLListOfSequences());
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Aggregations

ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)84 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)68 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)60 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)46 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)32 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)25 RowMeta (org.pentaho.di.core.row.RowMeta)22 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)18 Test (org.junit.Test)16 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 KettleException (org.pentaho.di.core.exception.KettleException)13 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 ObjectId (org.pentaho.di.repository.ObjectId)12 LongObjectId (org.pentaho.di.repository.LongObjectId)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)7 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6