Another feedback.

This commit is contained in:
Rudi Adianto 2018-08-14 17:58:13 +07:00
parent b8e56590f8
commit fc85b37299

View File

@ -31,14 +31,12 @@ public class HibernateLifecycleUtil {
private static Connection connection; private static Connection connection;
public static void init() throws Exception { public static void init() throws Exception {
Class.forName("org.h2.Driver"); Properties hbConfigProp = getHibernateProperties();
Properties hbConfigProp = new Properties(); Class.forName(hbConfigProp.getProperty("hibernate.connection.driver_class"));
try (InputStream hbPropStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("hibernate-lifecycle.properties"); connection = DriverManager.getConnection(hbConfigProp.getProperty("hibernate.connection.url"), hbConfigProp.getProperty("hibernate.connection.username"), hbConfigProp.getProperty("hibernate.connection.password"));
InputStream h2InitStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("lifecycle-init.sql");
InputStreamReader h2InitReader = new InputStreamReader(h2InitStream)) {
hbConfigProp.load(hbPropStream);
connection = DriverManager.getConnection(hbConfigProp.getProperty("hibernate.connection.url"), hbConfigProp.getProperty("hibernate.connection.username"), hbConfigProp.getProperty("hibernate.connection.password"));
try (InputStream h2InitStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("lifecycle-init.sql");
InputStreamReader h2InitReader = new InputStreamReader(h2InitStream)) {
RunScript.execute(connection, h2InitReader); RunScript.execute(connection, h2InitReader);
} }
@ -65,11 +63,11 @@ public class HibernateLifecycleUtil {
} }
private static ServiceRegistry configureServiceRegistry() throws IOException { private static ServiceRegistry configureServiceRegistry() throws IOException {
Properties properties = getProperties(); Properties properties = getHibernateProperties();
return new StandardServiceRegistryBuilder().applySettings(properties).build(); return new StandardServiceRegistryBuilder().applySettings(properties).build();
} }
private static Properties getProperties() throws IOException { private static Properties getHibernateProperties() throws IOException {
Properties properties = new Properties(); Properties properties = new Properties();
URL propertiesURL = Thread.currentThread().getContextClassLoader().getResource("hibernate-lifecycle.properties"); URL propertiesURL = Thread.currentThread().getContextClassLoader().getResource("hibernate-lifecycle.properties");
try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) {