Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
v3 release Merge pull request #476 from Frederikam/v3/release
Browse files Browse the repository at this point in the history
v3 release
  • Loading branch information
schnapster committed Mar 14, 2018
2 parents 1c817a7 + 537f62e commit 1e8743e
Show file tree
Hide file tree
Showing 83 changed files with 2,014 additions and 1,625 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ gc-*.log
.gradle/*
*/out/*
VERSION.txt
fredboat.yaml
fredboat.yml
application.yaml
application.yml
backend.yaml
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Obtaining a well functioning and productive setup of the IDE may be an intimidat

### Running the bot

Add `credentials.yaml` and `config.yaml` files to the FredBoat root directory.
Add the `fredboat.yaml` file to the FredBoat root directory (symlinking recommended).

To run the FredBoat bot in IntelliJ IDEA, find the little green play button in the main class `FredBoat.java` and start it from there:
<details><summary>Click me</summary>
Expand Down
28 changes: 28 additions & 0 deletions Database/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ version '1.0'
ext {
moduleName = 'Database'
}

apply plugin: 'maven-publish'

publishing {
publications {
mavenJava(MavenPublication) {
groupId rootProject.group
artifactId moduleName

from components.java

artifact sourceJar {
classifier "sources"
}
}
}
}

task install(dependsOn: 'publishToMavenLocal')
publishToMavenLocal.dependsOn 'jar'

task sourceJar(type: Jar) {
from sourceSets.main.allJava
}

dependencies {
compile project(':Shared')

Expand All @@ -14,4 +39,7 @@ dependencies {
compile group: 'org.hibernate', name: 'hibernate-ehcache', version: hibernateVersion
compile group: 'org.flywaydb', name: 'flyway-core', version: flywayVersion
compile group: 'net.ttddyy', name: 'datasource-proxy', version: dsProxyVersion
compile group: 'javax.xml.bind', name: 'jaxb-api', version: jaxbApiVersion // required by hibernate for java 9

compile group: 'com.google.code.gson', name: 'gson', version: gsonVersion
}
40 changes: 8 additions & 32 deletions Database/src/main/java/fredboat/db/DatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory;
import io.prometheus.client.hibernate.HibernateStatisticsCollector;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.PersistenceConfiguration;
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.flywaydb.core.Flyway;
Expand All @@ -40,7 +38,6 @@
import space.npstr.sqlsauce.DatabaseConnection;
import space.npstr.sqlsauce.DatabaseException;
import space.npstr.sqlsauce.DatabaseWrapper;
import space.npstr.sqlsauce.ssh.SshTunnel;

import javax.annotation.Nullable;
import java.util.Properties;
Expand All @@ -62,12 +59,8 @@ public class DatabaseManager {
private final boolean migrateAndValidate;
private final String mainJdbc;
@Nullable
private final SshTunnel.SshDetails mainTunnel;
@Nullable
private final String cacheJdbc;
@Nullable
private final SshTunnel.SshDetails cacheTunnel;
@Nullable
private final DatabaseConnection.EntityManagerFactoryBuilder entityManagerFactoryBuilder;

@Nullable
Expand All @@ -92,20 +85,23 @@ public DatabaseManager(@Nullable HibernateStatisticsCollector hibernateStats,
String appName,
boolean migrateAndValidate,
String mainJdbc,
@Nullable SshTunnel.SshDetails mainTunnel,
@Nullable String cacheJdbc,
@Nullable SshTunnel.SshDetails cacheTunnel,
@Nullable DatabaseConnection.EntityManagerFactoryBuilder entityManagerFactoryBuilder) {
this.hibernateStats = hibernateStats;
this.hikariStats = hikariStats;
this.poolsize = poolsize;
this.appName = appName;
this.migrateAndValidate = migrateAndValidate;
this.mainJdbc = mainJdbc;
this.mainTunnel = mainTunnel;
this.cacheJdbc = cacheJdbc;
this.cacheTunnel = cacheTunnel;
this.entityManagerFactoryBuilder = entityManagerFactoryBuilder;

if (mainJdbc.isEmpty()) {
log.error("Main jdbc url is empty - database creation will fail");
}
if (cacheJdbc != null && cacheJdbc.isEmpty()) {
log.error("Cache jdbc url is empty - database creation will fail");
}
}

public DatabaseConnection getMainDbConn() {
Expand Down Expand Up @@ -138,7 +134,7 @@ public DatabaseWrapper getMainDbWrapper() {

@Nullable //may return null if no cache db is configured
public DatabaseConnection getCacheDbConn() {
if (cacheJdbc == null) {
if (cacheJdbc == null || cacheJdbc.isEmpty()) {
return null;
}
DatabaseConnection singleton = cacheDbConn;
Expand Down Expand Up @@ -192,15 +188,9 @@ private DatabaseConnection initMainDbConn() throws DatabaseException {
DatabaseConnection databaseConnection = getBasicConnectionBuilder(MAIN_PERSISTENCE_UNIT_NAME, mainJdbc)
.setHibernateProps(buildHibernateProps("ehcache_main.xml"))
.addEntityPackage("fredboat.db.entity.main")
.setSshDetails(mainTunnel)
.setFlyway(flyway)
.build();

//adjusting the ehcache config
if (mainTunnel == null && cacheTunnel == null) {
//local database: turn off overflow to disk of the cache
turnOffLocalStorageForEhcacheManager("MAIN_CACHEMANAGER");
}
log.debug(CacheManager.getCacheManager("MAIN_CACHEMANAGER").getActiveConfigurationText());

return databaseConnection;
Expand All @@ -217,15 +207,9 @@ public DatabaseConnection initCacheConn(String jdbc) throws DatabaseException {
DatabaseConnection databaseConnection = getBasicConnectionBuilder(CACHE_PERSISTENCE_UNIT_NAME, jdbc)
.setHibernateProps(buildHibernateProps("ehcache_cache.xml"))
.addEntityPackage("fredboat.db.entity.cache")
.setSshDetails(cacheTunnel)
.setFlyway(flyway)
.build();

//adjusting the ehcache config
if (mainTunnel == null && cacheTunnel == null) {
//local database: turn off overflow to disk of the cache
turnOffLocalStorageForEhcacheManager("CACHE_CACHEMANAGER");
}
log.debug(CacheManager.getCacheManager("CACHE_CACHEMANAGER").getActiveConfigurationText());

return databaseConnection;
Expand Down Expand Up @@ -283,12 +267,4 @@ private Properties buildHibernateProps(String ehcacheXmlFile) {

return hibernateProps;
}

private void turnOffLocalStorageForEhcacheManager(String cacheManagerName) {
CacheManager cacheManager = CacheManager.getCacheManager(cacheManagerName);
for (String cacheName : cacheManager.getCacheNames()) {
CacheConfiguration cacheConfig = cacheManager.getCache(cacheName).getCacheConfiguration();
cacheConfig.getPersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.NONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface BlacklistIO {
public interface BlacklistService {

/**
* @return the whole blacklist aka all entries. Not a lightweight operation, and shouldn't be called outside
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface GuildConfigIO {
public interface GuildConfigService {

GuildConfig fetchGuildConfig(Guild guild);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface GuildDataIO {
public interface GuildDataService {

GuildData fetchGuildData(Guild guild);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface GuildModulesIO {
public interface GuildModulesService {

GuildModules fetchGuildModules(Guild guild);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface GuildPermsIO {
public interface GuildPermsService {

GuildPermissions fetchGuildPermissions(Guild guild);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface PrefixIO {
public interface PrefixService {

Prefix transformPrefix(Guild guild, Function<Prefix, Prefix> transformation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Created by napster on 07.02.18.
*/
public interface SearchResultIO {
public interface SearchResultService {

/**
* Merge a search result into the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public boolean equals(Object o) {
SearchResultId other = (SearchResultId) o;
return provider.equals(other.provider) && searchTerm.equals(other.searchTerm);
}

@Override
public String toString() {
return "Search: Provider " + provider + " Term " + searchTerm;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,20 @@

import net.dv8tion.jda.core.entities.Guild;

import javax.annotation.Nullable;

/**
* Created by napster on 05.02.18.
*/
public interface GuildBasedRepo<E> extends Repo<Long, E> {

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
*/
@Nullable
default E get(Guild guild) {
return get(guild.getIdLong());
}

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
* Type safety on top of {@link Repo#delete(Object)} for entities based on guilds.
*/
default void delete(Guild guild) {
delete(guild.getIdLong());
}

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
* Type safety on top of {@link Repo#fetch(Object)} for entities based on guilds.
*/
default E fetch(Guild guild) {
return fetch(guild.getIdLong());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import net.dv8tion.jda.core.entities.Guild;

import javax.annotation.Nullable;

/**
* Created by napster on 05.02.18.
* <p>
Expand All @@ -38,22 +36,14 @@
public interface LegacyGuildBasedRepo<E> extends Repo<String, E> {

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
*/
@Nullable
default E get(Guild guild) {
return get(guild.getId());
}

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
* Type safety on top of {@link Repo#delete(Object)} for entities based on guilds.
*/
default void delete(Guild guild) {
delete(guild.getId());
}

/**
* Type safety on top of {@link Repo#get(Object)} for entities based on guilds.
* Type safety on top of {@link Repo#fetch(Object)} for entities based on guilds.
*/
default E fetch(Guild guild) {
return fetch(guild.getId());
Expand Down
9 changes: 0 additions & 9 deletions Database/src/main/java/fredboat/db/repositories/api/Repo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,11 @@

package fredboat.db.repositories.api;

import javax.annotation.Nullable;

/**
* Created by napster on 05.02.18.
*/
public interface Repo<I, E> {

/**
* @param id id of the entity that shall be returned
* @return the entity of the provided id, if such an entity exists in the database, null otherwise
*/
@Nullable
E get(I id);

/**
* @param id of the entity that shall be deleted
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import space.npstr.sqlsauce.entities.SaucedEntity;
import space.npstr.sqlsauce.fp.types.EntityKey;

import javax.annotation.Nullable;
import java.io.Serializable;

/**
Expand All @@ -54,12 +53,6 @@ public Class<E> getEntityClass() {
return entityClass;
}

@Nullable
@Override
public E get(I id) {
return dbWrapper.getEntity(EntityKey.of(id, entityClass));
}

@Override
public void delete(I id) {
dbWrapper.deleteEntity(EntityKey.of(id, entityClass));
Expand Down
Loading

0 comments on commit 1e8743e

Please sign in to comment.