Skip to content
Snippets Groups Projects
Commit 4efb7819 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#663 - new database backend: postgresql

parent df5dc047
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
<groupId>de.deadlocker8</groupId>
<artifactId>BudgetMaster</artifactId>
<version>2.9.2</version>
<version>2.10.0</version>
<name>BudgetMaster</name>
<repositories>
......@@ -77,7 +77,7 @@
<app.versionDate>${maven.build.timestamp}</app.versionDate>
<maven.build.timestamp.format>dd.MM.yy</maven.build.timestamp.format>
<app.versionCode>37</app.versionCode>
<app.versionCode>38</app.versionCode>
<app.author>Robert Goldmann</app.author>
<project.outputDirectory>build/${project.version}</project.outputDirectory>
......@@ -155,6 +155,11 @@
<version>${h2database.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
......
package de.deadlocker8.budgetmaster;
import de.deadlocker8.budgetmaster.utils.DatabaseConfigurationProperties;
import de.thecodelabs.utils.io.PathUtils;
import de.thecodelabs.utils.util.Localization;
import de.thecodelabs.utils.util.SystemUtils;
......@@ -11,6 +12,7 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
......@@ -25,6 +27,7 @@ import java.util.*;
@EnableScheduling
@SpringBootApplication
@EnableConfigurationProperties(DatabaseConfigurationProperties.class)
public class Main extends SpringBootServletInitializer implements ApplicationRunner
{
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
......
......@@ -7,6 +7,7 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Entity
@Table(name = "login_user")
public class User
{
@Id
......
package de.deadlocker8.budgetmaster.utils;
import de.deadlocker8.budgetmaster.Main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -8,18 +8,31 @@ import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import javax.sql.DataSource;
import java.nio.file.Path;
import java.text.MessageFormat;
@Configuration
@Profile("!test")
public class DatabaseConfiguration
{
DatabaseConfigurationProperties databaseConfig;
@Autowired
public DatabaseConfiguration(DatabaseConfigurationProperties databaseConfig)
{
this.databaseConfig = databaseConfig;
}
@Bean
@Primary
public DataSource dataSource()
{
Path applicationSupportFolder = Main.getApplicationSupportFolder();
String jdbcString = "jdbc:h2:/" + applicationSupportFolder.toString() + "/" + "budgetmaster;DB_CLOSE_ON_EXIT=TRUE";
return DataSourceBuilder.create().username("sa").password("").url(jdbcString).driverClassName("org.h2.Driver").build();
final String jdbcString = MessageFormat.format("jdbc:postgresql://{0}:{1}/{2}", databaseConfig.getHostname(), Long.toString(databaseConfig.getPort()), databaseConfig.getDatabaseName());
return DataSourceBuilder.create()
.username(databaseConfig.getUsername())
.password(databaseConfig.getPassword())
.url(jdbcString)
.driverClassName("org.postgresql.Driver")
.build();
}
}
package de.deadlocker8.budgetmaster.utils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
@ConfigurationProperties(prefix = "budgetmaster.database")
public class DatabaseConfigurationProperties
{
@NotBlank
private String hostname;
@Min(1)
@Max(65536)
private int port;
@NotBlank
private String databaseName;
@NotBlank
private String username;
@NotBlank
private String password;
public String getHostname()
{
return hostname;
}
public void setHostname(String hostname)
{
this.hostname = hostname;
}
public int getPort()
{
return port;
}
public void setPort(int port)
{
this.port = port;
}
public String getDatabaseName()
{
return databaseName;
}
public void setDatabaseName(String databaseName)
{
this.databaseName = databaseName;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
@Override
public String toString()
{
return "DatabaseConfigurationProperties{" +
"hostname='" + hostname + '\'' +
", port=" + port +
", databaseName='" + databaseName + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
spring.mvc.log-resolved-exception=false
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
spring.servlet.multipart.max-file-size=100MB
......
......@@ -2,6 +2,13 @@
server.port=9000
### database settings ###
budgetmaster.database.hostname=localhost
budgetmaster.database.port=5432
budgetmaster.database.databaseName=budgetmaster
budgetmaster.database.username=budgetmaster
budgetmaster.database.password=budgetmaster
### SSL settings ###
# do not change this property
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment