Allow configuring database in config.properties.

This commit is contained in:
FireMasterK 2021-07-15 01:37:38 +05:30
parent e6711b197f
commit 1c39359279
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 10 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import org.schabi.newpipe.extractor.StreamingService;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import me.kavin.piped.utils.PageMixin; import me.kavin.piped.utils.PageMixin;
public class Constants { public class Constants {
@ -39,6 +40,8 @@ public class Constants {
public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class); public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
public static final Object2ObjectOpenHashMap<String, String> hibernateProperties = new Object2ObjectOpenHashMap<>();
static { static {
Properties prop = new Properties(); Properties prop = new Properties();
try { try {
@ -51,6 +54,11 @@ public class Constants {
CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL"); CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL");
CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY"); CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY");
PUBLIC_URL = prop.getProperty("API_URL"); PUBLIC_URL = prop.getProperty("API_URL");
prop.forEach((_key, _value) -> {
String key = String.valueOf(_key), value = String.valueOf(_value);
if (key.startsWith("hibernate"))
hibernateProperties.put(key, value);
});
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -4,6 +4,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.obj.db.Channel; import me.kavin.piped.utils.obj.db.Channel;
import me.kavin.piped.utils.obj.db.User; import me.kavin.piped.utils.obj.db.User;
import me.kavin.piped.utils.obj.db.Video; import me.kavin.piped.utils.obj.db.Video;
@ -16,11 +17,7 @@ public class DatabaseSessionFactory {
final Configuration configuration = new Configuration(); final Configuration configuration = new Configuration();
configuration.setProperty("hibernate.connection.url", "jdbc:postgresql://"); Constants.hibernateProperties.forEach((key, value) -> configuration.setProperty(key, value));
configuration.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.CockroachDB192Dialect");
configuration.setProperty("hibernate.connection.username", "piped");
configuration.setProperty("hibernate.connection.password", "@8LQuf7JUabCker$zQYS");
configuration.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false"); configuration.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
configuration.configure(); configuration.configure();