Browse Source

init 仓库初始化

master
Jianye.Wang 2 years ago
parent
commit
f4b749c188
  1. BIN
      Dm7JdbcDriver18.jar
  2. 18
      README.md
  3. BIN
      plugin-dm-platform-transfer.jar
  4. 24
      plugin.xml
  5. 18
      src/main/java/com/fr/plugin/platform/db/transfer/dm/DMClassLoaderHandler.java
  6. 19
      src/main/java/com/fr/plugin/platform/db/transfer/dm/DMDialect.java
  7. 44
      src/main/java/com/fr/plugin/platform/db/transfer/dm/DMDialectCreator.java
  8. 66
      src/main/java/com/fr/plugin/platform/db/transfer/dm/DMLifecycleMonitor.java
  9. 30
      src/main/java/com/fr/plugin/platform/db/transfer/dm/DMMigrationConfig.java
  10. 746
      src/main/java/com/fr/plugin/platform/db/transfer/dm/FRDMDialect.java
  11. 34
      src/main/java/com/fr/plugin/platform/db/transfer/dm/interceptor/DBInterceptorCreationHook.java
  12. 15
      src/main/java/com/fr/plugin/platform/db/transfer/dm/web/DMComponent.java
  13. 17
      src/main/java/com/fr/plugin/platform/db/transfer/dm/web/DMWebResource.java
  14. 37
      src/main/resources/com/fr/plugin/platform/db/transfer/dm/web/js/plugin.min.js

BIN
Dm7JdbcDriver18.jar

Binary file not shown.

18
README.md

