Search in sources :

Example 1 with ValueMetaDate

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

the class KettleDatabaseRepositoryTransDelegate method insertTransformation.

// CHECKSTYLE:LineLength:OFF
private synchronized void insertTransformation(TransMeta transMeta) throws KettleException {
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION), new LongObjectId(transMeta.getObjectId()));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME), transMeta.getName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION), transMeta.getDescription());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_EXTENDED_DESCRIPTION), transMeta.getExtendedDescription());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_VERSION), transMeta.getTransversion());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_STATUS), new Long(transMeta.getTransstatus() < 0 ? -1L : transMeta.getTransstatus()));
    TransLogTable logTable = transMeta.getTransLogTable();
    StepMeta step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_READ);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_READ), step == null ? null : step.getObjectId());
    step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_WRITTEN);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_WRITE), step == null ? null : step.getObjectId());
    step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_INPUT);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_INPUT), step == null ? null : step.getObjectId());
    step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_OUTPUT);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_OUTPUT), step == null ? null : step.getObjectId());
    step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_UPDATED);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_UPDATE), step == null ? null : step.getObjectId());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_LOG), logTable.getDatabaseMeta() == null ? new LongObjectId(-1L).longValue() : new LongObjectId(logTable.getDatabaseMeta().getObjectId()).longValue());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_LOG), logTable.getDatabaseMeta());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_BATCHID), Boolean.valueOf(logTable.isBatchIdUsed()));
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_LOGFIELD), Boolean.valueOf(logTable.isLogFieldUsed()));
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_MAXDATE), transMeta.getMaxDateConnection() == null ? new LongObjectId(-1L).longValue() : new LongObjectId(transMeta.getMaxDateConnection().getObjectId()).longValue());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_MAXDATE), transMeta.getMaxDateTable());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_FIELD_NAME_MAXDATE), transMeta.getMaxDateField());
    table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_OFFSET_MAXDATE), new Double(transMeta.getMaxDateOffset()));
    table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_DIFF_MAXDATE), new Double(transMeta.getMaxDateDifference()));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_USER), transMeta.getCreatedUser());
    table.addValue(new ValueMetaDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_DATE), transMeta.getCreatedDate());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER), transMeta.getModifiedUser());
    table.addValue(new ValueMetaDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE), transMeta.getModifiedDate());
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_SIZE_ROWSET), new Long(transMeta.getSizeRowset()));
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY), transMeta.getRepositoryDirectory().getObjectId());
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_TRANSFORMATION);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    step = (StepMeta) logTable.getSubject(TransLogTable.ID.LINES_REJECTED);
    if (step != null) {
        ObjectId rejectedId = step.getObjectId();
        repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_ID_STEP_REJECTED, rejectedId == null ? null : Long.valueOf(rejectedId.toString()), null);
    }
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_UNIQUE_CONNECTIONS, 0, transMeta.isUsingUniqueConnections() ? "Y" : "N");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SHOWN, 0, transMeta.isFeedbackShown() ? "Y" : "N");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SIZE, transMeta.getFeedbackSize(), "");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_USING_THREAD_PRIORITIES, 0, transMeta.isUsingThreadPriorityManagment() ? "Y" : "N");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SHARED_FILE, 0, transMeta.getSharedObjectsFile());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_CAPTURE_STEP_PERFORMANCE, 0, transMeta.isCapturingStepPerformanceSnapShots() ? "Y" : "N");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_DELAY, transMeta.getStepPerformanceCapturingDelay(), "");
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_SIZE_LIMIT, 0, transMeta.getStepPerformanceCapturingSizeLimit());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_LOG_TABLE, 0, transMeta.getPerformanceLogTable().getTableName());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_SIZE_LIMIT, 0, transMeta.getTransLogTable().getLogSizeLimit());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_INTERVAL, 0, transMeta.getTransLogTable().getLogInterval());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_TRANSFORMATION_TYPE, 0, transMeta.getTransformationType().getCode());
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_EMPTY, transMeta.getSleepTimeEmpty(), null);
    repository.connectionDelegate.insertTransAttribute(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_FULL, transMeta.getSleepTimeFull(), null);
    // Save the logging connection link...
    if (logTable.getDatabaseMeta() != null) {
        repository.insertStepDatabase(transMeta.getObjectId(), null, logTable.getDatabaseMeta().getObjectId());
    }
    // Save the maxdate connection link...
    if (transMeta.getMaxDateConnection() != null) {
        repository.insertStepDatabase(transMeta.getObjectId(), null, transMeta.getMaxDateConnection().getObjectId());
    }
    // Save the logging tables too..
    // 
    RepositoryAttributeInterface attributeInterface = new KettleDatabaseRepositoryTransAttribute(repository.connectionDelegate, transMeta.getObjectId());
    transMeta.getTransLogTable().saveToRepository(attributeInterface);
    transMeta.getStepLogTable().saveToRepository(attributeInterface);
    transMeta.getPerformanceLogTable().saveToRepository(attributeInterface);
    transMeta.getChannelLogTable().saveToRepository(attributeInterface);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) LongObjectId(org.pentaho.di.repository.LongObjectId) StepMeta(org.pentaho.di.trans.step.StepMeta) RepositoryAttributeInterface(org.pentaho.di.repository.RepositoryAttributeInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) TransLogTable(org.pentaho.di.core.logging.TransLogTable) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate)

