Skip to content

Commit

Permalink
MGR-88 use Flyway 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Müller authored and Matthias Müller committed Dec 12, 2019
1 parent 750c05c commit 053680a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 124 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Expand Up @@ -379,6 +379,10 @@
<version>8.5.47</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Expand Up @@ -36,13 +36,11 @@
import org.appng.application.manager.business.SqlExecutor.SqlStatement;
import org.appng.application.manager.service.ServiceAware;
import org.appng.core.domain.DatabaseConnection;
import org.appng.core.domain.DatabaseConnection.DatabaseType;
import org.flywaydb.core.internal.dbsupport.DbSupport;
import org.flywaydb.core.internal.dbsupport.SqlScript;
import org.flywaydb.core.internal.dbsupport.hsql.HsqlDbSupport;
import org.flywaydb.core.internal.dbsupport.mysql.MySQLDbSupport;
import org.flywaydb.core.internal.dbsupport.postgresql.PostgreSQLDbSupport;
import org.flywaydb.core.internal.dbsupport.sqlserver.SQLServerDbSupport;
import org.flywaydb.core.api.configuration.FluentConfiguration;
import org.flywaydb.core.internal.database.DatabaseFactory;
import org.flywaydb.core.internal.database.base.Database;
import org.flywaydb.core.internal.resource.StringResource;
import org.flywaydb.core.internal.sqlscript.SqlScript;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
Expand Down Expand Up @@ -80,7 +78,7 @@ public void perform(Site site, Application application, Environment environment,
DataSource dataSource = new SingleConnectionDataSource(databaseConnection.getJdbcUrl(),
databaseConnection.getUserName(), new String(databaseConnection.getPassword()), true);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<String> queries = getQueries(sql, databaseConnection.getType());
List<String> queries = getQueries(sql, databaseConnection);
StringBuilder results = new StringBuilder();
for (String query : queries) {
SqlStatement statementResult = processSingleStatement(query, jdbcTemplate);
Expand Down Expand Up @@ -187,23 +185,10 @@ public void setHasError(boolean hasError) {

}

public List<String> getQueries(String sql, DatabaseType type) {
DbSupport dbSupport = null;
switch (type) {
case MYSQL:
dbSupport = new MySQLDbSupport(null);
break;
case POSTGRESQL:
dbSupport = new PostgreSQLDbSupport(null);
break;
case MSSQL:
dbSupport = new SQLServerDbSupport(null);
break;
case HSQL:
dbSupport = new HsqlDbSupport(null);
break;
}
SqlScript sqlScript = new SqlScript(sql, dbSupport);
public List<String> getQueries(String sql, DatabaseConnection connection) {
Database<?> db = DatabaseFactory
.createDatabase(new FluentConfiguration().dataSource(connection.getDataSource()), true);
SqlScript sqlScript = new SqlScript(db.createSqlStatementBuilderFactory(), new StringResource(sql), false);
List<String> queries = new ArrayList<String>();
sqlScript.getSqlStatements().forEach(query -> queries.add(query.getSql()));
return queries;
Expand Down
Expand Up @@ -1760,7 +1760,7 @@ public List<Selection> getGrantedSelections(Integer siteId, Integer appId) {
public void grantSites(Integer siteId, Integer appId, Set<Integer> grantedSiteIds) {
SiteApplication siteApplication = getSiteApplication(siteId, appId);
siteApplication.getGrantedSites().clear();
List<SiteImpl> sites = siteRepository.findAllById(grantedSiteIds);
List<SiteImpl> sites = siteRepository.findAll(grantedSiteIds);
siteApplication.getGrantedSites().addAll(sites);
}

Expand Down
Expand Up @@ -46,8 +46,8 @@
import org.springframework.test.context.ContextConfiguration;

@Ignore
@ContextConfiguration(classes = ManagerTestConfig.class, initializers = AbstractTest.class)
public class AbstractTest extends TestBase /* implements PropertySourceFactory */ {
@ContextConfiguration(locations = { TestBase.TESTCONTEXT_CORE, TestBase.TESTCONTEXT_JPA }, initializers = AbstractTest.class)
public class AbstractTest extends TestBase {

@Autowired
SiteRepository siteRepository;
Expand Down Expand Up @@ -81,10 +81,6 @@ public class AbstractTest extends TestBase /* implements PropertySourceFactory *
WritingXmlValidator.writeXml = false;
}

// public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
// return new PropertiesPropertySource("testconfig", getProperties());
// }

protected AbstractTest() {
super("appng-manager", APPLICATION_HOME);
setUseFullClassname(false);
Expand Down Expand Up @@ -118,7 +114,6 @@ protected Properties getProperties() {
Properties properties = super.getProperties();
properties.put("hibernate.show_sql", "false");
properties.put("hibernate.format_sql", "false");
properties.put("platform.sharedSecret", "42");
return properties;
}

Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;

//@ContextConfiguration(locations = { "classpath:/beans-test.xml" })
@ContextConfiguration(locations = { "classpath:/beans-test.xml" })
public class DataBaseConnectionsTest extends AbstractTest {

static {
Expand Down

This file was deleted.

Expand Up @@ -16,22 +16,25 @@
package org.appng.application.manager.business;

import org.appng.api.support.CallableAction;
import org.appng.testsupport.validation.WritingXmlValidator;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = { "classpath:/beans-test.xml"})
@ContextConfiguration(locations = { "classpath:/beans-test.xml" })
public class SqlExecutorTest extends AbstractTest {

@Test
public void testExecute() throws Exception {

String sql = "--comment\r\nselect id,name version from site;\r\nselect count(*) from application;\n--comment";
String sql = "--comment\r\nselect id,name version from site;\r\nselect count(*) from application;\r\n--comment\r\n";
CallableAction callableAction = getAction("databaseConnectionEvent", "executeSql")
.withParam(FORM_ACTION, "executeSql").withParam("id", "1")
.getCallableAction(new SqlExecutor.SqlStatement(sql, null, false));

callableAction.perform();
WritingXmlValidator.writeXml = true;
validate(callableAction.getAction());
WritingXmlValidator.writeXml = false;
}

}
12 changes: 6 additions & 6 deletions src/test/resources/xml/SqlExecutorTest-testExecute.xml
Expand Up @@ -26,14 +26,14 @@
<data>
<result>
<field name="content" type="longtext">
<value>--comment&#xD;
select id,name version from site;&#xD;
select count(*) from application;
--comment</value>
<value>--comment&#13;
select id,name version from site;&#13;
select count(*) from application;&#13;
--comment&#13; </value>
</field>
<field name="result" type="richtext">
<value>&lt;div style='background:#F0F0F0;border:1px solid grey'&gt;select id,name version from
site&lt;/div&gt;&lt;table border='1px solid grey' cellpadding='0'
<value>&lt;div style='background:#F0F0F0;border:1px solid grey'&gt;--comment&#13;
select id,name version from site&lt;/div&gt;&lt;table border='1px solid grey' cellpadding='0'
cellspacing='0'&gt;&lt;tr&gt;&lt;th&gt;ID&lt;/th&gt;&lt;th&gt;NAME&lt;/th&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div&gt;0
row(s) selected&lt;/div&gt;&lt;p/&gt;&lt;div style='background:#F0F0F0;border:1px solid grey'&gt;select count(*)
from application&lt;/div&gt;&lt;table border='1px solid grey' cellpadding='0'
Expand Down

0 comments on commit 053680a

Please sign in to comment.