58fb3f25e948329b9b6db9d89c781433d518687f
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalsdk.analytics.system;
21
22 import java.sql.Connection;
23
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;
28
29 public class ConnectionUtils {
30         
31         public static DataSet getDataSet(String sql, String remoteDbPrefix)
32                         throws RaptorException {
33                 return getDataSet(sql, remoteDbPrefix, false);
34         }
35
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);
39                 } else {
40                         return DbUtils.getConnection();
41                 }
42         }
43         
44         public static DataSet getDataSet(String sql, String remoteDbPrefix,
45                         boolean pagesize) throws ReportSQLException  {
46                 DataSet ds = null;
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);
50                         else
51                                 ds = RemDbUtils.executeQuery(sql, Globals.getDefaultPageSize() + 1,remoteDbPrefix);
52                 } else {
53                         if (pagesize == false)
54                                 ds = DbUtils.executeQuery(sql);
55                         else
56                                 ds = DbUtils.executeQuery(sql, Globals.getDefaultPageSize() + 1);
57                 }
58                 return ds;
59         }
60         
61         public static boolean isNull(String a) {
62                 if ((a == null) || (a.length() == 0) || a.equalsIgnoreCase("null"))
63                         return true;
64                 else
65                         return false;
66         }
67
68
69 }