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 http://www.apache.org/licenses/LICENSE-2.0 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.trident.state;
 
 
 import java.util.List;
 import java.util.Map;
 
 public class JdbcState implements State {
 
     private static final Logger LOG = LoggerFactory.getLogger(JdbcState.class);
 
     private Options options;
     private JdbcClient jdbcClient;
     private Map map;
 
     protected JdbcState(Map mapint partitionIndexint numPartitionsOptions options) {
         this. = options;
         this. = map;
     }
 
     public static class Options implements Serializable {
         private JdbcMapper mapper;
         private JdbcLookupMapper jdbcLookupMapper;
         private ConnectionProvider connectionProvider;
         private String tableName;
         private String insertQuery;
         private String selectQuery;
         private Integer queryTimeoutSecs;
 
         public Options withConnectionPrvoider(ConnectionProvider connectionProvider) {
             this. = connectionProvider;
             return this;
         }
 
         public Options withTableName(String tableName) {
             this. = tableName;
             return this;
         }
 
         public Options withInsertQuery(String insertQuery) {
             this. = insertQuery;
             return this;
         }
 
         public Options withMapper(JdbcMapper mapper) {
             this. = mapper;
             return this;
         }
 
         public Options withJdbcLookupMapper(JdbcLookupMapper jdbcLookupMapper) {
             this. = jdbcLookupMapper;
             return this;
         }
 
         public Options withSelectQuery(String selectQuery) {
             this. = selectQuery;
             return this;
         }
 
         public Options withQueryTimeoutSecs(int queryTimeoutSecs) {
             this. = queryTimeoutSecs;
             return this;
         }
     }
 
     protected void prepare() {
        if(StringUtils.isBlank(.) && StringUtils.isBlank(.) && StringUtils.isBlank(.)) {
            throw new IllegalArgumentException("If you are trying to insert into DB you must supply either insertQuery or tableName." +
                    "If you are attempting to user a query state you must supply a select query.");
        }
        if(. == null) {
        }
    }
    @Override
    public void beginCommit(Long aLong) {
        .debug("beginCommit is noop.");
    }
    @Override
    public void commit(Long aLong) {
        .debug("commit is noop.");
    }
    public void updateState(List<TridentTupletuplesTridentCollector collector) {
        List<List<Column>> columnsLists = new ArrayList<List<Column>>();
        for (TridentTuple tuple : tuples) {
            columnsLists.add(..getColumns(tuple));
        }
        try {
            if(!StringUtils.isBlank(.)) {
                .insert(.columnsLists);
            } else {
                .executeInsertQuery(.columnsLists);
            }
        } catch (Exception e) {
            .warn("Batch write failed but some requests might have succeeded. Triggering replay."e);
            throw new FailedException(e);
        }
    }
    public List<List<Values>> batchRetrieve(List<TridentTupletridentTuples) {
        List<List<Values>> batchRetrieveResult = Lists.newArrayList();
        try {
            for (TridentTuple tuple : tridentTuples) {
                List<Columncolumns = ..getColumns(tuple);
                List<List<Column>> rows = .select(.columns);
                for(List<Columnrow : rows) {
                    List<Valuesvalues = ..toTuple(tuplerow);
                    batchRetrieveResult.add(values);
                }
            }
        } catch (Exception e) {
            .warn("Batch get operation failed. Triggering replay."e);
            throw new FailedException(e);
        }
        return batchRetrieveResult;
    }
New to GrepCode? Check out our FAQ X