Commit 265886b4 authored by 雍欢's avatar 雍欢

多数据库支持

parent 1efc746e
......@@ -280,7 +280,7 @@ public enum Dialect {
* @return String
*/
public static String getTotalSql(String sql) {
return "select count(0) from (" + sql + ")";
return "select count(0) from (" + sql + ") __t__";
}
/**
......
......@@ -163,7 +163,7 @@ public class SQLQueryImpl implements SQLQuery {
if (!StringUtil.isBlank(queryModel.getManageType())) {
sb.append(sql);
} else {
sb.append("select * from (").append(sql).append(")");
sb.append("select * from (").append(sql).append(") __t__");
sb.append(" where 1=1 ");
}
sb.append(queryModel.parseSortFields());
......
......@@ -3,5 +3,5 @@ package com.huigou.data.query;
import com.huigou.exception.ResourceLoadException;
public interface QueryXmlLoadInterface {
public QueryXmlModel loadConfigFile(String path) throws ResourceLoadException;
QueryXmlModel loadConfigFile(String path) throws ResourceLoadException;
}
package com.huigou.data.query;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.huigou.uasp.bmp.query.QueryDocument.Query;
import com.huigou.uasp.bmp.query.QueryMappingsDocument.QueryMappings;
import com.huigou.util.ConfigFileVersion;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 查询模型管理类
*/
......@@ -23,7 +26,11 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
/**
* 实体对象
*/
private Map<String, Query> querys;
private final Map<String, Query> querys;
/**
* @since 1.1.3
*/
private final Map<String, Query> dialectQuerys;
/**
* 版本
......@@ -32,10 +39,18 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
private String configFilePath;
public QueryXmlModel(QueryMappings queryMappings) {
querys = new HashMap<String, Query>(queryMappings.getQueryArray().length);
for (Query query : queryMappings.getQueryArray()) {
querys.put(query.getName(), query);
public QueryXmlModel(QueryMappings queryMappings, QueryMappings dialectQueryMappings) {
if (queryMappings != null) {
querys = Arrays.stream(queryMappings.getQueryArray())
.collect(Collectors.toMap(Query::getName, query -> query));
} else {
querys = Collections.emptyMap();
}
if (dialectQueryMappings != null) {
dialectQuerys = Arrays.stream(dialectQueryMappings.getQueryArray())
.collect(Collectors.toMap(Query::getName, query -> query));
} else {
dialectQuerys = Collections.emptyMap();
}
}
......@@ -51,8 +66,20 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
return querys;
}
/**
* @since 1.1.3
*/
public Map<String, Query> getDialectQuerys() {
return dialectQuerys;
}
public Query getQuery(String name) {
return querys.get(name);
// 优先从方言中获取
Query query = dialectQuerys.get(name);
if (query == null) {
query = querys.get(name);
}
return query;
}
public void setVersion(Long version) {
......@@ -64,6 +91,7 @@ public class QueryXmlModel implements Serializable, ConfigFileVersion {
return version;
}
@Override
public String getFilePath() {
return configFilePath;
}
......
......@@ -37,8 +37,8 @@ import com.huigou.util.Util;
* SQL执行对象
*
* @author xx
* @date 2017-1-26 上午09:39:34
* @version V1.0
* @date 2017-1-26 上午09:39:34
*/
public class SQLExecutor extends SQLModel {
......@@ -80,6 +80,13 @@ public class SQLExecutor extends SQLModel {
*/
private List<String> conditionIn;
/**
* NOT IN 参数名称
*
* @since 1.1.3
*/
private List<String> conditionNotIn = new ArrayList<>(1);
/**
* LIKE 参数名称
*/
......@@ -129,6 +136,12 @@ public class SQLExecutor extends SQLModel {
}
}
public void addConditionNotIn(String name) {
if(name != null) {
conditionNotIn.add(name);
}
}
public void addConditionHalfLike(String name) {
if (name != null) {
conditionHalfLike.add(name);
......@@ -202,7 +215,8 @@ public class SQLExecutor extends SQLModel {
obj = ClassHelper.convert(obj, String.class);
obj = obj + "%";
}
if (isIn(name)) {// 是in查询默认添加()
// 是in查询默认添加()
if (isIn(name) || isNotIn(name)) {
StringBuffer inSql = new StringBuffer("(");
String[] vals = obj.toString().split(",");
int vi = vals.length;
......@@ -268,6 +282,13 @@ public class SQLExecutor extends SQLModel {
return false;
}
/**
* @since 1.1.3
*/
private boolean isNotIn(String name) {
return conditionNotIn.contains(name);
}
/**
* 构建查询sql
*/
......@@ -313,6 +334,9 @@ public class SQLExecutor extends SQLModel {
if (symbol.equalsIgnoreCase("IN")) {
this.addConditionIn(name);
}
if ("not in".equalsIgnoreCase(symbol)) {
this.addConditionNotIn(name);
}
}
/**
......
......@@ -42,10 +42,12 @@ public class SQLExecutorDaoImpl extends JDBCDaoImpl implements SQLExecutorDao {
this.queryXmlManager = queryXmlManager;
}
@Override
public SQLBuilder getSqlBuilder() {
return sqlBuilder;
}
@Override
public SQLQuery getSqlQuery() {
return sqlQuery;
}
......@@ -54,6 +56,7 @@ public class SQLExecutorDaoImpl extends JDBCDaoImpl implements SQLExecutorDao {
return queryXmlManager.loadConfigFile(modelFilePath);
}
@Override
public QueryDescriptor getQuery(String queryFilePath, String queryName) {
QueryXmlModel model = getQueryXmlModel(queryFilePath);
QueryDescriptor queryDescriptor = new QueryDescriptor(model.getQuery(queryName));
......
......@@ -7,8 +7,8 @@
<version>1.1.3-SNAPSHOT</version>
</parent>
<artifactId>huigou-uasp</artifactId>
<name>统一架构平台</name>
<description>统一架构平台</description>
<name>huigou-uasp</name>
<description>huigou-uasp</description>
<dependencies>
<!-- 公用的组件包 -->
<dependency>
......
package com.huigou.uasp.bmp.common.query;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.core.io.ClassPathResource;
import com.huigou.data.query.QueryXmlLoadInterface;
import com.huigou.data.query.QueryXmlModel;
import com.huigou.exception.ResourceLoadException;
import com.huigou.uasp.bmp.query.QueryMappingsDocument;
import com.huigou.util.ResourceLoadManager;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.Assert;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* 查询模型管理类
*
* @author xx
*/
public class QueryXmlManager extends ResourceLoadManager<QueryXmlModel> implements QueryXmlLoadInterface {
public class QueryXmlManager extends ResourceLoadManager<QueryXmlModel> implements QueryXmlLoadInterface, InitializingBean {
/**
* SQL 方言。
*/
private String sqlDialect;
public void setSqlDialect(String sqlDialect) {
this.sqlDialect = sqlDialect;
}
/**
* 加载配置文件
*/
@Override
public QueryXmlModel loadConfigFile(String path) throws ResourceLoadException {
InputStream inputStream = null;
InputStream inputStream = null, dialectXmlStream = null;
try {
// 默认SQL XML 文件
ClassPathResource resource = getResource(path);
// 方言SQL XML文件
ClassPathResource dialectXml = getResource(getDialectXmlPath(path));
Assert.isTrue(resource.exists() || dialectXml.exists(), "文件不存在");
QueryMappingsDocument.QueryMappings queryMappings = null;
if (resource.exists()) {
inputStream = resource.getInputStream();
QueryMappingsDocument doc = QueryMappingsDocument.Factory.parse(inputStream);
QueryXmlModel model = new QueryXmlModel(doc.getQueryMappings());
model.setVersion(resource.lastModified());// 文件最后修改时间
queryMappings = QueryMappingsDocument.Factory.parse(inputStream).getQueryMappings();
}
QueryMappingsDocument.QueryMappings dialectQueryMappings = null;
if (dialectXml.exists()) {
dialectXmlStream = dialectXml.getInputStream();
dialectQueryMappings = QueryMappingsDocument.Factory.parse(dialectXmlStream)
.getQueryMappings();
}
QueryXmlModel model = new QueryXmlModel(queryMappings, dialectQueryMappings);
// 文件最后修改时间
long version;
if (resource.exists() && dialectXml.exists()) {
version = resource.lastModified() > dialectXml.lastModified()
? resource.lastModified()
: dialectXml.lastModified();
} else {
version = resource.exists() ? resource.lastModified() : dialectXml.lastModified();
}
model.setVersion(version);
model.setConfigFilePath(path);
return model;
} catch (Exception e) {
throw new ResourceLoadException(String.format("读取配置文件[%s]失败:%s", path, e.getMessage()));
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(dialectXmlStream);
}
}
private String getDialectXmlPath(String path) {
Path filePath = Paths.get(path);
Path dialectXmlPath = filePath.getParent().resolve(sqlDialect).resolve(filePath.getFileName());
return dialectXmlPath.toString();
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.hasText(sqlDialect, "sql方言不能为空");
}
}
\ No newline at end of file
......@@ -420,8 +420,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
......@@ -443,6 +444,11 @@
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
</dependencies>
<build>
<finalName>huigou-xt</finalName>
......
#pub.db.url=jdbc:oracle:thin:@192.168.2.200:1521:orcl
#pub.db.user=c##gtoa_fx
#pub.db.password=123456
pub.db.url=jdbc:mysql://127.0.0.1:3306/avic_sys?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false
pub.db.user=root
pub.db.password=root
#log.db.url=jdbc:oracle:thin:@192.168.2.200:1521:orcl
#log.db.user=c##gtoa_fx
#log.db.password=123456
pub.db.url=jdbc:oracle:thin:@192.168.2.200:1521:orcl
pub.db.user=iesms
pub.db.password=iesms123
log.db.url=jdbc:oracle:thin:@192.168.2.200:1521:orcl
log.db.user=iesms
log.db.password=iesms123
log.db.url=jdbc:mysql://127.0.0.1:3306/avic_sys?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false
log.db.user=root
log.db.password=root
shiro.host=127.0.0.1
shiro.port=6379
shiro.expire=18000
system.dataSource=dataSource
system.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
system.hibernate.dialect=org.hibernate.dialect.MySQL57InnoDBDialect
sqlDialect=mysql
#shiroFilter loginUrl
shiro.loginUrl=/Login.jsp
......
......@@ -14,29 +14,36 @@
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="${pub.db.url}" />
<property name="user" value="${pub.db.user}" />
<property name="password" value="${pub.db.password}" />
<property name="maxPoolSize" value="200" />
<property name="minPoolSize" value="3" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20" />
</bean>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${pub.db.url}"/>
<property name="username" value="${pub.db.user}"/>
<property name="password" value="${pub.db.password}"/>
<property name="filters" value="stat"/>
<property name="maxActive" value="20"/>
<property name="initialSize" value="1"/>
<property name="maxWait" value="60000"/>
<property name="minIdle" value="1"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>
<bean id="nativeJdbcExtractor" lazy-init="true" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor" />
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxOpenPreparedStatements" value="20"/>
<property name="asyncInit" value="true"/>
</bean>
<bean id="lobHandler" lazy-init="true"
class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor">
<ref bean="nativeJdbcExtractor" />
</property>
<bean id="lobHandler" lazy-init="true" class="com.alibaba.druid.support.spring.DruidLobHandler">
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
\ No newline at end of file
......@@ -5,16 +5,28 @@
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="logDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="${log.db.url}" />
<property name="user" value="${log.db.user}" />
<bean id="logDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${log.db.url}" />
<property name="username" value="${log.db.user}" />
<property name="password" value="${log.db.password}" />
<property name="maxPoolSize" value="200" />
<property name="minPoolSize" value="3" />
<property name="initialPoolSize" value="1" />
<property name="maxIdleTime" value="20" />
<property name="filters" value="stat"/>
<property name="maxActive" value="20"/>
<property name="initialSize" value="1"/>
<property name="maxWait" value="60000"/>
<property name="minIdle" value="1"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxOpenPreparedStatements" value="20"/>
<property name="asyncInit" value="true"/>
</bean>
<bean id="logEntityManagerFactory"
......
......@@ -7,7 +7,7 @@
<!-- freeMarker 配置-->
<bean id="freeMarkerConfigurer"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/template" />
<property name="templateLoaderPath" value="/template"/>
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
......@@ -20,31 +20,34 @@
<property name="freeMarkerConfigurer" ref="freeMarkerConfigurer"/>
</bean>
<!-- 查询配置文件读取 -->
<bean id="queryXmlManager" class="com.huigou.uasp.bmp.common.query.QueryXmlManager" />
<bean id="queryXmlManager" class="com.huigou.uasp.bmp.common.query.QueryXmlManager">
<property name="sqlDialect" value="${sqlDialect}"/>
</bean>
<!-- 快捷树查询配置 -->
<bean id="treeViewManager" class="com.huigou.uasp.bmp.common.treeview.TreeViewManager" />
<bean id="treeViewApplication" class="com.huigou.uasp.bmp.common.treeview.application.impl.TreeViewApplicationImpl" >
<property name="jdbcDao" ref="jdbcDao" />
<property name="permissionBuilder" ref="queryPermissionBuilder" />
<bean id="treeViewManager" class="com.huigou.uasp.bmp.common.treeview.TreeViewManager"/>
<bean id="treeViewApplication" class="com.huigou.uasp.bmp.common.treeview.application.impl.TreeViewApplicationImpl">
<property name="jdbcDao" ref="jdbcDao"/>
<property name="permissionBuilder" ref="queryPermissionBuilder"/>
</bean>
<!--快捷查询控件配置 -->
<bean id="easySearchManager" class="com.huigou.uasp.bmp.common.easysearch.EasySearchManager" />
<bean id="easySearchApplication" class="com.huigou.uasp.bmp.common.easysearch.application.impl.EasySearchApplicationImpl" >
<property name="sqlQuery" ref="sqlQuery" />
<property name="permissionBuilder" ref="queryPermissionBuilder" />
<bean id="easySearchManager" class="com.huigou.uasp.bmp.common.easysearch.EasySearchManager"/>
<bean id="easySearchApplication"
class="com.huigou.uasp.bmp.common.easysearch.application.impl.EasySearchApplicationImpl">
<property name="sqlQuery" ref="sqlQuery"/>
<property name="permissionBuilder" ref="queryPermissionBuilder"/>
</bean>
<!--properties 配置文件读取 -->
<bean id="propertiesReader" class="com.huigou.properties.PropertiesManager" />
<bean id="propertiesReader" class="com.huigou.properties.PropertiesManager"/>
<!--启动插件配置 -->
<bean id="plugInManager" class="com.huigou.uasp.bmp.plugin.PlugInManager">
<property name="plugIns">
<list>
<ref bean="sysDictionaryPlugIn" />
<ref bean="parameterPlugIn" />
<ref bean="tmspmPlugIn" />
<ref bean="threeMemberPermissionPlugIn" />
<ref bean="applicationSystemPlugIn" />
<ref bean="i18npropertiesPlugIn" />
<ref bean="sysDictionaryPlugIn"/>
<ref bean="parameterPlugIn"/>
<ref bean="tmspmPlugIn"/>
<ref bean="threeMemberPermissionPlugIn"/>
<ref bean="applicationSystemPlugIn"/>
<ref bean="i18npropertiesPlugIn"/>
</list>
</property>
</bean>
......@@ -52,10 +55,10 @@
<bean id="expressUtil" class="com.huigou.express.ExpressUtil">
<property name="beanNames">
<list>
<ref bean="commonFun" />
<ref bean="codeGenerator" />
<ref bean="orgFun" />
<ref bean="processFun" />
<ref bean="commonFun"/>
<ref bean="codeGenerator"/>
<ref bean="orgFun"/>
<ref bean="processFun"/>
</list>
</property>
</bean>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment