2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.system;
22 import java.sql.Connection;
24 import org.openecomp.portalsdk.analytics.error.RaptorException;
25 import org.openecomp.portalsdk.analytics.error.ReportSQLException;
26 import org.openecomp.portalsdk.analytics.util.AppConstants;
27 import org.openecomp.portalsdk.analytics.util.DataSet;
29 public class ConnectionUtils {
31 public static DataSet getDataSet(String sql, String remoteDbPrefix)
32 throws RaptorException {
33 return getDataSet(sql, remoteDbPrefix, false);
36 public static Connection getConnection(String remoteDbPrefix) throws ReportSQLException {
37 if (!isNull(remoteDbPrefix) && (!remoteDbPrefix.equals(AppConstants.DB_LOCAL)) && !Globals.getSystemType().equals(Globals.ST_GENERIC) ) {
38 return RemDbUtils.getConnection(remoteDbPrefix);
40 return DbUtils.getConnection();
44 public static DataSet getDataSet(String sql, String remoteDbPrefix,
45 boolean pagesize) throws ReportSQLException {
47 if (!isNull(remoteDbPrefix) && (!remoteDbPrefix.equals(AppConstants.DB_LOCAL)) && !Globals.getSystemType().equals(Globals.ST_GENERIC) ) {
48 if (pagesize == false)
49 ds = RemDbUtils.executeQuery(sql,remoteDbPrefix);
51 ds = RemDbUtils.executeQuery(sql, Globals.getDefaultPageSize() + 1,remoteDbPrefix);
53 if (pagesize == false)
54 ds = DbUtils.executeQuery(sql);
56 ds = DbUtils.executeQuery(sql, Globals.getDefaultPageSize() + 1);
61 public static boolean isNull(String a) {
62 if ((a == null) || (a.length() == 0) || a.equalsIgnoreCase("null"))