19 package org.turro.jpa.config;
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.util.List;
25 import java.util.Properties;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.file.Document;
28 import org.turro.file.Folder;
29 import org.turro.json.IJSONizable;
30 import org.turro.log.WebLoggers;
38 private String url, username, password;
45 this.username = username;
49 this.password = password;
52 private Properties properties() {
53 Properties properties =
new Properties();
54 properties.setProperty(
"hibernate.connection.url", url);
55 properties.setProperty(
"hibernate.connection.username", username);
56 properties.setProperty(
"hibernate.connection.password", password);
57 addDefaults(properties);
61 private void addDefaults(Properties properties) {
62 properties.setProperty(
"hibernate.dialect",
"org.hibernate.dialect.MySQL5Dialect");
63 properties.setProperty(
"hibernate.connection.driver_class",
"com.mysql.jdbc.Driver");
64 properties.setProperty(
"hibernate.hbm2ddl.auto",
"update");
65 properties.setProperty(
"hibernate.show_sql",
"false");
66 properties.setProperty(
"hibernate.format_sql",
"false");
67 properties.setProperty(
"hibernate.use_sql_comments",
"false");
68 properties.setProperty(
"hibernate.connection.provider_class",
"org.hibernate.connection.C3P0ConnectionProvider");
69 properties.setProperty(
"hibernate.c3p0.max_size",
"6");
70 properties.setProperty(
"hibernate.c3p0.min_size",
"2");
71 properties.setProperty(
"hibernate.c3p0.timeout",
"5000");
72 properties.setProperty(
"hibernate.c3p0.max_statements",
"200");
73 properties.setProperty(
"hibernate.c3p0.idle_test_period",
"3000");
74 properties.setProperty(
"hibernate.c3p0.acquire_increment",
"2");
75 properties.setProperty(
"hibernate.c3p0.validate",
"false");
80 public static List<Document>
daos() {
83 return daoFolder.documents(
"*.json");
84 }
catch (IOException ex) {
98 public String
toJson(Map<String, Object> properties) {
99 return toJson(
this, properties);
104 private static final String DAO_FOLDER =
"/WEB-INF/elephant/conf/dao";
106 public static Properties
from(String pu, String name) {
109 .resolve(pu +
".json"));
110 if(!configFile.exists()) {
113 return IJSONizable.fromJson(configFile.content(),
JpaConfig.class).properties();
114 }
catch (IOException ex) {
static String getRealPath(String path)
static void migrate(Document document, String name)
void setUsername(String username)
static Properties from(String pu, String name)
void setPassword(String password)
String toJson(Map< String, Object > properties)
static List< Document > daos()
static WebLoggers severe(Object entity)
WebLoggers exception(Throwable throwable)