@ -1,3 +1,19 @@
# com.fr.plugin.platform.db.transfer.dm
达梦数据库外置数据库迁移
达梦数据库外置数据库迁移
# 需求编号
JSD-7366 平台数据迁移数据库支持达梦数据库
# 插件说明
plugin-dm-platform-transfer.jar 以及 达梦连接驱动包(达梦7测试用的 Dm7JdbcDriver18.jar) 拷贝到 lib 目录下;
插件包正常安装即可。
# 实现逻辑
plugin-dm-platform-transfer.jar 中 FRDMDialect 继承 com.fr.third.org.hibernate.dialect
(https://repo1.maven.org/maven2/com/dameng/DmDialect-for-hibernate5.3/7.6.0.165/ 不同版本达梦 DmDialect 还不一定兼容)
DmDialect已知问题:
1、varchar 和 varbinary 字段不支持超过 8188
2、达梦数据库迁移报错 Violate not null constraint on [DEPARTMENTID]
DEPARTMENTID 字段是 not null, finedb中数据是空字符串,但是在迁移的过程报错不允许为空约束,这是因为达梦数据库 COMPATIBLE 参数可以修改配置(Server compatible mode, 0:none, 1:SQL92, 2:Oracle, 3:MS SQL Server, 4:MySQL, 5:DM6, 6:Teradata ,可通过 SELECT * FROM v$DM_INI WHERE PARA_NAME = 'COMPATIBLE_MODE' 查询),当值为 2的时候表示是识别为 oracle 模式,会出现上诉问题,
修改方案:在数据库安装目录下找到 dm.ini 文件修改其中的 COMPATIBLE 值为 0(其他值未验证),重启数据库。

BIN
plugin-dm-platform-transfer.jar

Binary file not shown.

24
plugin.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.platform.db.transfer.dm</id>
<name><![CDATA[达梦数据库外置数据库迁移]]></name>
<active>yes</active>
<hidden>no</hidden>
<version>1.0.6.1</version>
<env-version>10.0</env-version>
<jartime>2020-01-01</jartime>
<vendor>Jianye.Wang</vendor>
<description><![CDATA[达梦数据库外置数据库迁移]]></description>
<change-notes><![CDATA[
<p>[2021-06-21]调整产品JAR包时间要求范围</p>
]]></change-notes>
<extra-core>
<!--<DataSourceDriverLoader class="com.fr.plugin.platform.db.transfer.dm.DMClassLoaderHandler"/>-->
<DialectCreator class="com.fr.plugin.platform.db.transfer.dm.DMDialectCreator"/>
</extra-core>
<extra-decision>
<WebResourceProvider class="com.fr.plugin.platform.db.transfer.dm.web.DMWebResource"/>
</extra-decision>
<lifecycle-monitor class="com.fr.plugin.platform.db.transfer.dm.DMLifecycleMonitor"/>
<function-recorder class="com.fr.plugin.platform.db.transfer.dm.DMDialectCreator"/>
</plugin>

18
src/main/java/com/fr/plugin/platform/db/transfer/dm/DMClassLoaderHandler.java

@ -0,0 +1,18 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.fun.impl.AbstractDataSourceDriverLoader;
public class DMClassLoaderHandler extends AbstractDataSourceDriverLoader {
public boolean isInterceptAllowed(String databaseType, String url) {
if (url.startsWith("jdbc:dm")) {
FineLoggerFactory.getLogger().info("[dm datasource] The connection has been intercepted.");
return true;
}
return false;
}
public ClassLoader getClassLoader() {
return this.getClass().getClassLoader();
}
}

19
src/main/java/com/fr/plugin/platform/db/transfer/dm/DMDialect.java

@ -0,0 +1,19 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.data.core.db.dialect.DmDialect;
import com.fr.data.core.db.dialect.base.DialectKeyConstants;
import com.fr.data.core.db.dialect.base.key.check.schema.DialectHasSchemaExecutor;
import com.fr.data.core.db.dialect.base.key.hibernate.HibernateDialectClassExecutor;
import com.fr.data.core.db.dialect.base.key.schema.PhoenixDialectSchemaExecutor;
import com.fr.data.core.db.dialect.base.key.validationquery.SELECT1DialectDefaultValidationQueryExecutor;
public class DMDialect extends DmDialect {
public DMDialect() {
super();
putExecutor(DialectKeyConstants.HIBERNATE_DIALECT_CLASS_KEY, new HibernateDialectClassExecutor(FRDMDialect.class.getName()));
putExecutor(DialectKeyConstants.CHECK_HAS_SCHEMA_KEY, new DialectHasSchemaExecutor());
putExecutor(DialectKeyConstants.SCHEMA_KEY, new PhoenixDialectSchemaExecutor());
putExecutor(DialectKeyConstants.DEFAULT_VALIDATION_QUERY_KEY, new SELECT1DialectDefaultValidationQueryExecutor());
}
}

44
src/main/java/com/fr/plugin/platform/db/transfer/dm/DMDialectCreator.java

@ -0,0 +1,44 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.stable.UrlDriver;
import com.fr.stable.fun.impl.AbstractDialectCreator;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@FunctionRecorder
public class DMDialectCreator extends AbstractDialectCreator {
public final static String Driver = "dm.jdbc.driver.DmDriver";
public final static String DBName = "DM DBMS";
@ExecuteFunctionRecord
@Override
public Class<?> generate(UrlDriver urlDriver) {
if (null == urlDriver) {
return null;
}
// "dm.jdbc.driver.DmDriver"
if (Driver.equals(urlDriver.getDriver().trim())) {
return DMDialect.class;
}
return null;
}
@Override
public Class<?> generate(Connection connection) {
try {
DatabaseMetaData databaseMetaData = connection.getMetaData();
String databaseName = databaseMetaData.getDatabaseProductName();
//"DM DBMS"
if (DBName.equals(databaseName)) {
return DMDialect.class;
}
} catch (Exception e) {
}
return null;
}
}

66
src/main/java/com/fr/plugin/platform/db/transfer/dm/DMLifecycleMonitor.java

@ -0,0 +1,66 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.config.FineDBDriverClassLoaderStore;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.platform.db.transfer.dm.interceptor.DBInterceptorCreationHook;
import com.fr.stable.CommonUtils;
import com.fr.stable.db.DBContext;
import com.fr.third.guava.io.ByteStreams;
import com.fr.workspace.WorkContext;
import java.io.IOException;
import java.io.InputStream;
public class DMLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
//用配置项,而不放在afterInstall的原因:afterInstall的时候还读不到resource里的内容
if (!DMMigrationConfig.getInstance().isInit()) {
// 移动方言、jar包,防止重启后,外置数据库模块在插件模块之前启动,依赖不到方言和jar。
// 此处不放在生命周期类afterInstall方法中的原因是要考虑 1,此插件有可能升级的情况 2,在afterInstall处读不到resource中的内容
/*try {
moveDialectClass();
moveDriverLib();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e, e.getMessage());
}*/
DMMigrationConfig.getInstance().setInit(true);
}
// 产品内部逻辑实现是,注册之后的类加载器,在连接外置数据库时,都会传给druid。
//FineDBDriverClassLoaderStore.getInstance().add(this.getClass().getClassLoader());
DBContext.registerGlobalCreationHook(new DBInterceptorCreationHook());
}
@Override
public void beforeStop(PluginContext pluginContext) {
//FineDBDriverClassLoaderStore.getInstance().remove(this.getClass().getClassLoader());
DBContext.unregisterGlobalCreationHook(new DBInterceptorCreationHook());
}
@Override
public void beforeUninstall(PluginContext pluginContext) {
DMMigrationConfig.getInstance().setInit(false);
}
private void moveDialectClass() throws IOException {
InputStream is = IOUtils.readResource("FRDMDialect.class");
String path = CommonUtils.pathJoin("/classes", DMDialect.class.getName().replace('.', '/') + ".class");
if (!WorkContext.getWorkResource().exist(path)) {
WorkContext.getWorkResource().write(path, ByteStreams.toByteArray(is));
}
}
private void moveDriverLib() throws IOException {
InputStream is = IOUtils.readResource("Dm7JdbcDriver18.jar");
String path = "/lib/Dm7JdbcDriver18.jar";
if (!WorkContext.getWorkResource().exist(path)) {
WorkContext.getWorkResource().write(path, ByteStreams.toByteArray(is));
}
}
}

30
src/main/java/com/fr/plugin/platform/db/transfer/dm/DMMigrationConfig.java

@ -0,0 +1,30 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
import com.fr.config.Identifier;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
public class DMMigrationConfig extends DefaultConfiguration {
@Identifier(value = "init")
private Conf<Boolean> init = Holders.simple(false);
private static volatile DMMigrationConfig config = null;
public static DMMigrationConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(DMMigrationConfig.class);
}
return config;
}
public Boolean isInit() {
return init.get();
}
public void setInit(Boolean init) {
this.init.set(init);
}
}

