diff --git a/trunk/sqltoy-orm-core/pom.xml b/trunk/sqltoy-orm-core/pom.xml
index b7cd3576d..ea404d515 100644
--- a/trunk/sqltoy-orm-core/pom.xml
+++ b/trunk/sqltoy-orm-core/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sagframe
- 5.6.29
+ 5.6.30
sagacity-sqltoy
sqltoy core code
sagacity-sqltoy
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlToyContext.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlToyContext.java
index 06ee95a4e..2776bff0e 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlToyContext.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/SqlToyContext.java
@@ -798,6 +798,8 @@ public void setDialect(String dialect) {
this.dialect = Dialect.OSCAR;
} else if (tmp.startsWith(Dialect.VASTBASE)) {
this.dialect = Dialect.VASTBASE;
+ } else if (tmp.startsWith(Dialect.OPENGAUSS)) {
+ this.dialect = Dialect.OPENGAUSS;
} else {
this.dialect = dialect;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
index 9a2171ecc..2ef7bbb40 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
@@ -613,7 +613,7 @@ public static boolean isDynamicSql(String sql, String startMark, String endMark)
}
return false;
}
-
+
/**
* @todo 找到@elseif 或@else 对应的@if位置
* @param preSql
@@ -1411,13 +1411,20 @@ public static String processIfLogic(String contentSql, String startMark, String
logicType = 2;
} else if ((ifStart = StringUtil.matchIndex(sqlPart, START_ELSE_PATTERN)) >= 0) {
logicType = 3;
+ } else if ((ifStart = StringUtil.matchIndex(sqlPart, IF_PATTERN)) >= 0 && ifLogicCnt == 1) {
+ logicType = 1;
}
ifLogicModel.setType(logicType);
// @if() 和@elseif()
if (logicType == 1 || logicType == 2) {
ifEnd = StringUtil.getSymMarkIndex("(", ")", sqlPart, ifStart);
ifLogicModel.setLogicExpression(sqlPart.substring(sqlPart.indexOf("(", ifStart) + 1, ifEnd));
- sqlPart = sqlPart.substring(ifEnd + 1);
+ // 兼容老版本只有@if的逻辑
+ if (ifLogicCnt == 1 && logicType == 1) {
+ sqlPart = sqlPart.substring(0, ifStart).concat(sqlPart.substring(ifEnd + 1));
+ } else {
+ sqlPart = sqlPart.substring(ifEnd + 1);
+ }
ifLogicModel.setLogicParamsCnt(
StringUtil.matchCnt(ifLogicModel.getLogicExpression(), namedPattern, offset));
} else if (logicType == 3) {
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/DialectFactory.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/DialectFactory.java
index d7412f08d..6557d420a 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/DialectFactory.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/DialectFactory.java
@@ -48,13 +48,17 @@
import org.sagacity.sqltoy.dialect.impl.MogDBDialect;
import org.sagacity.sqltoy.dialect.impl.MySqlDialect;
import org.sagacity.sqltoy.dialect.impl.OceanBaseDialect;
+import org.sagacity.sqltoy.dialect.impl.OpenGaussDialect;
import org.sagacity.sqltoy.dialect.impl.Oracle11gDialect;
import org.sagacity.sqltoy.dialect.impl.OracleDialect;
+import org.sagacity.sqltoy.dialect.impl.OscarDialect;
import org.sagacity.sqltoy.dialect.impl.PostgreSqlDialect;
import org.sagacity.sqltoy.dialect.impl.SqlServerDialect;
import org.sagacity.sqltoy.dialect.impl.SqliteDialect;
+import org.sagacity.sqltoy.dialect.impl.StarDBDialect;
import org.sagacity.sqltoy.dialect.impl.TDengineDialect;
import org.sagacity.sqltoy.dialect.impl.TidbDialect;
+import org.sagacity.sqltoy.dialect.impl.VastbaseDialect;
import org.sagacity.sqltoy.dialect.utils.ClickHouseDialectUtils;
import org.sagacity.sqltoy.dialect.utils.DialectUtils;
import org.sagacity.sqltoy.dialect.utils.PageOptimizeUtils;
@@ -203,11 +207,30 @@ private Dialect getDialectSqlWrapper(Integer dbType) throws Exception {
dialectSqlWrapper = new GaussDBDialect();
break;
}
+ // 华为guassdb(postgresql 为蓝本的)
+ case DBType.OPENGAUSS: {
+ dialectSqlWrapper = new OpenGaussDialect();
+ break;
+ }
// mogdb
case DBType.MOGDB: {
dialectSqlWrapper = new MogDBDialect();
break;
}
+ // starDB(京东)
+ case DBType.STARDB: {
+ dialectSqlWrapper = new StarDBDialect();
+ break;
+ } // 神通数据库
+ case DBType.OSCAR: {
+ dialectSqlWrapper = new OscarDialect();
+ break;
+ }
+ // vastbase 海量数据库
+ case DBType.VASTBASE: {
+ dialectSqlWrapper = new VastbaseDialect();
+ break;
+ }
case DBType.IMPALA: {
dialectSqlWrapper = new ImpalaDialect();
break;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/DefaultDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/DefaultDialect.java
index e784deed3..5f84b54de 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/DefaultDialect.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/DefaultDialect.java
@@ -281,6 +281,11 @@ private String getLockSql(String sql, Integer dbType, LockMode lockMode) {
return " for update ";
}
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
private static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/GaussDBDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/GaussDBDialect.java
index 5196cad52..2b6ea73e4 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/GaussDBDialect.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/GaussDBDialect.java
@@ -1,38 +1,10 @@
package org.sagacity.sqltoy.dialect.impl;
-import java.io.Serializable;
import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import org.sagacity.sqltoy.SqlToyContext;
-import org.sagacity.sqltoy.callback.DecryptHandler;
-import org.sagacity.sqltoy.callback.GenerateSavePKStrategy;
-import org.sagacity.sqltoy.callback.GenerateSqlHandler;
-import org.sagacity.sqltoy.callback.ReflectPropsHandler;
-import org.sagacity.sqltoy.callback.UpdateRowHandler;
-import org.sagacity.sqltoy.config.model.EntityMeta;
-import org.sagacity.sqltoy.config.model.PKStrategy;
-import org.sagacity.sqltoy.config.model.SqlToyConfig;
-import org.sagacity.sqltoy.config.model.SqlType;
-import org.sagacity.sqltoy.dialect.Dialect;
-import org.sagacity.sqltoy.dialect.model.SavePKStrategy;
import org.sagacity.sqltoy.dialect.utils.DefaultDialectUtils;
-import org.sagacity.sqltoy.dialect.utils.DialectExtUtils;
-import org.sagacity.sqltoy.dialect.utils.DialectUtils;
-import org.sagacity.sqltoy.dialect.utils.GaussDialectUtils;
-import org.sagacity.sqltoy.dialect.utils.PostgreSqlDialectUtils;
import org.sagacity.sqltoy.model.ColumnMeta;
-import org.sagacity.sqltoy.model.LockMode;
-import org.sagacity.sqltoy.model.QueryExecutor;
-import org.sagacity.sqltoy.model.QueryResult;
-import org.sagacity.sqltoy.model.StoreResult;
-import org.sagacity.sqltoy.model.TableMeta;
-import org.sagacity.sqltoy.model.inner.QueryExecutorExtend;
-import org.sagacity.sqltoy.utils.SqlUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @project sqltoy-orm
@@ -41,389 +13,12 @@
* @version v1.0,Date:2020-6-9
* @modify {Date:2020-6-9,初始创建}
*/
-@SuppressWarnings({ "rawtypes" })
-public class GaussDBDialect implements Dialect {
-
- /**
- * 定义日志
- */
- protected final Logger logger = LoggerFactory.getLogger(GaussDBDialect.class);
-
- /**
- * 判定为null的函数
- */
- public static final String NVL_FUNCTION = "NVL";
-
- @Override
- public boolean isUnique(SqlToyContext sqlToyContext, Serializable entity, String[] paramsNamed, Connection conn,
- final Integer dbType, String tableName) {
- return DialectUtils.isUnique(sqlToyContext, entity, paramsNamed, conn, dbType, tableName,
- (entityMeta, realParamNamed, table, topSize) -> {
- String queryStr = DialectExtUtils.wrapUniqueSql(entityMeta, realParamNamed, dbType, table);
- return queryStr + " limit " + topSize;
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getRandomResult(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Long,
- * java.sql.Connection)
- */
- @Override
- public QueryResult getRandomResult(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
- QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long totalCount, Long randomCount,
- Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
- throws Exception {
- return PostgreSqlDialectUtils.getRandomResult(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler,
- totalCount, randomCount, conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findPageBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Integer,
- * java.sql.Connection)
- */
- @Override
- public QueryResult findPageBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
- QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long pageNo, Integer pageSize,
- Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
- throws Exception {
- return DefaultDialectUtils.findPageBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, pageNo,
- pageSize, conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findTopBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, double, java.sql.Connection)
- */
- @Override
- public QueryResult findTopBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, QueryExecutor queryExecutor,
- final DecryptHandler decryptHandler, Integer topSize, Connection conn, final Integer dbType,
- final String dialect, final int fetchSize, final int maxRows) throws Exception {
- return DefaultDialectUtils.findTopBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, topSize,
- conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * java.lang.String, java.lang.Object[],
- * org.sagacity.sqltoy.callback.RowCallbackHandler, java.sql.Connection)
- */
- @Override
- public QueryResult findBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
- Object[] paramsValue, QueryExecutorExtend queryExecutorExtend, final DecryptHandler decryptHandler,
- final Connection conn, final LockMode lockMode, final Integer dbType, final String dialect,
- final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql.concat(getLockSql(sql, dbType, lockMode));
- return DialectUtils.findBySql(sqlToyContext, sqlToyConfig, realSql, paramsValue, queryExecutorExtend,
- decryptHandler, conn, dbType, 0, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getCountBySql(org.sagacity.sqltoy.
- * SqlToyContext, java.lang.String, java.lang.Object[], boolean,
- * java.sql.Connection)
- */
- @Override
- public Long getCountBySql(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, String sql,
- Object[] paramsValue, boolean isLastSql, Connection conn, final Integer dbType, final String dialect)
- throws Exception {
- return DialectUtils.getCountBySql(sqlToyContext, sqlToyConfig, sql, paramsValue, isLastSql, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#load(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.util.List,
- * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
- */
- @Override
- public Serializable load(SqlToyContext sqlToyContext, Serializable entity, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
- // 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
- SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search,
- dialect, null);
- String loadSql = sqlToyConfig.getSql(dialect);
- loadSql = loadSql.concat(getLockSql(loadSql, dbType, lockMode));
- return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, onlySubTables,
- cascadeTypes, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#loadAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.util.List,
- * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
- */
- @Override
- public List> loadAll(SqlToyContext sqlToyContext, List> entities, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName, final int fetchSize, final int maxRows) throws Exception {
- return DialectUtils.loadAll(sqlToyContext, entities, onlySubTables, cascadeTypes, lockMode, conn, dbType,
- tableName, (sql, dbTypeValue, lockedMode) -> {
- return getLockSql(sql, dbTypeValue, lockedMode);
- }, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
- PKStrategy pkStrategy = GaussDialectUtils.getSavePkStrategy(entityMeta, entity, dbType, conn);
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entity,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- return DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType,
- entityMeta, pkStrategy, NVL_FUNCTION, sequence,
- GaussDialectUtils.isAssignPKValue(pkStrategy), null);
- }
- }, new GenerateSavePKStrategy() {
- @Override
- public SavePKStrategy generate(EntityMeta entityMeta) {
- return new SavePKStrategy(entityMeta.getIdStrategy(),
- GaussDialectUtils.isAssignPKValue(entityMeta.getIdStrategy()));
- }
- }, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long saveAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize,
- reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#update(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.lang.String[], boolean,
- * java.lang.Class[], java.util.HashMap, java.sql.Connection)
- */
- @Override
- public Long update(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields, boolean cascade,
- Class[] forceCascadeClasses, HashMap subTableForceUpdateProps, Connection conn,
- final Integer dbType, final String dialect, final String tableName) throws Exception {
- return DialectUtils.update(sqlToyContext, entity, NVL_FUNCTION, forceUpdateFields, cascade,
- (cascade == false) ? null : new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- // update 级联操作过程中会自动判断数据库类型
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
- isAssignPK, null);
- }
- }, forceCascadeClasses, subTableForceUpdateProps, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.lang.String[],
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long updateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- final String[] uniqueFields, String[] forceUpdateFields, ReflectPropsHandler reflectPropsHandler,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- return DialectUtils.updateAll(sqlToyContext, entities, batchSize, forceUpdateFields, reflectPropsHandler,
- NVL_FUNCTION, conn, dbType, autoCommit, tableName, false);
- }
-
- @Override
- public Serializable updateSaveFetch(SqlToyContext sqlToyContext, Serializable entity,
- UpdateRowHandler updateRowHandler, String[] uniqueProps, Connection conn, Integer dbType, String dialect,
- String tableName) throws Exception {
- return DefaultDialectUtils.updateSaveFetch(sqlToyContext, entity, updateRowHandler, uniqueProps, conn, dbType,
- dialect, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdate(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.lang.String[], java.sql.Connection,
- * java.lang.Boolean)
- */
- @Override
- public Long saveOrUpdate(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- List entities = new ArrayList();
- entities.add(entity);
- return saveOrUpdateAll(sqlToyContext, entities, sqlToyContext.getBatchSize(), null, forceUpdateFields, conn,
- dbType, dialect, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdateAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.lang.String[],
- * java.sql.Connection, java.lang.Boolean)
- */
- @Override
- public Long saveOrUpdateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, String[] forceUpdateFields, Connection conn, final Integer dbType,
- final String dialect, final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveOrUpdateAll(sqlToyContext, entities, batchSize, entityMeta, forceUpdateFields,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
- isAssignPK, tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- @Override
- public Long saveAllIgnoreExist(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveAllIgnoreExist(sqlToyContext, entities, batchSize, entityMeta,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- return DialectExtUtils.mergeIgnore(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, null, NVL_FUNCTION, sequence, isAssignPK, tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#delete(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Long delete(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- return DialectUtils.delete(sqlToyContext, entity, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#deleteAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.sql.Connection)
- */
- @Override
- public Long deleteAll(SqlToyContext sqlToyContext, List> entities, final int batchSize, Connection conn,
- final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName)
- throws Exception {
- return DialectUtils.deleteAll(sqlToyContext, entities, batchSize, conn, dbType, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateFetch(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * java.lang.String, java.lang.Object[],
- * org.sagacity.sqltoy.callback.UpdateRowHandler, java.sql.Connection)
- */
- @Override
- public QueryResult updateFetch(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
- Object[] paramValues, UpdateRowHandler updateRowHandler, Connection conn, final Integer dbType,
- final String dialect, final LockMode lockMode, final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql.concat(getLockSql(sql, dbType, (lockMode == null) ? LockMode.UPGRADE : lockMode));
- return DialectUtils.updateFetchBySql(sqlToyContext, sqlToyConfig, realSql, paramValues, updateRowHandler, conn,
- dbType, 0, fetchSize, maxRows);
- }
-
- @Override
- public StoreResult executeStore(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
- final Object[] inParamsValue, final Integer[] outParamsType, final boolean moreResult,
- final Connection conn, final Integer dbType, final String dialect, final int fetchSize) throws Exception {
- return DialectUtils.executeStore(sqlToyConfig, sqlToyContext, sql, inParamsValue, outParamsType, moreResult,
- conn, dbType, fetchSize);
- }
+public class GaussDBDialect extends OpenGaussDialect {
@Override
public List getTableColumns(String catalog, String schema, String tableName, Connection conn,
Integer dbType, String dialect) throws Exception {
+ // gaussdb tableName无需转小写
return DefaultDialectUtils.getTableColumns(catalog, schema, tableName, conn, dbType, dialect);
}
-
- @Override
- public List getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType,
- String dialect) throws Exception {
- return DefaultDialectUtils.getTables(catalog, schema, tableName, conn, dbType, dialect);
- }
-
- private String getLockSql(String sql, Integer dbType, LockMode lockMode) {
- // 判断是否已经包含for update
- if (lockMode == null || SqlUtil.hasLock(sql, dbType)) {
- return "";
- }
- if (lockMode == LockMode.UPGRADE_NOWAIT) {
- return " for update nowait ";
- }
- if (lockMode == LockMode.UPGRADE_SKIPLOCK) {
- return " for update skip locked";
- }
- return " for update ";
- }
-
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/MogDBDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/MogDBDialect.java
index 740de22c2..0b6135fe6 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/MogDBDialect.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/MogDBDialect.java
@@ -1,40 +1,5 @@
package org.sagacity.sqltoy.dialect.impl;
-import java.io.Serializable;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.sagacity.sqltoy.SqlToyContext;
-import org.sagacity.sqltoy.callback.DecryptHandler;
-import org.sagacity.sqltoy.callback.GenerateSavePKStrategy;
-import org.sagacity.sqltoy.callback.GenerateSqlHandler;
-import org.sagacity.sqltoy.callback.ReflectPropsHandler;
-import org.sagacity.sqltoy.callback.UpdateRowHandler;
-import org.sagacity.sqltoy.config.model.EntityMeta;
-import org.sagacity.sqltoy.config.model.PKStrategy;
-import org.sagacity.sqltoy.config.model.SqlToyConfig;
-import org.sagacity.sqltoy.config.model.SqlType;
-import org.sagacity.sqltoy.dialect.Dialect;
-import org.sagacity.sqltoy.dialect.model.SavePKStrategy;
-import org.sagacity.sqltoy.dialect.utils.DefaultDialectUtils;
-import org.sagacity.sqltoy.dialect.utils.DialectExtUtils;
-import org.sagacity.sqltoy.dialect.utils.DialectUtils;
-import org.sagacity.sqltoy.dialect.utils.GaussDialectUtils;
-import org.sagacity.sqltoy.dialect.utils.MogDBDialectUtils;
-import org.sagacity.sqltoy.dialect.utils.PostgreSqlDialectUtils;
-import org.sagacity.sqltoy.model.ColumnMeta;
-import org.sagacity.sqltoy.model.LockMode;
-import org.sagacity.sqltoy.model.QueryExecutor;
-import org.sagacity.sqltoy.model.QueryResult;
-import org.sagacity.sqltoy.model.StoreResult;
-import org.sagacity.sqltoy.model.TableMeta;
-import org.sagacity.sqltoy.model.inner.QueryExecutorExtend;
-import org.sagacity.sqltoy.utils.SqlUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* @project sqltoy-orm
* @description 提供适配Mogdb数据库方言的实现(以postgresql9.5+为蓝本实现)
@@ -42,389 +7,5 @@
* @version v1.0,Date:2024-7-2
* @modify {Date:2024-7-2,初始创建}
*/
-@SuppressWarnings({ "rawtypes" })
-public class MogDBDialect implements Dialect {
-
- /**
- * 定义日志
- */
- protected final Logger logger = LoggerFactory.getLogger(MogDBDialect.class);
-
- /**
- * 判定为null的函数
- */
- public static final String NVL_FUNCTION = "NVL";
-
- @Override
- public boolean isUnique(SqlToyContext sqlToyContext, Serializable entity, String[] paramsNamed, Connection conn,
- final Integer dbType, String tableName) {
- return DialectUtils.isUnique(sqlToyContext, entity, paramsNamed, conn, dbType, tableName,
- (entityMeta, realParamNamed, table, topSize) -> {
- String queryStr = DialectExtUtils.wrapUniqueSql(entityMeta, realParamNamed, dbType, table);
- return queryStr + " limit " + topSize;
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getRandomResult(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Long,
- * java.sql.Connection)
- */
- @Override
- public QueryResult getRandomResult(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
- QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long totalCount, Long randomCount,
- Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
- throws Exception {
- return PostgreSqlDialectUtils.getRandomResult(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler,
- totalCount, randomCount, conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findPageBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Integer,
- * java.sql.Connection)
- */
- @Override
- public QueryResult findPageBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
- QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long pageNo, Integer pageSize,
- Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
- throws Exception {
- return DefaultDialectUtils.findPageBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, pageNo,
- pageSize, conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findTopBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, double, java.sql.Connection)
- */
- @Override
- public QueryResult findTopBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, QueryExecutor queryExecutor,
- final DecryptHandler decryptHandler, Integer topSize, Connection conn, final Integer dbType,
- final String dialect, final int fetchSize, final int maxRows) throws Exception {
- return DefaultDialectUtils.findTopBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, topSize,
- conn, dbType, dialect, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findBySql(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * java.lang.String, java.lang.Object[],
- * org.sagacity.sqltoy.callback.RowCallbackHandler, java.sql.Connection)
- */
- @Override
- public QueryResult findBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
- Object[] paramsValue, QueryExecutorExtend queryExecutorExtend, final DecryptHandler decryptHandler,
- final Connection conn, final LockMode lockMode, final Integer dbType, final String dialect,
- final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql.concat(getLockSql(sql, dbType, lockMode));
- return DialectUtils.findBySql(sqlToyContext, sqlToyConfig, realSql, paramsValue, queryExecutorExtend,
- decryptHandler, conn, dbType, 0, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getCountBySql(org.sagacity.sqltoy.
- * SqlToyContext, java.lang.String, java.lang.Object[], boolean,
- * java.sql.Connection)
- */
- @Override
- public Long getCountBySql(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, String sql,
- Object[] paramsValue, boolean isLastSql, Connection conn, final Integer dbType, final String dialect)
- throws Exception {
- return DialectUtils.getCountBySql(sqlToyContext, sqlToyConfig, sql, paramsValue, isLastSql, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#load(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.util.List,
- * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
- */
- @Override
- public Serializable load(SqlToyContext sqlToyContext, Serializable entity, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
- // 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
- SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search,
- dialect, null);
- String loadSql = sqlToyConfig.getSql(dialect);
- loadSql = loadSql.concat(getLockSql(loadSql, dbType, lockMode));
- return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, onlySubTables,
- cascadeTypes, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#loadAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.util.List,
- * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
- */
- @Override
- public List> loadAll(SqlToyContext sqlToyContext, List> entities, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName, final int fetchSize, final int maxRows) throws Exception {
- return DialectUtils.loadAll(sqlToyContext, entities, onlySubTables, cascadeTypes, lockMode, conn, dbType,
- tableName, (sql, dbTypeValue, lockedMode) -> {
- return getLockSql(sql, dbTypeValue, lockedMode);
- }, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
- PKStrategy pkStrategy = GaussDialectUtils.getSavePkStrategy(entityMeta, entity, dbType, conn);
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entity,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- return DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType,
- entityMeta, pkStrategy, NVL_FUNCTION, sequence,
- MogDBDialectUtils.isAssignPKValue(pkStrategy), null);
- }
- }, new GenerateSavePKStrategy() {
- @Override
- public SavePKStrategy generate(EntityMeta entityMeta) {
- return new SavePKStrategy(entityMeta.getIdStrategy(),
- MogDBDialectUtils.isAssignPKValue(entityMeta.getIdStrategy()));
- }
- }, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long saveAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize,
- reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#update(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.lang.String[], boolean,
- * java.lang.Class[], java.util.HashMap, java.sql.Connection)
- */
- @Override
- public Long update(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields, boolean cascade,
- Class[] forceCascadeClasses, HashMap subTableForceUpdateProps, Connection conn,
- final Integer dbType, final String dialect, final String tableName) throws Exception {
- return DialectUtils.update(sqlToyContext, entity, NVL_FUNCTION, forceUpdateFields, cascade,
- (cascade == false) ? null : new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
- // update 级联操作过程中会自动判断数据库类型
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
- isAssignPK, null);
- }
- }, forceCascadeClasses, subTableForceUpdateProps, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.lang.String[],
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long updateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- final String[] uniqueFields, String[] forceUpdateFields, ReflectPropsHandler reflectPropsHandler,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- return DialectUtils.updateAll(sqlToyContext, entities, batchSize, forceUpdateFields, reflectPropsHandler,
- NVL_FUNCTION, conn, dbType, autoCommit, tableName, false);
- }
-
- @Override
- public Serializable updateSaveFetch(SqlToyContext sqlToyContext, Serializable entity,
- UpdateRowHandler updateRowHandler, String[] uniqueProps, Connection conn, Integer dbType, String dialect,
- String tableName) throws Exception {
- return DefaultDialectUtils.updateSaveFetch(sqlToyContext, entity, updateRowHandler, uniqueProps, conn, dbType,
- dialect, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdate(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.lang.String[], java.sql.Connection,
- * java.lang.Boolean)
- */
- @Override
- public Long saveOrUpdate(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- List entities = new ArrayList();
- entities.add(entity);
- return saveOrUpdateAll(sqlToyContext, entities, sqlToyContext.getBatchSize(), null, forceUpdateFields, conn,
- dbType, dialect, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdateAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.lang.String[],
- * java.sql.Connection, java.lang.Boolean)
- */
- @Override
- public Long saveOrUpdateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, String[] forceUpdateFields, Connection conn, final Integer dbType,
- final String dialect, final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveOrUpdateAll(sqlToyContext, entities, batchSize, entityMeta, forceUpdateFields,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
- isAssignPK, tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- @Override
- public Long saveAllIgnoreExist(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveAllIgnoreExist(sqlToyContext, entities, batchSize, entityMeta,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
- boolean isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
- return DialectExtUtils.mergeIgnore(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, null, NVL_FUNCTION, sequence, isAssignPK, tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#delete(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Long delete(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- return DialectUtils.delete(sqlToyContext, entity, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#deleteAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.sql.Connection)
- */
- @Override
- public Long deleteAll(SqlToyContext sqlToyContext, List> entities, final int batchSize, Connection conn,
- final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName)
- throws Exception {
- return DialectUtils.deleteAll(sqlToyContext, entities, batchSize, conn, dbType, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateFetch(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * java.lang.String, java.lang.Object[],
- * org.sagacity.sqltoy.callback.UpdateRowHandler, java.sql.Connection)
- */
- @Override
- public QueryResult updateFetch(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
- Object[] paramValues, UpdateRowHandler updateRowHandler, Connection conn, final Integer dbType,
- final String dialect, final LockMode lockMode, final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql.concat(getLockSql(sql, dbType, (lockMode == null) ? LockMode.UPGRADE : lockMode));
- return DialectUtils.updateFetchBySql(sqlToyContext, sqlToyConfig, realSql, paramValues, updateRowHandler, conn,
- dbType, 0, fetchSize, maxRows);
- }
-
- @Override
- public StoreResult executeStore(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
- final Object[] inParamsValue, final Integer[] outParamsType, final boolean moreResult,
- final Connection conn, final Integer dbType, final String dialect, final int fetchSize) throws Exception {
- return DialectUtils.executeStore(sqlToyConfig, sqlToyContext, sql, inParamsValue, outParamsType, moreResult,
- conn, dbType, fetchSize);
- }
-
- @Override
- public List getTableColumns(String catalog, String schema, String tableName, Connection conn,
- Integer dbType, String dialect) throws Exception {
- return MogDBDialectUtils.getTableColumns(catalog, schema, tableName, conn, dbType, dialect);
- }
-
- @Override
- public List getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType,
- String dialect) throws Exception {
- return MogDBDialectUtils.getTables(catalog, schema, tableName, conn, dbType, dialect);
- }
-
- private String getLockSql(String sql, Integer dbType, LockMode lockMode) {
- // 判断是否已经包含for update
- if (lockMode == null || SqlUtil.hasLock(sql, dbType)) {
- return "";
- }
- if (lockMode == LockMode.UPGRADE_NOWAIT) {
- return " for update nowait ";
- }
- if (lockMode == LockMode.UPGRADE_SKIPLOCK) {
- return " for update skip locked";
- }
- return " for update ";
- }
-
+public class MogDBDialect extends OpenGaussDialect {
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OpenGaussDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OpenGaussDialect.java
new file mode 100644
index 000000000..3e90a3f3a
--- /dev/null
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OpenGaussDialect.java
@@ -0,0 +1,416 @@
+package org.sagacity.sqltoy.dialect.impl;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.sagacity.sqltoy.SqlToyContext;
+import org.sagacity.sqltoy.callback.DecryptHandler;
+import org.sagacity.sqltoy.callback.GenerateSavePKStrategy;
+import org.sagacity.sqltoy.callback.GenerateSqlHandler;
+import org.sagacity.sqltoy.callback.ReflectPropsHandler;
+import org.sagacity.sqltoy.callback.UpdateRowHandler;
+import org.sagacity.sqltoy.config.model.EntityMeta;
+import org.sagacity.sqltoy.config.model.PKStrategy;
+import org.sagacity.sqltoy.config.model.SqlToyConfig;
+import org.sagacity.sqltoy.config.model.SqlType;
+import org.sagacity.sqltoy.dialect.Dialect;
+import org.sagacity.sqltoy.dialect.model.SavePKStrategy;
+import org.sagacity.sqltoy.dialect.utils.DefaultDialectUtils;
+import org.sagacity.sqltoy.dialect.utils.DialectExtUtils;
+import org.sagacity.sqltoy.dialect.utils.DialectUtils;
+import org.sagacity.sqltoy.dialect.utils.OpenGaussDialectUtils;
+import org.sagacity.sqltoy.dialect.utils.PostgreSqlDialectUtils;
+import org.sagacity.sqltoy.model.ColumnMeta;
+import org.sagacity.sqltoy.model.LockMode;
+import org.sagacity.sqltoy.model.QueryExecutor;
+import org.sagacity.sqltoy.model.QueryResult;
+import org.sagacity.sqltoy.model.StoreResult;
+import org.sagacity.sqltoy.model.TableMeta;
+import org.sagacity.sqltoy.model.inner.QueryExecutorExtend;
+import org.sagacity.sqltoy.utils.SqlUtil;
+
+@SuppressWarnings({ "rawtypes" })
+public class OpenGaussDialect implements Dialect {
+
+ /**
+ * 判定为null的函数
+ */
+ public static final String NVL_FUNCTION = "NVL";
+
+ @Override
+ public boolean isUnique(SqlToyContext sqlToyContext, Serializable entity, String[] paramsNamed, Connection conn,
+ final Integer dbType, String tableName) {
+ return DialectUtils.isUnique(sqlToyContext, entity, paramsNamed, conn, dbType, tableName,
+ (entityMeta, realParamNamed, table, topSize) -> {
+ String queryStr = DialectExtUtils.wrapUniqueSql(entityMeta, realParamNamed, dbType, table);
+ return queryStr + " limit " + topSize;
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#getRandomResult(org.sagacity.sqltoy.
+ * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
+ * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Long,
+ * java.sql.Connection)
+ */
+ @Override
+ public QueryResult getRandomResult(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
+ QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long totalCount, Long randomCount,
+ Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
+ throws Exception {
+ return PostgreSqlDialectUtils.getRandomResult(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler,
+ totalCount, randomCount, conn, dbType, dialect, fetchSize, maxRows);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#findPageBySql(org.sagacity.sqltoy.
+ * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
+ * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Integer,
+ * java.sql.Connection)
+ */
+ @Override
+ public QueryResult findPageBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
+ QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long pageNo, Integer pageSize,
+ Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
+ throws Exception {
+ return DefaultDialectUtils.findPageBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, pageNo,
+ pageSize, conn, dbType, dialect, fetchSize, maxRows);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#findTopBySql(org.sagacity.sqltoy.
+ * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
+ * org.sagacity.sqltoy.model.QueryExecutor, double, java.sql.Connection)
+ */
+ @Override
+ public QueryResult findTopBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, QueryExecutor queryExecutor,
+ final DecryptHandler decryptHandler, Integer topSize, Connection conn, final Integer dbType,
+ final String dialect, final int fetchSize, final int maxRows) throws Exception {
+ return DefaultDialectUtils.findTopBySql(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler, topSize,
+ conn, dbType, dialect, fetchSize, maxRows);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#findBySql(org.sagacity.sqltoy.
+ * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
+ * java.lang.String, java.lang.Object[],
+ * org.sagacity.sqltoy.callback.RowCallbackHandler, java.sql.Connection)
+ */
+ @Override
+ public QueryResult findBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
+ Object[] paramsValue, QueryExecutorExtend queryExecutorExtend, final DecryptHandler decryptHandler,
+ final Connection conn, final LockMode lockMode, final Integer dbType, final String dialect,
+ final int fetchSize, final int maxRows) throws Exception {
+ String realSql = sql.concat(getLockSql(sql, dbType, lockMode));
+ return DialectUtils.findBySql(sqlToyContext, sqlToyConfig, realSql, paramsValue, queryExecutorExtend,
+ decryptHandler, conn, dbType, 0, fetchSize, maxRows);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#getCountBySql(org.sagacity.sqltoy.
+ * SqlToyContext, java.lang.String, java.lang.Object[], boolean,
+ * java.sql.Connection)
+ */
+ @Override
+ public Long getCountBySql(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, String sql,
+ Object[] paramsValue, boolean isLastSql, Connection conn, final Integer dbType, final String dialect)
+ throws Exception {
+ return DialectUtils.getCountBySql(sqlToyContext, sqlToyConfig, sql, paramsValue, isLastSql, conn, dbType);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#load(org.sagacity.sqltoy.
+ * SqlToyContext, java.io.Serializable, java.util.List,
+ * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
+ */
+ @Override
+ public Serializable load(SqlToyContext sqlToyContext, Serializable entity, boolean onlySubTables,
+ List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
+ final String tableName) throws Exception {
+ EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
+ // 获取loadsql(loadsql 可以通过@loadSql进行改变,所以需要sqltoyContext重新获取)
+ SqlToyConfig sqlToyConfig = sqlToyContext.getSqlToyConfig(entityMeta.getLoadSql(tableName), SqlType.search,
+ dialect, null);
+ String loadSql = sqlToyConfig.getSql(dialect);
+ loadSql = loadSql.concat(getLockSql(loadSql, dbType, lockMode));
+ return (Serializable) DialectUtils.load(sqlToyContext, sqlToyConfig, loadSql, entityMeta, entity, onlySubTables,
+ cascadeTypes, conn, dbType);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#loadAll(org.sagacity.sqltoy.
+ * SqlToyContext, java.util.List, java.util.List,
+ * org.sagacity.sqltoy.lock.LockMode, java.sql.Connection)
+ */
+ @Override
+ public List> loadAll(SqlToyContext sqlToyContext, List> entities, boolean onlySubTables,
+ List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
+ final String tableName, final int fetchSize, final int maxRows) throws Exception {
+ return DialectUtils.loadAll(sqlToyContext, entities, onlySubTables, cascadeTypes, lockMode, conn, dbType,
+ tableName, (sql, dbTypeValue, lockedMode) -> {
+ return getLockSql(sql, dbTypeValue, lockedMode);
+ }, fetchSize, maxRows);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
+ * SqlToyContext, java.io.Serializable, java.sql.Connection)
+ */
+ @Override
+ public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
+ final String dialect, final String tableName) throws Exception {
+ EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
+ PKStrategy pkStrategy = OpenGaussDialectUtils.getSavePkStrategy(entityMeta, entity, dbType, conn);
+ String sequence = entityMeta.getSequence() + ".nextval";
+ boolean isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
+ String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
+ pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
+ return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entity,
+ new GenerateSqlHandler() {
+ @Override
+ public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
+ PKStrategy pkStrategy = entityMeta.getIdStrategy();
+ String sequence = entityMeta.getSequence() + ".nextval";
+ return DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType,
+ entityMeta, pkStrategy, NVL_FUNCTION, sequence,
+ OpenGaussDialectUtils.isAssignPKValue(pkStrategy), null);
+ }
+ }, new GenerateSavePKStrategy() {
+ @Override
+ public SavePKStrategy generate(EntityMeta entityMeta) {
+ return new SavePKStrategy(entityMeta.getIdStrategy(),
+ OpenGaussDialectUtils.isAssignPKValue(entityMeta.getIdStrategy()));
+ }
+ }, conn, dbType);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
+ * SqlToyContext, java.util.List,
+ * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
+ */
+ @Override
+ public Long saveAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
+ ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
+ final Boolean autoCommit, final String tableName) throws Exception {
+ EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
+ PKStrategy pkStrategy = entityMeta.getIdStrategy();
+ String sequence = entityMeta.getSequence() + ".nextval";
+ boolean isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
+ String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
+ pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
+ return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize,
+ reflectPropsHandler, conn, dbType, autoCommit);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#update(org.sagacity.sqltoy.
+ * SqlToyContext, java.io.Serializable, java.lang.String[], boolean,
+ * java.lang.Class[], java.util.HashMap, java.sql.Connection)
+ */
+ @Override
+ public Long update(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields, boolean cascade,
+ Class[] forceCascadeClasses, HashMap subTableForceUpdateProps, Connection conn,
+ final Integer dbType, final String dialect, final String tableName) throws Exception {
+ return DialectUtils.update(sqlToyContext, entity, NVL_FUNCTION, forceUpdateFields, cascade,
+ (cascade == false) ? null : new GenerateSqlHandler() {
+ @Override
+ public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
+ PKStrategy pkStrategy = entityMeta.getIdStrategy();
+ String sequence = entityMeta.getSequence() + ".nextval";
+ boolean isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
+ // update 级联操作过程中会自动判断数据库类型
+ return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
+ dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
+ isAssignPK, null);
+ }
+ }, forceCascadeClasses, subTableForceUpdateProps, conn, dbType, tableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#updateAll(org.sagacity.sqltoy.
+ * SqlToyContext, java.util.List, java.lang.String[],
+ * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
+ */
+ @Override
+ public Long updateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
+ final String[] uniqueFields, String[] forceUpdateFields, ReflectPropsHandler reflectPropsHandler,
+ Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
+ final String tableName) throws Exception {
+ return DialectUtils.updateAll(sqlToyContext, entities, batchSize, forceUpdateFields, reflectPropsHandler,
+ NVL_FUNCTION, conn, dbType, autoCommit, tableName, false);
+ }
+
+ @Override
+ public Serializable updateSaveFetch(SqlToyContext sqlToyContext, Serializable entity,
+ UpdateRowHandler updateRowHandler, String[] uniqueProps, Connection conn, Integer dbType, String dialect,
+ String tableName) throws Exception {
+ return DefaultDialectUtils.updateSaveFetch(sqlToyContext, entity, updateRowHandler, uniqueProps, conn, dbType,
+ dialect, tableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdate(org.sagacity.sqltoy.
+ * SqlToyContext, java.io.Serializable, java.lang.String[], java.sql.Connection,
+ * java.lang.Boolean)
+ */
+ @Override
+ public Long saveOrUpdate(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields,
+ Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
+ final String tableName) throws Exception {
+ List entities = new ArrayList();
+ entities.add(entity);
+ return saveOrUpdateAll(sqlToyContext, entities, sqlToyContext.getBatchSize(), null, forceUpdateFields, conn,
+ dbType, dialect, autoCommit, tableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdateAll(org.sagacity.sqltoy.
+ * SqlToyContext, java.util.List,
+ * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.lang.String[],
+ * java.sql.Connection, java.lang.Boolean)
+ */
+ @Override
+ public Long saveOrUpdateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
+ ReflectPropsHandler reflectPropsHandler, String[] forceUpdateFields, Connection conn, final Integer dbType,
+ final String dialect, final Boolean autoCommit, final String tableName) throws Exception {
+ EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
+ return DialectUtils.saveOrUpdateAll(sqlToyContext, entities, batchSize, entityMeta, forceUpdateFields,
+ new GenerateSqlHandler() {
+ @Override
+ public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
+ PKStrategy pkStrategy = entityMeta.getIdStrategy();
+ String sequence = entityMeta.getSequence() + ".nextval";
+ boolean isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
+ return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
+ dbType, entityMeta, pkStrategy, forceUpdateFields, null, NVL_FUNCTION, sequence,
+ isAssignPK, tableName);
+ }
+ }, reflectPropsHandler, conn, dbType, autoCommit);
+ }
+
+ @Override
+ public Long saveAllIgnoreExist(SqlToyContext sqlToyContext, List> entities, final int batchSize,
+ ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
+ final Boolean autoCommit, final String tableName) throws Exception {
+ EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
+ return DialectUtils.saveAllIgnoreExist(sqlToyContext, entities, batchSize, entityMeta,
+ new GenerateSqlHandler() {
+ @Override
+ public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
+ PKStrategy pkStrategy = entityMeta.getIdStrategy();
+ String sequence = entityMeta.getSequence() + ".nextval";
+ boolean isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
+ return DialectExtUtils.mergeIgnore(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
+ pkStrategy, null, NVL_FUNCTION, sequence, isAssignPK, tableName);
+ }
+ }, reflectPropsHandler, conn, dbType, autoCommit);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#delete(org.sagacity.sqltoy.
+ * SqlToyContext, java.io.Serializable, java.sql.Connection)
+ */
+ @Override
+ public Long delete(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
+ final String dialect, final String tableName) throws Exception {
+ return DialectUtils.delete(sqlToyContext, entity, conn, dbType, tableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#deleteAll(org.sagacity.sqltoy.
+ * SqlToyContext, java.util.List, java.sql.Connection)
+ */
+ @Override
+ public Long deleteAll(SqlToyContext sqlToyContext, List> entities, final int batchSize, Connection conn,
+ final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName)
+ throws Exception {
+ return DialectUtils.deleteAll(sqlToyContext, entities, batchSize, conn, dbType, autoCommit, tableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.sagacity.sqltoy.dialect.Dialect#updateFetch(org.sagacity.sqltoy.
+ * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
+ * java.lang.String, java.lang.Object[],
+ * org.sagacity.sqltoy.callback.UpdateRowHandler, java.sql.Connection)
+ */
+ @Override
+ public QueryResult updateFetch(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
+ Object[] paramValues, UpdateRowHandler updateRowHandler, Connection conn, final Integer dbType,
+ final String dialect, final LockMode lockMode, final int fetchSize, final int maxRows) throws Exception {
+ String realSql = sql.concat(getLockSql(sql, dbType, (lockMode == null) ? LockMode.UPGRADE : lockMode));
+ return DialectUtils.updateFetchBySql(sqlToyContext, sqlToyConfig, realSql, paramValues, updateRowHandler, conn,
+ dbType, 0, fetchSize, maxRows);
+ }
+
+ @Override
+ public StoreResult executeStore(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
+ final Object[] inParamsValue, final Integer[] outParamsType, final boolean moreResult,
+ final Connection conn, final Integer dbType, final String dialect, final int fetchSize) throws Exception {
+ return DialectUtils.executeStore(sqlToyConfig, sqlToyContext, sql, inParamsValue, outParamsType, moreResult,
+ conn, dbType, fetchSize);
+ }
+
+ @Override
+ public List getTableColumns(String catalog, String schema, String tableName, Connection conn,
+ Integer dbType, String dialect) throws Exception {
+ // 表名转小写
+ return DefaultDialectUtils.getTableColumns(catalog, schema, tableName.toLowerCase(), conn, dbType, dialect);
+ }
+
+ @Override
+ public List getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType,
+ String dialect) throws Exception {
+ // 这里tableName不是具体的名字,而是正则表达式,要变小写则(?i)
+ return DefaultDialectUtils.getTables(catalog, schema, tableName, conn, dbType, dialect);
+ }
+
+ private String getLockSql(String sql, Integer dbType, LockMode lockMode) {
+ // 判断是否已经包含for update
+ if (lockMode == null || SqlUtil.hasLock(sql, dbType)) {
+ return "";
+ }
+ if (lockMode == LockMode.UPGRADE_NOWAIT) {
+ return " for update nowait ";
+ }
+ if (lockMode == LockMode.UPGRADE_SKIPLOCK) {
+ return " for update skip locked";
+ }
+ return " for update ";
+ }
+}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/Oracle11gDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/Oracle11gDialect.java
index 6b6c3ad0a..faa1c8097 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/Oracle11gDialect.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/Oracle11gDialect.java
@@ -5,42 +5,20 @@
import java.io.Serializable;
import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import org.sagacity.sqltoy.SqlToyConstants;
import org.sagacity.sqltoy.SqlToyContext;
import org.sagacity.sqltoy.callback.DecryptHandler;
-import org.sagacity.sqltoy.callback.GenerateSavePKStrategy;
-import org.sagacity.sqltoy.callback.GenerateSqlHandler;
-import org.sagacity.sqltoy.callback.ReflectPropsHandler;
-import org.sagacity.sqltoy.callback.UpdateRowHandler;
-import org.sagacity.sqltoy.config.model.EntityMeta;
import org.sagacity.sqltoy.config.model.OperateType;
-import org.sagacity.sqltoy.config.model.PKStrategy;
import org.sagacity.sqltoy.config.model.SqlToyConfig;
import org.sagacity.sqltoy.config.model.SqlToyResult;
-import org.sagacity.sqltoy.dialect.Dialect;
-import org.sagacity.sqltoy.dialect.model.SavePKStrategy;
-import org.sagacity.sqltoy.dialect.utils.DefaultDialectUtils;
import org.sagacity.sqltoy.dialect.utils.DialectExtUtils;
import org.sagacity.sqltoy.dialect.utils.DialectUtils;
-import org.sagacity.sqltoy.dialect.utils.OracleDialectUtils;
-import org.sagacity.sqltoy.model.ColumnMeta;
-import org.sagacity.sqltoy.model.LockMode;
import org.sagacity.sqltoy.model.QueryExecutor;
import org.sagacity.sqltoy.model.QueryResult;
-import org.sagacity.sqltoy.model.StoreResult;
-import org.sagacity.sqltoy.model.TableMeta;
import org.sagacity.sqltoy.model.inner.QueryExecutorExtend;
-import org.sagacity.sqltoy.utils.BeanUtil;
import org.sagacity.sqltoy.utils.SqlUtil;
import org.sagacity.sqltoy.utils.SqlUtilsExt;
-import org.sagacity.sqltoy.utils.StringUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @project sqltoy-orm
@@ -49,20 +27,7 @@
* @version v1.0,Date:2013-3-21
*/
@SuppressWarnings({ "rawtypes" })
-public class Oracle11gDialect implements Dialect {
- /**
- * 定义日志
- */
- protected final Logger logger = LoggerFactory.getLogger(Oracle11gDialect.class);
-
- /**
- * 判定为null的函数
- */
- public static final String NVL_FUNCTION = "nvl";
-
- public static final String NEXTVAL = ".nextval";
-
- public static final String VIRTUAL_TABLE = "dual";
+public class Oracle11gDialect extends OracleDialect {
@Override
public boolean isUnique(SqlToyContext sqlToyContext, Serializable entity, String[] paramsNamed, Connection conn,
@@ -78,23 +43,6 @@ public boolean isUnique(SqlToyContext sqlToyContext, Serializable entity, String
});
}
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getRandomResult(org. sagacity
- * .sqltoy.SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor, java.lang.Long, java.lang.Long,
- * java.sql.Connection)
- */
- @Override
- public QueryResult getRandomResult(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig,
- QueryExecutor queryExecutor, final DecryptHandler decryptHandler, Long totalCount, Long randomCount,
- Connection conn, final Integer dbType, final String dialect, final int fetchSize, final int maxRows)
- throws Exception {
- return OracleDialectUtils.getRandomResult(sqlToyContext, sqlToyConfig, queryExecutor, decryptHandler,
- totalCount, randomCount, conn, dbType, dialect, fetchSize, maxRows);
- }
-
/*
* (non-Javadoc)
*
@@ -203,353 +151,4 @@ public QueryResult findTopBySql(SqlToyContext sqlToyContext, SqlToyConfig sqlToy
return DialectUtils.findBySql(sqlToyContext, sqlToyConfig, queryParam.getSql(), queryParam.getParamsValue(),
extend, decryptHandler, conn, dbType, 0, fetchSize, maxRows);
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#findBySql(org.sagacity.
- * sqltoy.config.model.SqlToyConfig, java.lang.String[], java.lang.Object[],
- * java.lang.reflect.Type, org.sagacity.sqltoy.callback.RowCallbackHandler,
- * java.sql.Connection)
- */
- @Override
- public QueryResult findBySql(final SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
- final Object[] paramsValue, final QueryExecutorExtend queryExecutorExtend,
- final DecryptHandler decryptHandler, final Connection conn, final LockMode lockMode, final Integer dbType,
- final String dialect, final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql.concat(OracleDialectUtils.getLockSql(sql, dbType, lockMode));
- return DialectUtils.findBySql(sqlToyContext, sqlToyConfig, realSql, paramsValue, queryExecutorExtend,
- decryptHandler, conn, dbType, 0, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#getCountBySql(java.lang .String,
- * java.lang.String[], java.lang.Object[], java.sql.Connection)
- */
- @Override
- public Long getCountBySql(final SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
- final Object[] paramsValue, final boolean isLastSql, final Connection conn, final Integer dbType,
- final String dialect) throws Exception {
- return DialectUtils.getCountBySql(sqlToyContext, sqlToyConfig, sql, paramsValue, isLastSql, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdate(org.sagacity.sqltoy.
- * SqlToyContext, java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Long saveOrUpdate(SqlToyContext sqlToyContext, Serializable entity, final String[] forceUpdateFields,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- List entities = new ArrayList();
- entities.add(entity);
- return saveOrUpdateAll(sqlToyContext, entities, sqlToyContext.getBatchSize(), null, forceUpdateFields, conn,
- dbType, dialect, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveOrUpdateAll(org.sagacity.sqltoy
- * .SqlToyContext, java.util.List, java.sql.Connection)
- */
- @Override
- public Long saveOrUpdateAll(final SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, final String[] forceUpdateFields, Connection conn,
- final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName)
- throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveOrUpdateAll(sqlToyContext, entities, batchSize, entityMeta, forceUpdateFields,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + NEXTVAL;
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, VIRTUAL_TABLE, NVL_FUNCTION,
- sequence, isAssignPKValue(pkStrategy), tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveAllNotExist(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection,
- * java.lang.Boolean)
- */
- @Override
- public Long saveAllIgnoreExist(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- return DialectUtils.saveAllIgnoreExist(sqlToyContext, entities, batchSize, entityMeta,
- new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + NEXTVAL;
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- return DialectExtUtils.mergeIgnore(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, VIRTUAL_TABLE, NVL_FUNCTION, sequence, isAssignPKValue(pkStrategy),
- tableName);
- }
- }, reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#load(java.io.Serializable,
- * java.util.List, java.sql.Connection)
- */
- @Override
- public Serializable load(final SqlToyContext sqlToyContext, Serializable entity, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName) throws Exception {
- return OracleDialectUtils.load(sqlToyContext, entity, onlySubTables, cascadeTypes, lockMode, conn, dbType,
- dialect, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#loadAll(java.util.List,
- * java.util.List, java.sql.Connection)
- */
- @Override
- public List> loadAll(final SqlToyContext sqlToyContext, List> entities, boolean onlySubTables,
- List cascadeTypes, LockMode lockMode, Connection conn, final Integer dbType, final String dialect,
- final String tableName, final int fetchSize, final int maxRows) throws Exception {
- return OracleDialectUtils.loadAll(sqlToyContext, entities, onlySubTables, cascadeTypes, lockMode, conn, dbType,
- tableName, fetchSize, maxRows);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
- * SqlToyContext , java.io.Serializable, java.util.List, java.sql.Connection)
- */
- @Override
- public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + NEXTVAL;
- // oracle11 是不支持identity主键策略的
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- // 主键值已经存在,则主键策略改为assign,避免跳号
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.SEQUENCE)) {
- Object id = BeanUtil.getProperty(entity, entityMeta.getIdArray()[0]);
- if (StringUtil.isNotBlank(id)) {
- pkStrategy = PKStrategy.ASSIGN;
- }
- }
- boolean isAssignPK = isAssignPKValue(pkStrategy);
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entity,
- new GenerateSqlHandler() {
- // 通过反调方式提供oracle insert语句
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + NEXTVAL;
- // oracle sequence主键策略
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- return DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType,
- entityMeta, pkStrategy, NVL_FUNCTION, sequence, isAssignPKValue(pkStrategy), null);
- }
- }, new GenerateSavePKStrategy() {
- @Override
- public SavePKStrategy generate(EntityMeta entityMeta) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- }
- return new SavePKStrategy(pkStrategy, isAssignPKValue(pkStrategy));
- }
- }, conn, dbType);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
- * SqlToyContext , java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long saveAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect,
- final Boolean autoCommit, final String tableName) throws Exception {
- // oracle12c 开始支持identity机制
- EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- boolean isAssignPK = isAssignPKValue(pkStrategy);
- String sequence = entityMeta.getSequence() + NEXTVAL;
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- String insertSql = DialectExtUtils.generateInsertSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
- pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
- return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize,
- reflectPropsHandler, conn, dbType, autoCommit);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#update(org.sagacity.sqltoy.
- * SqlToyContext , java.io.Serializable, java.lang.String[],
- * java.sql.Connection)
- */
- @Override
- public Long update(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields,
- final boolean cascade, final Class[] forceCascadeClasses,
- final HashMap subTableForceUpdateProps, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- return DialectUtils.update(sqlToyContext, entity, NVL_FUNCTION, forceUpdateFields, cascade,
- (cascade == false) ? null : new GenerateSqlHandler() {
- @Override
- public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
- PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + NEXTVAL;
- if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
- pkStrategy = PKStrategy.SEQUENCE;
- sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
- }
- return DialectUtils.getSaveOrUpdateSql(sqlToyContext, sqlToyContext.getUnifyFieldsHandler(),
- dbType, entityMeta, pkStrategy, forceUpdateFields, VIRTUAL_TABLE, NVL_FUNCTION,
- sequence, isAssignPKValue(pkStrategy), null);
- }
- }, forceCascadeClasses, subTableForceUpdateProps, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List,
- * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
- */
- @Override
- public Long updateAll(SqlToyContext sqlToyContext, List> entities, final int batchSize,
- final String[] uniqueFields, final String[] forceUpdateFields, ReflectPropsHandler reflectPropsHandler,
- Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit,
- final String tableName) throws Exception {
- return DialectUtils.updateAll(sqlToyContext, entities, batchSize, forceUpdateFields, reflectPropsHandler,
- NVL_FUNCTION, conn, dbType, autoCommit, tableName, false);
- }
-
- @Override
- public Serializable updateSaveFetch(SqlToyContext sqlToyContext, Serializable entity,
- UpdateRowHandler updateRowHandler, String[] uniqueProps, Connection conn, Integer dbType, String dialect,
- String tableName) throws Exception {
- return DefaultDialectUtils.updateSaveFetch(sqlToyContext, entity, updateRowHandler, uniqueProps, conn, dbType,
- dialect, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#delete(org.sagacity.sqltoy.
- * SqlToyContext , java.io.Serializable, java.sql.Connection)
- */
- @Override
- public Long delete(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType,
- final String dialect, final String tableName) throws Exception {
- return DialectUtils.delete(sqlToyContext, entity, conn, dbType, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#deleteAll(org.sagacity.sqltoy.
- * SqlToyContext, java.util.List, java.sql.Connection)
- */
- @Override
- public Long deleteAll(SqlToyContext sqlToyContext, List> entities, final int batchSize, Connection conn,
- final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName)
- throws Exception {
- return DialectUtils.deleteAll(sqlToyContext, entities, batchSize, conn, dbType, autoCommit, tableName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.sagacity.sqltoy.dialect.Dialect#updateFetch(org.sagacity.sqltoy.
- * SqlToyContext, org.sagacity.sqltoy.config.model.SqlToyConfig,
- * org.sagacity.sqltoy.model.QueryExecutor,
- * org.sagacity.sqltoy.callback.UpdateRowHandler, java.sql.Connection)
- */
- @Override
- public QueryResult updateFetch(SqlToyContext sqlToyContext, SqlToyConfig sqlToyConfig, String sql,
- Object[] paramsValue, UpdateRowHandler updateRowHandler, Connection conn, final Integer dbType,
- final String dialect, final LockMode lockMode, final int fetchSize, final int maxRows) throws Exception {
- String realSql = sql
- .concat(OracleDialectUtils.getLockSql(sql, dbType, (lockMode == null) ? LockMode.UPGRADE : lockMode));
- return DialectUtils.updateFetchBySql(sqlToyContext, sqlToyConfig, realSql, paramsValue, updateRowHandler, conn,
- dbType, 0, fetchSize, maxRows);
- }
-
- @Override
- public StoreResult executeStore(SqlToyContext sqlToyContext, final SqlToyConfig sqlToyConfig, final String sql,
- final Object[] inParamsValue, final Integer[] outParamsType, final boolean moreResult,
- final Connection conn, final Integer dbType, final String dialect, final int fetchSize) throws Exception {
- return OracleDialectUtils.executeStore(sqlToyConfig, sqlToyContext, sql, inParamsValue, outParamsType,
- moreResult, conn, dbType, fetchSize);
- }
-
- @Override
- public List getTableColumns(String catalog, String schema, String tableName, Connection conn,
- Integer dbType, String dialect) throws Exception {
- List tableColumns = OracleDialectUtils.getTableColumns(catalog, schema, tableName, conn, dbType,
- dialect);
- // 获取主键信息
- Map pkMap = DefaultDialectUtils.getTablePrimaryKeys(catalog, schema, tableName, conn,
- dbType, dialect);
- if (pkMap == null || pkMap.isEmpty()) {
- return tableColumns;
- }
- ColumnMeta mapMeta;
- for (ColumnMeta colMeta : tableColumns) {
- mapMeta = pkMap.get(colMeta.getColName());
- if (mapMeta != null) {
- colMeta.setPK(true);
- }
- }
- return tableColumns;
- }
-
- @Override
- public List getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType,
- String dialect) throws Exception {
- return OracleDialectUtils.getTables(catalog, schema, tableName, conn, dbType, dialect);
- }
-
- private boolean isAssignPKValue(PKStrategy pkStrategy) {
- return true;
- }
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OracleDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OracleDialect.java
index a7f32cad0..b4242011a 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OracleDialect.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OracleDialect.java
@@ -56,6 +56,8 @@ public class OracleDialect implements Dialect {
*/
public static final String NVL_FUNCTION = "nvl";
+ public static final String NEXTVAL = ".nextval";
+
/**
* 虚表
*/
@@ -185,7 +187,7 @@ public Long saveOrUpdateAll(final SqlToyContext sqlToyContext, List> entities,
@Override
public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
+ String sequence = entityMeta.getSequence() + NEXTVAL;
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
@@ -215,7 +217,7 @@ public Long saveAllIgnoreExist(SqlToyContext sqlToyContext, List> entities, fi
@Override
public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence() + ".nextval";
+ String sequence = entityMeta.getSequence() + NEXTVAL;
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
@@ -266,7 +268,7 @@ public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection
final String dialect, final String tableName) throws Exception {
EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence().concat(".nextval");
+ String sequence = entityMeta.getSequence() + NEXTVAL;
// oracle identity本质是用sequence模拟(主键策略尽量少用跟数据库相关的)
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
@@ -287,7 +289,7 @@ public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection
@Override
public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence().concat(".nextval");
+ String sequence = entityMeta.getSequence() + NEXTVAL;
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
@@ -323,7 +325,7 @@ public Long saveAll(SqlToyContext sqlToyContext, List> entities, final int bat
EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
PKStrategy pkStrategy = entityMeta.getIdStrategy();
boolean isAssignPK = OracleDialectUtils.isAssignPKValue(pkStrategy);
- String sequence = entityMeta.getSequence().concat(".nextval");
+ String sequence = entityMeta.getSequence() + NEXTVAL;
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
@@ -351,7 +353,7 @@ public Long update(final SqlToyContext sqlToyContext, Serializable entity, Strin
@Override
public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- String sequence = entityMeta.getSequence().concat(".nextval");
+ String sequence = entityMeta.getSequence() + NEXTVAL;
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
pkStrategy = PKStrategy.SEQUENCE;
sequence = entityMeta.getFieldMeta(entityMeta.getIdArray()[0]).getDefaultValue();
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OscarDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OscarDialect.java
new file mode 100644
index 000000000..cbde8a916
--- /dev/null
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/OscarDialect.java
@@ -0,0 +1,23 @@
+package org.sagacity.sqltoy.dialect.impl;
+
+import java.sql.Connection;
+import java.util.List;
+
+import org.sagacity.sqltoy.dialect.utils.DefaultDialectUtils;
+import org.sagacity.sqltoy.model.ColumnMeta;
+
+/**
+ * @project sqltoy-orm
+ * @description 神通数据库适配
+ * @author zhongxuchen
+ * @version v1.0,Date:2024-10-29
+ * @modify {Date:2024-10-29,初始创建}
+ */
+public class OscarDialect extends OpenGaussDialect {
+ @Override
+ public List getTableColumns(String catalog, String schema, String tableName, Connection conn,
+ Integer dbType, String dialect) throws Exception {
+ // gaussdb tableName无需转小写
+ return DefaultDialectUtils.getTableColumns(catalog, schema, tableName, conn, dbType, dialect);
+ }
+}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/StarDBDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/StarDBDialect.java
new file mode 100644
index 000000000..88827deb8
--- /dev/null
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/StarDBDialect.java
@@ -0,0 +1,12 @@
+package org.sagacity.sqltoy.dialect.impl;
+
+/**
+ * @project sqltoy-orm
+ * @description 京东的StarDB适配(基于opengauss5.x)
+ * @author zhongxuchen
+ * @version v1.0,Date:2024-10-29
+ * @modify {Date:2024-10-29,初始创建}
+ */
+public class StarDBDialect extends OpenGaussDialect {
+
+}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/VastbaseDialect.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/VastbaseDialect.java
new file mode 100644
index 000000000..f8284f9a5
--- /dev/null
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/impl/VastbaseDialect.java
@@ -0,0 +1,11 @@
+package org.sagacity.sqltoy.dialect.impl;
+
+/**
+ * @project sqltoy-orm
+ * @description 提供适配Mogdb数据库方言的实现((基于opengauss5.x))
+ * @author ming
+ * @version v1.0, Date:2024-10-25
+ * @modify {Date:2024-10-25,初始创建}
+ */
+public class VastbaseDialect extends OpenGaussDialect {
+}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/ClickHouseDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/ClickHouseDialectUtils.java
index 769cf1475..8623011f1 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/ClickHouseDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/ClickHouseDialectUtils.java
@@ -133,6 +133,7 @@ public static Object save(SqlToyContext sqlToyContext, final EntityMeta entityMe
if (isIdentity || isSequence) {
pst = conn.prepareStatement(insertSql, new String[] { DataSourceUtils
.getReturnPrimaryKeyColumn(entityMeta.getColumnName(entityMeta.getIdArray()[0]), dbType) });
+ // pst = conn.prepareStatement(insertSql, Statement.RETURN_GENERATED_KEYS);
} else {
pst = conn.prepareStatement(insertSql);
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DB2DialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DB2DialectUtils.java
index 8ccd5a35b..4575308a4 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DB2DialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DB2DialectUtils.java
@@ -142,6 +142,12 @@ public static void wrapSelectFields(StringBuilder sql, String columnName, FieldM
sql.append(columnName);
}
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ *
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DMDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DMDialectUtils.java
index 281ebd033..0b340f263 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DMDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DMDialectUtils.java
@@ -13,6 +13,11 @@
* @modify 2020年7月30日,修改说明
*/
public class DMDialectUtils {
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java
index e22cf9a4c..039f03100 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DefaultDialectUtils.java
@@ -706,7 +706,8 @@ private static void resultUpdate(Connection conn, ResultSet rs, FieldMeta fieldM
private static void setArray(Integer dbType, Connection conn, ResultSet rs, String columnName, Object paramValue)
throws SQLException {
// 目前只支持Integer 和 String两种类型
- if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB) {
+ if (dbType == DBType.GAUSSDB || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB || dbType == DBType.OSCAR
+ || dbType == DBType.STARDB || dbType == DBType.VASTBASE) {
if (paramValue instanceof Integer[]) {
Array array = conn.createArrayOf("INTEGER", (Integer[]) paramValue);
rs.updateArray(columnName, array);
@@ -928,7 +929,7 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
}
/**
- * @TODO 获取表的索引信息
+ * @TODO 获取表的索引信息(这里只能用于标记字段是否是索引列)
* @param catalog
* @param schema
* @param tableName
@@ -941,14 +942,17 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
@SuppressWarnings("unchecked")
public static Map getTableIndexes(String catalog, String schema, String tableName,
Connection conn, final Integer dbType, String dialect) throws Exception {
- ResultSet rs = null;
- try {
- rs = conn.getMetaData().getIndexInfo(catalog, schema, tableName, false, false);
- } catch (Exception e) {
-
+ if (dbType == DBType.ORACLE || dbType == DBType.ORACLE11) {
+ return getOracleTableIndexes(catalog, schema, tableName, conn, dbType, dialect);
}
- if (rs != null) {
- return (Map) SqlUtil.preparedStatementProcess(null, null, rs,
+ Map result = new HashMap<>();
+ boolean[] uniqueAndNotUnique = { false, true };
+ ResultSet rs;
+ Map tableIndexes;
+ for (int i = 0; i < uniqueAndNotUnique.length; i++) {
+ boolean isUnique = uniqueAndNotUnique[i];
+ rs = conn.getMetaData().getIndexInfo(catalog, schema, tableName, false, false);
+ tableIndexes = (Map) SqlUtil.preparedStatementProcess(null, null, rs,
new PreparedStatementResultHandler() {
@Override
public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
@@ -957,42 +961,48 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
ColumnMeta colMeta = new ColumnMeta();
colMeta.setColName(rs.getString("COLUMN_NAME"));
colMeta.setIndex(true);
- colMeta.setUnique(!rs.getBoolean("NON_UNIQUE"));
+ colMeta.setUnique(isUnique);
colMeta.setIndexName(rs.getString("INDEX_NAME"));
indexsMeta.put(colMeta.getColName(), colMeta);
}
this.setResult(indexsMeta);
}
});
- } // 针对旧版本jdbc驱动起作用
- else if (dbType == DBType.ORACLE || dbType == DBType.ORACLE11) {
- String tableNameUp = tableName.toUpperCase();
- String sql = "SELECT t1.INDEX_NAME,t1.COLUMN_NAME,t0.UNIQUENESS FROM USER_IND_COLUMNS t1 LEFT JOIN "
- + " (SELECT INDEX_NAME,UNIQUENESS FROM USER_INDEXES WHERE TABLE_NAME ='" + tableNameUp + "') t0 ON "
- + " t1.INDEX_NAME = t0.INDEX_NAME WHERE TABLE_NAME ='" + tableNameUp + "'";
- rs = conn.createStatement().executeQuery(sql);
- return (Map) SqlUtil.preparedStatementProcess(null, null, rs,
- new PreparedStatementResultHandler() {
+ if (tableIndexes != null) {
+ result.putAll(tableIndexes);
+ }
+ }
+ return result;
+ }
- @Override
- public void execute(Object obj, PreparedStatement pst, ResultSet rs) throws SQLException {
- Map indexsMeta = new HashMap();
- while (rs.next()) {
- ColumnMeta colMeta = new ColumnMeta();
- colMeta.setColName(rs.getString("COLUMN_NAME"));
- colMeta.setIndex(true);
- if ("UNIQUE".equalsIgnoreCase(rs.getString("UNIQUENESS"))) {
- colMeta.setUnique(true);
- }
- colMeta.setIndexName(rs.getString("INDEX_NAME"));
- indexsMeta.put(colMeta.getColName(), colMeta);
+ @SuppressWarnings("unchecked")
+ private static Map getOracleTableIndexes(String catalog, String schema, String tableName,
+ Connection conn, final Integer dbType, String dialect) throws Exception {
+ String tableNameUp = tableName.toUpperCase();
+ String sql = "SELECT t1.INDEX_NAME,t1.COLUMN_NAME,t0.UNIQUENESS FROM USER_IND_COLUMNS t1 LEFT JOIN "
+ + " (SELECT INDEX_NAME,UNIQUENESS FROM USER_INDEXES WHERE TABLE_NAME ='" + tableNameUp + "') t0 ON "
+ + " t1.INDEX_NAME = t0.INDEX_NAME WHERE TABLE_NAME ='" + tableNameUp + "'";
+ ResultSet rs = conn.createStatement().executeQuery(sql);
+ return (Map) SqlUtil.preparedStatementProcess(null, null, rs,
+ new PreparedStatementResultHandler() {
+
+ @Override
+ public void execute(Object obj, PreparedStatement pst, ResultSet rs) throws SQLException {
+ Map indexsMeta = new HashMap();
+ while (rs.next()) {
+ ColumnMeta colMeta = new ColumnMeta();
+ colMeta.setColName(rs.getString("COLUMN_NAME"));
+ colMeta.setIndex(true);
+ if ("UNIQUE".equalsIgnoreCase(rs.getString("UNIQUENESS"))) {
+ colMeta.setUnique(true);
}
- this.setResult(indexsMeta);
+ colMeta.setIndexName(rs.getString("INDEX_NAME"));
+ indexsMeta.put(colMeta.getColName(), colMeta);
}
+ this.setResult(indexsMeta);
+ }
- });
- }
- return null;
+ });
}
/**
@@ -1030,7 +1040,8 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
this.setResult(pkMeta);
}
});
- } else if (dbType == DBType.MYSQL || dbType == DBType.MYSQL57) {
+ } // 针对starrocks(用的mysql驱动)
+ else if (dbType == DBType.MYSQL || dbType == DBType.MYSQL57) {
rs = conn.createStatement().executeQuery("desc " + tableName);
return (Map) SqlUtil.preparedStatementProcess(null, null, rs,
new PreparedStatementResultHandler() {
@@ -1053,10 +1064,11 @@ public void execute(Object obj, PreparedStatement pst, ResultSet rs) throws SQLE
}
@SuppressWarnings("unchecked")
- public static List getTables(String catalog, String schema, String tableName, Connection conn,
- Integer dbType, String dialect) throws Exception {
+ public static List getTables(String catalogPattern, String schemaPattern, String tableNamePattern,
+ Connection conn, Integer dbType, String dialect) throws Exception {
// 可自定义 PreparedStatement pst=conn.xxx;
- ResultSet rs = conn.getMetaData().getTables(catalog, schema, tableName, new String[] { "TABLE", "VIEW" });
+ ResultSet rs = conn.getMetaData().getTables(catalogPattern, schemaPattern, tableNamePattern,
+ new String[] { "TABLE", "VIEW" });
// 通过preparedStatementProcess反调,第二个参数是pst
return (List) SqlUtil.preparedStatementProcess(null, null, rs, new PreparedStatementResultHandler() {
@Override
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java
index 6a3b83492..3e240f630 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectExtUtils.java
@@ -244,9 +244,10 @@ else if (dateType == 4) {
}
} else if (dbType == DBType.MYSQL || dbType == DBType.MYSQL57 || dbType == DBType.POSTGRESQL
|| dbType == DBType.POSTGRESQL15 || dbType == DBType.DM || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB || dbType == DBType.OCEANBASE || dbType == DBType.SQLITE
- || dbType == DBType.KINGBASE || dbType == DBType.SQLSERVER || dbType == DBType.TIDB
- || dbType == DBType.H2) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.VASTBASE || dbType == DBType.OCEANBASE
+ || dbType == DBType.SQLITE || dbType == DBType.KINGBASE || dbType == DBType.SQLSERVER
+ || dbType == DBType.TIDB || dbType == DBType.H2) {
if (isCurrentTime) {
result = "CURRENT_TIMESTAMP";
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java
index cecd93c02..da30ab652 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java
@@ -1673,6 +1673,8 @@ public static Object save(final SqlToyContext sqlToyContext, final EntityMeta en
final Integer[] paramsType = entityMeta.getFieldsTypeArray();
PreparedStatement pst = null;
if (isIdentity || isSequence) {
+ // RETURN_GENERATED_KEYS 适合auto_increment,不适合sequence
+ // pst = conn.prepareStatement(realInsertSql, Statement.RETURN_GENERATED_KEYS);
pst = conn.prepareStatement(realInsertSql, new String[] { DataSourceUtils
.getReturnPrimaryKeyColumn(entityMeta.getColumnName(entityMeta.getIdArray()[0]), dbType) });
} else {
@@ -2192,8 +2194,9 @@ private static void postgreSaveOrUpdateAll(SqlToyContext sqlToyContext, final En
public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
String sequence = "nextval('" + entityMeta.getSequence() + "')";
- if ((dbType == DBType.GAUSSDB || dbType == DBType.MOGDB) && pkStrategy != null
- && pkStrategy.equals(PKStrategy.SEQUENCE)) {
+ if ((dbType == DBType.GAUSSDB || dbType == DBType.OPENGAUSS || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.MOGDB || dbType == DBType.VASTBASE)
+ && pkStrategy != null && pkStrategy.equals(PKStrategy.SEQUENCE)) {
sequence = entityMeta.getSequence() + ".nextval";
}
if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
@@ -2202,10 +2205,9 @@ public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
sequence = "DEFAULT";
}
boolean isAssignPK = PostgreSqlDialectUtils.isAssignPKValue(pkStrategy);
- if (dbType == DBType.GAUSSDB) {
- isAssignPK = GaussDialectUtils.isAssignPKValue(pkStrategy);
- } else if (dbType == DBType.MOGDB) {
- isAssignPK = MogDBDialectUtils.isAssignPKValue(pkStrategy);
+ if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.OPENGAUSS || dbType == DBType.VASTBASE) {
+ isAssignPK = OpenGaussDialectUtils.isAssignPKValue(pkStrategy);
}
return DialectExtUtils.insertIgnore(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta,
pkStrategy, "COALESCE", sequence, isAssignPK, tableName);
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/KingbaseDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/KingbaseDialectUtils.java
index fae938b06..76563b28e 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/KingbaseDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/KingbaseDialectUtils.java
@@ -15,6 +15,11 @@ public class KingbaseDialectUtils {
*/
public static final String NVL_FUNCTION = "isnull";
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MogDBDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MogDBDialectUtils.java
deleted file mode 100644
index da9274750..000000000
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MogDBDialectUtils.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package org.sagacity.sqltoy.dialect.utils;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.sagacity.sqltoy.callback.PreparedStatementResultHandler;
-import org.sagacity.sqltoy.config.model.PKStrategy;
-import org.sagacity.sqltoy.model.ColumnMeta;
-import org.sagacity.sqltoy.model.TableMeta;
-import org.sagacity.sqltoy.utils.SqlUtil;
-
-/**
- * @author ming
- * @version v1.0, Date:2024年7月3日
- * @project sagacity-sqltoy
- * @description 提供gaussdb数据库相关的特殊逻辑处理封装
- * @modify 2024年7月3日, 修改说明
- */
-public class MogDBDialectUtils {
- /**
- * @param pkStrategy
- * @return
- * @TODO 定义当使用sequence或identity时, 是否允许自定义值(即不通过sequence或identity产生 , 而是由外部直接赋值)
- */
- public static boolean isAssignPKValue(PKStrategy pkStrategy) {
- if (pkStrategy == null) {
- return true;
- }
- // sequence
- if (pkStrategy.equals(PKStrategy.SEQUENCE)) {
- return true;
- }
- // postgresql10+ 支持identity
- if (pkStrategy.equals(PKStrategy.IDENTITY)) {
- return true;
- }
- return true;
- }
-
- /**
- * @todo 获取表全部字段信息
- * @param catalog
- * @param schema
- * @param tableName 小写
- * @param conn
- * @param dbType
- * @param dialect
- * @return
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- public static List getTableColumns(String catalog, String schema, String tableName, Connection conn,
- Integer dbType, String dialect) throws Exception {
- ResultSet rs = conn.getMetaData().getColumns(catalog, schema, tableName.toLowerCase(), "%");
- // 通过preparedStatementProcess反调,第二个参数是pst
- List tableCols = (List) SqlUtil.preparedStatementProcess(null, null, rs,
- new PreparedStatementResultHandler() {
- @Override
- public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
- List colMetas = new ArrayList();
- String isAutoIncrement;
- ColumnMeta colMeta;
- while (rs.next()) {
- colMeta = new ColumnMeta();
- colMeta.setColName(rs.getString("COLUMN_NAME"));
- colMeta.setDataType(rs.getInt("DATA_TYPE"));
- colMeta.setTypeName(rs.getString("TYPE_NAME"));
- colMeta.setDefaultValue(SqlUtil.clearDefaultValue(rs.getString("COLUMN_DEF")));
- colMeta.setColumnSize(rs.getInt("COLUMN_SIZE"));
- colMeta.setDecimalDigits(rs.getInt("DECIMAL_DIGITS"));
- colMeta.setNumPrecRadix(rs.getInt("NUM_PREC_RADIX"));
- colMeta.setComments(rs.getString("REMARKS"));
- colMeta.setAutoIncrement(false);
- isAutoIncrement = rs.getString("IS_AUTOINCREMENT");
- try {
- if (("true".equalsIgnoreCase(isAutoIncrement) || "YES".equalsIgnoreCase(isAutoIncrement)
- || "Y".equalsIgnoreCase(isAutoIncrement) || "1".equals(isAutoIncrement))) {
- colMeta.setAutoIncrement(true);
- }
- } catch (Exception ignore) {
- }
- colMeta.setNullable(rs.getInt("NULLABLE") == 1);
- colMetas.add(colMeta);
- }
- this.setResult(colMetas);
- }
- });
- ColumnMeta mapMeta;
- // 获取主键信息
- Map pkMap = DefaultDialectUtils.getTablePrimaryKeys(catalog, schema, tableName, conn,
- dbType, dialect);
- if (pkMap != null && !pkMap.isEmpty()) {
- for (ColumnMeta colMeta : tableCols) {
- mapMeta = pkMap.get(colMeta.getColName());
- if (mapMeta != null) {
- colMeta.setPK(true);
- }
- }
- }
- // 获取索引信息
- Map indexsMap = DefaultDialectUtils.getTableIndexes(catalog, schema, tableName, conn,
- dbType, dialect);
- if (indexsMap != null && !indexsMap.isEmpty()) {
- for (ColumnMeta colMeta : tableCols) {
- mapMeta = indexsMap.get(colMeta.getColName());
- if (mapMeta != null) {
- colMeta.setIndexName(mapMeta.getIndexName());
- colMeta.setUnique(mapMeta.isUnique());
- colMeta.setIndex(true);
- }
- }
- }
- return tableCols;
- }
-
- /**
- * @param catalog
- * @param schema
- * @param tableName 要小写
- * @param conn
- * @param dbType
- * @param dialect
- * @return
- * @throws Exception
- */
- @SuppressWarnings({ "unchecked" })
- public static List getTables(String catalog, String schema, String tableName, Connection conn,
- Integer dbType, String dialect) throws Exception {
- // 可自定义 PreparedStatement pst=conn.xxx;
- ResultSet rs = conn.getMetaData().getTables(catalog, schema, tableName.toLowerCase(),
- new String[] { "TABLE", "VIEW" });
- // 通过preparedStatementProcess反调,第二个参数是pst
- return (List) SqlUtil.preparedStatementProcess(null, null, rs, new PreparedStatementResultHandler() {
- @Override
- public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
- List tables = new ArrayList();
- while (rs.next()) {
- TableMeta tableMeta = new TableMeta();
- tableMeta.setTableName(rs.getString("TABLE_NAME"));
- tableMeta.setSchema(rs.getString("TABLE_SCHEM"));
- tableMeta.setType(rs.getString("TABLE_TYPE"));
- tableMeta.setRemarks(rs.getString("REMARKS"));
- tables.add(tableMeta);
- }
- this.setResult(tables);
- }
- });
- }
-}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MySqlDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MySqlDialectUtils.java
index 067f541c2..074a30489 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MySqlDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/MySqlDialectUtils.java
@@ -12,7 +12,12 @@
* @version v1.0,Date:2015年2月13日
*/
public class MySqlDialectUtils {
-
+
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/GaussDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OpenGaussDialectUtils.java
similarity index 81%
rename from trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/GaussDialectUtils.java
rename to trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OpenGaussDialectUtils.java
index 037a99181..57cc19401 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/GaussDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OpenGaussDialectUtils.java
@@ -10,17 +10,17 @@
import org.sagacity.sqltoy.utils.StringUtil;
/**
+ * @author ming
+ * @version v1.0, Date:2024年10月25日
* @project sagacity-sqltoy
* @description 提供gaussdb数据库相关的特殊逻辑处理封装
- * @author zhongxuchen
- * @version v1.0, Date:2023年6月8日
- * @modify 2023年6月8日,修改说明
+ * @modify 2024年10月25日, 修改说明
*/
-public class GaussDialectUtils {
+public class OpenGaussDialectUtils {
/**
- * @TODO 定义当使用sequence或identity时,是否允许自定义值(即不通过sequence或identity产生,而是由外部直接赋值)
* @param pkStrategy
* @return
+ * @TODO 定义当使用sequence或identity时, 是否允许自定义值(即不通过sequence或identity产生 , 而是由外部直接赋值)
*/
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
@@ -49,7 +49,7 @@ public static boolean isAssignPKValue(PKStrategy pkStrategy) {
public static PKStrategy getSavePkStrategy(EntityMeta entityMeta, Serializable entity, Integer dbType,
Connection conn) {
PKStrategy pkStrategy = entityMeta.getIdStrategy();
- // gaussdb\mogdb 主键策略是sequence模式需要先获取主键值
+ // gaussdb\mogdb\vastbase\opengauss 主键策略是sequence模式需要先获取主键值
if (pkStrategy != null && pkStrategy.equals(PKStrategy.SEQUENCE)) {
// 取实体对象的主键值
Object id = BeanUtil.getProperty(entity, entityMeta.getIdArray()[0]);
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OracleDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OracleDialectUtils.java
index 215809dc7..9f882080a 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OracleDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/OracleDialectUtils.java
@@ -510,6 +510,11 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
});
}
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
return true;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqlServerDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqlServerDialectUtils.java
index 425f60bec..abb9c6652 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqlServerDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqlServerDialectUtils.java
@@ -45,6 +45,7 @@
import org.sagacity.sqltoy.plugins.IUnifyFieldsHandler;
import org.sagacity.sqltoy.utils.BeanUtil;
import org.sagacity.sqltoy.utils.CollectionUtil;
+import org.sagacity.sqltoy.utils.DataSourceUtils;
import org.sagacity.sqltoy.utils.DataSourceUtils.DBType;
import org.sagacity.sqltoy.utils.DataSourceUtils.Dialect;
import org.sagacity.sqltoy.utils.ReservedWordsUtil;
@@ -739,8 +740,9 @@ public static Object save(SqlToyContext sqlToyContext, Serializable entity, fina
SqlExecuteStat.showSql("mssql单条记录插入", realInsertSql, null);
PreparedStatement pst = null;
if (isIdentity) {
- pst = conn.prepareStatement(realInsertSql,
- new String[] { entityMeta.getColumnName(entityMeta.getIdArray()[0]) });
+ pst = conn.prepareStatement(realInsertSql, new String[] { DataSourceUtils
+ .getReturnPrimaryKeyColumn(entityMeta.getColumnName(entityMeta.getIdArray()[0]), dbType) });
+ // pst = conn.prepareStatement(realInsertSql, Statement.RETURN_GENERATED_KEYS);
} else {
pst = conn.prepareStatement(realInsertSql);
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqliteDialectUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqliteDialectUtils.java
index a847ef691..666813100 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqliteDialectUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dialect/utils/SqliteDialectUtils.java
@@ -12,6 +12,11 @@
* @version v1.0,Date:2015年3月5日
*/
public class SqliteDialectUtils {
+ /**
+ * 指的是在identity、sequence主键场景下,是否允许手工给主键赋值
+ * @param pkStrategy
+ * @return
+ */
public static boolean isAssignPKValue(PKStrategy pkStrategy) {
if (pkStrategy == null) {
return true;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLFactory.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLFactory.java
index a31532ace..2d99061b7 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLFactory.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLFactory.java
@@ -54,6 +54,10 @@ private static DialectDDLGenerator getGenerator(Integer dbType) {
}
case DBType.GAUSSDB:
case DBType.MOGDB:
+ case DBType.OSCAR:
+ case DBType.STARDB:
+ case DBType.OPENGAUSS:
+ case DBType.VASTBASE:
case DBType.POSTGRESQL:
case DBType.POSTGRESQL15: {
generator = new PostgreSqlDDLGenerator();
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLUtils.java
index e3ab906da..a8c677aac 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/ddl/DDLUtils.java
@@ -177,7 +177,8 @@ public static String convertType(ColumnMeta colMeta, int dbType) {
return "JSON";
} else if (colMeta.getNativeType().equalsIgnoreCase("BSON")) {
if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.VASTBASE) {
return "BSON";
} else {
return "JSON";
@@ -228,7 +229,8 @@ public static String convertType(ColumnMeta colMeta, int dbType) {
break;
case java.sql.Types.BLOB:
if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.VASTBASE) {
typeName = "bytea";
} else if (dbType == DBType.SQLSERVER) {
typeName = "IMAGE";
@@ -239,7 +241,8 @@ public static String convertType(ColumnMeta colMeta, int dbType) {
break;
case java.sql.Types.BINARY:
if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.STARDB || dbType == DBType.OSCAR
+ || dbType == DBType.MOGDB || dbType == DBType.VASTBASE) {
typeName = "bytea";
} else if (dbType == DBType.ORACLE || dbType == DBType.ORACLE11 || dbType == DBType.DM) {
typeName = "BLOB";
@@ -254,7 +257,8 @@ public static String convertType(ColumnMeta colMeta, int dbType) {
case java.sql.Types.VARBINARY:
case java.sql.Types.LONGVARBINARY:
if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.STARDB || dbType == DBType.OSCAR
+ || dbType == DBType.MOGDB || dbType == DBType.VASTBASE) {
typeName = "bytea";
} else if (dbType == DBType.ORACLE || dbType == DBType.ORACLE11 || dbType == DBType.DM) {
typeName = "BLOB";
@@ -329,8 +333,9 @@ public static String convertType(ColumnMeta colMeta, int dbType) {
}
// 数组类型
if ((dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB) && colMeta.getTypeName().endsWith("[]") && !isBytes
- && !typeName.startsWith("_")) {
+ || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.VASTBASE) && colMeta.getTypeName().endsWith("[]")
+ && !isBytes && !typeName.startsWith("_")) {
return "_".concat(typeName);
}
return typeName;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateDiff.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateDiff.java
new file mode 100644
index 000000000..75072ce75
--- /dev/null
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateDiff.java
@@ -0,0 +1,88 @@
+package org.sagacity.sqltoy.plugins.function.impl;
+
+import java.util.regex.Pattern;
+
+import org.sagacity.sqltoy.plugins.function.IFunction;
+import org.sagacity.sqltoy.utils.DataSourceUtils.DBType;
+
+/**
+ * 增加date_diff/datediff函数不同数据库适配(暂时不启用)
+ */
+public class DateDiff extends IFunction {
+ private static Pattern regex = Pattern.compile("(?i)\\W(datediff|timestampdiff)\\(");
+
+ public String dialects() {
+ return ALL;
+ }
+
+ @Override
+ public Pattern regex() {
+ return regex;
+ }
+
+ @Override
+ public String wrap(int dialect, String functionName, boolean hasArgs, String... args) {
+ if (args == null || args.length < 2) {
+ return super.IGNORE;
+ }
+ // 默认为天
+ String[] realArgs;
+ if (args.length == 2) {
+ realArgs = new String[] { "DAY", args[0], args[1] };
+ } else {
+ realArgs = args;
+ }
+ // 去除掉单引号、双引号
+ String unitType = realArgs[0].toUpperCase().replace("'", "").replace("\"", "");
+ String realFunctionName = "datediff";
+ String[][] unitConstracts = null;
+ if (dialect == DBType.MYSQL || dialect == DBType.MYSQL57) {
+ unitConstracts = new String[][] { { "DD", "DAY" }, { "MM", "MONTH" }, { "YY", "YEAR" },
+ { "YYYY", "YEAR" } };
+ realFunctionName = "timestampdiff";
+ } else if (dialect == DBType.ORACLE || dialect == DBType.ORACLE11) {
+ if (unitType.equals("YEAR")) {
+ return "TRUNC(MONTHS_BETWEEN(" + realArgs[1] + "," + realArgs[2] + ")/12,1)";
+ }else if (unitType.equals("MONTH")) {
+ return "TRUNC(MONTHS_BETWEEN(" + realArgs[1] + "," + realArgs[2] + "),1)";
+ }else if (unitType.equals("DAY")) {
+ return "EXTRACT(DAY FROM (" + realArgs[2] + "-" + realArgs[1] + "))";
+ }
+ } else if (dialect == DBType.MOGDB || dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15
+ || dialect == DBType.OPENGAUSS || dialect == DBType.VASTBASE || dialect == DBType.STARDB) {
+ // round(extract(epoch from(tni.update_time-tni.utime))/3600,2)
+ if (unitType.equals("YEAR")) {
+ return "(date_part('year'," + realArgs[2] + ")-date_part('year'," + realArgs[1] + "))";
+ } else if (unitType.equals("MONTH")) {
+ return "((date_part('year'," + realArgs[2] + ")-date_part('year'," + realArgs[1]
+ + "))*12+date_part('month'," + realArgs[2] + ")-date_part('month'," + realArgs[1] + "))";
+ } else if (unitType.equals("WEEK")) {
+ return "round(date_part('day'," + realArgs[2] + "-" + realArgs[1] + ")/7,1)";
+ } else if (unitType.equals("DAY")) {
+ return "date_part('day'," + realArgs[2] + "-" + realArgs[1] + ")";
+ } else if (unitType.equals("HOUR")) {
+ return "round(extract(epoch from(" + realArgs[2] + "-" + realArgs[1] + "))/3600,1)";
+ } else if (unitType.equals("MINUTE")) {
+ return "round(extract(epoch from(" + realArgs[2] + "-" + realArgs[1] + "))/60,1)";
+ } else if (unitType.equals("SECOND")) {
+ return "round(extract(epoch from(" + realArgs[2] + "-" + realArgs[1] + ")),0)";
+ }
+ } else if (dialect == DBType.SQLSERVER) {
+
+ }
+ if (unitConstracts != null) {
+ realArgs[0] = getMatchedType(unitType, unitConstracts);
+ return wrapArgs(realFunctionName, realArgs);
+ }
+ return super.IGNORE;
+ }
+
+ private String getMatchedType(String unitType, String[][] matchConstract) {
+ for (String[] constract : matchConstract) {
+ if (unitType.equals(constract[0])) {
+ return constract[1];
+ }
+ }
+ return unitType;
+ }
+}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java
index a0a45df83..2e1c88581 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/DateFormat.java
@@ -56,6 +56,10 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
case DBType.ORACLE:
case DBType.GAUSSDB:
case DBType.MOGDB:
+ case DBType.STARDB:
+ case DBType.OSCAR:
+ case DBType.OPENGAUSS:
+ case DBType.VASTBASE:
case DBType.OCEANBASE:
case DBType.DM:
case DBType.ORACLE11: {
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/GroupConcat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/GroupConcat.java
index 365c88130..ba83ec8e7 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/GroupConcat.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/GroupConcat.java
@@ -39,7 +39,8 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
sign = tmp.substring(matchIndex + 11).trim();
}
if (dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15 || dialect == DBType.GAUSSDB
- || dialect == DBType.MOGDB) {
+ || dialect == DBType.OPENGAUSS || dialect == DBType.OSCAR || dialect == DBType.STARDB
+ || dialect == DBType.MOGDB || dialect == DBType.VASTBASE) {
if ("string_agg".equals(functionName.toLowerCase())) {
return super.IGNORE;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java
index ce2f0f3c7..953e4c179 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Instr.java
@@ -96,7 +96,8 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
return result.append(")").toString();
}
if (dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15 || dialect == DBType.GAUSSDB
- || dialect == DBType.MOGDB) {
+ || dialect == DBType.OPENGAUSS || dialect == DBType.OSCAR || dialect == DBType.STARDB
+ || dialect == DBType.MOGDB || dialect == DBType.VASTBASE) {
if ("position".equals(funLow)) {
return super.IGNORE;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java
index 0d6705f63..83e8c8935 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Length.java
@@ -57,7 +57,9 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
}
if (dialect == DBType.ORACLE || dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15
|| dialect == DBType.DB2 || dialect == DBType.GAUSSDB || dialect == DBType.MOGDB
- || dialect == DBType.OCEANBASE || dialect == DBType.DM || dialect == DBType.ORACLE11) {
+ || dialect == DBType.VASTBASE || dialect == DBType.OPENGAUSS || dialect == DBType.STARDB
+ || dialect == DBType.OSCAR || dialect == DBType.OCEANBASE || dialect == DBType.DM
+ || dialect == DBType.ORACLE11) {
if ("datalength".equals(funLow) || "char_length".equals(funLow) || "len".equals(funLow)) {
return wrapArgs("length", args);
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Now.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Now.java
index 9aa8432d2..13079184c 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Now.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Now.java
@@ -46,8 +46,9 @@ public Pattern regex() {
@Override
public String wrap(int dialect, String functionName, boolean hasArgs, String... args) {
if (dialect == DBType.MYSQL || dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15
- || dialect == DBType.TIDB || dialect == DBType.GAUSSDB || dialect == DBType.MOGDB
- || dialect == DBType.MYSQL57 || dialect == DBType.H2) {
+ || dialect == DBType.TIDB || dialect == DBType.GAUSSDB || dialect == DBType.OPENGAUSS
+ || dialect == DBType.MOGDB || dialect == DBType.STARDB || dialect == DBType.OSCAR
+ || dialect == DBType.VASTBASE || dialect == DBType.MYSQL57 || dialect == DBType.H2) {
return wrapArgs("now", args);
}
if (dialect == DBType.ORACLE || dialect == DBType.OCEANBASE || dialect == DBType.DM
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java
index daca9fc92..4a4456ac8 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/Nvl.java
@@ -50,12 +50,14 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
if (args == null || args.length == 0) {
return super.IGNORE;
}
- //String funLow = functionName.toLowerCase();
+ // String funLow = functionName.toLowerCase();
if (dialect == DBType.SQLSERVER) {
return wrapArgs("isnull", args);
}
if (dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15 || dialect == DBType.DB2
- || dialect == DBType.GAUSSDB || dialect == DBType.MOGDB || dialect == DBType.H2) {
+ || dialect == DBType.OPENGAUSS || dialect == DBType.STARDB || dialect == DBType.OSCAR
+ || dialect == DBType.GAUSSDB || dialect == DBType.MOGDB || dialect == DBType.VASTBASE
+ || dialect == DBType.H2) {
return wrapArgs("coalesce", args);
}
if (dialect == DBType.MYSQL || dialect == DBType.TIDB || dialect == DBType.MYSQL57) {
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java
index bbe791424..e40666bc3 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/SubStr.java
@@ -42,7 +42,9 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
return super.IGNORE;
}
if (dialect == DBType.POSTGRESQL || dialect == DBType.POSTGRESQL15 || dialect == DBType.GAUSSDB
- || dialect == DBType.MOGDB || dialect == DBType.SQLSERVER || dialect == DBType.H2) {
+ || dialect == DBType.OPENGAUSS || dialect == DBType.MOGDB || dialect == DBType.VASTBASE
+ || dialect == DBType.SQLSERVER || dialect == DBType.H2 || dialect == DBType.STARDB
+ || dialect == DBType.OSCAR) {
if (dialect == DBType.SQLSERVER && args.length == 2) {
return "substring(" + args[0] + "," + args[1] + ",len(" + args[0] + "))";
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java
index c90299c3e..e05d2c0ac 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/function/impl/ToChar.java
@@ -48,6 +48,10 @@ public String wrap(int dialect, String functionName, boolean hasArgs, String...
case DBType.ORACLE:
case DBType.GAUSSDB:
case DBType.MOGDB:
+ case DBType.STARDB:
+ case DBType.OSCAR:
+ case DBType.OPENGAUSS:
+ case DBType.VASTBASE:
case DBType.OCEANBASE:
case DBType.DM:
case DBType.ORACLE11: {
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/DataSourceUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/DataSourceUtils.java
index 5377634bb..3ea4887f4 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/DataSourceUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/DataSourceUtils.java
@@ -106,7 +106,8 @@ public static final class Dialect {
public final static String MOGDB = "mogdb";
// 海量数据库(opengauss)
public final static String VASTBASE = "vastbase";
-
+ public final static String OPENGAUSS = "opengauss";
+ public final static String STARDB = "stardb";
public final static String UNDEFINE = "UNDEFINE";
}
@@ -158,6 +159,8 @@ public static final class DBType {
// MOGDB 基于openGauss开发。
public final static int MOGDB = 190;
public final static int VASTBASE = 200;
+ public final static int OPENGAUSS = 210;
+ public final static int STARDB = 220;
}
static {
@@ -181,7 +184,8 @@ public static void initialize() {
DBNameTypeMap.put(Dialect.GAUSSDB, DBType.GAUSSDB);
// 20240702 增加对mogdb的支持
DBNameTypeMap.put(Dialect.MOGDB, DBType.MOGDB);
-
+ DBNameTypeMap.put(Dialect.OPENGAUSS, DBType.OPENGAUSS);
+ DBNameTypeMap.put(Dialect.STARDB, DBType.STARDB);
DBNameTypeMap.put(Dialect.MONGO, DBType.MONGO);
DBNameTypeMap.put(Dialect.ES, DBType.ES);
DBNameTypeMap.put(Dialect.SQLITE, DBType.SQLITE);
@@ -202,8 +206,7 @@ public static void initialize() {
DBNameTypeMap.put(Dialect.VASTBASE, DBType.VASTBASE);
// 默认设置oscar、vastbase数据库用gaussdb方言来实现
- dialectMap.put(Dialect.OSCAR, Dialect.GAUSSDB);
- dialectMap.put(Dialect.VASTBASE, Dialect.GAUSSDB);
+ // dialectMap.put(Dialect.OSCAR, Dialect.OPENGAUSS);
}
/**
@@ -243,6 +246,12 @@ public static String getDialect(Integer dbType) {
case DBType.MOGDB: {
return Dialect.MOGDB;
}
+ case DBType.STARDB: {
+ return Dialect.STARDB;
+ }
+ case DBType.OPENGAUSS: {
+ return Dialect.OPENGAUSS;
+ }
case DBType.CLICKHOUSE: {
return Dialect.CLICKHOUSE;
}
@@ -344,13 +353,19 @@ else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.CLICKHOUSE) != -1) {
} // OCEANBASE
else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.OCEANBASE) != -1) {
dilectName = Dialect.OCEANBASE;
- } // GAUSSDB
+ } // opengauss
+ else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.OPENGAUSS) != -1) {
+ dilectName = Dialect.OPENGAUSS;
+ }
+ // GAUSSDB
else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.GAUSSDB) != -1
- || "zenith".equalsIgnoreCase(dbDialect) || "opengauss".equalsIgnoreCase(dbDialect)) {
+ || "zenith".equalsIgnoreCase(dbDialect)) {
dilectName = Dialect.GAUSSDB;
} // MOGDB
else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.MOGDB) != -1) {
dilectName = Dialect.MOGDB;
+ } else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.STARDB) != -1) {
+ dilectName = Dialect.STARDB;
} else if (StringUtil.indexOfIgnoreCase(dbDialect, Dialect.SQLITE) != -1) {
dilectName = Dialect.SQLITE;
} // dm
@@ -463,10 +478,14 @@ else if (dbDialect.equals(Dialect.DB2)) {
dbType = DBType.CLICKHOUSE;
} else if (dbDialect.equals(Dialect.OCEANBASE)) {
dbType = DBType.OCEANBASE;
+ } else if (dbDialect.equals(Dialect.OPENGAUSS)) {
+ dbType = DBType.OPENGAUSS;
} else if (dbDialect.equals(Dialect.GAUSSDB)) {
dbType = DBType.GAUSSDB;
} else if (dbDialect.equals(Dialect.MOGDB)) {
dbType = DBType.MOGDB;
+ } else if (dbDialect.equals(Dialect.STARDB)) {
+ dbType = DBType.STARDB;
} else if (dbDialect.equals(Dialect.SQLITE)) {
dbType = DBType.SQLITE;
} else if (dbDialect.equals(Dialect.DM)) {
@@ -540,6 +559,8 @@ public static String getValidateQuery(final int dbType) throws Exception {
case DBType.OSCAR:
case DBType.VASTBASE:
case DBType.MOGDB:
+ case DBType.STARDB:
+ case DBType.OPENGAUSS:
case DBType.GAUSSDB: {
return "select version()";
}
@@ -709,10 +730,14 @@ private static String getDialect(Connection conn) throws Exception {
return Dialect.KINGBASE;
case DBType.TDENGINE:
return Dialect.TDENGINE;
+ case DBType.OPENGAUSS:
+ return Dialect.OPENGAUSS;
case DBType.GAUSSDB:
return Dialect.GAUSSDB;
case DBType.MOGDB:
return Dialect.MOGDB;
+ case DBType.STARDB:
+ return Dialect.STARDB;
case DBType.IMPALA:
return Dialect.IMPALA;
case DBType.H2:
@@ -757,7 +782,9 @@ public static String getNvlFunction(Integer dbType) {
case DBType.DM:
return "nvl";
case DBType.GAUSSDB:
+ case DBType.OPENGAUSS:
case DBType.MOGDB:
+ case DBType.STARDB:
case DBType.OSCAR:
case DBType.VASTBASE:
return "nvl";
@@ -773,6 +800,7 @@ public static String getNvlFunction(Integer dbType) {
}
/**
+ * 默认postgresql、gaussdb、mogdb、vastbase要转小写
*
* @param dbType
* @return
@@ -784,10 +812,10 @@ public static CaseType getReturnPrimaryKeyColumnCase(Integer dbType) {
if (caseType != null) {
return CaseType.getCaseType(caseType);
}
- // postgresql系列数据库默认转小写
- if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15) {
- return CaseType.LOWER;
- }
+ }
+ // postgresql系列数据库默认转小写
+ if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15) {
+ return CaseType.LOWER;
}
return CaseType.DEFAULT;
}
@@ -821,9 +849,10 @@ public static boolean isSupportMultiFieldIn(Integer dbType) {
}
if (dbType == DBType.MYSQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.GAUSSDB
|| dbType == DBType.SQLSERVER || dbType == DBType.ORACLE || dbType == DBType.DM || dbType == DBType.TIDB
- || dbType == DBType.KINGBASE || dbType == DBType.MOGDB || dbType == DBType.OSCAR
- || dbType == DBType.VASTBASE || dbType == DBType.POSTGRESQL || dbType == DBType.CLICKHOUSE
- || dbType == DBType.H2 || dbType == DBType.SQLITE || dbType == DBType.ORACLE11) {
+ || dbType == DBType.KINGBASE || dbType == DBType.MOGDB || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR || dbType == DBType.OPENGAUSS || dbType == DBType.VASTBASE
+ || dbType == DBType.POSTGRESQL || dbType == DBType.CLICKHOUSE || dbType == DBType.H2
+ || dbType == DBType.SQLITE || dbType == DBType.ORACLE11) {
return true;
}
return false;
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/ReservedWordsUtil.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/ReservedWordsUtil.java
index 5d2672b80..ea3f67f3f 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/ReservedWordsUtil.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/ReservedWordsUtil.java
@@ -60,7 +60,8 @@ public static String convertSimpleSql(String sql, Integer dbType) {
}
if (dbType == DBType.ORACLE || dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15
|| dbType == DBType.DB2 || dbType == DBType.DM || dbType == DBType.GAUSSDB || dbType == DBType.MOGDB
- || dbType == DBType.OCEANBASE || dbType == DBType.ORACLE11) {
+ || dbType == DBType.STARDB || dbType == DBType.OSCAR || dbType == DBType.OPENGAUSS
+ || dbType == DBType.VASTBASE || dbType == DBType.OCEANBASE || dbType == DBType.ORACLE11) {
return sql.replaceAll("\\[", "\"").replaceAll("\\]", "\"");
}
if (dbType == DBType.H2) {
@@ -103,8 +104,9 @@ public static String convertWord(String column, Integer dbType) {
}
if (dbType == DBType.ORACLE || dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15
|| dbType == DBType.KINGBASE || dbType == DBType.DB2 || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB || dbType == DBType.DM || dbType == DBType.OCEANBASE
- || dbType == DBType.ORACLE11) {
+ || dbType == DBType.MOGDB || dbType == DBType.OPENGAUSS || dbType == DBType.VASTBASE
+ || dbType == DBType.STARDB || dbType == DBType.OSCAR || dbType == DBType.DM
+ || dbType == DBType.OCEANBASE || dbType == DBType.ORACLE11) {
return "\"".concat(column).concat("\"");
}
return column;
@@ -146,8 +148,9 @@ public static String convertSql(String sql, Integer dbType) {
}
if (dbType == DBType.POSTGRESQL || dbType == DBType.POSTGRESQL15 || dbType == DBType.ORACLE
|| dbType == DBType.DB2 || dbType == DBType.KINGBASE || dbType == DBType.GAUSSDB
- || dbType == DBType.MOGDB || dbType == DBType.DM || dbType == DBType.OCEANBASE
- || dbType == DBType.ORACLE11) {
+ || dbType == DBType.MOGDB || dbType == DBType.OPENGAUSS || dbType == DBType.VASTBASE
+ || dbType == DBType.DM || dbType == DBType.OCEANBASE || dbType == DBType.ORACLE11
+ || dbType == DBType.STARDB || dbType == DBType.OSCAR) {
sqlBuff.append("\"").append(keyWord).append("\"");
} else if (dbType == DBType.SQLSERVER || dbType == DBType.SQLITE) {
sqlBuff.append("[").append(keyWord).append("]");
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java
index a049ce944..f0da1a451 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/SqlUtil.java
@@ -391,7 +391,8 @@ public static void setParamValue(TypeHandler typeHandler, Connection conn, final
pst.setString(paramIndex, tmpStr);
} else if (paramValue instanceof byte[]) {
if (jdbcType == java.sql.Types.BLOB) {
- if (dbType == DBType.MOGDB) {
+ if (dbType == DBType.MOGDB || dbType == DBType.VASTBASE || dbType == DBType.OPENGAUSS
+ || dbType == DBType.STARDB) {
pst.setBlob(paramIndex, new ByteArrayInputStream((byte[]) paramValue));
} else {
Blob blob = null;
@@ -485,7 +486,8 @@ else if (paramValue instanceof Collection) {
private static void setArray(Integer dbType, Connection conn, PreparedStatement pst, int paramIndex,
Object paramValue) throws SQLException {
// 目前只支持Integer 和 String两种类型
- if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB) {
+ if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB || dbType == DBType.OPENGAUSS
+ || dbType == DBType.VASTBASE || dbType == DBType.STARDB || dbType == DBType.OSCAR) {
if (paramValue instanceof Integer[]) {
Array array = conn.createArrayOf("INTEGER", (Integer[]) paramValue);
pst.setArray(paramIndex, array);
@@ -932,8 +934,10 @@ public static Object getSequenceValue(Connection conn, String sequence, Integer
sql = "select nextval('" + sequence + "')";
} else if (dbType == DBType.SQLSERVER) {
sql = "select NEXT VALUE FOR " + sequence;
- } else if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB || dbType == DBType.OCEANBASE
- || dbType == DBType.ORACLE || dbType == DBType.ORACLE11 || dbType == DBType.DM) {
+ } else if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB || dbType == DBType.OPENGAUSS
+ || dbType == DBType.VASTBASE || dbType == DBType.OCEANBASE || dbType == DBType.ORACLE
+ || dbType == DBType.ORACLE11 || dbType == DBType.DM || dbType == DBType.STARDB
+ || dbType == DBType.OSCAR) {
sql = "select " + sequence + ".nextval";
} else {
sql = "select NEXTVAL FOR " + sequence;
@@ -2010,7 +2014,8 @@ public static String getDBTime(Integer dbType, FieldMeta fieldMeta, IgnoreCaseSe
|| dbType == DBType.POSTGRESQL15 || dbType == DBType.KINGBASE || dbType == DBType.DB2
|| dbType == DBType.OCEANBASE) {
return "current_time";
- } else if (dbType == DBType.GAUSSDB || dbType == DBType.MOGDB) {
+ } else if (dbType == DBType.GAUSSDB || dbType == DBType.OPENGAUSS || dbType == DBType.MOGDB
+ || dbType == DBType.VASTBASE || dbType == DBType.STARDB || dbType == DBType.OSCAR) {
return "now()";
} else if (dbType == DBType.SQLSERVER) {
return "getdate()";
diff --git a/trunk/sqltoy-orm-core/src/main/resources/sqltoy-test.sql.xml b/trunk/sqltoy-orm-core/src/main/resources/sqltoy-test.sql.xml
index dbbe489ae..5f7e88579 100644
--- a/trunk/sqltoy-orm-core/src/main/resources/sqltoy-test.sql.xml
+++ b/trunk/sqltoy-orm-core/src/main/resources/sqltoy-test.sql.xml
@@ -8,13 +8,15 @@
-
+
-
+
-
+
@@ -23,11 +25,12 @@
-
+
-
+
@@ -39,15 +42,16 @@
-
-
-
+
+
+
-
-
+
@@ -58,16 +62,16 @@
-
-
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
+
\ No newline at end of file
diff --git a/trunk/sqltoy-orm-solon-plugin/pom.xml b/trunk/sqltoy-orm-solon-plugin/pom.xml
index 07821510b..5143362ba 100644
--- a/trunk/sqltoy-orm-solon-plugin/pom.xml
+++ b/trunk/sqltoy-orm-solon-plugin/pom.xml
@@ -5,7 +5,7 @@
4.0.0
com.sagframe
- 5.6.29
+ 5.6.30
sagacity-sqltoy-solon-plugin
sagacity-sqltoy-solon-plugin
diff --git a/trunk/sqltoy-orm-spring-starter/pom.xml b/trunk/sqltoy-orm-spring-starter/pom.xml
index 9798ef296..d9a7847a2 100644
--- a/trunk/sqltoy-orm-spring-starter/pom.xml
+++ b/trunk/sqltoy-orm-spring-starter/pom.xml
@@ -4,14 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sagframe
- 5.6.29
+ 5.6.30
sagacity-sqltoy-spring-starter
sagacity-sqltoy-spring-starter
sqltoy springboot starter
https://github.com/sagframe/sagacity-sqltoy
UTF-8
- 3.3.4
+ 3.3.5
3.3.5
3.3.5
4.3.5
diff --git a/trunk/sqltoy-orm-spring-starter/src/main/resources/application.yml b/trunk/sqltoy-orm-spring-starter/src/main/resources/application.yml
deleted file mode 100644
index 0a4f5ba8c..000000000
--- a/trunk/sqltoy-orm-spring-starter/src/main/resources/application.yml
+++ /dev/null
@@ -1,41 +0,0 @@
-## 备注前面有单个# 的表示默认无需配置
-## 正常情况下只需配置sqlResourcesDir\translateConfig\unifyFieldsHandler\debug 四个参数即可
-spring:
- sqltoy:
- ## sqlResourcesDir 常用配置,如多个路径用;符号分割
- sqlResourcesDir: classpath:com/sagframe/modules
- ## translateConfig 常用配置,使用缓存翻译时需要配置
- translateConfig: classpath:sqltoy-translate.xml
- ## 开发阶段设置debug,便于打印执行的sql,默认为false
- debug: true
- ## functionConverts 跨数据库函数替换,如单一数据库类型则无需设置
- #functionConverts: default
- ## unifyFieldsHandler 统一对createTime、updateTime、createBy、updateBy 进行统一赋值的处理类
- #unifyFieldsHandler: com.sagframe.sqltoy.plugins.SqlToyUnifyFieldsHandler
- ## dialect 如单一数据库可设置
- #dialect: mysql
- ## 默认batchSize为200
- #batchSize: 200
- ## 设置分页查询最大提取数据记录,防止过多数据获取,默认100000
- #pageFetchSizeLimit: 50000
- #printSqlStrategy: error
- ## sql执行多少毫秒需要打印,默认30秒
- #printSqlTimeoutMillis: 30000
- ## elastic 如未使用可以不用配置
- elastic:
- ## 多个elastic地址默认使用地址,对应id
- defaultId: default
- endpoints:
- ## 单个地址id
- -id: default
- ## es对应的地址,如果是集群多个地址则用;分割
- url: http://192.168.56.104:9200
- ## es版本,可以是x.x 或x.x.x
- version: 7.5
- username: elastic
- password: elastic
-
-
-
-
-
\ No newline at end of file
diff --git a/trunk/sqltoy-orm-spring/pom.xml b/trunk/sqltoy-orm-spring/pom.xml
index 462c66196..8f9f96366 100644
--- a/trunk/sqltoy-orm-spring/pom.xml
+++ b/trunk/sqltoy-orm-spring/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.sagframe
- 5.6.29
+ 5.6.30
sagacity-sqltoy-spring
sagacity-sqltoy-spring
sagacity-sqltoy-spring