mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
Option for command line db updater - do not execute groovy update scripts #PL-4369
This commit is contained in:
parent
e4f8d73dfa
commit
d646d62aa6
@ -5,7 +5,6 @@
|
||||
|
||||
package com.haulmont.cuba.core.sys;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.haulmont.bali.db.DbUtils;
|
||||
import com.haulmont.bali.db.QueryRunner;
|
||||
import com.haulmont.bali.db.ResultSetHandler;
|
||||
@ -27,7 +26,6 @@ import org.apache.commons.lang.text.StrTokenizer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
@ -182,12 +180,6 @@ public class DbUpdaterEngine implements DbUpdater {
|
||||
|
||||
@Override
|
||||
public List<String> findUpdateDatabaseScripts() throws DBNotInitializedException {
|
||||
return findUpdateDatabaseScripts(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findUpdateDatabaseScripts(@Nullable com.google.common.base.Predicate<File>
|
||||
predicate) throws DBNotInitializedException {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (dbInitialized()) {
|
||||
if (!changelogTableExists) {
|
||||
@ -196,15 +188,7 @@ public class DbUpdaterEngine implements DbUpdater {
|
||||
} else {
|
||||
List<File> files = getUpdateScripts();
|
||||
Set<String> scripts = getExecutedScripts();
|
||||
|
||||
Iterable<File> filesFiltered;
|
||||
if (predicate != null) {
|
||||
filesFiltered = Iterables.filter(files, predicate);
|
||||
} else {
|
||||
filesFiltered = files;
|
||||
}
|
||||
|
||||
for (File file : filesFiltered) {
|
||||
for (File file : files) {
|
||||
String name = getScriptName(file);
|
||||
if (!scripts.contains(name)) {
|
||||
list.add(name);
|
||||
|
@ -5,13 +5,13 @@
|
||||
|
||||
package com.haulmont.cuba.core.sys.utils;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.haulmont.cuba.core.global.MssqlDbDialect;
|
||||
import com.haulmont.cuba.core.global.OracleDbDialect;
|
||||
import com.haulmont.cuba.core.global.PostgresDbDialect;
|
||||
import com.haulmont.cuba.core.sys.DBNotInitializedException;
|
||||
import com.haulmont.cuba.core.sys.DbUpdaterEngine;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
@ -24,6 +24,7 @@ import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Logger;
|
||||
@ -36,6 +37,8 @@ public class DbUpdaterUtil extends DbUpdaterEngine {
|
||||
|
||||
private static Log log = LogFactory.getLog(DbUpdaterEngine.class);
|
||||
|
||||
private boolean executeGroovy = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
DOMConfigurator.configure(DbUpdaterUtil.class.getResource("/com/haulmont/cuba/core/sys/utils/dbutil-log4j.xml"));
|
||||
|
||||
@ -206,19 +209,12 @@ public class DbUpdaterUtil extends DbUpdaterEngine {
|
||||
boolean updatesAvailable = false;
|
||||
try {
|
||||
List<String> scripts;
|
||||
if (cmd.hasOption(dbExecuteGroovyOption.getOpt())
|
||||
&& cmd.getOptionValue(dbExecuteGroovyOption.getOpt()).equals("false")) {
|
||||
|
||||
scripts = findUpdateDatabaseScripts(new Predicate<File>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable File input) {
|
||||
return input != null && !input.getName().endsWith("groovy");
|
||||
}
|
||||
});
|
||||
executeGroovy = !(cmd.hasOption(dbExecuteGroovyOption.getOpt())
|
||||
&& cmd.getOptionValue(dbExecuteGroovyOption.getOpt()).equals("false"));
|
||||
|
||||
scripts = findUpdateDatabaseScripts();
|
||||
|
||||
} else {
|
||||
scripts = findUpdateDatabaseScripts();
|
||||
}
|
||||
if (!scripts.isEmpty()) {
|
||||
StringBuilder availableScripts = new StringBuilder();
|
||||
for (String script : scripts) {
|
||||
@ -244,6 +240,24 @@ public class DbUpdaterUtil extends DbUpdaterEngine {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<File> getUpdateScripts() {
|
||||
if (executeGroovy) {
|
||||
return super.getUpdateScripts();
|
||||
} else {
|
||||
final List<File> files = new ArrayList<>(super.getUpdateScripts());
|
||||
|
||||
CollectionUtils.filter(files, new org.apache.commons.collections.Predicate() {
|
||||
@Override
|
||||
public boolean evaluate(Object object) {
|
||||
return !(object == null || ((File) object).getName().endsWith("groovy"));
|
||||
}
|
||||
});
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SingleConnectionDataSource implements DataSource {
|
||||
|
||||
private String url;
|
||||
|
@ -16,6 +16,4 @@ public interface DbUpdater {
|
||||
void updateDatabase();
|
||||
|
||||
List<String> findUpdateDatabaseScripts() throws DBNotInitializedException;
|
||||
|
||||
List<String> findUpdateDatabaseScripts(Predicate<File> predicate) throws DBNotInitializedException;
|
||||
}
|
Loading…
Reference in New Issue
Block a user