Skip to content

Commit

Permalink
Implement #466 Remove hsql/mysql (#471)
Browse files Browse the repository at this point in the history
* remove mysql and hsqldb

* add pgsql embedded for test/integration

* remove query override
  • Loading branch information
syjer authored and cbellone committed Jun 21, 2018
1 parent 9a01f9a commit b28226b
Show file tree
Hide file tree
Showing 224 changed files with 161 additions and 7,277 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ logs/
out/
.clever.json
!/src/main/webapp/resources/bower_components/angular-growl-v2/build/
alfio-itest
58 changes: 6 additions & 52 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,22 @@
language: java
before_script:
- psql -c 'create database alfio;' -U postgres
- bash .travis.install-mysql-5.7.sh
- mysql -u root -e 'CREATE DATABASE alfio CHARACTER SET utf8 COLLATE utf8_bin;'
- mysql -u root -e 'select VERSION()'
- mysql -u root -e 'select @@sql_mode'
dist: trusty
sudo: required
install:
- TERM=dumb ./gradlew -q assemble
matrix:
include:
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=HSQLDB"
dist: precise
env: PROFILE="-Dspring.profiles.active=travis -Ddbenv=PGSQL-TRAVIS -Dpgsql9.5"
dist: trusty
addons:
apt:
packages:
- mysql-server
- mysql-client-core-5.5
- mysql-client
postgresql: "9.5"
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=PGSQL-TRAVIS -Dpgsql9.1"
dist: precise
env: PROFILE="-Dspring.profiles.active=travis -Ddbenv=PGSQL-TRAVIS -Dpgsql9.6"
dist: trusty
addons:
postgresql: "9.1"
apt:
packages:
- mysql-server
- mysql-client-core-5.5
- mysql-client
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=PGSQL-TRAVIS -Dpgsql9.4"
dist: precise
addons:
postgresql: "9.4"
apt:
packages:
- mysql-server
- mysql-client-core-5.5
- mysql-client
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=MYSQL -Dmysql5.5"
dist: precise
addons:
apt:
packages:
- mysql-server
- mysql-client-core-5.5
- mysql-client
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=MYSQL -Dmysql5.6"
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=MYSQL -Dmariadb10.1"
addons:
mariadb: 10.1
- jdk: oraclejdk8
env: PROFILE="-Ddbenv=MYSQL -Dmysql.5.7"
postgresql: "9.6"

