本文整理匯總了Java中com.baomidou.mybatisplus.enums.DBType類的典型用法代碼示例。如果您正苦於以下問題:Java DBType類的具體用法?Java DBType怎麽用?Java DBType使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
DBType類屬於com.baomidou.mybatisplus.enums包,在下文中一共展示了DBType類的21個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: intercept
點讚 4
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public Object intercept(Invocation invocation) throws Throwable {
/**
* 處理 DELETE UPDATE 語句
*/
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
Executor executor = (Executor) invocation.getTarget();
Configuration configuration = ms.getConfiguration();
Object parameter = invocation.getArgs()[1];
BoundSql boundSql = ms.getBoundSql(parameter);
Connection connection = executor.getTransaction().getConnection();
String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
&& VersionUtils.compare(minMySQLVersion, databaseVersion)) {
logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
return invocation.proceed();
}
/**
* 執行 SQL 分析
*/
sqlExplain(configuration, ms, boundSql, connection, parameter);
}
return invocation.proceed();
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:25,
示例2: getiDialect
點讚 3
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 獲取數據庫方言
*
*
* @param dbType 數據庫類型
* @param dialectClazz 自定義方言實現類
* @return
* @throws Exception
*/
private static IDialect getiDialect(DBType dbType, String dialectClazz) throws Exception {
IDialect dialect = null;
if (Objects.nonNull(dbType)) {
dialect = getDialectByDbtype(dbType);
} else {
if (StringUtils.isNotEmpty(dialectClazz)) {
try {
Class> clazz = Class.forName(dialectClazz);
if (IDialect.class.isAssignableFrom(clazz)) {
dialect = (IDialect) clazz.newInstance();
}
} catch (ClassNotFoundException e) {
throw new MybatisPlusException("Class :" + dialectClazz + " is not found");
}
}
}
/* 未配置方言則拋出異常 */
if (dialect == null) {
throw new MybatisPlusException("The value of the dialect property in mybatis configuration.xml is not defined.");
}
return dialect;
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:33,
示例3: getDialectByDbtype
點讚 3
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 根據數據庫類型選擇不同分頁方言
*
*
* @param dbType 數據庫類型
* @return
* @throws Exception
*/
private static IDialect getDialectByDbtype(DBType dbType) {
switch (dbType) {
case MYSQL:
return MySqlDialect.INSTANCE;
case ORACLE:
return OracleDialect.INSTANCE;
case DB2:
return DB2Dialect.INSTANCE;
case H2:
return H2Dialect.INSTANCE;
case SQLSERVER:
return SQLServerDialect.INSTANCE;
case SQLSERVER2005:
return SQLServer2005Dialect.INSTANCE;
case POSTGRE:
return PostgreDialect.INSTANCE;
case HSQL:
return HSQLDialect.INSTANCE;
case SQLITE:
return SQLiteDialect.INSTANCE;
default:
throw new MybatisPlusException("Error: Unknown database type, or do not support changing database!\n");
}
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:34,
示例4: getDialect
點讚 3
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 獲取數據庫方言
*
*
* @param dbType 數據庫類型
* @param dialectClazz 自定義方言實現類
* @return
* @throws Exception
*/
private static IDialect getDialect(DBType dbType, String dialectClazz) throws Exception {
IDialect dialect = null;
if (StringUtils.isNotEmpty(dialectClazz)) {
try {
Class> clazz = Class.forName(dialectClazz);
if (IDialect.class.isAssignableFrom(clazz)) {
dialect = (IDialect) clazz.newInstance();
}
} catch (ClassNotFoundException e) {
throw new MybatisPlusException("Class :" + dialectClazz + " is not found");
}
} else if (null != dbType) {
dialect = getDialectByDbtype(dbType);
}
/* 未配置方言則拋出異常 */
if (dialect == null) {
throw new MybatisPlusException("The value of the dialect property in mybatis configuration.xml is not defined.");
}
return dialect;
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:31,
示例5: intercept
點讚 3
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
@Override
public Object intercept(Invocation invocation) throws Throwable {
/**
* 處理 DELETE UPDATE 語句
*/
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
Executor executor = (Executor) invocation.getTarget();
Configuration configuration = ms.getConfiguration();
Object parameter = invocation.getArgs()[1];
BoundSql boundSql = ms.getBoundSql(parameter);
Connection connection = executor.getTransaction().getConnection();
String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
&& VersionUtils.compare(minMySQLVersion, databaseVersion)) {
logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
return invocation.proceed();
}
/**
* 執行 SQL 分析
*/
sqlExplain(configuration, ms, boundSql, connection, parameter);
}
return invocation.proceed();
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:26,
示例6: getAs
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public String getAs() {
if (StringUtils.isEmpty(getColumn()) || StringUtils.isEmpty(as)) {
return StringUtils.EMPTY;
}
String quote = null;
if (isEscape() && FACTORY != null) {
GlobalConfiguration globalConfig = GlobalConfigUtils.getGlobalConfig(FACTORY.getConfiguration());
quote = globalConfig.getIdentifierQuote() == null ? DBType.getQuote(globalConfig.getDbType()) : globalConfig.getIdentifierQuote();
}
return AS + (StringUtils.isNotEmpty(quote) ? String.format(quote, as) : as);
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:12,
示例7: getDbType
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 根據連接地址判斷數據庫類型
*
*
* @param jdbcUrl 連接地址
* @return
*/
public static DBType getDbType(String jdbcUrl) {
if (StringUtils.isEmpty(jdbcUrl)) {
return DBType.MYSQL;
}
if (jdbcUrl.startsWith("jdbc:mysql:") || jdbcUrl.startsWith("jdbc:cobar:")
|| jdbcUrl.startsWith("jdbc:log4jdbc:mysql:")) {
return DBType.MYSQL;
} else if (jdbcUrl.startsWith("jdbc:oracle:") || jdbcUrl.startsWith("jdbc:log4jdbc:oracle:")) {
return DBType.ORACLE;
} else if (jdbcUrl.startsWith("jdbc:microsoft:") || jdbcUrl.startsWith("jdbc:log4jdbc:microsoft:")) {
return DBType.SQLSERVER;
} else if (jdbcUrl.startsWith("jdbc:sqlserver:") || jdbcUrl.startsWith("jdbc:log4jdbc:sqlserver:")) {
return DBType.SQLSERVER;
} else if (jdbcUrl.startsWith("jdbc:postgresql:") || jdbcUrl.startsWith("jdbc:log4jdbc:postgresql:")) {
return DBType.POSTGRE;
} else if (jdbcUrl.startsWith("jdbc:hsqldb:") || jdbcUrl.startsWith("jdbc:log4jdbc:hsqldb:")) {
return DBType.HSQL;
} else if (jdbcUrl.startsWith("jdbc:db2:")) {
return DBType.DB2;
} else if (jdbcUrl.startsWith("jdbc:sqlite:")) {
return DBType.SQLITE;
} else if (jdbcUrl.startsWith("jdbc:h2:") || jdbcUrl.startsWith("jdbc:log4jdbc:h2:")) {
return DBType.H2;
} else {
throw new MybatisPlusException("Error: Unknown database type, or do not support changing database!\n");
}
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:36,
示例8: intercept
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
* Physical Pagination Interceptor for all the queries with parameter {@link org.apache.ibatis.session.RowBounds}
*/
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
// 先判斷是不是SELECT操作
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
return invocation.proceed();
}
RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
/* 不需要分頁的場合 */
if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
return invocation.proceed();
}
BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
String originalSql = boundSql.getSql();
Connection connection = (Connection) invocation.getArgs()[0];
DBType dbType = JdbcUtils.getDbType(connection.getMetaData().getURL());
if (rowBounds instanceof Pagination) {
Pagination page = (Pagination) rowBounds;
if (page.isSearchCount()) {
this.queryTotal(JsqlParserUtils.jsqlparserCount(originalSql), mappedStatement, boundSql, page, connection);
if (page.getTotal() <= 0) {
return invocation.proceed();
}
}
originalSql = DialectFactory.buildPaginationSql(page, originalSql, dbType, null);
} else {
// support physical Pagination for RowBounds
originalSql = DialectFactory.buildPaginationSql(rowBounds, originalSql, dbType, null);
}
/*
*
禁用內存分頁
內存分頁會查詢所有結果出來處理(這個很嚇人的),如果結果變化頻繁這個數據還會不準。
*/
metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:43,
示例9: getDialectByDbtype
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 根據數據庫類型選擇不同分頁方言
*
*
* @param dbType 數據庫類型
* @return
* @throws Exception
*/
private static IDialect getDialectByDbtype(DBType dbType) {
IDialect dialect;
switch (dbType) {
case MYSQL:
dialect = MySqlDialect.INSTANCE;
break;
case ORACLE:
dialect = OracleDialect.INSTANCE;
break;
case DB2:
dialect = DB2Dialect.INSTANCE;
break;
case H2:
dialect = H2Dialect.INSTANCE;
break;
case SQLSERVER:
dialect = SQLServerDialect.INSTANCE;
break;
case SQLSERVER2005:
dialect = SQLServer2005Dialect.INSTANCE;
break;
case POSTGRE:
dialect = PostgreDialect.INSTANCE;
break;
case HSQL:
dialect = HSQLDialect.INSTANCE;
break;
case SQLITE:
dialect = SQLiteDialect.INSTANCE;
break;
default:
throw new MybatisPlusException("The Database's Not Supported! DBType:" + dbType);
}
return dialect;
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:45,
示例10: getDbType
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 根據連接地址判斷數據庫類型
*
*
* @param jdbcUrl 連接地址
* @return
*/
public static DBType getDbType(String jdbcUrl) {
if (StringUtils.isEmpty(jdbcUrl)) {
throw new MybatisPlusException("Error: The jdbcUrl is Null, Cannot read database type");
}
if (jdbcUrl.startsWith("jdbc:mysql:") || jdbcUrl.startsWith("jdbc:cobar:")
|| jdbcUrl.startsWith("jdbc:log4jdbc:mysql:")) {
return DBType.MYSQL;
} else if (jdbcUrl.startsWith("jdbc:oracle:") || jdbcUrl.startsWith("jdbc:log4jdbc:oracle:")) {
return DBType.ORACLE;
} else if (jdbcUrl.startsWith("jdbc:sqlserver:") || jdbcUrl.startsWith("jdbc:microsoft:")) {
return DBType.SQLSERVER2005;
} else if (jdbcUrl.startsWith("jdbc:sqlserver2012:")) {
return DBType.SQLSERVER;
} else if (jdbcUrl.startsWith("jdbc:postgresql:") || jdbcUrl.startsWith("jdbc:log4jdbc:postgresql:")) {
return DBType.POSTGRE;
} else if (jdbcUrl.startsWith("jdbc:hsqldb:") || jdbcUrl.startsWith("jdbc:log4jdbc:hsqldb:")) {
return DBType.HSQL;
} else if (jdbcUrl.startsWith("jdbc:db2:")) {
return DBType.DB2;
} else if (jdbcUrl.startsWith("jdbc:sqlite:")) {
return DBType.SQLITE;
} else if (jdbcUrl.startsWith("jdbc:h2:") || jdbcUrl.startsWith("jdbc:log4jdbc:h2:")) {
return DBType.H2;
} else {
logger.warn("The jdbcUrl is " + jdbcUrl + ", Mybatis Plus Cannot Read Database type or The Database's Not Supported!");
return DBType.OTHER;
}
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:37,
示例11: getDbType
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public DBType getDbType() {
return dbType;
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:4,
示例12: getIdentifierQuote
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public String getIdentifierQuote() {
if (null == identifierQuote) {
return DBType.getQuote(dbType);
}
return identifierQuote;
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:7,
示例13: getDbType
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public static DBType getDbType(Configuration configuration) {
return getGlobalConfig(configuration).getDbType();
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:4,
示例14: mybatisSqlSessionFactoryBean
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
* 這裏全部使用mybatis-autoconfigure 已經自動加載的資源。不手動指定
* 配置文件和mybatis-boot的配置文件同步
* @return
*/
@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean(DataSource dataSource) {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(dataSource);
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
mybatisPlus.setConfiguration(properties.getConfiguration());
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
// MP 全局配置,更多內容進入類看注釋
GlobalConfiguration globalConfig = new GlobalConfiguration();
globalConfig.setDbType(DBType.MYSQL.name());//數據庫類型
// ID 策略 AUTO->`0`("數據庫ID自增") INPUT->`1`(用戶輸入ID") ID_WORKER->`2`("全局唯一ID") UUID->`3`("全局唯一ID")
globalConfig.setIdType(3);
//MP 屬性下劃線 轉 駝峰 , 如果原生配置 mc.setMapUnderscoreToCamelCase(true) 開啟,該配置可以無。
globalConfig.setDbColumnUnderline(false);
mybatisPlus.setGlobalConfig(globalConfig);
MybatisConfiguration mc = new MybatisConfiguration();
// 對於完全自定義的mapper需要加此項配置,才能實現下劃線轉駝峰
mc.setMapUnderscoreToCamelCase(false);
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) {
mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
}
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
}
return mybatisPlus;
}
開發者ID:timtu,項目名稱:spring-boot-wechat,代碼行數:56,
示例15: mybatisSqlSessionFactoryBean
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
* 這裏全部使用mybatis-autoconfigure 已經自動加載的資源。不手動指定
* 配置文件和mybatis-boot的配置文件同步
* @return
*/
@Bean
@ConditionalOnMissingBean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(dataSource);
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
mybatisPlus.setConfiguration(properties.getConfiguration());
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
// MP 全局配置,更多內容進入類看注釋
GlobalConfiguration globalConfig = new GlobalConfiguration();
//駝峰下劃線規則
globalConfig.setDbColumnUnderline(true);
globalConfig.setDbType(DBType.MYSQL.name());
// ID 策略
// AUTO->`0`("數據庫ID自增")
// INPUT->`1`(用戶輸入ID")
// ID_WORKER->`2`("全局唯一ID")
// UUID->`3`("全局唯一ID")
globalConfig.setIdType(3);
mybatisPlus.setGlobalConfig(globalConfig);
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) {
mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
}
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
}
return mybatisPlus;
}
開發者ID:MIYAOW,項目名稱:MI-S,代碼行數:48,
示例16: mybatisSqlSessionFactoryBean
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
* 這裏全部使用mybatis-autoconfigure 已經自動加載的資源。不手動指定
* 配置文件和mybatis-boot的配置文件同步
* @return
*/
@Bean
@ConditionalOnMissingBean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(roundRobinDataSouceProxy());
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
mybatisPlus.setConfiguration(properties.getConfiguration());
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
// MP 全局配置,更多內容進入類看注釋
GlobalConfiguration globalConfig = new GlobalConfiguration();
//駝峰下劃線規則
globalConfig.setDbColumnUnderline(true);
globalConfig.setDbType(DBType.MYSQL.name());
// ID 策略
// AUTO->`0`("數據庫ID自增")
// INPUT->`1`(用戶輸入ID")
// ID_WORKER->`2`("全局唯一ID")
// UUID->`3`("全局唯一ID")
globalConfig.setIdType(3);
mybatisPlus.setGlobalConfig(globalConfig);
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) {
mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
}
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
}
return mybatisPlus;
}
開發者ID:MIYAOW,項目名稱:MI-S,代碼行數:48,
示例17: intercept
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
* Physical Pagination Interceptor for all the queries with parameter {@link org.apache.ibatis.session.RowBounds}
*/
@Override
public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
this.sqlParser(metaObject);
// 先判斷是不是SELECT操作
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
return invocation.proceed();
}
RowBounds rowBounds = (RowBounds) metaObject.getValue("delegate.rowBounds");
/* 不需要分頁的場合 */
if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
// 本地線程分頁
if (localPage) {
// 采用ThreadLocal變量處理的分頁
rowBounds = PageHelper.getPagination();
if (rowBounds == null) {
return invocation.proceed();
}
} else {
// 無需分頁
return invocation.proceed();
}
}
// 針對定義了rowBounds,做為mapper接口方法的參數
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
String originalSql = boundSql.getSql();
Connection connection = (Connection) invocation.getArgs()[0];
DBType dbType = StringUtils.isNotEmpty(dialectType) ? DBType.getDBType(dialectType) : JdbcUtils.getDbType(connection.getMetaData().getURL());
if (rowBounds instanceof Pagination) {
Pagination page = (Pagination) rowBounds;
boolean orderBy = true;
if (page.isSearchCount()) {
SqlInfo sqlInfo = SqlUtils.getCountOptimize(sqlParser, originalSql);
orderBy = sqlInfo.isOrderBy();
this.queryTotal(overflowCurrent, sqlInfo.getSql(), mappedStatement, boundSql, page, connection);
if (page.getTotal() <= 0) {
return invocation.proceed();
}
}
String buildSql = SqlUtils.concatOrderBy(originalSql, page, orderBy);
originalSql = DialectFactory.buildPaginationSql(page, buildSql, dbType, dialectClazz);
} else {
// support physical Pagination for RowBounds
originalSql = DialectFactory.buildPaginationSql(rowBounds, originalSql, dbType, dialectClazz);
}
/*
*
禁用內存分頁
*
內存分頁會查詢所有結果出來處理(這個很嚇人的),如果結果變化頻繁這個數據還會不準。
*/
metaObject.setValue("delegate.boundSql.sql", originalSql);
metaObject.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
metaObject.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
return invocation.proceed();
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:61,
示例18: setDbType
點讚 2
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
public void setDbType(String dbType) {
this.dbType = DBType.getDBType(dbType);
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:4,
示例19: convert
點讚 1
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 數據庫字段轉義
*
*
* @param globalConfig 全局配置
* @param column 數據庫字段
* @return
*/
public static String convert(GlobalConfiguration globalConfig, String column) {
if (globalConfig.getDbType() == DBType.POSTGRE) {
// POSTGRE 直接轉換
return convertQuote(globalConfig, column);
}
return containsWord(column) ? convertQuote(globalConfig, column) : column;
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:17,
示例20: buildPaginationSql
點讚 1
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 生成翻頁執行 SQL
*
*
* @param page 翻頁對象
* @param buildSql 執行 SQL
* @param dbType 數據庫類型
* @param dialectClazz 自定義方言實現類
* @return
* @throws Exception
*/
public static String buildPaginationSql(Pagination page, String buildSql, DBType dbType, String dialectClazz)
throws Exception {
// fix #172, 196
return getiDialect(dbType, dialectClazz).buildPaginationSql(buildSql, page.getOffsetCurrent(), page.getSize());
}
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:18,
示例21: buildPaginationSql
點讚 1
import com.baomidou.mybatisplus.enums.DBType; //導入依賴的package包/類
/**
*
* 生成翻頁執行 SQL
*
*
* @param page 翻頁對象
* @param buildSql 執行 SQL
* @param dbType 數據庫類型
* @param dialectClazz 自定義方言實現類
* @return
* @throws Exception
*/
public static String buildPaginationSql(Pagination page, String buildSql, DBType dbType, String dialectClazz)
throws Exception {
// fix #172, 196
return getDialect(dbType, dialectClazz).buildPaginationSql(buildSql, page.offsetCurrent(), page.getSize());
}
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:18,
注:本文中的com.baomidou.mybatisplus.enums.DBType類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。