Search in sources :

Example 1 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testMetdataPreviewSqlNumericWithStrictBigNumberInterpretationUsingOracle.

@Test
public void testMetdataPreviewSqlNumericWithStrictBigNumberInterpretationUsingOracle() throws SQLException, KettleDatabaseException {
    doReturn(Types.NUMERIC).when(resultSet).getInt("DATA_TYPE");
    doReturn(38).when(resultSet).getInt("COLUMN_SIZE");
    doReturn(mock(Object.class)).when(resultSet).getObject("DECIMAL_DIGITS");
    doReturn(0).when(resultSet).getInt("DECIMAL_DIGITS");
    doReturn(mock(OracleDatabaseMeta.class)).when(dbMetaMock).getDatabaseInterface();
    when(((OracleDatabaseMeta) dbMetaMock.getDatabaseInterface()).strictBigNumberInterpretation()).thenReturn(true);
    ValueMetaInterface valueMeta = valueMetaBase.getMetadataPreview(dbMetaMock, resultSet);
    assertTrue(valueMeta.isBigNumber());
}
Also used : OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) LoggingObject(org.pentaho.di.core.logging.LoggingObject) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 2 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method getInfo.

protected void getInfo(DatabaseMeta meta) {
    getControls();
    if (this.databaseMeta != null && this.databaseMeta != meta) {
        meta.initializeVariablesFrom(this.databaseMeta);
    }
    // Let's not remove any (default) options or attributes
    // We just need to display the correct ones for the database type below...
    // 
    // In fact, let's just clear the database port...
    // 
    // TODO: what about the port number?
    // Name:
    meta.setName(connectionNameBox.getValue());
    // Display Name: (PDI-12292)
    meta.setDisplayName(connectionNameBox.getValue());
    // Connection type:
    Object connection = connectionBox.getSelectedItem();
    if (connection != null) {
        meta.setDatabaseType((String) connection);
    }
    // Access type:
    Object access = accessBox.getSelectedItem();
    if (access != null) {
        meta.setAccessType(DatabaseMeta.getAccessType((String) access));
    }
    getConnectionSpecificInfo(meta);
    // Port number:
    if (portNumberBox != null) {
        meta.setDBPort(portNumberBox.getValue());
    }
    if (optionsParameterTree != null) {
        Object[][] values = optionsParameterTree.getValues();
        for (int i = 0; i < values.length; i++) {
            String parameter = (String) values[i][0];
            String value = (String) values[i][1];
            if (value == null) {
                value = "";
            }
            String dbType = meta.getPluginId();
            // Only if parameter are supplied, we will add to the map...
            if ((parameter != null) && (parameter.trim().length() > 0)) {
                if (value.trim().length() <= 0) {
                    value = DatabaseMeta.EMPTY_OPTIONS_STRING;
                }
                meta.addExtraOption(dbType, parameter, value);
            }
        }
    }
    if (supportBooleanDataType != null) {
        meta.setSupportsBooleanDataType(supportBooleanDataType.isChecked());
    }
    if (supportTimestampDataType != null) {
        meta.setSupportsTimestampDataType(supportTimestampDataType.isChecked());
    }
    if (quoteIdentifiersCheck != null) {
        meta.setQuoteAllFields(quoteIdentifiersCheck.isChecked());
    }
    if (lowerCaseIdentifiersCheck != null) {
        meta.setForcingIdentifiersToLowerCase(lowerCaseIdentifiersCheck.isChecked());
    }
    if (upperCaseIdentifiersCheck != null) {
        meta.setForcingIdentifiersToUpperCase(upperCaseIdentifiersCheck.isChecked());
    }
    if (preserveReservedCaseCheck != null) {
        meta.setPreserveReservedCase(preserveReservedCaseCheck.isChecked());
    }
    if (strictBigNumberInterpretaion != null && meta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
        ((OracleDatabaseMeta) meta.getDatabaseInterface()).setStrictBigNumberInterpretation(strictBigNumberInterpretaion.isChecked());
    }
    if (preferredSchemaName != null) {
        meta.setPreferredSchemaName(preferredSchemaName.getValue());
    }
    if (sqlBox != null) {
        meta.setConnectSQL(sqlBox.getValue());
    }
    // Cluster panel settings
    if (clusteringCheck != null) {
        meta.setPartitioned(clusteringCheck.isChecked());
    }
    if ((clusterParameterTree != null) && (meta.isPartitioned())) {
        Object[][] values = clusterParameterTree.getValues();
        List<PartitionDatabaseMeta> pdms = new ArrayList<PartitionDatabaseMeta>();
        for (int i = 0; i < values.length; i++) {
            String partitionId = (String) values[i][0];
            if ((partitionId == null) || (partitionId.trim().length() <= 0)) {
                continue;
            }
            String hostname = (String) values[i][1];
            String port = (String) values[i][2];
            String dbName = (String) values[i][3];
            String username = (String) values[i][4];
            String password = (String) values[i][5];
            PartitionDatabaseMeta pdm = new PartitionDatabaseMeta(partitionId, hostname, port, dbName);
            pdm.setUsername(username);
            pdm.setPassword(password);
            pdms.add(pdm);
        }
        PartitionDatabaseMeta[] pdmArray = new PartitionDatabaseMeta[pdms.size()];
        meta.setPartitioningInformation(pdms.toArray(pdmArray));
    }
    if (poolingCheck != null) {
        meta.setUsingConnectionPool(poolingCheck.isChecked());
    }
    if (meta.isUsingConnectionPool()) {
        if (poolSizeBox != null) {
            try {
                meta.setInitialPoolSizeString(poolSizeBox.getValue());
            } catch (NumberFormatException e) {
            // TODO log exception and move on ...
            }
        }
        if (maxPoolSizeBox != null) {
            try {
                meta.setMaximumPoolSizeString(maxPoolSizeBox.getValue());
            } catch (NumberFormatException e) {
            // TODO log exception and move on ...
            }
        }
        if (poolParameterTree != null) {
            Object[][] values = poolParameterTree.getValues();
            Properties properties = new Properties();
            for (int i = 0; i < values.length; i++) {
                boolean isChecked = false;
                if (values[i][0] instanceof Boolean) {
                    isChecked = ((Boolean) values[i][0]).booleanValue();
                } else {
                    isChecked = Boolean.valueOf((String) values[i][0]);
                }
                if (!isChecked) {
                    continue;
                }
                String parameter = (String) values[i][1];
                String value = (String) values[i][2];
                if ((parameter != null) && (parameter.trim().length() > 0) && (value != null) && (value.trim().length() > 0)) {
                    properties.setProperty(parameter, value);
                }
            }
            meta.setConnectionPoolingProperties(properties);
        }
    }
}
Also used : OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) ArrayList(java.util.ArrayList) PartitionDatabaseMeta(org.pentaho.di.core.database.PartitionDatabaseMeta) Properties(java.util.Properties)