746
src/main/java/com/fr/plugin/platform/db/transfer/dm/FRDMDialect.java

@ -0,0 +1,746 @@
package com.fr.plugin.platform.db.transfer.dm;
import com.fr.third.org.hibernate.LockMode;
import com.fr.third.org.hibernate.MappingException;
import com.fr.third.org.hibernate.dialect.Dialect;
import com.fr.third.org.hibernate.dialect.function.*;
import com.fr.third.org.hibernate.dialect.identity.GetGeneratedKeysDelegate;
import com.fr.third.org.hibernate.dialect.identity.IdentityColumnSupport;
import com.fr.third.org.hibernate.dialect.pagination.AbstractLimitHandler;
import com.fr.third.org.hibernate.dialect.pagination.LimitHandler;
import com.fr.third.org.hibernate.dialect.pagination.LimitHelper;
import com.fr.third.org.hibernate.engine.spi.RowSelection;
import com.fr.third.org.hibernate.exception.internal.SQLStateConverter;
import com.fr.third.org.hibernate.exception.spi.SQLExceptionConverter;
import com.fr.third.org.hibernate.exception.spi.ViolatedConstraintNameExtracter;
import com.fr.third.org.hibernate.hql.spi.id.IdTableSupportStandardImpl;
import com.fr.third.org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
import com.fr.third.org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy;
import com.fr.third.org.hibernate.hql.spi.id.local.AfterUseAction;
import com.fr.third.org.hibernate.id.PostInsertIdentityPersister;
import com.fr.third.org.hibernate.internal.util.ReflectHelper;
import com.fr.third.org.hibernate.type.StandardBasicTypes;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class FRDMDialect extends Dialect {
private static final AbstractLimitHandler LIMIT_HANDLER = new AbstractLimitHandler() {
public String processSql(String sql, RowSelection selection) {
boolean hasOffset = LimitHelper.hasFirstRow(selection);
sql = sql.trim();
while (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1);
}
boolean isForUpdate = false;
if (sql.toLowerCase().endsWith(" for update")) {
sql = sql.substring(0, sql.length() - 11);
isForUpdate = true;
}
StringBuilder pagingSelect = new StringBuilder(sql.length() + 100);
if (hasOffset) {
pagingSelect.append(sql).append(" limit ? offset ? ");
} else {
pagingSelect.append(sql).append(" limit ? ");
}
if (isForUpdate) {
pagingSelect.append(" for update");
}
return pagingSelect.toString();
}
public boolean supportsLimit() {
return true;
}
public boolean supportsLimitOffset() {
return supportsLimit();
}
public boolean supportsVariableLimit() {
return supportsLimit();
}
public boolean bindLimitParametersInReverseOrder() {
return true;
}
public boolean bindLimitParametersFirst() {
return false;
}
public boolean useMaxForLimit() {
return false;
}
public boolean forceLimitUsage() {
return false;
}
public int convertToFirstRowValue(int zeroBasedFirstResult) {
return zeroBasedFirstResult;
}
};
int dmdbtype_cursor = 0;
private static final ViolatedConstraintNameExtracter EXTRACTER = new ViolatedConstraintNameExtracter() {
public String extractConstraintName(SQLException sqle) {
return null;
}
};
public FRDMDialect() {
registerColumnType(-7, "bit");
registerColumnType(16, "bit");
registerColumnType(-6, "tinyint");
registerColumnType(5, "smallint");
registerColumnType(4, "integer");
registerColumnType(-5, "bigint");
registerColumnType(6, "float");
registerColumnType(8, "double");
registerColumnType(2, "numeric($p,$s)");
registerColumnType(7, "real");
registerColumnType(3, "decimal($p,$s)");
registerColumnType(91, "date");
registerColumnType(92, "time");
registerColumnType(93, "datetime");
registerColumnType(-2, "binary($l)");
registerColumnType(-3, "varbinary($l)");
registerColumnType(-4, "image");
registerColumnType(2004, "blob");
registerColumnType(1, "char(1)");
registerColumnType(12, "varchar($l)");
registerColumnType(-1, "text");
registerColumnType(2005, "clob");
registerColumnType(-15, "char(1)");
registerColumnType(-9, "varchar($l)");
registerColumnType(-16, "text");
registerColumnType(2011, "clob");
// 字段过长需要修改下类型
registerColumnType(12, 8188, "varchar($l)");
registerColumnType(12, "text");
registerColumnType(-3, 8188, "varbinary($l)");
registerColumnType(-3, "text");
registerKeyword("last");
registerKeyword("size");
registerHibernateType(5, StandardBasicTypes.SHORT.getName());
registerFunction("substring",
new SQLFunctionTemplate(StandardBasicTypes.STRING, "substring(?1, ?2, ?3)"));
registerFunction("locate", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "locate(?1, ?2, ?3)"));
registerFunction("trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1 ?2 ?3 ?4)"));
registerFunction("length", new StandardSQLFunction("length", StandardBasicTypes.INTEGER));
registerFunction("bit_length", new StandardSQLFunction("bit_length", StandardBasicTypes.INTEGER));
registerFunction("coalesce", new StandardSQLFunction("coalesce"));
registerFunction("nullif", new StandardSQLFunction("nullif"));
registerFunction("abs", new StandardSQLFunction("abs"));
registerFunction("mod", new StandardSQLFunction("mod", StandardBasicTypes.LONG));
registerFunction("sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE));
registerFunction("upper", new StandardSQLFunction("upper"));
registerFunction("lower", new StandardSQLFunction("lower"));
registerFunction("cast", new CastFunction());
registerFunction("extract", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "extract(?1 ?2 ?3)"));
registerFunction("second", new StandardSQLFunction("second", StandardBasicTypes.INTEGER));
registerFunction("minute", new StandardSQLFunction("minute", StandardBasicTypes.INTEGER));
registerFunction("hour", new StandardSQLFunction("hour", StandardBasicTypes.INTEGER));
registerFunction("day", new StandardSQLFunction("day", StandardBasicTypes.INTEGER));
registerFunction("month", new StandardSQLFunction("month", StandardBasicTypes.INTEGER));
registerFunction("year", new StandardSQLFunction("year", StandardBasicTypes.INTEGER));
registerFunction("str", new StandardSQLFunction("to_char", StandardBasicTypes.STRING));
registerFunction("asin", new StandardSQLFunction("asin", StandardBasicTypes.DOUBLE));
registerFunction("acos", new StandardSQLFunction("acos", StandardBasicTypes.DOUBLE));
registerFunction("atan", new StandardSQLFunction("atan", StandardBasicTypes.DOUBLE));
registerFunction("atan2", new StandardSQLFunction("atan2", StandardBasicTypes.DOUBLE));
registerFunction("ceil", new StandardSQLFunction("ceil", StandardBasicTypes.INTEGER));
registerFunction("ceiling", new StandardSQLFunction("ceiling", StandardBasicTypes.INTEGER));
registerFunction("cos", new StandardSQLFunction("cos", StandardBasicTypes.DOUBLE));
registerFunction("cot", new StandardSQLFunction("cot", StandardBasicTypes.DOUBLE));
registerFunction("cosh", new StandardSQLFunction("cosh", StandardBasicTypes.DOUBLE));
registerFunction("degrees", new StandardSQLFunction("degrees"));
registerFunction("exp", new StandardSQLFunction("exp", StandardBasicTypes.DOUBLE));
registerFunction("GREATEST", new StandardSQLFunction("GREATEST", StandardBasicTypes.DOUBLE));
registerFunction("floor", new StandardSQLFunction("floor", StandardBasicTypes.INTEGER));
registerFunction("ln", new StandardSQLFunction("ln", StandardBasicTypes.DOUBLE));
registerFunction("log", new StandardSQLFunction("log", StandardBasicTypes.DOUBLE));
registerFunction("log10", new StandardSQLFunction("log10", StandardBasicTypes.DOUBLE));
registerFunction("pi", new NoArgSQLFunction("pi", StandardBasicTypes.DOUBLE));
registerFunction("power", new StandardSQLFunction("power", StandardBasicTypes.DOUBLE));
registerFunction("radians", new StandardSQLFunction("radians"));
registerFunction("rand", new NoArgSQLFunction("rand", StandardBasicTypes.DOUBLE));
registerFunction("round", new StandardSQLFunction("round"));
registerFunction("sign", new StandardSQLFunction("sign", StandardBasicTypes.INTEGER));
registerFunction("sin", new StandardSQLFunction("sin", StandardBasicTypes.DOUBLE));
registerFunction("sinh", new StandardSQLFunction("sinh", StandardBasicTypes.DOUBLE));
registerFunction("tan", new StandardSQLFunction("tan", StandardBasicTypes.DOUBLE));
registerFunction("tanh", new StandardSQLFunction("tanh", StandardBasicTypes.DOUBLE));
registerFunction("trunc", new StandardSQLFunction("trunc"));
registerFunction("truncate", new StandardSQLFunction("truncate"));
registerFunction("stddev", new StandardSQLFunction("stddev", StandardBasicTypes.DOUBLE));
registerFunction("variance", new StandardSQLFunction("variance", StandardBasicTypes.DOUBLE));
registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
registerFunction("ascii", new StandardSQLFunction("ascii", StandardBasicTypes.INTEGER));
registerFunction("char", new StandardSQLFunction("char", StandardBasicTypes.CHARACTER));
registerFunction("difference", new StandardSQLFunction("difference", StandardBasicTypes.INTEGER));
registerFunction("char_length", new StandardSQLFunction("char_length", StandardBasicTypes.LONG));
registerFunction("character_length",
new StandardSQLFunction("character_length", StandardBasicTypes.LONG));
registerFunction("chr", new StandardSQLFunction("chr", StandardBasicTypes.CHARACTER));
registerFunction("initcap", new StandardSQLFunction("initcap", StandardBasicTypes.STRING));
registerFunction("insert", new StandardSQLFunction("insert", StandardBasicTypes.STRING));
registerFunction("insstr", new StandardSQLFunction("insstr", StandardBasicTypes.STRING));
registerFunction("instr", new StandardSQLFunction("instr", StandardBasicTypes.LONG));
registerFunction("instrb", new StandardSQLFunction("instrb", StandardBasicTypes.LONG));
registerFunction("lcase", new StandardSQLFunction("lcase", StandardBasicTypes.STRING));
registerFunction("left", new StandardSQLFunction("left", StandardBasicTypes.STRING));
registerFunction("leftstr", new StandardSQLFunction("leftstr", StandardBasicTypes.STRING));
registerFunction("len", new StandardSQLFunction("len", StandardBasicTypes.INTEGER));
registerFunction("LENGTHB", new StandardSQLFunction("LENGTHB", StandardBasicTypes.INTEGER));
registerFunction("octet_length", new StandardSQLFunction("octet_length", StandardBasicTypes.LONG));
registerFunction("lpad", new StandardSQLFunction("lpad", StandardBasicTypes.STRING));
registerFunction("ltrim", new StandardSQLFunction("ltrim", StandardBasicTypes.STRING));
registerFunction("position", new StandardSQLFunction("position", StandardBasicTypes.INTEGER));
registerFunction("INS", new StandardSQLFunction("INS", StandardBasicTypes.STRING));
registerFunction("repeat", new StandardSQLFunction("repeat", StandardBasicTypes.STRING));
registerFunction("REPLICATE", new StandardSQLFunction("REPLICATE", StandardBasicTypes.STRING));
registerFunction("STUFF", new StandardSQLFunction("STUFF", StandardBasicTypes.STRING));
registerFunction("repeatstr", new StandardSQLFunction("repeatstr", StandardBasicTypes.STRING));
registerFunction("replace", new StandardSQLFunction("replace", StandardBasicTypes.STRING));
registerFunction("reverse", new StandardSQLFunction("reverse", StandardBasicTypes.STRING));
registerFunction("right", new StandardSQLFunction("right", StandardBasicTypes.STRING));
registerFunction("rightstr", new StandardSQLFunction("rightstr", StandardBasicTypes.STRING));
registerFunction("rpad", new StandardSQLFunction("rpad", StandardBasicTypes.STRING));
registerFunction("TO_NUMBER", new StandardSQLFunction("TO_NUMBER"));
registerFunction("rtrim", new StandardSQLFunction("rtrim", StandardBasicTypes.STRING));
registerFunction("soundex", new StandardSQLFunction("soundex", StandardBasicTypes.STRING));
registerFunction("space", new StandardSQLFunction("space", StandardBasicTypes.STRING));
registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
registerFunction("substrb", new StandardSQLFunction("substrb", StandardBasicTypes.STRING));
registerFunction("to_char", new StandardSQLFunction("to_char", StandardBasicTypes.STRING));
registerFunction("STRPOSDEC", new StandardSQLFunction("STRPOSDEC", StandardBasicTypes.STRING));
registerFunction("STRPOSINC", new StandardSQLFunction("STRPOSINC", StandardBasicTypes.STRING));
registerFunction("VSIZE", new StandardSQLFunction("VSIZE", StandardBasicTypes.INTEGER));
registerFunction("translate", new StandardSQLFunction("translate", StandardBasicTypes.STRING));
registerFunction("ucase", new StandardSQLFunction("ucase", StandardBasicTypes.STRING));
registerFunction("OVERLAPS", new StandardSQLFunction("OVERLAPS"));
registerFunction("DATEPART", new StandardSQLFunction("DATEPART"));
registerFunction("DATE_PART", new StandardSQLFunction("DATE_PART"));
registerFunction("add_days", new StandardSQLFunction("add_days"));
registerFunction("add_months", new StandardSQLFunction("add_months"));
registerFunction("add_weeks", new StandardSQLFunction("add_weeks"));
registerFunction("curdate", new NoArgSQLFunction("curdate", StandardBasicTypes.DATE));
registerFunction("curtime", new NoArgSQLFunction("curtime", StandardBasicTypes.TIME));
registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE));
registerFunction("current_time", new NoArgSQLFunction("current_time", StandardBasicTypes.TIME));
registerFunction("current_timestamp",
new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP));
registerFunction("dateadd", new StandardSQLFunction("dateadd", StandardBasicTypes.TIMESTAMP));
registerFunction("CUR_TICK_TIME", new StandardSQLFunction("CUR_TICK_TIME"));
registerFunction("datediff", new StandardSQLFunction("datediff", StandardBasicTypes.INTEGER));
registerFunction("datepart", new StandardSQLFunction("datepart", StandardBasicTypes.INTEGER));
registerFunction("dayname", new StandardSQLFunction("dayname", StandardBasicTypes.STRING));
registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", StandardBasicTypes.INTEGER));
registerFunction("dayofweek", new StandardSQLFunction("dayofweek", StandardBasicTypes.INTEGER));
registerFunction("dayofyear", new StandardSQLFunction("dayofyear", StandardBasicTypes.INTEGER));
registerFunction("days_between", new StandardSQLFunction("days_between", StandardBasicTypes.INTEGER));
registerFunction("getdate", new StandardSQLFunction("getdate", StandardBasicTypes.TIMESTAMP));
registerFunction("LOCALTIMESTAMP", new StandardSQLFunction("LOCALTIMESTAMP"));
registerFunction("NOW", new StandardSQLFunction("NOW"));
registerFunction("last_day", new StandardSQLFunction("last_day"));
registerFunction("month", new StandardSQLFunction("month", StandardBasicTypes.INTEGER));
registerFunction("monthname", new StandardSQLFunction("monthname", StandardBasicTypes.STRING));
registerFunction("months_between", new StandardSQLFunction("months_between"));
registerFunction("GREATEST", new StandardSQLFunction("GREATEST", StandardBasicTypes.DATE));
registerFunction("TO_DATETIME", new StandardSQLFunction("TO_DATETIME"));
registerFunction("next_day", new StandardSQLFunction("next_day"));
registerFunction("quarter", new StandardSQLFunction("quarter", StandardBasicTypes.INTEGER));
registerFunction("round", new StandardSQLFunction("round"));
registerFunction("timestampadd",
new StandardSQLFunction("timestampadd", StandardBasicTypes.TIMESTAMP));
registerFunction("timestampdiff",
new StandardSQLFunction("timestampdiff", StandardBasicTypes.INTEGER));
registerFunction("BIGDATEDIFF",
new StandardSQLFunction("BIGDATEDIFF", StandardBasicTypes.BIG_INTEGER));
registerFunction("sysdate", new StandardSQLFunction("sysdate", StandardBasicTypes.TIME));
registerFunction("LEAST", new StandardSQLFunction("LEAST"));
registerFunction("trunc", new StandardSQLFunction("trunc"));
registerFunction("week", new StandardSQLFunction("week", StandardBasicTypes.INTEGER));
registerFunction("weekday", new StandardSQLFunction("weekday", StandardBasicTypes.INTEGER));
registerFunction("weeks_between",
new StandardSQLFunction("weeks_between", StandardBasicTypes.INTEGER));
registerFunction("year", new StandardSQLFunction("year", StandardBasicTypes.INTEGER));
registerFunction("years_between",
new StandardSQLFunction("years_between", StandardBasicTypes.INTEGER));
registerFunction("to_date", new StandardSQLFunction("to_date", StandardBasicTypes.TIMESTAMP));
registerFunction("systimestamp", new NoArgSQLFunction("systimestamp", StandardBasicTypes.TIMESTAMP));
registerFunction("ifnull", new StandardSQLFunction("ifnull"));
registerFunction("isnull", new StandardSQLFunction("isnull"));
registerFunction("nvl", new StandardSQLFunction("nvl"));
registerFunction("decode", new StandardSQLFunction("decode"));
registerFunction("cur_database", new StandardSQLFunction("cur_database", StandardBasicTypes.STRING));
registerFunction("page", new StandardSQLFunction("page", StandardBasicTypes.INTEGER));
registerFunction("sessid", new StandardSQLFunction("sessid", StandardBasicTypes.LONG));
registerFunction("uid", new StandardSQLFunction("uid", StandardBasicTypes.LONG));
registerFunction("user", new StandardSQLFunction("user", StandardBasicTypes.STRING));
registerFunction("vsize", new StandardSQLFunction("vsize", StandardBasicTypes.INTEGER));
registerFunction("tabledef", new StandardSQLFunction("tabledef", StandardBasicTypes.STRING));
getDefaultProperties().setProperty("hibernate.use_outer_join", "true");
getDefaultProperties().setProperty("hibernate.jdbc.batch_size", "0");
}
public IdentityColumnSupport getIdentityColumnSupport() {
return new IdentityColumnSupport() {
public boolean supportsIdentityColumns() {
return true;
}
public boolean supportsInsertSelectIdentity() {
return false;
}
public boolean hasDataTypeInIdentityColumn() {
return true;
}
public String appendIdentitySelectToInsert(String insertString) {
return null;
}
public String getIdentitySelectString(String table, String column, int type)
throws MappingException {
return "select SCOPE_IDENTITY()";
}
public String getIdentityColumnString(int type)
throws MappingException {
return "identity";
}
public String getIdentityInsertString() {
return null;
}
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(PostInsertIdentityPersister persister, Dialect dialect) {
return new GetGeneratedKeysDelegate(persister, dialect);
}
};
}
public boolean supportsSequences() {
return true;
}
public boolean supportsPooledSequences() {
return true;
}
public String getSequenceNextValString(String sequenceName) {
return "select " + getSelectSequenceNextValString(sequenceName);
}
public String getSelectSequenceNextValString(String sequenceName) {
return sequenceName + ".nextval";
}
/**
* @deprecated
*/
public String[] getCreateSequenceStrings(String sequenceName) {
return new String[]{getCreateSequenceString(sequenceName)};
}
public String[] getCreateSequenceStrings(String sequenceName, int initialValue, int incrementSize) {
return new String[]{getCreateSequenceString(sequenceName, initialValue, incrementSize)};
}
protected String getCreateSequenceString(String sequenceName) {
return "create sequence " + sequenceName;
}
protected String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) {
return getCreateSequenceString(sequenceName) + " increment by " + incrementSize + " start with " +
initialValue;
}
public String[] getDropSequenceStrings(String sequenceName) {
return new String[]{getDropSequenceString(sequenceName)};
}
protected String getDropSequenceString(String sequenceName) {
return "drop sequence " + sequenceName;
}
public String getQuerySequencesString() {
return "select name from sysobjects where type$ = 'SCHOBJ' and subtype$ = 'SEQ';";
}
public String getSelectGUIDString() {
return "select GUID()";
}
public LimitHandler getLimitHandler() {
return LIMIT_HANDLER;
}
static int getAfterSelectInsertPoint(String sql) {
int selectIndex = sql.toLowerCase().indexOf("select");
int selectDistinctIndex = sql.toLowerCase().indexOf("select distinct");
return (selectIndex + ((selectDistinctIndex != selectIndex) ? 6 : 15));
}
public boolean supportsLockTimeouts() {
return true;
}
public boolean isLockTimeoutParameterized() {
return false;
}
public String getForUpdateString() {
return " for update";
}
public String getWriteLockString(int timeout) {
if (timeout == 0) {
return " for update nowait";
}
if (timeout > 0) {
float seconds = timeout / 1000.0F;
timeout = Math.round(seconds);
return " for update wait " + timeout;
}
return " for update";
}
public String getReadLockString(int timeout) {
return getWriteLockString(timeout);
}
public boolean forUpdateOfColumns() {
return true;
}
public boolean supportsOuterJoinForUpdate() {
return true;
}
public String getForUpdateString(String aliases) {
return getForUpdateString() + " of " + aliases;
}
public String getForUpdateNowaitString() {
return getForUpdateString() + " nowait";
}
public String getForUpdateNowaitString(String aliases) {
return getForUpdateString() + " of " + aliases + " nowait";
}
public String appendLockHint(LockMode mode, String tableName) {
return tableName;
}
public int registerResultSetOutParameter(CallableStatement statement, int col)
throws SQLException {
if (this.dmdbtype_cursor == 0) {
try {
Class types = ReflectHelper.classForName("dm.jdbc.driver.DmdbType");
this.dmdbtype_cursor = types.getField("CURSOR").getInt(types.newInstance());
} catch (Exception se) {
throw new SQLException("Problem while trying to load or access DmdbType.CURSOR value", se);
}
}
statement.registerOutParameter(col, this.dmdbtype_cursor);
++col;
return col;
}
public ResultSet getResultSet(CallableStatement statement)
throws SQLException {
statement.execute();
return ((ResultSet) statement.getObject(1));
}
public boolean supportsCurrentTimestampSelection() {
return true;
}
public boolean isCurrentTimestampSelectStringCallable() {
return false;
}
public String getCurrentTimestampSelectString() {
return "select current_timestamp()";
}
public String getCurrentTimestampSQLFunctionName() {
return "current_timestamp";
}
public SQLExceptionConverter buildSQLExceptionConverter() {
return new SQLStateConverter(getViolatedConstraintNameExtracter());
}
public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter() {
return EXTRACTER;
}
public String getSelectClauseNullString(int sqlType) {
return "null";
}
public boolean supportsUnionAll() {
return true;
}
public String getLowercaseFunction() {
return "lower";
}
public String transformSelectString(String select) {
return select;
}
public String toBooleanValueString(boolean bool) {
return ((bool) ? "1" : "0");
}
public char openQuote() {
return '"';
}
public char closeQuote() {
return '"';
}
public boolean hasAlterTable() {
return true;
}
public boolean dropConstraints() {
return false;
}
public boolean qualifyIndexName() {
return true;
}
public boolean supportsUnique() {
return true;
}
public boolean supportsUniqueConstraintInCreateAlterTable() {
return true;
}
public String getAddColumnString() {
return " add column ";
}
public String getDropForeignKeyString() {
return " drop constraint ";
}
public String getTableTypeString() {
return "";
}
public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey) {
StringBuffer res = new StringBuffer(30);
res.append(" add constraint ").append(constraintName).append(" foreign key (")
.append(join(", ", foreignKey)).append(") references ").append(referencedTable);
if (!(referencesPrimaryKey)) {
res.append(" (").append(join(", ", primaryKey)).append(')');
}
return res.toString();
}
public String getAddPrimaryKeyConstraintString(String constraintName) {
return " add constraint " + constraintName + " primary key ";
}
public boolean hasSelfReferentialForeignKeyBug() {
return false;
}
public String getNullColumnString() {
return "";
}
public boolean supportsCommentOn() {
return false;
}
public String getTableComment(String comment) {
return "";
}
public String getColumnComment(String comment) {
return "";
}
public boolean supportsIfExistsBeforeTableName() {
return false;
}
public boolean supportsIfExistsAfterTableName() {
return false;
}
public boolean supportsColumnCheck() {
return true;
}
public boolean supportsTableCheck() {
return true;
}
public boolean supportsCascadeDelete() {
return true;
}
public boolean supportsNotNullUnique() {
return true;
}
public String getCascadeConstraintsString() {
return " cascade ";
}
public String getCrossJoinSeparator() {
return " cross join ";
}
public boolean supportsEmptyInList() {
return false;
}
public boolean supportsRowValueConstructorSyntax() {
return false;
}
public boolean supportsRowValueConstructorSyntaxInInList() {
return true;
}
public boolean useInputStreamToInsertBlob() {
return true;
}
public boolean replaceResultVariableInOrderByClauseWithPosition() {
return false;
}
public boolean requiresCastingOfParametersInSelectClause() {
return false;
}
public boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() {
return true;
}
public boolean supportsCircularCascadeDeleteConstraints() {
return false;
}
public boolean supportsSubselectAsInPredicateLHS() {
return true;
}
public boolean supportsExpectedLobUsagePattern() {
return true;
}
public boolean supportsLobValueChangePropogation() {
return false;
}
public boolean supportsUnboundedLobLocatorMaterialization() {
return false;
}
public boolean supportsSubqueryOnMutatingTable() {
return true;
}
public boolean supportsExistsInSelect() {
return false;
}
public boolean doesReadCommittedCauseWritersToBlockReaders() {
return false;
}
public boolean doesRepeatableReadCauseReadersToBlockWriters() {
return false;
}
public boolean supportsBindAsCallableArgument() {
return true;
}
public boolean supportsTupleCounts() {
return false;
}
public boolean supportsTupleDistinctCounts() {
return false;
}
public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() {
return new GlobalTemporaryTableBulkIdStrategy(new IdTableSupportStandardImpl() {
public String generateIdTableName(String baseName) {
String name = super.generateIdTableName(baseName);
return ((name.length() > 30) ? name.substring(0, 30) : name);
}
public String getCreateIdTableCommand() {
return "create global temporary table";
}
public String getCreateIdTableStatementOptions() {
return "on commit delete rows";
}
}
, AfterUseAction.CLEAN);
}
public boolean supportsPartitionBy() {
return true;
}
private String join(String seperator, String[] strings) {
int length = strings.length;
if (length == 0)
return "";
StringBuffer buf = new StringBuffer(length * strings[0].length()).append(strings[0]);
for (int i = 1; i < length; ++i) {
buf.append(seperator).append(strings[i]);
}
return buf.toString();
}
}

