Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.apache.storm.jdbc.mapper;
public class SimpleJdbcMapper implements JdbcMapper {
    private List<ColumnschemaColumns;
    public SimpleJdbcMapper(String tableNameConnectionProvider connectionProvider) {
        int queryTimeoutSecs = 30;
        JdbcClient client = new JdbcClient(connectionProviderqueryTimeoutSecs);
        this. = client.getColumnSchema(tableName);
    public SimpleJdbcMapper(List<ColumnschemaColumns) {
        this. = schemaColumns;
    public List<ColumngetColumns(ITuple tuple) {
        List<Columncolumns = new ArrayList<Column>();
        for(Column column : ) {
            String columnName = column.getColumnName();
            Integer columnSqlType = column.getSqlType();
            if(Util.getJavaType(columnSqlType).equals(String.class)) {
                String value = tuple.getStringByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Short.class)) {
                Short value = tuple.getShortByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Integer.class)) {
                Integer value = tuple.getIntegerByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Long.class)) {
                Long value = tuple.getLongByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Double.class)) {
                Double value = tuple.getDoubleByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Float.class)) {
                Float value = tuple.getFloatByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Boolean.class)) {
                Boolean value = tuple.getBooleanByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(byte[].class)) {
                byte[] value = tuple.getBinaryByField(columnName);
                columns.add(new Column(columnNamevaluecolumnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Date.class)) {
                Long value = tuple.getLongByField(columnName);
                columns.add(new Column(columnNamenew Date(value), columnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Time.class)) {
                Long value = tuple.getLongByField(columnName);
                columns.add(new Column(columnNamenew Time(value), columnSqlType));
            } else if(Util.getJavaType(columnSqlType).equals(Timestamp.class)) {
                Long value = tuple.getLongByField(columnName);
                columns.add(new Column(columnNamenew Timestamp(value), columnSqlType));
            } else {
                throw new RuntimeException("Unsupported java type in tuple " + Util.getJavaType(columnSqlType));
        return columns;
New to GrepCode? Check out our FAQ X