Example 3 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method setConnectionSpecificInfo.

protected void setConnectionSpecificInfo(DatabaseMeta meta) {
    getControls();
    if (databaseDialectList != null) {
        databaseDialectList.setElements(databaseDialects);
        DatabaseInterface databaseInterface = meta.getDatabaseInterface();
        if (databaseInterface instanceof GenericDatabaseMeta) {
            databaseDialectList.setSelectedItem(((GenericDatabaseMeta) databaseInterface).getDatabaseDialect());
        }
    }
    if (namedClusterList != null) {
        List<String> namedClusters = meta.getDatabaseInterface().getNamedClusterList();
        if (namedClusters != null) {
            namedClusterList.setElements(namedClusters);
            if (meta.getNamedCluster() != null) {
                namedClusterList.setSelectedItem(meta.getDatabaseInterface().getNamedCluster());
                namedClusterList.setValue(meta.getDatabaseInterface().getNamedCluster());
            }
        }
    }
    if (hostNameBox != null) {
        hostNameBox.setValue(meta.getHostname());
    }
    // Database name:
    if (databaseNameBox != null) {
        databaseNameBox.setValue(meta.getDatabaseName());
    }
    // Username:
    if (userNameBox != null) {
        userNameBox.setValue(meta.getUsername());
    }
    // Password:
    if (passwordBox != null) {
        passwordBox.setValue(meta.getPassword());
    }
    // Streaming result cursor:
    if (resultStreamingCursorCheck != null) {
        resultStreamingCursorCheck.setChecked(meta.isStreamingResults());
    }
    // Data tablespace:
    if (dataTablespaceBox != null) {
        dataTablespaceBox.setValue(meta.getDataTablespace());
    }
    // Index tablespace
    if (indexTablespaceBox != null) {
        indexTablespaceBox.setValue(meta.getIndexTablespace());
    }
    // Strict Number(38) interpretation
    if (strictBigNumberInterpretaion != null) {
        // Check if oracle
        if (meta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
            strictBigNumberInterpretaion.setVisible(true);
            strictBigNumberInterpretaion.setChecked(((OracleDatabaseMeta) meta.getDatabaseInterface()).strictBigNumberInterpretation());
        } else {
            strictBigNumberInterpretaion.setVisible(false);
            strictBigNumberInterpretaion.setChecked(false);
        }
    }
    if (serverInstanceBox != null) {
        serverInstanceBox.setValue(meta.getSQLServerInstance());
    }
    // SQL Server double decimal separator
    if (doubleDecimalSeparatorCheck != null) {
        doubleDecimalSeparatorCheck.setChecked(meta.isUsingDoubleDecimalAsSchemaTableSeparator());
    }
    // SAP Attributes...
    if (languageBox != null) {
        languageBox.setValue(meta.getAttributes().getProperty("SAPLanguage"));
    }
    if (systemNumberBox != null) {
        systemNumberBox.setValue(meta.getAttributes().getProperty("SAPSystemNumber"));
    }
    if (clientBox != null) {
        clientBox.setValue(meta.getAttributes().getProperty("SAPClient"));
    }
    // Snowflake
    if (warehouseBox != null) {
        warehouseBox.setValue(meta.getAttributes().getProperty(WAREHOUSE));
    }
    // Generic settings...
    if (customUrlBox != null) {
        customUrlBox.setValue(meta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL));
    }
    if (customDriverClassBox != null) {
        customDriverClassBox.setValue(meta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS));
    }
    // Server Name: (Informix)
    if (serverNameBox != null) {
        serverNameBox.setValue(meta.getServername());
    }
    // Microsoft SQL Server Use Integrated Security
    if (useIntegratedSecurityCheck != null) {
        Object value = meta.getAttributes().get(MSSQLServerNativeDatabaseMeta.ATTRIBUTE_USE_INTEGRATED_SECURITY);
        if (value != null && value instanceof String) {
            String useIntegratedSecurity = (String) value;
            useIntegratedSecurityCheck.setChecked(Boolean.parseBoolean(useIntegratedSecurity));
        } else {
            useIntegratedSecurityCheck.setChecked(false);
        }
    }
    if (azureSqlDBJdbcAuthMethod != null) {
        azureSqlDBJdbcAuthMethod.setValue(meta.getAttributes().getProperty(JDBC_AUTH_METHOD, SQL_AUTHENTICATION));
    }
    if (azureSqlDBAlwaysEncryptionEnabled != null && meta.getAttributes().getProperty(IS_ALWAYS_ENCRYPTION_ENABLED) != null) {
        azureSqlDBAlwaysEncryptionEnabled.setChecked(meta.getAttributes().getProperty(IS_ALWAYS_ENCRYPTION_ENABLED).equals("true"));
    }
    if (azureSqlDBClientSecretId != null) {
        azureSqlDBClientSecretId.setValue(meta.getAttributes().getProperty(CLIENT_ID));
    }
    if (azureSqlDBClientSecretKey != null) {
        azureSqlDBClientSecretKey.setValue(meta.getAttributes().getProperty(CLIENT_SECRET_KEY));
    }
    if (jdbcAuthMethod != null) {
        jdbcAuthMethod.setValue(meta.getAttributes().getProperty(JDBC_AUTH_METHOD, STANDARD_CREDENTIALS));
        setAuthFieldsVisible();
    }
    if (iamAccessKeyId != null) {
        iamAccessKeyId.setValue(meta.getAttributes().getProperty(IAM_ACCESS_KEY_ID));
    }
    if (iamSecretKeyId != null) {
        iamSecretKeyId.setValue(Encr.decryptPassword(meta.getAttributes().getProperty(IAM_SECRET_ACCESS_KEY)));
    }
    if (iamSessionToken != null) {
        iamSessionToken.setValue(meta.getAttributes().getProperty(IAM_SESSION_TOKEN));
    }
    if (iamProfileName != null) {
        iamProfileName.setValue(meta.getAttributes().getProperty(IAM_PROFILE_NAME));
    }
    if (webAppName != null) {
        // Insert default value only for new connection, allowing it to be empty in case of editing existing one
        if (databaseMeta == null || Utils.isEmpty(databaseMeta.getDisplayName())) {
            webAppName.setValue(DEFAULT_WEB_APPLICATION_NAME);
        } else {
            webAppName.setValue(meta.getDatabaseName());
        }
    }
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) GenericDatabaseMeta(org.pentaho.di.core.database.GenericDatabaseMeta)