34
src/main/java/com/fr/plugin/platform/db/transfer/dm/interceptor/DBInterceptorCreationHook.java

@ -0,0 +1,34 @@
package com.fr.plugin.platform.db.transfer.dm.interceptor;
import com.fr.log.FineLoggerFactory;
import com.fr.log.FineLoggerProvider;
import com.fr.stable.db.extra.DBCreationHook;
import com.fr.stable.db.extra.interceptor.impl.EmptyStringConvertInterceptor;
import com.fr.stable.db.option.DBCreationOption;
import com.fr.third.org.hibernate.cfg.Configuration;
import java.util.Properties;
/**
* @Author JianYe.Wang
* @Data 2021/7/2 13:47
* @Description 达梦数据库 COMPATIBLE 参数为 2 的情况
* @Version 10.0
**/
public class DBInterceptorCreationHook implements DBCreationHook {
public DBInterceptorCreationHook() {
}
public void onCreateSessionFactory(DBCreationOption option, Configuration configuration) {
Properties properties = configuration.getProperties();
if (isDM(properties)) {
option.addInterceptor(EmptyStringConvertInterceptor.INSTANCE);
}
}
private boolean isDM(Properties properties) {
String driver = properties.getProperty("hibernate.connection.driver_class");
FineLoggerFactory.getLogger().info("DBInterceptorCreationHook properties :{} driver :{}", properties, driver);
return driver != null && driver.toLowerCase().contains("dm.jdbc");
}
}

