-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ Add database access to Komunumo closes #668
Signed-off-by: Marcus Fihlon <marcus@fihlon.swiss>
- Loading branch information
Showing
10 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/org/komunumo/configuration/Configuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.configuration; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
|
||
public final class Configuration { | ||
|
||
@SuppressWarnings("java:S1172") | ||
public Configuration(@NotNull final Map<String, String> configuration) { } | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/komunumo/data/service/ConfigurationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.data.service; | ||
|
||
import org.komunumo.configuration.Configuration; | ||
import org.komunumo.data.service.getter.DSLContextGetter; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
|
||
import static org.komunumo.data.db.tables.Configuration.CONFIGURATION; | ||
|
||
interface ConfigurationService extends DSLContextGetter { | ||
|
||
default Configuration loadConfigurationFromDatabase() { | ||
final var configurationData = new HashMap<String, String>(); | ||
dsl().selectFrom(CONFIGURATION) | ||
.forEach(configurationRecord -> configurationData.put(configurationRecord.getConfKey(), configurationRecord.getConfValue())); | ||
return new Configuration(Collections.unmodifiableMap(configurationData)); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/komunumo/data/service/DatabaseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.data.service; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jooq.DSLContext; | ||
import org.komunumo.configuration.Configuration; | ||
import org.komunumo.data.service.getter.ConfigurationGetter; | ||
import org.komunumo.data.service.getter.DSLContextGetter; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class DatabaseService implements DSLContextGetter, ConfigurationGetter, ConfigurationService { | ||
|
||
private final DSLContext dsl; | ||
|
||
private Configuration configuration; | ||
|
||
public DatabaseService(@NotNull final DSLContext dsl) { | ||
this.dsl = dsl; | ||
this.configuration = loadConfigurationFromDatabase(); | ||
} | ||
|
||
/** | ||
* Get the {@link Configuration}. | ||
* @return the {@link Configuration} | ||
*/ | ||
@Override | ||
public Configuration configuration() { | ||
return configuration; | ||
} | ||
|
||
/** | ||
* Get the {@link DSLContext} to access the database. | ||
* @return the {@link DSLContext} | ||
*/ | ||
@Override | ||
public DSLContext dsl() { | ||
return dsl; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/komunumo/data/service/getter/ConfigurationGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.data.service.getter; | ||
|
||
import org.komunumo.configuration.Configuration; | ||
|
||
public interface ConfigurationGetter { | ||
|
||
Configuration configuration(); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/komunumo/data/service/getter/DSLContextGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.data.service.getter; | ||
|
||
import org.jooq.DSLContext; | ||
|
||
public interface DSLContextGetter { | ||
|
||
DSLContext dsl(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
server.port=${PORT:8080} | ||
logging.level.org.atmosphere = warn | ||
|
||
spring.datasource.url=${DB_URL} | ||
spring.datasource.username=${DB_USER} | ||
spring.datasource.password=${DB_PASS} | ||
spring.flyway.placeholderReplacement=false | ||
|
||
# Launch the default browser when starting the application in development mode | ||
vaadin.launch-browser=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE `configuration` ( | ||
`conf_key` VARCHAR(255) NOT NULL, | ||
`conf_value` MEDIUMTEXT NOT NULL DEFAULT '', | ||
|
||
PRIMARY KEY (`conf_key`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
spring.datasource.url=jdbc:tc:mariadb:lts:///test?allowMultiQueries=true | ||
spring.datasource.username=test | ||
spring.datasource.password=test | ||
spring.flyway.placeholderReplacement=false |