Example 4 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class DataHandler method setInfo.

private void setInfo(DatabaseMeta meta) {
    if (meta == null) {
        return;
    }
    if (meta.getAttributes().containsKey(EXTRA_OPTION_WEB_APPLICATION_NAME)) {
        meta.setDBName((String) meta.getAttributes().get(EXTRA_OPTION_WEB_APPLICATION_NAME));
        meta.getAttributes().remove(EXTRA_OPTION_WEB_APPLICATION_NAME);
        meta.setChanged();
    }
    getControls();
    // Name:
    if (connectionNameBox != null) {
        connectionNameBox.setValue(meta.getDisplayName());
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface dInterface = registry.getPlugin(DatabasePluginType.class, meta.getPluginId());
    // Connection type:
    int index = (dInterface == null ? -1 : new ArrayList<>(connectionMap.keySet()).indexOf(dInterface.getName()));
    if (index >= 0) {
        connectionBox.setSelectedIndex(index);
    } else {
        LogChannel.GENERAL.logError("Unable to find database type " + (dInterface == null ? "null" : dInterface.getName()) + " in our connection map");
    }
    // Access type:
    accessBox.setSelectedItem(DatabaseMeta.getAccessTypeDescLong(meta.getAccessType()));
    // this is broken out so we can set the cache information only when caching
    // connection values
    setConnectionSpecificInfo(meta);
    loadAccessData();
    // Port number:
    if (portNumberBox != null) {
        portNumberBox.setValue(meta.getDatabasePortNumberString());
    }
    // Options Parameters:
    setOptionsData(meta.getExtraOptions());
    // Advanced panel settings:
    if (supportBooleanDataType != null) {
        supportBooleanDataType.setChecked(meta.supportsBooleanDataType());
    }
    if (supportTimestampDataType != null) {
        supportTimestampDataType.setChecked(meta.supportsTimestampDataType());
    }
    if (quoteIdentifiersCheck != null) {
        quoteIdentifiersCheck.setChecked(meta.isQuoteAllFields());
    }
    if (lowerCaseIdentifiersCheck != null) {
        lowerCaseIdentifiersCheck.setChecked(meta.isForcingIdentifiersToLowerCase());
    }
    if (upperCaseIdentifiersCheck != null) {
        upperCaseIdentifiersCheck.setChecked(meta.isForcingIdentifiersToUpperCase());
    }
    if (preserveReservedCaseCheck != null) {
        preserveReservedCaseCheck.setChecked(meta.preserveReservedCase());
    }
    if (strictBigNumberInterpretaion != null) {
        // check if Oracle
        if (meta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
            strictBigNumberInterpretaion.setVisible(true);
            strictBigNumberInterpretaion.setChecked(((OracleDatabaseMeta) meta.getDatabaseInterface()).strictBigNumberInterpretation());
        } else {
            strictBigNumberInterpretaion.setVisible(false);
            strictBigNumberInterpretaion.setChecked(false);
        }
    }
    if (preferredSchemaName != null) {
        preferredSchemaName.setValue(Const.NVL(meta.getPreferredSchemaName(), ""));
    }
    if (sqlBox != null) {
        sqlBox.setValue(meta.getConnectSQL() == null ? "" : meta.getConnectSQL());
    }
    if (clusteringCheck != null) {
        clusteringCheck.setChecked(meta.isPartitioned());
    }
    setClusterData(meta.getPartitioningInformation());
    if (poolingCheck != null) {
        poolingCheck.setChecked(meta.isUsingConnectionPool());
    }
    if (meta.isUsingConnectionPool()) {
        if (poolSizeBox != null) {
            poolSizeBox.setValue(meta.getInitialPoolSizeString());
        }
        if (maxPoolSizeBox != null) {
            maxPoolSizeBox.setValue(meta.getMaximumPoolSizeString());
        }
        setPoolProperties(meta.getConnectionPoolingProperties());
    }
    setReadOnly(meta.isReadOnly());
    setDeckChildIndex();
    onPoolingCheck();
    onClusterCheck();
    enableAzureSqlDBEncryption();
    setAzureSqlDBAuthRelatedFieldsVisible();
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta)

Example 5 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class ValueMetaBase method getValueFromSQLType.

@SuppressWarnings("fallthrough")
@Override
public ValueMetaInterface getValueFromSQLType(DatabaseMeta databaseMeta, String name, java.sql.ResultSetMetaData rm, int index, boolean ignoreLength, boolean lazyConversion) throws KettleDatabaseException {
    try {
        int length = -1;
        int precision = -1;
        int valtype = ValueMetaInterface.TYPE_NONE;
        boolean isClob = false;
        int type = rm.getColumnType(index);
        boolean signed = false;
        try {
            signed = rm.isSigned(index);
        } catch (Exception ignored) {
        // This JDBC Driver doesn't support the isSigned method
        // nothing more we can do here by catch the exception.
        }
        switch(type) {
            case java.sql.Types.CHAR:
            case java.sql.Types.VARCHAR:
            case java.sql.Types.NVARCHAR:
            case // Character Large Object
            java.sql.Types.LONGVARCHAR:
                valtype = ValueMetaInterface.TYPE_STRING;
                if (!ignoreLength) {
                    length = rm.getColumnDisplaySize(index);
                }
                break;
            case java.sql.Types.CLOB:
            case java.sql.Types.NCLOB:
                valtype = ValueMetaInterface.TYPE_STRING;
                length = DatabaseMeta.CLOB_LENGTH;
                isClob = true;
                break;
            case java.sql.Types.BIGINT:
                // 
                if (signed) {
                    valtype = ValueMetaInterface.TYPE_INTEGER;
                    // Max 9.223.372.036.854.775.807
                    precision = 0;
                    length = 15;
                } else {
                    valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                    // Max 18.446.744.073.709.551.615
                    precision = 0;
                    length = 16;
                }
                break;
            case java.sql.Types.INTEGER:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 2.147.483.647
                precision = 0;
                length = 9;
                break;
            case java.sql.Types.SMALLINT:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 32.767
                precision = 0;
                length = 4;
                break;
            case java.sql.Types.TINYINT:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 127
                precision = 0;
                length = 2;
                break;
            case java.sql.Types.DECIMAL:
            case java.sql.Types.DOUBLE:
            case java.sql.Types.FLOAT:
            case java.sql.Types.REAL:
            case java.sql.Types.NUMERIC:
                valtype = ValueMetaInterface.TYPE_NUMBER;
                length = rm.getPrecision(index);
                precision = rm.getScale(index);
                if (length >= 126) {
                    length = -1;
                }
                if (precision >= 126) {
                    precision = -1;
                }
                if (type == java.sql.Types.DOUBLE || type == java.sql.Types.FLOAT || type == java.sql.Types.REAL) {
                    if (precision == 0) {
                        // precision is obviously incorrect if the type if
                        precision = -1;
                    // Double/Float/Real
                    }
                    // If we're dealing with PostgreSQL and double precision types
                    if (databaseMeta.getDatabaseInterface() instanceof PostgreSQLDatabaseMeta && type == java.sql.Types.DOUBLE && precision >= 16 && length >= 16) {
                        precision = -1;
                        length = -1;
                    }
                    // The (12,31) that is given back is not correct
                    if (databaseMeta.getDatabaseInterface().isMySQLVariant()) {
                        if (precision >= length) {
                            precision = -1;
                            length = -1;
                        }
                    }
                    // if the length or precision needs a BIGNUMBER
                    if (length > 15 || precision > 15) {
                        valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                    }
                } else {
                    if (precision == 0) {
                        if (length <= 18 && length > 0) {
                            // Among others Oracle is affected
                            // here.
                            // Long can hold up to 18
                            valtype = ValueMetaInterface.TYPE_INTEGER;
                        // significant digits
                        } else if (length > 18) {
                            valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                        }
                    } else {
                        // we have a precision: keep NUMBER or change to BIGNUMBER?
                        if (length > 15 || precision > 15) {
                            valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                        }
                    }
                }
                if (databaseMeta.getDatabaseInterface() instanceof PostgreSQLDatabaseMeta || databaseMeta.getDatabaseInterface() instanceof GreenplumDatabaseMeta) {
                    // undefined size => arbitrary precision
                    if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
                        valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                        length = -1;
                        precision = -1;
                    }
                }
                if (databaseMeta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
                    if (precision == 0 && length == 38) {
                        valtype = ((OracleDatabaseMeta) databaseMeta.getDatabaseInterface()).strictBigNumberInterpretation() ? TYPE_BIGNUMBER : TYPE_INTEGER;
                    }
                    if (precision <= 0 && length <= 0) {
                        // undefined size: BIGNUMBER,
                        // precision on Oracle can be 38, too
                        // big for a Number type
                        valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                        length = -1;
                        precision = -1;
                    }
                }
                break;
            case java.sql.Types.TIMESTAMP:
                if (databaseMeta.supportsTimestampDataType()) {
                    valtype = ValueMetaInterface.TYPE_TIMESTAMP;
                    length = rm.getScale(index);
                }
                break;
            case java.sql.Types.DATE:
                if (databaseMeta.getDatabaseInterface() instanceof TeradataDatabaseMeta) {
                    precision = 1;
                }
            case java.sql.Types.TIME:
                valtype = ValueMetaInterface.TYPE_DATE;
                // 
                if (databaseMeta.getDatabaseInterface().isMySQLVariant()) {
                    String property = databaseMeta.getConnectionProperties().getProperty("yearIsDateType");
                    if (property != null && property.equalsIgnoreCase("false") && rm.getColumnTypeName(index).equalsIgnoreCase("YEAR")) {
                        valtype = ValueMetaInterface.TYPE_INTEGER;
                        precision = 0;
                        length = 4;
                        break;
                    }
                }
                break;
            case java.sql.Types.BOOLEAN:
            case java.sql.Types.BIT:
                valtype = ValueMetaInterface.TYPE_BOOLEAN;
                break;
            case java.sql.Types.BINARY:
            case java.sql.Types.BLOB:
            case java.sql.Types.VARBINARY:
            case java.sql.Types.LONGVARBINARY:
                valtype = ValueMetaInterface.TYPE_BINARY;
                if (databaseMeta.isDisplaySizeTwiceThePrecision() && (2 * rm.getPrecision(index)) == rm.getColumnDisplaySize(index)) {
                    // set the length for "CHAR(X) FOR BIT DATA"
                    length = rm.getPrecision(index);
                } else if ((databaseMeta.getDatabaseInterface() instanceof OracleDatabaseMeta) && (type == java.sql.Types.VARBINARY || type == java.sql.Types.LONGVARBINARY)) {
                    // set the length for Oracle "RAW" or "LONGRAW" data types
                    valtype = ValueMetaInterface.TYPE_STRING;
                    length = rm.getColumnDisplaySize(index);
                } else if (databaseMeta.isMySQLVariant() && (type == java.sql.Types.VARBINARY || type == java.sql.Types.LONGVARBINARY)) {
                    // PDI-6677 - don't call 'length = rm.getColumnDisplaySize(index);'
                    // keep the length to -1, e.g. for string functions (e.g.
                    length = -1;
                // CONCAT see PDI-4812)
                } else {
                    length = -1;
                }
                precision = -1;
                break;
            default:
                valtype = ValueMetaInterface.TYPE_STRING;
                precision = rm.getScale(index);
                break;
        }
        ValueMetaInterface v = ValueMetaFactory.createValueMeta(name, valtype);
        v.setLength(length);
        v.setPrecision(precision);
        v.setLargeTextField(isClob);
        getOriginalColumnMetadata(v, rm, index, ignoreLength);
        // 
        if (lazyConversion && valtype == ValueMetaInterface.TYPE_STRING) {
            v.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
            // 
            try {
                ValueMetaInterface storageMetaData = ValueMetaFactory.cloneValueMeta(v, ValueMetaInterface.TYPE_STRING);
                storageMetaData.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                v.setStorageMetadata(storageMetaData);
            } catch (Exception e) {
                throw new SQLException(e);
            }
        }
        ValueMetaInterface newV = null;
        try {
            newV = databaseMeta.getDatabaseInterface().customizeValueFromSQLType(v, rm, index);
        } catch (SQLException e) {
            throw new SQLException(e);
        }
        return newV == null ? v : newV;
    } catch (Exception e) {
        throw new KettleDatabaseException("Error determining value metadata from SQL resultset metadata", e);
    }
}
Also used : SQLException(java.sql.SQLException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) TeradataDatabaseMeta(org.pentaho.di.core.database.TeradataDatabaseMeta) KettleFileException(org.pentaho.di.core.exception.KettleFileException) ParseException(java.text.ParseException) KettleEOFException(org.pentaho.di.core.exception.KettleEOFException) EOFException(java.io.EOFException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) PostgreSQLDatabaseMeta(org.pentaho.di.core.database.PostgreSQLDatabaseMeta) GreenplumDatabaseMeta(org.pentaho.di.core.database.GreenplumDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

OracleDatabaseMeta (org.pentaho.di.core.database.OracleDatabaseMeta)10 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 Test (org.junit.Test)3 KettleException (org.pentaho.di.core.exception.KettleException)3 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 SQLException (java.sql.SQLException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Database (org.pentaho.di.core.database.Database)2 GreenplumDatabaseMeta (org.pentaho.di.core.database.GreenplumDatabaseMeta)2 PostgreSQLDatabaseMeta (org.pentaho.di.core.database.PostgreSQLDatabaseMeta)2 TeradataDatabaseMeta (org.pentaho.di.core.database.TeradataDatabaseMeta)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 LoggingObject (org.pentaho.di.core.logging.LoggingObject)2