|
|
@ -20,6 +20,7 @@ import cn.escheduler.common.utils.MysqlUtil; |
|
|
|
import cn.escheduler.common.utils.ScriptRunner; |
|
|
|
import cn.escheduler.common.utils.ScriptRunner; |
|
|
|
import cn.escheduler.dao.AbstractBaseDao; |
|
|
|
import cn.escheduler.dao.AbstractBaseDao; |
|
|
|
import cn.escheduler.dao.datasource.ConnectionFactory; |
|
|
|
import cn.escheduler.dao.datasource.ConnectionFactory; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
@ -33,6 +34,7 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class); |
|
|
|
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class); |
|
|
|
private static final String T_VERSION_NAME = "t_escheduler_version"; |
|
|
|
private static final String T_VERSION_NAME = "t_escheduler_version"; |
|
|
|
|
|
|
|
private static final String rootDir = System.getProperty("user.dir"); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void init() { |
|
|
|
protected void init() { |
|
|
@ -64,6 +66,10 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
private void runInitEschedulerDML() { |
|
|
|
private void runInitEschedulerDML() { |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(rootDir)) { |
|
|
|
|
|
|
|
throw new RuntimeException("Environment variable user.dir not found"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String mysqlSQLFilePath = rootDir + "/sql/create/release-1.0.0_schema/mysql/escheduler_dml.sql"; |
|
|
|
try { |
|
|
|
try { |
|
|
|
conn = ConnectionFactory.getDataSource().getConnection(); |
|
|
|
conn = ConnectionFactory.getDataSource().getConnection(); |
|
|
|
conn.setAutoCommit(false); |
|
|
|
conn.setAutoCommit(false); |
|
|
@ -71,7 +77,7 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
// Execute the ark_manager_dml.sql script to import the data related to escheduler
|
|
|
|
// Execute the ark_manager_dml.sql script to import the data related to escheduler
|
|
|
|
|
|
|
|
|
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, false, true); |
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, false, true); |
|
|
|
Reader initSqlReader = new FileReader(new File("sql/create/release-1.0.0_schema/mysql/escheduler_dml.sql")); |
|
|
|
Reader initSqlReader = new FileReader(new File(mysqlSQLFilePath)); |
|
|
|
initScriptRunner.runScript(initSqlReader); |
|
|
|
initScriptRunner.runScript(initSqlReader); |
|
|
|
|
|
|
|
|
|
|
|
conn.commit(); |
|
|
|
conn.commit(); |
|
|
@ -100,11 +106,15 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
private void runInitEschedulerDDL() { |
|
|
|
private void runInitEschedulerDDL() { |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(rootDir)) { |
|
|
|
|
|
|
|
throw new RuntimeException("Environment variable user.dir not found"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String mysqlSQLFilePath = rootDir + "/sql/create/release-1.0.0_schema/mysql/escheduler_ddl.sql"; |
|
|
|
try { |
|
|
|
try { |
|
|
|
conn = ConnectionFactory.getDataSource().getConnection(); |
|
|
|
conn = ConnectionFactory.getDataSource().getConnection(); |
|
|
|
// Execute the escheduler_ddl.sql script to create the table structure of escheduler
|
|
|
|
// Execute the escheduler_ddl.sql script to create the table structure of escheduler
|
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, true, true); |
|
|
|
ScriptRunner initScriptRunner = new ScriptRunner(conn, true, true); |
|
|
|
Reader initSqlReader = new FileReader(new File("sql/create/release-1.0.0_schema/mysql/escheduler_ddl.sql")); |
|
|
|
Reader initSqlReader = new FileReader(new File(mysqlSQLFilePath)); |
|
|
|
initScriptRunner.runScript(initSqlReader); |
|
|
|
initScriptRunner.runScript(initSqlReader); |
|
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
@ -122,7 +132,11 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determines whether a table exists |
|
|
|
|
|
|
|
* @param tableName |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
public boolean isExistsTable(String tableName) { |
|
|
|
public boolean isExistsTable(String tableName) { |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
try { |
|
|
|
try { |
|
|
@ -144,6 +158,33 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determines whether a field exists in the specified table |
|
|
|
|
|
|
|
* @param tableName |
|
|
|
|
|
|
|
* @param columnName |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean isExistsColumn(String tableName,String columnName) { |
|
|
|
|
|
|
|
Connection conn = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
conn = ConnectionFactory.getDataSource().getConnection(); |
|
|
|
|
|
|
|
ResultSet rs = conn.getMetaData().getColumns(null,null,tableName,columnName); |
|
|
|
|
|
|
|
if (rs.next()) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
|
|
|
|
throw new RuntimeException(e.getMessage(),e); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
MysqlUtil.realeaseResource(null, null, conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getCurrentVersion() { |
|
|
|
public String getCurrentVersion() { |
|
|
|
String sql = String.format("select version from %s",T_VERSION_NAME); |
|
|
|
String sql = String.format("select version from %s",T_VERSION_NAME); |
|
|
@ -182,7 +223,10 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
private void upgradeEschedulerDML(String schemaDir) { |
|
|
|
private void upgradeEschedulerDML(String schemaDir) { |
|
|
|
String schemaVersion = schemaDir.split("_")[0]; |
|
|
|
String schemaVersion = schemaDir.split("_")[0]; |
|
|
|
String mysqlSQLFilePath = "sql/upgrade/" + schemaDir + "/mysql/escheduler_dml.sql"; |
|
|
|
if (StringUtils.isEmpty(rootDir)) { |
|
|
|
|
|
|
|
throw new RuntimeException("Environment variable user.dir not found"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String mysqlSQLFilePath = rootDir + "/sql/upgrade/" + schemaDir + "/mysql/escheduler_dml.sql"; |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
PreparedStatement pstmt = null; |
|
|
|
PreparedStatement pstmt = null; |
|
|
|
try { |
|
|
|
try { |
|
|
@ -239,7 +283,10 @@ public class UpgradeDao extends AbstractBaseDao { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void upgradeEschedulerDDL(String schemaDir) { |
|
|
|
private void upgradeEschedulerDDL(String schemaDir) { |
|
|
|
String mysqlSQLFilePath = "sql/upgrade/" + schemaDir + "/mysql/escheduler_ddl.sql"; |
|
|
|
if (StringUtils.isEmpty(rootDir)) { |
|
|
|
|
|
|
|
throw new RuntimeException("Environment variable user.dir not found"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String mysqlSQLFilePath = rootDir + "/sql/upgrade/" + schemaDir + "/mysql/escheduler_ddl.sql"; |
|
|
|
Connection conn = null; |
|
|
|
Connection conn = null; |
|
|
|
PreparedStatement pstmt = null; |
|
|
|
PreparedStatement pstmt = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|