Example 2 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate 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 3 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate 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 4 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate 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)

Example 5 with ValueMetaDate

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

the class NeoviewDatabaseMetaTest method testGetValueFromResultSet.

@Test
public void testGetValueFromResultSet() throws Exception {
    Object rtn = null;
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(resultSet.getTimestamp(1)).thenReturn(new java.sql.Timestamp(65535));
    Mockito.when(resultSet.getTime(2)).thenReturn(new java.sql.Time(1000));
    // ValueMetaDate -> Timestamp
    Mockito.when(resultSet.getTimestamp(3)).thenReturn(new java.sql.Timestamp(65535));
    ValueMetaTimestamp ts = new ValueMetaTimestamp("FOO");
    ts.setOriginalColumnType(java.sql.Types.TIMESTAMP);
    ValueMetaDate tm = new ValueMetaDate("BAR");
    tm.setOriginalColumnType(java.sql.Types.TIME);
    ValueMetaDate dt = new ValueMetaDate("WIBBLE");
    dt.setOriginalColumnType(java.sql.Types.DATE);
    rtn = nativeMeta.getValueFromResultSet(resultSet, ts, 0);
    assertNotNull(rtn);
    assertEquals("java.sql.Timestamp", rtn.getClass().getName());
    rtn = nativeMeta.getValueFromResultSet(resultSet, tm, 1);
    assertNotNull(rtn);
    assertEquals("java.sql.Time", rtn.getClass().getName());
    rtn = nativeMeta.getValueFromResultSet(resultSet, dt, 2);
    assertNotNull(rtn);
    assertEquals("java.sql.Timestamp", rtn.getClass().getName());
    Mockito.when(resultSet.wasNull()).thenReturn(true);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaString("WOBBLE"), 3);
    assertNull(rtn);
    // Verify that getDate is not called, getTime is called once, and getTimestamp was called 2 times (once for TimeStamp, once for Date)
    Mockito.verify(resultSet, Mockito.times(0)).getDate(Mockito.anyInt());
    Mockito.verify(resultSet, Mockito.times(1)).getTime(Mockito.anyInt());
    Mockito.verify(resultSet, Mockito.times(2)).getTimestamp(Mockito.anyInt());
    // Now that the date stuff is done, validate the behaviors of other aspects of getValueFromResultSet
    Mockito.when(resultSet.wasNull()).thenReturn(false);
    Mockito.when(resultSet.getBoolean(1)).thenReturn(new Boolean(true));
    Mockito.when(resultSet.getDouble(1)).thenReturn(new Double(15));
    Mockito.when(resultSet.getBigDecimal(1)).thenReturn(new BigDecimal("15"));
    Mockito.when(resultSet.getLong(1)).thenReturn(new Long("15"));
    Mockito.when(resultSet.getString(1)).thenReturn("ASTRING");
    Mockito.when(resultSet.getBytes(1)).thenReturn("ASTRING".getBytes());
    Blob mockBlob = Mockito.mock(Blob.class);
    byte[] bytes = "FOO".getBytes();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    Mockito.when(mockBlob.getBinaryStream()).thenReturn(bais);
    Mockito.when(mockBlob.length()).thenReturn(new Long(bytes.length));
    Mockito.when(mockBlob.getBytes(Mockito.anyLong(), Mockito.anyInt())).thenReturn(bytes);
    Mockito.when(resultSet.getBlob(1)).thenReturn(mockBlob);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaBoolean("FOO"), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof Boolean);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaNumber("FOO", 15, 5), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof Double);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaBigNumber("FOO", 15, 5), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof BigDecimal);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaInteger("FOO", 5, 0), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof Long);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaString("FOO", 25, 0), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof String);
    ValueMetaString binStr = new ValueMetaString("FOO");
    binStr.setStorageType(ValueMetaString.STORAGE_TYPE_BINARY_STRING);
    rtn = nativeMeta.getValueFromResultSet(resultSet, binStr, 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof byte[]);
    rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaBinary("FOO", 150, 0), 0);
    assertNotNull(rtn);
    assertTrue(rtn instanceof byte[]);
    try {
        Mockito.when(resultSet.getBoolean(15)).thenThrow(new SQLException("Expected Exception Here"));
        rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaBoolean("FOO"), 14);
        fail("Should not get here");
    } catch (Exception someException) {
        assertTrue(someException instanceof KettleDatabaseException);
    }
}
Also used : SQLException(java.sql.SQLException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ResultSetMetaData(java.sql.ResultSetMetaData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ResultSet(java.sql.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Blob(java.sql.Blob) BigDecimal(java.math.BigDecimal) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)104 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)63 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)59 Test (org.junit.Test)50 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)44 RowMeta (org.pentaho.di.core.row.RowMeta)43 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)34 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)33 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)25 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)23 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 Calendar (java.util.Calendar)17 Date (java.util.Date)17 KettleException (org.pentaho.di.core.exception.KettleException)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)14 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)10 KettleStepException (org.pentaho.di.core.exception.KettleStepException)10 SQLException (java.sql.SQLException)8