2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.ccsdk.sli.adaptors.ra.rule.dao;
 
  24 import java.sql.ResultSet;
 
  25 import java.sql.SQLException;
 
  26 import java.util.List;
 
  28 import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil;
 
  29 import org.slf4j.Logger;
 
  30 import org.slf4j.LoggerFactory;
 
  31 import org.springframework.jdbc.core.JdbcTemplate;
 
  32 import org.springframework.jdbc.core.RowMapper;
 
  34 public class MaxPortSpeedDaoImpl implements MaxPortSpeedDao {
 
  36     @SuppressWarnings("unused")
 
  37     private static final Logger log = LoggerFactory.getLogger(MaxPortSpeedDaoImpl.class);
 
  39     private final static String GET_SQL =
 
  40             "SELECT * FROM MAX_PORT_SPEED WHERE image_file_name = ? AND end_point_position = ? AND interface_name = ?";
 
  42     private JdbcTemplate jdbcTemplate;
 
  43     private long defaultMaxPortSpeed = 5000000;
 
  44     private SpeedUtil speedUtil;
 
  47     public long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName) {
 
  48         List<MaxPortSpeed> maxPortSpeedList =
 
  49                 jdbcTemplate.query(GET_SQL, new Object[] { imageFile, endPointPosition, interfaceName },
 
  50                         new RowMapper<MaxPortSpeed>() {
 
  53                             public MaxPortSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
 
  54                                 MaxPortSpeed mps = new MaxPortSpeed();
 
  55                                 mps.maxSpeed = rs.getLong("max_speed");
 
  56                                 mps.unit = rs.getString("unit");
 
  61         if (maxPortSpeedList.isEmpty())
 
  62             return defaultMaxPortSpeed;
 
  64         MaxPortSpeed mps = maxPortSpeedList.get(0);
 
  65         return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
 
  68     private static class MaxPortSpeed {
 
  74     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
 
  75         this.jdbcTemplate = jdbcTemplate;
 
  78     public void setDefaultMaxPortSpeed(long defaultMaxPortSpeed) {
 
  79         this.defaultMaxPortSpeed = defaultMaxPortSpeed;
 
  82     public void setSpeedUtil(SpeedUtil speedUtil) {
 
  83         this.speedUtil = speedUtil;