15
src/main/java/com/fr/plugin/platform/db/transfer/dm/web/DMComponent.java

@ -0,0 +1,15 @@
package com.fr.plugin.platform.db.transfer.dm.web;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
public class DMComponent extends Component {
public static DMComponent KEY = new DMComponent();
@Override
public ScriptPath script(RequestClient req) {
return ScriptPath.build("com/fr/plugin/platform/db/transfer/dm/web/js/plugin.min.js");
}
}

17
src/main/java/com/fr/plugin/platform/db/transfer/dm/web/DMWebResource.java

@ -0,0 +1,17 @@
package com.fr.plugin.platform.db.transfer.dm.web;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class DMWebResource extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return MainComponent.KEY;
}
@Override
public Atom client() {
return DMComponent.KEY;
}
}

37
src/main/resources/com/fr/plugin/platform/db/transfer/dm/web/js/plugin.min.js vendored

@ -0,0 +1,37 @@
!(function () {
try {
BI.Providers.getProvider("dec.provider.migration");
// 20.08.31 以及版本
BI.config('dec.provider.migration', provider => {
provider.registerDatabase({
value: 'dm',
driver: ['dm.jdbc.driver.DmDriver'],
url: 'jdbc:dm://{host}:{port}/{database}',
schema: true,
port: 5236,
}, url => {
const result = url.match(/^jdbc:dm:\/\/([0-9a-zA-Z_\\.-]+)(:([0-9]+))?\/([0-9a-zA-Z_\\.]+)(.*)/i);
if (result) {
return {
host: result[1],
port: result[3],
databaseName: result[4],
urlInfo: result[5],
};
}
});
});
} catch (e) {
// 20.08.31 之前版本
BI.config("dec.constant.migration.config.databases", function (items) {
items.push({
value: 'dm',
driver: ['dm.jdbc.driver.DmDriver'],
url: 'jdbc:dm://{host}:{port}/{database}',
schema: true,
port: 5236
});
return items;
})
}
}());
Loading…
Cancel
Save