script:
- TERM=dumb ./gradlew build jacocoTestReport $PROFILE
Expand Down
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,34 @@ You must specify a project property at the command line, such as
./gradlew -Pprofile=dev :bootRun
```

Note: if you want to test without installing a pgsql instance, we have configured the following tasks:

- startEmbeddedPgSQL
- stopEmbeddedPgSQL

So, in a terminal first launch pgsql:

```
./gradlew startEmbeddedPgSQL
```

In another one launch alf.io

```
./gradlew -Pprofile=dev :bootRun
```

When you are done, kill the pgsql instance with:

```
./gradlew stopEmbeddedPgSQL
```


The following profiles are supported

* `dev`
* `dev-pgsql`
* `dev-mysql`
* `docker-test`

You can get a list of all supported Gradle tasks by running
Expand All @@ -51,18 +74,6 @@ Please be aware that since this file could contain sensitive information (such a
Add a new line with: `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005` in custom.jvmargs


#### Using hsqldb gui

In the custom.jvmargs add the following 2 lines:

```
-Djava.awt.headless=false
-DstartDBManager=true
```

Then, when executing `./gradlew -Pprofile=dev :bootRun`, the ui will automatically launch.


## Developing alf.io
Importing the Gradle project into Intellij and Eclipse both work.

Expand Down
75 changes: 45 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import org.apache.tools.ant.filters.ReplaceTokens

import java.nio.file.Files
import java.nio.file.Paths
import java.time.Year
import java.time.ZoneId
import java.time.ZonedDateTime
Expand All @@ -8,7 +10,8 @@ import java.util.regex.Pattern

buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE")
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE'
classpath 'ru.yandex.qatools.embed:postgresql-embedded:+'
}
repositories {
jcenter()
Expand Down Expand Up @@ -76,12 +79,12 @@ ext {
// default settings
jettyPort = 8080
jettyHost = '0.0.0.0'
datasourceDialect = 'HSQLDB'
datasourceDriver = 'org.hsqldb.jdbcDriver'
datasourceUrl = 'jdbc:hsqldb:mem:alfio'
datasourceUsername = 'sa'
datasourcePassword = ''
datasourceValidationQuery = 'SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS'
datasourceDialect = 'PGSQL'
datasourceDriver = 'org.postgresql.Driver'
datasourceUrl = 'jdbc:postgresql://localhost:5432/alfio'
datasourceUsername = 'postgres'
datasourcePassword = 'password'
datasourceValidationQuery = 'SELECT 1'
//springProfilesActive = 'dev,debug-csp' //enable csp report. FIXME For some reasons it doesn't work on Chrome
//springProfilesActive = 'dev,demo'
//springProfilesActive = 'dev,demo,jdbc-session'
Expand All @@ -90,27 +93,7 @@ ext {
port = "8080"


// dockerfile template attributes



switch (profile) {
case 'dev-pgsql':
datasourceDialect = 'PGSQL'
datasourceDriver = 'org.postgresql.Driver'
datasourceUrl = 'jdbc:postgresql://localhost:5432/alfio'
datasourceUsername = 'postgres'
datasourcePassword = 'password'
datasourceValidationQuery = 'SELECT 1'
break
case 'dev-mysql':
datasourceDialect = 'MYSQL'
datasourceDriver = 'com.mysql.jdbc.Driver'
datasourceUrl = 'jdbc:mysql://localhost:3306/alfio'
datasourceUsername = 'root'
datasourcePassword = ''
datasourceValidationQuery = 'SELECT 1'
break
case 'docker-test':
datasourceDialect = 'PGSQL'
datasourceDriver = 'org.postgresql.Driver'
Expand All @@ -119,6 +102,9 @@ ext {
datasourcePassword = 'postgres'
datasourceValidationQuery = 'SELECT 1'
break
case 'travis':
project.springProfilesActive = 'travis'
break
}
}

Expand Down Expand Up @@ -163,7 +149,6 @@ dependencies {
compile "com.google.zxing:javase:3.3.2"
compile "org.flywaydb:flyway-core:4.2.0"
compile "org.postgresql:postgresql:42.1.4"
compile 'mysql:mysql-connector-java:5.1.42'
compile "com.zaxxer:HikariCP:2.7.7"
compile "org.apache.logging.log4j:log4j-api:$log4jVersion"
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
Expand All @@ -189,12 +174,12 @@ dependencies {

compileOnly "org.projectlombok:lombok:1.16.20"
testCompile "org.projectlombok:lombok:1.16.20"
testCompile "ru.yandex.qatools.embed:postgresql-embedded:2.8"

compileOnly "javax.servlet:javax.servlet-api:3.1.0"
testCompile "javax.servlet:javax.servlet-api:3.1.0"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "net.sourceforge.htmlunit:htmlunit:2.29"
runtime "org.hsqldb:hsqldb:2.4.0"
runtime "commons-fileupload:commons-fileupload:1.3.3"
providedCompile "org.springframework.boot:spring-boot-starter-web@jar"
providedCompile "org.springframework.boot:spring-boot-starter@jar"
Expand Down Expand Up @@ -250,7 +235,7 @@ compileJava {

//propagate the system properties to the tests
test {
systemProperties = System.getProperties()
systemProperties = System.properties
testLogging {
events "failed"
exceptionFormat "full"
Expand Down Expand Up @@ -332,6 +317,36 @@ task clever(type: Copy) {
dependsOn build
}

import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres
import ru.yandex.qatools.embed.postgresql.distribution.Version.Main

task startEmbeddedPgSQL {
doLast {
final pgsqlPath = Paths.get(".", "alfio-itest")
Files.createDirectories(pgsqlPath)
final tmpDataDir = Files.createTempDirectory(pgsqlPath, "alfio-data")
final postgres = new EmbeddedPostgres(Main.PRODUCTION, tmpDataDir.normalize().toAbsolutePath().toString())
postgres.start(EmbeddedPostgres.cachedRuntimeConfig(Paths.get(System.getProperty("java.io.tmpdir"), "pgembed")),
"localhost", 5432, "alfio", "postgres", "password", Arrays.asList("-E", "SQL_ASCII", "--locale=C", "--lc-collate=C", "--lc-ctype=C"))

postgres.getProcess().ifPresent({
final pid = it.getProcessId()
Files.write(Paths.get(".", "alfio-itest", "pgsql-pid"), Arrays.asList(Long.toString(pid)))
System.out.println("Launched pgsql with pid " + pid)
})
}
}

task stopEmbeddedPgSQL {
doLast {
final pidFile = Paths.get(".", "alfio-itest", "pgsql-pid");
final pid = Files.readAllLines(pidFile).get(0)
Files.deleteIfExists(pidFile)
Runtime.runtime.exec("kill -9 " + pid)
System.out.println("Killed pgsql with pid " + pid)
}
}

release {
git {
requireBranch = ''
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/alfio/config/DataSourceConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.springframework.web.servlet.view.mustache.jmustache.JMustacheTemplateLoader;

import javax.sql.DataSource;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
Expand All @@ -76,6 +75,7 @@ public class DataSourceConfiguration implements ResourceLoaderAware {
private ResourceLoader resourceLoader;

@Bean
@Profile({"!"+Initializer.PROFILE_INTEGRATION_TEST, "travis"})
public PlatformProvider getCloudProvider(Environment environment) {
PlatformProvider current = PLATFORM_PROVIDERS
.stream()
Expand All @@ -96,7 +96,8 @@ public PlatformProvider getCloudProvider(Environment environment) {
}

@Bean
public DataSource getDataSource(Environment env, PlatformProvider platform) throws URISyntaxException {
@Profile({"!"+Initializer.PROFILE_INTEGRATION_TEST, "travis"})
public DataSource getDataSource(Environment env, PlatformProvider platform) {
if(platform == PlatformProvider.CLOUD_FOUNDRY) {
return new FakeCFDataSource();
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/alfio/config/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {

public static final String PROFILE_DEV = "dev";
public static final String PROFILE_INTEGRATION_TEST = "integration-test";
public static final String PROFILE_DEBUG_CSP = "debug-csp";
public static final String PROFILE_LIVE = "!dev";
static final String PROFILE_HTTP = "http";
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/alfio/config/SpringBootLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import alfio.util.DefaultExceptionHandler;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
Expand Down Expand Up @@ -55,19 +53,5 @@ public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = application.run(args);
ConfigurableEnvironment environment = applicationContext.getEnvironment();
log.info("profiles: requested {}, active {}", profiles, String.join(", ", (CharSequence[]) environment.getActiveProfiles()));
if ("true".equals(System.getProperty("startDBManager"))) {
launchHsqlGUI();
}
}


private static void launchHsqlGUI() {
Class<?> cls;
try {
cls = ClassUtils.getClass("org.hsqldb.util.DatabaseManagerSwing");
MethodUtils.invokeStaticMethod(cls, "main", new Object[]{new String[]{"--url", "jdbc:hsqldb:mem:alfio", "--noexit"}});
} catch (ReflectiveOperationException e) {
log.warn("error starting db manager", e);
}
}
}

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/alfio/repository/TicketFieldRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ public interface TicketFieldRepository extends FieldRepository {
int deleteAllValuesForTicketIds(@Bind("ticketIds") List<Integer> ticketIds);

@Query("delete from ticket_field_value fv using ticket t where t.id = fv.ticket_id_fk and t.tickets_reservation_id in(:reservationIds)")
@QueriesOverride({
@QueryOverride(db = PlatformProvider.MYSQL, value = "delete tv.* from ticket_field_value tv inner join ticket t on t.id = tv.ticket_id_fk where t.tickets_reservation_id in(:reservationIds)"),
@QueryOverride(db = "HSQLDB", value = "delete from ticket_field_value where ticket_id_fk in (select id from ticket where tickets_reservation_id in(:reservationIds))")
})
int deleteAllValuesForReservations(@Bind("reservationIds") List<String> reservationIds);

@Query("select ticket_field_configuration_id_fk, field_locale, description from ticket_field_description inner join ticket_field_configuration on ticket_field_configuration_id_fk = id where field_locale = :locale and event_id_fk = :eventId")
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/alfio/repository/TicketRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,9 @@ public interface TicketRepository {
int freeFromReservation(@Bind("reservationIds") List<String> reservationIds);

@Query("update ticket set category_id = null where tickets_reservation_id in (:reservationIds) and status in ('PENDING', 'OFFLINE_PAYMENT') and category_id in (select tc.id from ticket_category tc, ticket t where t.tickets_reservation_id in (:reservationIds) and t.category_id = tc.id and tc.bounded = false)")
@QueriesOverride({
@QueryOverride(db = "MYSQL", value = "update ticket set category_id = null where tickets_reservation_id in (:reservationIds) and status in ('PENDING', 'OFFLINE_PAYMENT') and category_id in (select * from (select tc.id from ticket_category tc, ticket t where t.tickets_reservation_id in (:reservationIds) and t.category_id = tc.id and tc.bounded = false) as sq)")
})
int resetCategoryIdForUnboundedCategories(@Bind("reservationIds") List<String> reservationIds);

@Query("update ticket set category_id = null where id in (:ticketIds) and category_id in (select tc.id from ticket_category tc, ticket t where t.id in (:ticketIds) and t.category_id = tc.id and tc.bounded = false)")
@QueriesOverride({
@QueryOverride(db = "MYSQL", value = "update ticket set category_id = null where id in (:ticketIds) and category_id in (select * from (select tc.id from ticket_category tc, ticket t where t.id in (:ticketIds) and t.category_id = tc.id and tc.bounded = false) as sq)")
})
int resetCategoryIdForUnboundedCategoriesWithTicketIds(@Bind("ticketIds") List<Integer> ticketIds);

@Query("update ticket set category_id = null where event_id = :eventId and category_id = :categoryId and id in (:ticketIds)")
Expand Down
Loading

0 comments on commit b28226b

Please sign in to comment.