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.openecomp.sdnc.ra.rule.dao;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
26 import java.util.List;
28 import org.openecomp.sdnc.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 MaxServerSpeedDaoImpl implements MaxServerSpeedDao {
36 @SuppressWarnings("unused")
37 private static final Logger log = LoggerFactory.getLogger(MaxServerSpeedDaoImpl.class);
39 private final static String GET_SQL =
40 "SELECT * FROM MAX_SERVER_SPEED\n" +
41 "WHERE (server_model = ? OR server_model = 'ALL') AND evc_count >= ?\n" +
44 private JdbcTemplate jdbcTemplate;
45 private long defaultMaxServerSpeed = 1600000;
46 private SpeedUtil speedUtil;
49 public long getMaxServerSpeed(String serverModel, int evcCount) {
50 List<MaxServerSpeed> maxServerSpeedList =
51 jdbcTemplate.query(GET_SQL, new Object[] { serverModel, evcCount }, new RowMapper<MaxServerSpeed>() {
54 public MaxServerSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
55 MaxServerSpeed mps = new MaxServerSpeed();
56 mps.maxSpeed = rs.getLong("max_speed");
57 mps.unit = rs.getString("unit");
62 if (maxServerSpeedList.isEmpty())
63 return defaultMaxServerSpeed;
65 MaxServerSpeed mps = maxServerSpeedList.get(0);
66 return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
69 private static class MaxServerSpeed {
75 public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
76 this.jdbcTemplate = jdbcTemplate;
79 public void setDefaultMaxServerSpeed(long defaultMaxServerSpeed) {
80 this.defaultMaxServerSpeed = defaultMaxServerSpeed;
83 public void setSpeedUtil(SpeedUtil speedUtil) {
84 this.speedUtil = speedUtil;