/*
 * Copyright (C) 2017. OpenLattice, Inc
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You can contact the owner of the copyright at support@openlattice.com
 *
 */

package com.openlattice.jdbc;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.kryptnostic.rhizome.configuration.RhizomeConfiguration;
import com.kryptnostic.rhizome.pods.ConfigurationPod;
import com.kryptnostic.rhizome.pods.MetricsPod;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.inject.Inject;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author Matthew Tamayo-Rios &lt;matthew@openlattice.com&gt;
 */
@Configuration
@Import( { ConfigurationPod.class, MetricsPod.class } )
public class JdbcPod {
    private static final Logger logger = LoggerFactory.getLogger( JdbcPod.class );

    @Inject
    private RhizomeConfiguration rhizomeConfiguration;

    @Inject
    private HealthCheckRegistry healthCheckRegistry;

    @Inject
    private MetricRegistry metricRegistry;

    @Bean
    public HikariDataSource hikariDataSource() {
        if ( rhizomeConfiguration.getPostgresConfiguration().isPresent() ) {
            final var pgConfig = rhizomeConfiguration.getPostgresConfiguration().get();
            HikariConfig hc = new HikariConfig( pgConfig.getHikariConfiguration() );
            logger.info( "JDBC URL = {}", hc.getJdbcUrl() );
            HikariDataSource hds = new HikariDataSource( hc );
            hds.setHealthCheckRegistry( healthCheckRegistry );
            hds.setMetricRegistry( metricRegistry );
            return hds;
        } else {
            return null;
        }
    }

    @Bean
    public Jdbi jdbi() {
        Jdbi jdbi = Jdbi.create( hikariDataSource() );
        jdbi.installPlugin( new SqlObjectPlugin() );
        return jdbi;
    }
}

@@ -2155,28 +2155,25 @@
         
-HikariConfig
+final var
  hc = ne
@@ -2229,147 +2229,23 @@
  );%0A
-            logger.info( %22JDBC URL = %7B%7D%22, hc.getJdbcUrl() );%0A            HikariDataSource hds = new HikariDataSource( hc );%0A            hds
+%0A            hc
 .set
@@ -2301,18 +2301,17 @@
        h
-ds
+c
 .setMetr
@@ -2344,30 +2344,114 @@
  );%0A
-            return hds
+%0A            logger.info( %22JDBC URL = %7B%7D%22, hc.getJdbcUrl() );%0A%0A            return new HikariDataSource(hc)
 ;%0A  

Fix initialize as hikari now seals state after starting.