2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.dbcapi.database;
23 import java.io.FileReader;
24 import java.io.LineNumberReader;
25 import java.sql.Connection;
26 import java.sql.Statement;
27 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
29 public class LoadSchema extends BaseLoggingClass {
31 private LoadSchema(){}
33 static void loadSchema() {
34 ConnectionFactory cf = ConnectionFactory.getDefaultInstance();
35 try (LineNumberReader lineReader = new LineNumberReader(new FileReader("/opt/app/dmaapbc/misc/schema_all.sql"));
36 Connection c = cf.get(true);
37 Statement stmt = c.createStatement()) {
38 StringBuilder strBuilder = new StringBuilder();
40 while ((line = lineReader.readLine()) != null) {
41 if (!line.startsWith("--")) {
43 strBuilder.append(line);
44 if (line.endsWith(";")) {
45 String sql = strBuilder.toString();
46 strBuilder.setLength(0);
48 appLogger.debug("SQL EXECUTE SUCCESS: " + sql);
52 strBuilder.setLength(0);
53 } catch (Exception e) {
54 errorLogger.error("Error when initializing table: " + e.getMessage(), e);