2 * Copyright 2016 [ZTE] and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.commontosca.catalog.db.hibernate;
19 import io.dropwizard.ConfiguredBundle;
20 import io.dropwizard.setup.Bootstrap;
21 import io.dropwizard.setup.Environment;
23 import org.openo.commontosca.catalog.CatalogAppConfiguration;
24 import org.openo.commontosca.catalog.db.dao.DaoManager;
25 import org.openo.commontosca.catalog.db.entity.NodeTemplateData;
26 import org.openo.commontosca.catalog.db.entity.PackageData;
27 import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;
28 import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class HibernateBundleAgent implements ConfiguredBundle<CatalogAppConfiguration> {
34 private final HibernateBundleExt bundle = new HibernateBundleExt(ServiceTemplateData.class,
35 PackageData.class, NodeTemplateData.class, ServiceTemplateMappingData.class);
36 private static final Logger LOGGER = LoggerFactory.getLogger(HibernateBundleAgent.class);
39 public void run(final CatalogAppConfiguration configuration, final Environment environment)
41 Thread thread = new Thread(new Runnable() {
46 while (retry < 1000) {
47 LOGGER.info("init hibernateBundle.retry:" + retry);
50 bundle.runExt(configuration, environment);
51 } catch (Exception e1) {
54 "init hibernateBundle failed, sleep 15S and try again.errorMsg:" + e1.getMessage());
58 LOGGER.info("init hibernateBundle success!");
65 thread.setName("init hibernateBundle");
69 private void initDao() {
70 DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());
73 private void threadSleep(int second) {
74 LOGGER.info("start sleep ....");
77 } catch (InterruptedException error) {
78 LOGGER.error("thread sleep error.errorMsg:" + error.getMessage());
80 LOGGER.info("sleep end .");
84 public void initialize(Bootstrap<?> bootstrap) {
85 bundle.initializeExt(bootstrap);
88 // public SessionFactory getSessionFactory() {
89 // return bundle.getSessionFactory();