package com.hoserdude.toboot.config;

import com.mongodb.MongoURI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * This is only activated in the heroku environment, otherwise Spring Boot
 * automaticially sets you up for local config
 */
@Profile("heroku")
@Configuration
public class HerokuDatabaseConfig {
    @Bean
    public MongoDbFactory mongoDbFactory() throws Exception {
        MongoURI mongoURI = new MongoURI(System.getenv("MONGOHQ_URL"));
        return new SimpleMongoDbFactory(mongoURI);
    }

    @Bean
    public Connection getConnection() throws URISyntaxException, SQLException {
        URI dbUri = new URI(System.getenv("DATABASE_URL"));

        String username = dbUri.getUserInfo().split(":")[0];
        String password = dbUri.getUserInfo().split(":")[1];
        String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + dbUri.getPath();

        return DriverManager.getConnection(dbUrl, username, password);
    }
}

@@ -412,97 +412,8 @@
 ion;
-%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.SQLException;
 %0A%0A/*
@@ -837,32 +837,17 @@
 lic 
-Connection getConnection
+URI dbUrl
 () t
@@ -874,22 +874,8 @@
 tion
-, SQLException
  %7B%0A 
@@ -933,25 +933,24 @@
 URL%22));%0A
-%0A
         
 String u
@@ -945,273 +945,20 @@
     
-String username = dbUri.getUserInfo().split(%22:%22)%5B0%5D;%0A        String password = dbUri.getUserInfo().split(%22:%22)%5B1%5D;%0A        String dbUrl = %22jdbc:postgresql://%22 + dbUri.getHost() + dbUri.getPath();%0A%0A        return DriverManager.getConnection(dbUrl, username, password)
+return dbUri
 ;%0A  

simplify db connection