mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-09 17:34:50 +08:00
@@ -1,4 +1,4 @@
|
||||
## 后台管理基础框架
|
||||
## hsweb后台管理基础框架
|
||||
|
||||
[](https://travis-ci.org/hs-web/hsweb-framework)
|
||||
[](https://www.apache.org/licenses/LICENSE-2.0.html)
|
||||
@@ -37,6 +37,7 @@
|
||||
7. 数据库支持 mysql,oracle,h2.
|
||||
8. websocket支持.
|
||||
9. 定时调度支持,可在页面配置定时任务,编写任务脚本执行。
|
||||
10. **强大的dsl查询方式,复杂条件一句生成**
|
||||
|
||||
### 演示
|
||||
1. 示例:[demo.hsweb.me](http://demo.hsweb.me)
|
||||
|
||||
53
doc/2.API.md
Normal file
53
doc/2.API.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# hsweb 常用api
|
||||
|
||||
## CRUD
|
||||
[如何创建通用crud](./create-crud.md)
|
||||
|
||||
查询:
|
||||
```java
|
||||
|
||||
import static MyBean.Property.*; //属性名
|
||||
myService.createQuery()
|
||||
.where(name,"admin")
|
||||
.or(name,"root")
|
||||
.list(); //list(), list(0,10), single(),total();
|
||||
//or
|
||||
myService.createQuery().fromBean(myBean)
|
||||
.where(name)
|
||||
.or(name)
|
||||
.list();
|
||||
|
||||
// 复杂查询条件
|
||||
// 等同sql where name is not null and (name like '李%' or name like '周%') and age >0
|
||||
// 参数全部预编译,不用担心注入
|
||||
myService.createQuery()
|
||||
.where().notNull(name)
|
||||
.nest().or().like$(name,"李").or().like$(name,"周").end()
|
||||
.and().gt(age,10).list();
|
||||
|
||||
//自定义sql条件
|
||||
|
||||
myService.createQuery()
|
||||
.where()
|
||||
.and().sql("name !=''")
|
||||
.or().sql("age < #{age}",{age:10})// 使用预编译方式
|
||||
.or().sql("age = #{[0]}",Arrays.asList(20))//获取集合参数
|
||||
.or().sql("age > ? and (age <?)",60,100)//使用参数列表方式
|
||||
.list();
|
||||
```
|
||||
|
||||
修改,支持和query一致的条件
|
||||
```java
|
||||
import static MyBean.Property.*;
|
||||
myService.createUpdate()
|
||||
.set(status,1)
|
||||
.where(id,"data-id").exec();
|
||||
// or
|
||||
myService.createUpdate(myBean).fromBean().where(id).exec();
|
||||
```
|
||||
|
||||
删除,支持和query一致的条件
|
||||
```java
|
||||
import static MyBean.Property.*;
|
||||
myService.createDelete().where(id,"data-id").exec();
|
||||
```
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-bean</artifactId>
|
||||
@@ -18,7 +18,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-easy-orm</artifactId>
|
||||
<artifactId>hsweb-easy-orm-rdb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.hsweb.web.bean.common;
|
||||
/**
|
||||
* Created by zhouhao on 16-4-19.
|
||||
*/
|
||||
public class DeleteParam extends SqlParam<DeleteParam> {
|
||||
public class DeleteParam extends SqlParam {
|
||||
public static DeleteParam build() {
|
||||
return new DeleteParam();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.hsweb.web.bean.common;
|
||||
/**
|
||||
* Created by zhouhao on 16-4-19.
|
||||
*/
|
||||
public class InsertParam<T> extends org.hsweb.ezorm.param.InsertParam<T> {
|
||||
public class InsertParam<T> extends org.hsweb.ezorm.core.param.InsertParam<T> {
|
||||
|
||||
public InsertParam() {
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package org.hsweb.web.bean.common;
|
||||
|
||||
|
||||
import org.hsweb.ezorm.param.Term;
|
||||
import org.hsweb.ezorm.param.TermType;
|
||||
import org.hsweb.ezorm.core.param.Term;
|
||||
import org.hsweb.ezorm.core.param.TermType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by 浩 on 2016-01-16 0016.
|
||||
*/
|
||||
public class QueryParam extends org.hsweb.ezorm.param.QueryParam<QueryParam> implements Serializable {
|
||||
private static final long serialVersionUID = 7941767360194797891L;
|
||||
private Map<String, Object> param = new HashMap<>();
|
||||
public class QueryParam extends org.hsweb.ezorm.core.param.QueryParam implements Serializable {
|
||||
private static final long serialVersionUID = 7941767360194797891L;
|
||||
private Map<String, Object> param = new HashMap<>();
|
||||
|
||||
public QueryParam noPaging() {
|
||||
setPaging(false);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.hsweb.web.bean.common;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-5-14.
|
||||
*/
|
||||
public class Sort extends org.hsweb.ezorm.param.Sort {
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by zhouhao on 16-4-19.
|
||||
*/
|
||||
public class SqlParam<R extends SqlParam> extends org.hsweb.ezorm.param.SqlParam<R> {
|
||||
public class SqlParam extends org.hsweb.ezorm.core.param.Param {
|
||||
|
||||
protected Map<String, Object> params = new HashMap<>();
|
||||
|
||||
@@ -26,6 +26,6 @@ public class SqlParam<R extends SqlParam> extends org.hsweb.ezorm.param.SqlParam
|
||||
}
|
||||
|
||||
public static SqlParam build() {
|
||||
return new SqlParam<>();
|
||||
return new SqlParam();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UpdateMapParam extends UpdateParam<Map<String, Object>> {
|
||||
}
|
||||
|
||||
public UpdateMapParam set(String key, Object value) {
|
||||
this.getData().put(key, value);
|
||||
((Map<String, Object>) this.getData()).put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.hsweb.web.bean.common;
|
||||
/**
|
||||
* Created by zhouhao on 16-4-19.
|
||||
*/
|
||||
public class UpdateParam<T> extends org.hsweb.ezorm.param.UpdateParam<T,UpdateParam<T>> {
|
||||
public class UpdateParam<T> extends org.hsweb.ezorm.core.param.UpdateParam<T> {
|
||||
|
||||
public UpdateParam() {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.hsweb.web.bean.po;
|
||||
|
||||
|
||||
import org.hsweb.commons.MD5;
|
||||
import org.hsweb.web.bean.po.module.Module;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -60,7 +61,6 @@ public class GenericPo<PK> implements Serializable, Cloneable {
|
||||
/**
|
||||
* 创建一个主键
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String createUID() {
|
||||
return MD5.encode(UUID.randomUUID().toString());
|
||||
@@ -74,12 +74,19 @@ public class GenericPo<PK> implements Serializable, Cloneable {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
|
||||
}
|
||||
return super.clone();
|
||||
public interface Property {
|
||||
/**
|
||||
* 主键
|
||||
*
|
||||
* @see GenericPo#id
|
||||
*/
|
||||
String id = "id";
|
||||
|
||||
/**
|
||||
* 其他属性
|
||||
*
|
||||
* @see GenericPo#properties
|
||||
*/
|
||||
String properties = "properties";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,4 +151,44 @@ public class Classified extends GenericPo<String> {
|
||||
public void setSortIndex(int sortIndex) {
|
||||
this.sortIndex = sortIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Classified#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Classified#remark
|
||||
*/
|
||||
String remark="remark";
|
||||
/**
|
||||
*
|
||||
* @see Classified#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see Classified#parentId
|
||||
*/
|
||||
String parentId="parentId";
|
||||
/**
|
||||
*
|
||||
* @see Classified#icon
|
||||
*/
|
||||
String icon="icon";
|
||||
/**
|
||||
*
|
||||
* @see Classified#config
|
||||
*/
|
||||
String config="config";
|
||||
/**
|
||||
*
|
||||
* @see Classified#sortIndex
|
||||
*/
|
||||
String sortIndex="sortIndex";
|
||||
}
|
||||
}
|
||||
@@ -165,4 +165,27 @@ public class Config extends GenericPo<String> {
|
||||
List<Map<Object, Object>> array = (List) JSON.parseArray(getContent(), Map.class);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public interface Property extends GenericPo.Property {
|
||||
/**
|
||||
* @see Config#remark
|
||||
*/
|
||||
String remark = "remark";
|
||||
/**
|
||||
* @see Config#content
|
||||
*/
|
||||
String content = "content";
|
||||
/**
|
||||
* @see Config#createDate
|
||||
*/
|
||||
String createDate = "createDate";
|
||||
/**
|
||||
* @see Config#updateDate
|
||||
*/
|
||||
String updateDate = "updateDate";
|
||||
/**
|
||||
* @see Config#classifiedId
|
||||
*/
|
||||
String classifiedId = "classifiedId";
|
||||
}
|
||||
}
|
||||
@@ -154,4 +154,49 @@ public class DataSource extends GenericPo<String> {
|
||||
builder.append(driver).append(url).append(username).append(password).append(enabled);
|
||||
return builder.toString().hashCode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see DataSource#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#driver
|
||||
*/
|
||||
String driver="driver";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#url
|
||||
*/
|
||||
String url="url";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#username
|
||||
*/
|
||||
String username="username";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#testSql
|
||||
*/
|
||||
String testSql="testSql";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#password
|
||||
*/
|
||||
String password="password";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#enabled
|
||||
*/
|
||||
String enabled="enabled";
|
||||
/**
|
||||
*
|
||||
* @see DataSource#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,34 @@ public class Draft extends GenericPo<String> {
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Draft#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Draft#value
|
||||
*/
|
||||
String value="value";
|
||||
/**
|
||||
*
|
||||
* @see Draft#key
|
||||
*/
|
||||
String key="key";
|
||||
/**
|
||||
*
|
||||
* @see Draft#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
/**
|
||||
*
|
||||
* @see Draft#creatorId
|
||||
*/
|
||||
String creatorId="creatorId";
|
||||
}
|
||||
}
|
||||
@@ -189,4 +189,69 @@ public class Form extends GenericPo<String> {
|
||||
public void setClassifiedId(String classifiedId) {
|
||||
this.classifiedId = classifiedId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Form#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Form#html
|
||||
*/
|
||||
String html="html";
|
||||
/**
|
||||
*
|
||||
* @see Form#meta
|
||||
*/
|
||||
String meta="meta";
|
||||
/**
|
||||
*
|
||||
* @see Form#config
|
||||
*/
|
||||
String config="config";
|
||||
/**
|
||||
*
|
||||
* @see Form#remark
|
||||
*/
|
||||
String remark="remark";
|
||||
/**
|
||||
*
|
||||
* @see Form#version
|
||||
*/
|
||||
String version="version";
|
||||
/**
|
||||
*
|
||||
* @see Form#revision
|
||||
*/
|
||||
String revision="revision";
|
||||
/**
|
||||
*
|
||||
* @see Form#release
|
||||
*/
|
||||
String release="release";
|
||||
/**
|
||||
*
|
||||
* @see Form#using
|
||||
*/
|
||||
String using="using";
|
||||
/**
|
||||
*
|
||||
* @see Form#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
/**
|
||||
*
|
||||
* @see Form#updateDate
|
||||
*/
|
||||
String updateDate="updateDate";
|
||||
/**
|
||||
*
|
||||
* @see Form#classifiedId
|
||||
*/
|
||||
String classifiedId="classifiedId";
|
||||
}
|
||||
}
|
||||
@@ -131,4 +131,49 @@ public class History extends GenericPo<String> {
|
||||
history.setCreatorId("Sys");
|
||||
return history;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see History#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see History#describe
|
||||
*/
|
||||
String describe="describe";
|
||||
/**
|
||||
*
|
||||
* @see History#primaryKeyName
|
||||
*/
|
||||
String primaryKeyName="primaryKeyName";
|
||||
/**
|
||||
*
|
||||
* @see History#primaryKeyValue
|
||||
*/
|
||||
String primaryKeyValue="primaryKeyValue";
|
||||
/**
|
||||
*
|
||||
* @see History#changeBefore
|
||||
*/
|
||||
String changeBefore="changeBefore";
|
||||
/**
|
||||
*
|
||||
* @see History#changeAfter
|
||||
*/
|
||||
String changeAfter="changeAfter";
|
||||
/**
|
||||
*
|
||||
* @see History#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
/**
|
||||
*
|
||||
* @see History#creatorId
|
||||
*/
|
||||
String creatorId="creatorId";
|
||||
}
|
||||
}
|
||||
@@ -246,4 +246,99 @@ public class LoggerInfo extends GenericPo<String> {
|
||||
public void setCacheKey(String cacheKey) {
|
||||
this.cacheKey = cacheKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#clientIp
|
||||
*/
|
||||
String clientIp="clientIp";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestUri
|
||||
*/
|
||||
String requestUri="requestUri";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestUrl
|
||||
*/
|
||||
String requestUrl="requestUrl";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestMethod
|
||||
*/
|
||||
String requestMethod="requestMethod";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#responseContent
|
||||
*/
|
||||
String responseContent="responseContent";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#userId
|
||||
*/
|
||||
String userId="userId";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestTime
|
||||
*/
|
||||
String requestTime="requestTime";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#responseTime
|
||||
*/
|
||||
String responseTime="responseTime";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#useTime
|
||||
*/
|
||||
String useTime="useTime";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#referer
|
||||
*/
|
||||
String referer="referer";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#userAgent
|
||||
*/
|
||||
String userAgent="userAgent";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#responseCode
|
||||
*/
|
||||
String responseCode="responseCode";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestHeader
|
||||
*/
|
||||
String requestHeader="requestHeader";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#className
|
||||
*/
|
||||
String className="className";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#moduleDesc
|
||||
*/
|
||||
String moduleDesc="moduleDesc";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#requestParam
|
||||
*/
|
||||
String requestParam="requestParam";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#exceptionInfo
|
||||
*/
|
||||
String exceptionInfo="exceptionInfo";
|
||||
/**
|
||||
*
|
||||
* @see LoggerInfo#cacheKey
|
||||
*/
|
||||
String cacheKey="cacheKey";
|
||||
}
|
||||
}
|
||||
@@ -196,4 +196,40 @@ public class Module extends GenericPo<String> implements Comparable<Module> {
|
||||
return ((Long) getSortIndex()).compareTo(o.getSortIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Property extends GenericPo.Property {
|
||||
/**
|
||||
* @see Module#name
|
||||
*/
|
||||
String name = "name";
|
||||
/**
|
||||
* @see Module#uri
|
||||
*/
|
||||
String uri = "uri";
|
||||
/**
|
||||
* @see Module#icon
|
||||
*/
|
||||
String icon = "icon";
|
||||
/**
|
||||
* @see Module#parentId
|
||||
*/
|
||||
String parentId = "parentId";
|
||||
/**
|
||||
* @see Module#remark
|
||||
*/
|
||||
String remark = "remark";
|
||||
/**
|
||||
* @see Module#status
|
||||
*/
|
||||
String status = "status";
|
||||
/**
|
||||
* @see Module#optional
|
||||
*/
|
||||
String optional = "optional";
|
||||
/**
|
||||
* @see Module#sortIndex
|
||||
*/
|
||||
String sortIndex = "sortIndex";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,4 +81,39 @@ public class ModuleMeta extends GenericPo<String> {
|
||||
builder.append(status);
|
||||
return MD5.defaultEncode(builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#key
|
||||
*/
|
||||
String key="key";
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#remark
|
||||
*/
|
||||
String remark="remark";
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#moduleId
|
||||
*/
|
||||
String moduleId="moduleId";
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#roleId
|
||||
*/
|
||||
String roleId="roleId";
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#meta
|
||||
*/
|
||||
String meta="meta";
|
||||
/**
|
||||
*
|
||||
* @see ModuleMeta#status
|
||||
*/
|
||||
String status="status";
|
||||
}
|
||||
}
|
||||
@@ -134,4 +134,39 @@ public class QueryPlan extends GenericPo<String> {
|
||||
public void setCreateDate(java.util.Date createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#config
|
||||
*/
|
||||
String config="config";
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#sharing
|
||||
*/
|
||||
String sharing="sharing";
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#creatorId
|
||||
*/
|
||||
String creatorId="creatorId";
|
||||
/**
|
||||
*
|
||||
* @see QueryPlan#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,24 @@ public class UserProfile extends GenericPo<String> {
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see UserProfile#userId
|
||||
*/
|
||||
String userId="userId";
|
||||
/**
|
||||
*
|
||||
* @see UserProfile#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see UserProfile#content
|
||||
*/
|
||||
String content="content";
|
||||
}
|
||||
}
|
||||
@@ -183,4 +183,40 @@ public class QuartzJob extends GenericPo<String> {
|
||||
public void setType(byte type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property {
|
||||
/**
|
||||
* @see QuartzJob#name
|
||||
*/
|
||||
String name = "name";
|
||||
/**
|
||||
* @see QuartzJob#remark
|
||||
*/
|
||||
String remark = "remark";
|
||||
/**
|
||||
* @see QuartzJob#cron
|
||||
*/
|
||||
String cron = "cron";
|
||||
/**
|
||||
* @see QuartzJob#script
|
||||
*/
|
||||
String script = "script";
|
||||
/**
|
||||
* @see QuartzJob#language
|
||||
*/
|
||||
String language = "language";
|
||||
/**
|
||||
* @see QuartzJob#enabled
|
||||
*/
|
||||
String enabled = "enabled";
|
||||
/**
|
||||
* @see QuartzJob#parameters
|
||||
*/
|
||||
String parameters = "parameters";
|
||||
/**
|
||||
* @see QuartzJob#type
|
||||
*/
|
||||
String type = "type";
|
||||
}
|
||||
}
|
||||
@@ -163,4 +163,34 @@ public class QuartzJobHistory extends GenericPo<String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see QuartzJobHistory#jobId
|
||||
*/
|
||||
String jobId="jobId";
|
||||
/**
|
||||
*
|
||||
* @see QuartzJobHistory#startTime
|
||||
*/
|
||||
String startTime="startTime";
|
||||
/**
|
||||
*
|
||||
* @see QuartzJobHistory#endTime
|
||||
*/
|
||||
String endTime="endTime";
|
||||
/**
|
||||
*
|
||||
* @see QuartzJobHistory#result
|
||||
*/
|
||||
String result="result";
|
||||
/**
|
||||
*
|
||||
* @see QuartzJobHistory#status
|
||||
*/
|
||||
String status="status";
|
||||
}
|
||||
}
|
||||
@@ -180,4 +180,54 @@ public class Resources extends GenericPo<String> {
|
||||
return FileUtils.getSuffix(getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Resources#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Resources#path
|
||||
*/
|
||||
String path="path";
|
||||
/**
|
||||
*
|
||||
* @see Resources#createDate
|
||||
*/
|
||||
String createDate="createDate";
|
||||
/**
|
||||
*
|
||||
* @see Resources#creatorId
|
||||
*/
|
||||
String creatorId="creatorId";
|
||||
/**
|
||||
*
|
||||
* @see Resources#md5
|
||||
*/
|
||||
String md5="md5";
|
||||
/**
|
||||
*
|
||||
* @see Resources#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see Resources#classified
|
||||
*/
|
||||
String classified="classified";
|
||||
/**
|
||||
*
|
||||
* @see Resources#size
|
||||
*/
|
||||
String size="size";
|
||||
/**
|
||||
*
|
||||
* @see Resources#status
|
||||
*/
|
||||
String status="status";
|
||||
}
|
||||
}
|
||||
@@ -91,4 +91,29 @@ public class Role extends GenericPo<String> {
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Role#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Role#remark
|
||||
*/
|
||||
String remark="remark";
|
||||
/**
|
||||
*
|
||||
* @see Role#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see Role#modules
|
||||
*/
|
||||
String modules="modules";
|
||||
}
|
||||
}
|
||||
@@ -80,4 +80,29 @@ public class RoleModule extends GenericPo<String> {
|
||||
public void setActions(List<String> actions) {
|
||||
this.actions = actions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see RoleModule#moduleId
|
||||
*/
|
||||
String moduleId="moduleId";
|
||||
/**
|
||||
*
|
||||
* @see RoleModule#roleId
|
||||
*/
|
||||
String roleId="roleId";
|
||||
/**
|
||||
*
|
||||
* @see RoleModule#actions
|
||||
*/
|
||||
String actions="actions";
|
||||
/**
|
||||
*
|
||||
* @see RoleModule#module
|
||||
*/
|
||||
String module="module";
|
||||
}
|
||||
}
|
||||
@@ -66,4 +66,20 @@ public class UserRole extends GenericPo<String> {
|
||||
public void setRole(Role role) {
|
||||
this.role = role;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface Property {
|
||||
/**
|
||||
* @see UserRole#userId
|
||||
*/
|
||||
String userId = "userId";
|
||||
/**
|
||||
* @see UserRole#roleId
|
||||
*/
|
||||
String roleId = "roleId";
|
||||
/**
|
||||
* @see UserRole#role
|
||||
*/
|
||||
String role = "role";
|
||||
}
|
||||
}
|
||||
@@ -131,4 +131,30 @@ public class DynamicScript extends GenericPo<String> {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
public interface Property extends GenericPo.Property {
|
||||
/**
|
||||
* @see DynamicScript#name
|
||||
*/
|
||||
String name = "name";
|
||||
/**
|
||||
* @see DynamicScript#type
|
||||
*/
|
||||
String type = "type";
|
||||
/**
|
||||
* @see DynamicScript#content
|
||||
*/
|
||||
String content = "content";
|
||||
/**
|
||||
* @see DynamicScript#remark
|
||||
*/
|
||||
String remark = "remark";
|
||||
/**
|
||||
* @see DynamicScript#classifiedId
|
||||
*/
|
||||
String classifiedId = "classifiedId";
|
||||
/**
|
||||
* @see DynamicScript#status
|
||||
*/
|
||||
String status = "status";
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 http://hsweb.me
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.hsweb.web.bean.po.system;
|
||||
|
||||
public class SystemVersion implements Comparable<SystemVersion> {
|
||||
public String name;
|
||||
public String comment;
|
||||
public String website;
|
||||
public int majorVersion = 1;
|
||||
public int minorVersion = 0;
|
||||
public int revisionVersion = 0;
|
||||
public boolean snapshot;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public String getWebsite() {
|
||||
return website;
|
||||
}
|
||||
|
||||
public void setWebsite(String website) {
|
||||
this.website = website;
|
||||
}
|
||||
|
||||
public int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
public void setMajorVersion(int majorVersion) {
|
||||
this.majorVersion = majorVersion;
|
||||
}
|
||||
|
||||
public int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
public void setMinorVersion(int minorVersion) {
|
||||
this.minorVersion = minorVersion;
|
||||
}
|
||||
|
||||
public int getRevisionVersion() {
|
||||
return revisionVersion;
|
||||
}
|
||||
|
||||
public void setRevisionVersion(int revisionVersion) {
|
||||
this.revisionVersion = revisionVersion;
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public void setSnapshot(boolean snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(SystemVersion o) {
|
||||
if (null == o) return -1;
|
||||
if (o.getMajorVersion() > this.getMajorVersion()) return -1;
|
||||
if (o.getMajorVersion() == this.getMajorVersion()) {
|
||||
if (o.getMinorVersion() > this.getMinorVersion()) return -1;
|
||||
if (o.getMinorVersion() == this.getMinorVersion()) {
|
||||
if (o.getRevisionVersion() > this.getRevisionVersion()) return -1;
|
||||
if (o.getRevisionVersion() == this.getRevisionVersion()) return 0;
|
||||
return 1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SystemVersion systemVersion = new SystemVersion();
|
||||
systemVersion.setMajorVersion(2);
|
||||
systemVersion.setMinorVersion(2);
|
||||
systemVersion.setRevisionVersion(1);
|
||||
|
||||
SystemVersion systemVersion2 = new SystemVersion();
|
||||
systemVersion2.setMajorVersion(3);
|
||||
systemVersion2.setMinorVersion(2);
|
||||
systemVersion2.setRevisionVersion(1);
|
||||
|
||||
System.out.println(systemVersion.compareTo(systemVersion2));
|
||||
}
|
||||
}
|
||||
@@ -135,4 +135,74 @@ public class Template extends GenericPo<String> {
|
||||
public void setUsing(boolean using) {
|
||||
this.using = using;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property{
|
||||
/**
|
||||
*
|
||||
* @see Template#name
|
||||
*/
|
||||
String name="name";
|
||||
/**
|
||||
*
|
||||
* @see Template#remark
|
||||
*/
|
||||
String remark="remark";
|
||||
/**
|
||||
*
|
||||
* @see Template#template
|
||||
*/
|
||||
String template="template";
|
||||
/**
|
||||
*
|
||||
* @see Template#classifiedId
|
||||
*/
|
||||
String classifiedId="classifiedId";
|
||||
/**
|
||||
*
|
||||
* @see Template#type
|
||||
*/
|
||||
String type="type";
|
||||
/**
|
||||
*
|
||||
* @see Template#script
|
||||
*/
|
||||
String script="script";
|
||||
/**
|
||||
*
|
||||
* @see Template#css
|
||||
*/
|
||||
String css="css";
|
||||
/**
|
||||
*
|
||||
* @see Template#cssLinks
|
||||
*/
|
||||
String cssLinks="cssLinks";
|
||||
/**
|
||||
*
|
||||
* @see Template#scriptLinks
|
||||
*/
|
||||
String scriptLinks="scriptLinks";
|
||||
/**
|
||||
*
|
||||
* @see Template#version
|
||||
*/
|
||||
String version="version";
|
||||
/**
|
||||
*
|
||||
* @see Template#revision
|
||||
*/
|
||||
String revision="revision";
|
||||
/**
|
||||
*
|
||||
* @see Template#release
|
||||
*/
|
||||
String release="release";
|
||||
/**
|
||||
*
|
||||
* @see Template#using
|
||||
*/
|
||||
String using="using";
|
||||
}
|
||||
}
|
||||
@@ -299,4 +299,53 @@ public class User extends GenericPo<String> {
|
||||
public void setRoleInfo(Map<Module, Set<String>> roleInfo) {
|
||||
this.roleInfo = roleInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface Property extends GenericPo.Property {
|
||||
/**
|
||||
* @see User#username
|
||||
*/
|
||||
String username = "username";
|
||||
/**
|
||||
* @see User#password
|
||||
*/
|
||||
String password = "password";
|
||||
/**
|
||||
* @see User#name
|
||||
*/
|
||||
String name = "name";
|
||||
/**
|
||||
* @see User#email
|
||||
*/
|
||||
String email = "email";
|
||||
/**
|
||||
* @see User#phone
|
||||
*/
|
||||
String phone = "phone";
|
||||
/**
|
||||
* @see User#status
|
||||
*/
|
||||
String status = "status";
|
||||
/**
|
||||
* @see User#createDate
|
||||
*/
|
||||
String createDate = "createDate";
|
||||
/**
|
||||
* @see User#updateDate
|
||||
*/
|
||||
String updateDate = "updateDate";
|
||||
/**
|
||||
* @see User#userRoles
|
||||
*/
|
||||
String userRoles = "userRoles";
|
||||
/**
|
||||
* @see User#roleInfo
|
||||
*/
|
||||
String roleInfo = "roleInfo";
|
||||
|
||||
/**
|
||||
* @see User#getModules()
|
||||
*/
|
||||
String modules = "modules";
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-concurrent</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-concurrent-cache</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-concurrent</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-concurrent-lock</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-controller</artifactId>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.hsweb.web.controller;
|
||||
|
||||
import org.hsweb.web.core.datasource.DynamicDataSource;
|
||||
import org.hsweb.web.core.utils.ThreadLocalUtils;
|
||||
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -7,7 +10,9 @@ import org.springframework.context.support.ReloadableResourceBundleMessageSource
|
||||
import org.springframework.ui.context.support.ResourceBundleThemeSource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.ThemeResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
@@ -41,6 +46,24 @@ public class ControllerAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new HandlerInterceptor() {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
|
||||
//ThreadLocalUtils.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
|
||||
ThreadLocalUtils.clear();
|
||||
DynamicDataSource.useDefault();
|
||||
}
|
||||
});
|
||||
|
||||
ThemeChangeInterceptor themeChangeInterceptor = new ThemeChangeInterceptor() {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
|
||||
@@ -96,7 +119,7 @@ public class ControllerAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
registry.addInterceptor(themeChangeInterceptor);
|
||||
}
|
||||
|
||||
@Bean(name="localeResolver")
|
||||
@Bean(name = "localeResolver")
|
||||
public CookieLocaleResolver cookieLocaleResolver() {
|
||||
CookieLocaleResolver resolver = new CookieLocaleResolver();
|
||||
resolver.setDefaultLocale(Locale.CHINA);
|
||||
@@ -110,7 +133,7 @@ public class ControllerAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
return resourceBundleThemeSource;
|
||||
}
|
||||
|
||||
@Bean(name="themeResolver")
|
||||
@Bean(name = "themeResolver")
|
||||
public CookieThemeResolver cookieThemeResolver() {
|
||||
CookieThemeResolver cookieThemeResolver = new CookieThemeResolver();
|
||||
cookieThemeResolver.setDefaultThemeName("default");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.hsweb.web.controller;
|
||||
|
||||
import org.hsweb.ezorm.exception.ValidationException;
|
||||
import org.hsweb.commons.ClassUtils;
|
||||
import org.hsweb.ezorm.rdb.exception.ValidationException;
|
||||
import org.hsweb.web.core.exception.BusinessException;
|
||||
import org.hsweb.web.core.exception.ExceptionHandler;
|
||||
import org.hsweb.web.core.message.ResponseMessage;
|
||||
@@ -8,23 +9,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes;
|
||||
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
|
||||
import org.springframework.boot.autoconfigure.web.ErrorController;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.hsweb.commons.ClassUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.hsweb.web.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.hsweb.ezorm.rdb.exception.*;
|
||||
import org.hsweb.web.core.exception.*;
|
||||
import org.hsweb.web.core.exception.ValidationException;
|
||||
import org.hsweb.web.core.message.ResponseMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,10 +27,10 @@ public class RestControllerExceptionTranslator {
|
||||
return ResponseMessage.error(exception.getMessage(), 400);
|
||||
}
|
||||
|
||||
@ExceptionHandler(org.hsweb.ezorm.exception.ValidationException.class)
|
||||
@ExceptionHandler(org.hsweb.ezorm.rdb.exception.ValidationException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
ResponseMessage handleException(org.hsweb.ezorm.exception.ValidationException exception) {
|
||||
ResponseMessage handleException(org.hsweb.ezorm.rdb.exception.ValidationException exception) {
|
||||
return ResponseMessage.error(JSON.toJSONString(exception.getValidateResult()), 400);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.hsweb.web.controller.form;
|
||||
|
||||
import org.hsweb.ezorm.meta.FieldMetaData;
|
||||
import org.hsweb.ezorm.meta.TableMetaData;
|
||||
import org.hsweb.ezorm.meta.expand.OptionConverter;
|
||||
import org.hsweb.ezorm.core.OptionConverter;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateMapParam;
|
||||
import org.hsweb.web.bean.po.form.Form;
|
||||
@@ -31,7 +31,6 @@ import org.hsweb.web.core.message.ResponseMessage;
|
||||
import org.hsweb.web.service.form.DynamicFormService;
|
||||
import org.hsweb.web.service.form.FormService;
|
||||
import org.hsweb.web.service.resource.FileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -171,9 +170,9 @@ public class DynamicFormController {
|
||||
* @param name 表单名称
|
||||
* @param data 数据
|
||||
* @return 新增成功后返回被新增数据的主键值
|
||||
* @throws SQLException 执行查询sql错误
|
||||
* @throws NotFoundException 表单不存在或在未发布
|
||||
* @throws org.hsweb.ezorm.exception.ValidationException 数据格式验证失败时抛出此异常
|
||||
* @throws SQLException 执行查询sql错误
|
||||
* @throws NotFoundException 表单不存在或在未发布
|
||||
* @throws org.hsweb.ezorm.rdb.exception.ValidationException 数据格式验证失败时抛出此异常
|
||||
*/
|
||||
@RequestMapping(value = "/{name}", method = RequestMethod.POST)
|
||||
@AccessLogger("新增数据")
|
||||
@@ -191,9 +190,9 @@ public class DynamicFormController {
|
||||
* @param primaryKey 数据主键值
|
||||
* @param data 数据
|
||||
* @return 更新记录数量
|
||||
* @throws SQLException 执行查询sql错误
|
||||
* @throws NotFoundException 表单不存在或在未发布
|
||||
* @throws org.hsweb.ezorm.exception.ValidationException 数据格式验证失败时抛出此异常
|
||||
* @throws SQLException 执行查询sql错误
|
||||
* @throws NotFoundException 表单不存在或在未发布
|
||||
* @throws org.hsweb.ezorm.rdb.exception.ValidationException 数据格式验证失败时抛出此异常
|
||||
*/
|
||||
@RequestMapping(value = "/{name}/{primaryKey}", method = RequestMethod.PUT)
|
||||
@AccessLogger("更新数据")
|
||||
@@ -293,8 +292,8 @@ public class DynamicFormController {
|
||||
@PathVariable("data") String data,
|
||||
@PathVariable("type") String type) {
|
||||
try {
|
||||
TableMetaData metaData = dynamicFormService.getDefaultDatabase().getTable(name).getMeta();
|
||||
FieldMetaData fieldMetaData = metaData.findFieldByName(field);
|
||||
RDBTableMetaData metaData = dynamicFormService.getDefaultDatabase().getTable(name).getMeta();
|
||||
RDBColumnMetaData fieldMetaData = metaData.findColumn(field);
|
||||
if (fieldMetaData == null) throw new NullPointerException();
|
||||
OptionConverter converter = fieldMetaData.getOptionConverter();
|
||||
if (converter == null) return ResponseMessage.ok(data);
|
||||
|
||||
@@ -25,13 +25,13 @@ import org.hsweb.web.core.logger.annotation.AccessLogger;
|
||||
import org.hsweb.web.core.message.ResponseMessage;
|
||||
import org.hsweb.web.core.utils.WebUtil;
|
||||
import org.hsweb.web.service.module.ModuleService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,24 @@ public class UserModuleController {
|
||||
@Resource
|
||||
public ModuleService moduleService;
|
||||
|
||||
@RequestMapping(value = "/loginUser", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
@ResponseBody
|
||||
@Authorize
|
||||
public ResponseMessage loginUserInfo() {
|
||||
User user = WebUtil.getLoginUser();
|
||||
Map<String, Set<String>> modules = user.getRoleInfo()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(entry -> entry.getKey().getId(), entry -> entry.getValue()));
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("username", user.getUsername());
|
||||
map.put("name", user.getName());
|
||||
map.put("properties", user.getProperties());
|
||||
map.put("modules", modules);
|
||||
map.put("roles", user.getUserRoles());
|
||||
map.put("modulesData", user.getModules());
|
||||
return ResponseMessage.ok(map).exclude(Module.class, "optional").onlyData();
|
||||
}
|
||||
@RequestMapping
|
||||
@Authorize
|
||||
@AccessLogger("用户模块信息")
|
||||
@@ -53,9 +71,7 @@ public class UserModuleController {
|
||||
User user = WebUtil.getLoginUser();
|
||||
List<Module> modules;
|
||||
if (user == null) {
|
||||
QueryParam queryParam = new QueryParam();
|
||||
queryParam.includes(includes).orderBy("sortIndex");
|
||||
modules = moduleService.select(queryParam);
|
||||
modules = moduleService.createQuery().select(includes).orderByAsc(Module.Property.sortIndex).listNoPaging();
|
||||
modules = modules.stream()
|
||||
.filter(module -> {
|
||||
Object obj = module.getOptionalMap().get("M");
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.hsweb.web.controller.system;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.hsweb.ezorm.meta.FieldMetaData;
|
||||
import org.hsweb.ezorm.meta.TableMetaData;
|
||||
import org.hsweb.ezorm.render.SqlAppender;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.SqlAppender;
|
||||
import org.hsweb.web.bean.po.user.User;
|
||||
import org.hsweb.web.core.authorize.annotation.Authorize;
|
||||
import org.hsweb.web.core.datasource.DynamicDataSource;
|
||||
@@ -20,10 +20,10 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.hsweb.web.core.message.ResponseMessage.ok;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/database")
|
||||
@@ -37,6 +37,8 @@ public class DatabaseManagerController {
|
||||
@Autowired(required = false)
|
||||
protected DynamicDataSource dynamicDataSource;
|
||||
|
||||
protected Map<String, List<RDBTableMetaData>> cache = new ConcurrentHashMap<>();
|
||||
|
||||
protected void checkDynamicDataSourceSupport() {
|
||||
if (dynamicDataSource == null)
|
||||
logger.warn("\ndynamicDataSource is not support! if you want use it,please import " +
|
||||
@@ -52,41 +54,51 @@ public class DatabaseManagerController {
|
||||
@RequestMapping(value = "/tables", method = RequestMethod.GET)
|
||||
@Authorize(action = "R")
|
||||
@AccessLogger("获取所有表结构")
|
||||
public ResponseMessage showTables() throws SQLException {
|
||||
return ResponseMessage.ok(dataBaseManagerService.getTableList())
|
||||
.include(TableMetaData.class, "name", "alias", "comment", "fields")
|
||||
.include(FieldMetaData.class, "name", "alias", "comment", "dataType", "properties")
|
||||
public ResponseMessage showTables(boolean reload) throws SQLException {
|
||||
List<RDBTableMetaData> cached = cache.get("default");
|
||||
if (cached == null || reload) {
|
||||
cached = dataBaseManagerService.getTableList();
|
||||
cache.put("default", cached);
|
||||
}
|
||||
return ok(cached)
|
||||
.include(RDBTableMetaData.class, "name", "alias", "comment", "columns")
|
||||
.include(RDBColumnMetaData.class, "name", "alias", "comment", "dataType","jdbcType", "javaType", "notNull", "primaryKey", "properties")
|
||||
.onlyData();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/exec", method = RequestMethod.POST)
|
||||
@AccessLogger("执行SQL")
|
||||
public ResponseMessage exec(@RequestBody String sql) throws Exception {
|
||||
return ResponseMessage.ok(dataBaseManagerService.execSql(buildSqlList(sql)));
|
||||
return ok(dataBaseManagerService.execSql(buildSqlList(sql)));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sql/alter", method = RequestMethod.POST)
|
||||
@AccessLogger("查询修改表结构SQL")
|
||||
public ResponseMessage showAlterSql(@RequestBody JSONObject jsonObject) throws Exception {
|
||||
return ResponseMessage.ok(dataBaseManagerService.createAlterSql(createTableMetaDataByJson(jsonObject)));
|
||||
return ok(dataBaseManagerService.createAlterSql(createTableMetaDataByJson(jsonObject)));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/sql/create", method = RequestMethod.POST)
|
||||
@AccessLogger("查询创建表结构SQL")
|
||||
public ResponseMessage showCreateSql(@RequestBody JSONObject jsonObject) throws Exception {
|
||||
return ResponseMessage.ok(dataBaseManagerService.createCreateSql(createTableMetaDataByJson(jsonObject)));
|
||||
return ok(dataBaseManagerService.createCreateSql(createTableMetaDataByJson(jsonObject)));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/tables/{dataSourceId}", method = RequestMethod.GET)
|
||||
@Authorize(action = "R")
|
||||
@AccessLogger("指定数据源获取表结构")
|
||||
public ResponseMessage showTables(@PathVariable("dataSourceId") String dataSourceId) throws SQLException {
|
||||
public ResponseMessage showTables(@PathVariable("dataSourceId") String dataSourceId, boolean reload) throws SQLException {
|
||||
try {
|
||||
checkDynamicDataSourceSupport();
|
||||
DynamicDataSource.use(dataSourceId);
|
||||
return ResponseMessage.ok(dataBaseManagerService.getTableList())
|
||||
.include(TableMetaData.class, "name", "alias", "comment", "fields")
|
||||
.include(FieldMetaData.class, "name", "alias", "comment", "dataType", "properties")
|
||||
List<RDBTableMetaData> cached = cache.get(dataSourceId);
|
||||
if (cached == null || reload) {
|
||||
cached = dataBaseManagerService.getTableList();
|
||||
cache.put(dataSourceId, cached);
|
||||
}
|
||||
return ok(cached)
|
||||
.include(RDBTableMetaData.class, "name", "alias", "comment", "columns")
|
||||
.include(RDBColumnMetaData.class, "name", "alias", "comment", "jdbcType", "javaType", "dataType", "notNull", "primaryKey", "properties")
|
||||
.onlyData();
|
||||
} finally {
|
||||
DynamicDataSource.useDefault(false);
|
||||
@@ -128,7 +140,7 @@ public class DatabaseManagerController {
|
||||
checkDynamicDataSourceSupport();
|
||||
DynamicDataSource.use(dataSourceId);
|
||||
try {
|
||||
return ResponseMessage.ok(dataBaseManagerService.execSql(buildSqlList(sql)));
|
||||
return ok(dataBaseManagerService.execSql(buildSqlList(sql)));
|
||||
} finally {
|
||||
DynamicDataSource.useDefault(false);
|
||||
}
|
||||
@@ -140,7 +152,7 @@ public class DatabaseManagerController {
|
||||
try {
|
||||
checkDynamicDataSourceSupport();
|
||||
DynamicDataSource.use(dataSourceId);
|
||||
return ResponseMessage.ok(dataBaseManagerService.createAlterSql(createTableMetaDataByJson(jsonObject)));
|
||||
return ok(dataBaseManagerService.createAlterSql(createTableMetaDataByJson(jsonObject)));
|
||||
} finally {
|
||||
DynamicDataSource.useDefault(false);
|
||||
}
|
||||
@@ -152,20 +164,20 @@ public class DatabaseManagerController {
|
||||
try {
|
||||
checkDynamicDataSourceSupport();
|
||||
DynamicDataSource.use(dataSourceId);
|
||||
return ResponseMessage.ok(dataBaseManagerService.createCreateSql(createTableMetaDataByJson(jsonObject)));
|
||||
return ok(dataBaseManagerService.createCreateSql(createTableMetaDataByJson(jsonObject)));
|
||||
} finally {
|
||||
DynamicDataSource.useDefault(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected TableMetaData createTableMetaDataByJson(JSONObject jsonObject) {
|
||||
TableMetaData tableMetaData = new TableMetaData();
|
||||
protected RDBTableMetaData createTableMetaDataByJson(JSONObject jsonObject) {
|
||||
RDBTableMetaData tableMetaData = new RDBTableMetaData();
|
||||
tableMetaData.setName(jsonObject.getString("name"));
|
||||
tableMetaData.setComment(jsonObject.getString("comment"));
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("fields");
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("columns");
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
FieldMetaData field = jsonArray.getObject(i, FieldMetaData.class);
|
||||
tableMetaData.addField(field);
|
||||
RDBColumnMetaData columnMetaData = jsonArray.getObject(i, RDBColumnMetaData.class);
|
||||
tableMetaData.addColumn(columnMetaData);
|
||||
}
|
||||
return tableMetaData;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.hsweb.web.bean.po.user.User.Property.*;
|
||||
|
||||
/**
|
||||
* 后台管理用户控制器,继承自GenericController,使用rest+json
|
||||
* Created by generator 2015-8-26 10:35:57
|
||||
@@ -34,22 +36,22 @@ public class UserController extends GenericController<User, String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage list(QueryParam param) {
|
||||
param.excludes("password");
|
||||
public ResponseMessage list(QueryParam param) {
|
||||
param.excludes(password);
|
||||
return super.list(param)
|
||||
.exclude(User.class, "password", "modules", "userRoles")
|
||||
.exclude(User.class, password, modules, userRoles)
|
||||
.onlyData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseMessage info(@PathVariable("id") String id) {
|
||||
return super.info(id).exclude(User.class, "password", "modules");
|
||||
public ResponseMessage info(@PathVariable("id") String id) {
|
||||
return super.info(id).exclude(User.class, password, modules);
|
||||
}
|
||||
|
||||
@AccessLogger("禁用")
|
||||
@RequestMapping(value = "/{id}/disable", method = RequestMethod.PUT)
|
||||
@Authorize(action = "disable")
|
||||
public ResponseMessage disable(@PathVariable("id") String id) {
|
||||
public ResponseMessage disable(@PathVariable("id") String id) {
|
||||
getService().disableUser(id);
|
||||
return ResponseMessage.ok();
|
||||
}
|
||||
@@ -57,7 +59,7 @@ public class UserController extends GenericController<User, String> {
|
||||
@AccessLogger("启用")
|
||||
@RequestMapping(value = "/{id}/enable", method = RequestMethod.PUT)
|
||||
@Authorize(action = "enable")
|
||||
public ResponseMessage enable(@PathVariable("id") String id) {
|
||||
public ResponseMessage enable(@PathVariable("id") String id) {
|
||||
getService().enableUser(id);
|
||||
return ResponseMessage.ok();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-core</artifactId>
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-easy-orm</artifactId>
|
||||
<artifactId>hsweb-easy-orm-rdb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package org.hsweb.web.core;
|
||||
|
||||
import org.hsweb.commons.file.FileUtils;
|
||||
import org.hsweb.ezorm.executor.SqlExecutor;
|
||||
import org.hsweb.ezorm.render.SqlAppender;
|
||||
import org.hsweb.ezorm.render.support.simple.SimpleSQL;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class Install {
|
||||
/**
|
||||
* 获取当前数据库类型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDatabaseType() {
|
||||
return DataSourceHolder.getActiveDatabaseType().name();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SqlExecutor sqlExecutor;
|
||||
|
||||
@PostConstruct
|
||||
public void install() throws Exception {
|
||||
String dbType = DataSourceHolder.getActiveDatabaseType().name();
|
||||
Assert.notNull(dbType, "不支持的数据库类型");
|
||||
try {
|
||||
boolean firstInstall = false;
|
||||
try {
|
||||
sqlExecutor.exec(new SimpleSQL("select * from s_user where 1=2"));
|
||||
} catch (Exception e) {
|
||||
firstInstall = true;
|
||||
}
|
||||
if (firstInstall) {
|
||||
//表结构
|
||||
InputStream reader = FileUtils.getResourceAsStream("system/install/sql/" + dbType + "/install.sql");
|
||||
execInstallSql(reader);
|
||||
String installSqlName = "classpath*:/system/install/sql/" + dbType + "/*-data.sql";
|
||||
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(installSqlName);
|
||||
for (Resource resource : resources) {
|
||||
if (resource.isReadable()) {
|
||||
execInstallSql(resource.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected void execInstallSql(InputStream sqlStream) throws Exception {
|
||||
String username = "";
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = DataSourceHolder.getActiveSource().getConnection();
|
||||
username = connection.getMetaData().getUserName();
|
||||
} finally {
|
||||
if (null != connection) connection.close();
|
||||
}
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(sqlStream, "utf-8"));
|
||||
List<String> sqlList = new ArrayList<>();
|
||||
SqlAppender tmp = new SqlAppender();
|
||||
String uname = username;
|
||||
bufferedReader.lines().forEach((line) -> {
|
||||
if (line.startsWith("--")) return;
|
||||
line = line.replace("${jdbc.username}", uname);
|
||||
//去除sql中的;
|
||||
if (line.endsWith(";"))
|
||||
tmp.add(line.substring(0, line.length() - 1));
|
||||
else
|
||||
tmp.add(line);
|
||||
tmp.add("\n");
|
||||
if (line.endsWith(";")) {
|
||||
sqlList.add(tmp.toString());
|
||||
tmp.clear();
|
||||
}
|
||||
});
|
||||
sqlList.forEach((sql) -> {
|
||||
try {
|
||||
sqlExecutor.exec(new SimpleSQL(sql));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("install sql fail", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,14 @@ public class DataSourceHolder {
|
||||
return defaultDataSource;
|
||||
}
|
||||
|
||||
public static String getActiveSourceId() {
|
||||
if (DynamicDataSource.getActiveDataSourceId() != null) {
|
||||
return DynamicDataSource.getActiveDataSourceId();
|
||||
}
|
||||
return "default";
|
||||
}
|
||||
|
||||
|
||||
public static DatabaseType getActiveDatabaseType() {
|
||||
if (dynamicDataSource != null) {
|
||||
return dynamicDataSource.getActiveDataBaseType();
|
||||
|
||||
@@ -16,19 +16,21 @@
|
||||
|
||||
package org.hsweb.web.core.datasource;
|
||||
|
||||
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public enum DatabaseType {
|
||||
unknown(null, null, null),
|
||||
mysql("com.mysql.jdbc.Driver", "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", "select 1"),
|
||||
h2("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource", "select 1"),
|
||||
oracle("oracle.jdbc.driver.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource", "select 1 from dual");
|
||||
unknown(null, null, null,null),
|
||||
mysql("com.mysql.jdbc.Driver", "com.mysql.jdbc.jdbc2.optional.MysqlXADataSource", "select 1",Dialect.MYSQL),
|
||||
h2("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource", "select 1",Dialect.H2),
|
||||
oracle("oracle.jdbc.driver.OracleDriver", "oracle.jdbc.xa.client.OracleXADataSource", "select 1 from dual",Dialect.ORACLE);
|
||||
|
||||
DatabaseType(String driverClassName, String xaDataSourceClassName, String testQuery) {
|
||||
DatabaseType(String driverClassName, String xaDataSourceClassName, String testQuery,Dialect dialect) {
|
||||
this.driverClassName = driverClassName;
|
||||
this.testQuery = testQuery;
|
||||
this.xaDataSourceClassName = xaDataSourceClassName;
|
||||
this.dialect=dialect;
|
||||
}
|
||||
|
||||
private final String testQuery;
|
||||
@@ -36,7 +38,7 @@ public enum DatabaseType {
|
||||
private final String driverClassName;
|
||||
|
||||
private final String xaDataSourceClassName;
|
||||
|
||||
private final Dialect dialect;
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
@@ -49,6 +51,10 @@ public enum DatabaseType {
|
||||
return testQuery;
|
||||
}
|
||||
|
||||
public Dialect getDialect() {
|
||||
return dialect;
|
||||
}
|
||||
|
||||
public static DatabaseType fromJdbcUrl(String url) {
|
||||
if (StringUtils.hasLength(url)) {
|
||||
Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
|
||||
|
||||
@@ -7,12 +7,7 @@ import java.util.Map;
|
||||
* Created by zhouhao on 16-5-26.
|
||||
*/
|
||||
public class ThreadLocalUtils {
|
||||
private static final ThreadLocal<Map<String, Object>> local = new ThreadLocal<Map<String, Object>>() {
|
||||
@Override
|
||||
protected Map<String, Object> initialValue() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
};
|
||||
private static final ThreadLocal<Map<String, Object>> local = ThreadLocal.withInitial(() -> new HashMap<>());
|
||||
|
||||
public static <T> T put(String key, T value) {
|
||||
local.get().put(key, value);
|
||||
@@ -23,6 +18,10 @@ public class ThreadLocalUtils {
|
||||
local.get().remove(key);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
local.remove();
|
||||
}
|
||||
|
||||
public static <T> T get(String key) {
|
||||
return ((T) local.get().get(key));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-dao</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-dao-api</artifactId>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface CRUMapper<Po, Pk> extends InsertMapper<Po>, QueryMapper<Po, Pk>, UpdateMapper<Po> {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
import org.hsweb.web.bean.common.DeleteParam;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface DeleteMapper {
|
||||
int delete(DeleteParam param);
|
||||
}
|
||||
@@ -1,74 +1,8 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
import org.hsweb.web.bean.common.DeleteParam;
|
||||
import org.hsweb.web.bean.common.InsertParam;
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通用dao,定义常用的增删改查操作。其他daoMapper接口继承此接口,则无需再定义这些方法
|
||||
* <p>
|
||||
* Created by zh.sqy@qq.com on 2015-07-20 0020.
|
||||
*/
|
||||
public interface GenericMapper<Po, Pk> {
|
||||
/**
|
||||
* 根据参数添加一条数据
|
||||
*
|
||||
* @param param 参数对象
|
||||
* @return 添加后生成的主键
|
||||
*/
|
||||
int insert(InsertParam<Po> param);
|
||||
public interface GenericMapper<Po, Pk> extends QueryMapper<Po, Pk>, UpdateMapper<Po>, InsertMapper<Po>, DeleteMapper {
|
||||
|
||||
/**
|
||||
* 根据条件删除数据
|
||||
*
|
||||
* @param param 主键
|
||||
* @return 影响记录数
|
||||
*/
|
||||
int delete(DeleteParam param);
|
||||
|
||||
/**
|
||||
* 修改记录信息
|
||||
*
|
||||
* @param data 要修改的对象
|
||||
* @return 影响记录数
|
||||
*/
|
||||
int update(UpdateParam<Po> data);
|
||||
|
||||
/**
|
||||
* 根据条件集合查询记录,支持分页,排序。
|
||||
* <br/>查询条件支持 类似$LIKE,$IN 表达式查询,如传入 name$LIKE 则进行name字段模糊查询
|
||||
* <br/>$LIKE -->模糊查询 (只支持字符)
|
||||
* <br/>$START -->以?开始 (只支持字符 和数字)
|
||||
* <br/>$END -->以?结尾 (只支持字符 和数字)
|
||||
* <br/>$IN -->in查询,参数必须为List实现,传入类似 1,2,3 是非法的
|
||||
* <br/>$GT -->大于 (只支持 数字和日期)
|
||||
* <br/>$LT -->小于 (只支持 数字和日期)
|
||||
* <br/>$NOT -->不等于
|
||||
* <br/>$NOTNULL -->值不为空
|
||||
* <br/>$ISNULL -->值为空
|
||||
* <br/>所有操作支持取反
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 查询结果
|
||||
*/
|
||||
List<Po> select(QueryParam param);
|
||||
|
||||
/**
|
||||
* 查询记录总数,用于分页等操作。查询条件同 {@link GenericMapper#select}
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 查询结果,实现mapper中的sql应指定默认值,否则可能抛出异常
|
||||
*/
|
||||
int total(QueryParam param);
|
||||
|
||||
/**
|
||||
* 根据主键查询记录
|
||||
*
|
||||
* @param pk 主键
|
||||
* @return 查询结果
|
||||
*/
|
||||
Po selectByPk(Pk pk);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
import org.hsweb.web.bean.common.InsertParam;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface InsertMapper<Po> {
|
||||
int insert(InsertParam<Po> param);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface QueryMapper<Po, Pk> {
|
||||
/**
|
||||
* 根据条件集合查询记录,支持分页,排序。
|
||||
* <br/>查询条件支持 类似$LIKE,$IN 表达式查询,如传入 name$LIKE 则进行name字段模糊查询
|
||||
* <br/>$LIKE -->模糊查询 (只支持字符)
|
||||
* <br/>$START -->以?开始 (只支持字符 和数字)
|
||||
* <br/>$END -->以?结尾 (只支持字符 和数字)
|
||||
* <br/>$IN -->in查询,参数必须为List实现,传入类似 1,2,3 是非法的
|
||||
* <br/>$GT -->大于 (只支持 数字和日期)
|
||||
* <br/>$LT -->小于 (只支持 数字和日期)
|
||||
* <br/>$NOT -->不等于
|
||||
* <br/>$NOTNULL -->值不为空
|
||||
* <br/>$ISNULL -->值为空
|
||||
* <br/>所有操作支持取反
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 查询结果
|
||||
*/
|
||||
List<Po> select(QueryParam param);
|
||||
|
||||
/**
|
||||
* 查询记录总数,用于分页等操作。查询条件同 {@link GenericMapper#select}
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 查询结果,实现mapper中的sql应指定默认值,否则可能抛出异常
|
||||
*/
|
||||
int total(QueryParam param);
|
||||
|
||||
/**
|
||||
* 根据主键查询记录
|
||||
*
|
||||
* @param pk 主键
|
||||
* @return 查询结果
|
||||
*/
|
||||
Po selectByPk(Pk pk);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.hsweb.web.dao;
|
||||
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface UpdateMapper<Po> {
|
||||
/**
|
||||
* 修改记录信息
|
||||
*
|
||||
* @param data 要修改的对象
|
||||
* @return 影响记录数
|
||||
*/
|
||||
int update(UpdateParam<Po> data);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.hsweb.web.dao.form;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.ezorm.core.param.QueryParam;
|
||||
import org.hsweb.web.dao.GenericMapper;
|
||||
import org.hsweb.web.bean.po.form.Form;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.hsweb.web.dao.template;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.ezorm.core.param.QueryParam;
|
||||
import org.hsweb.web.bean.po.template.Template;
|
||||
import org.hsweb.web.dao.GenericMapper;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-web-dao-mybatis</artifactId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -5,19 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-dao</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-dao-mybatis</artifactId>
|
||||
|
||||
<properties>
|
||||
<mybatis.version>3.3.2</mybatis.version>
|
||||
<mybatis.spring.version>1.2.3</mybatis.spring.version>
|
||||
<druid.version>1.0.5</druid.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--test-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -30,7 +23,16 @@
|
||||
<version>1.0.26</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-web-dao-api</artifactId>
|
||||
@@ -56,7 +58,7 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>1.0.2</version>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis end-->
|
||||
|
||||
@@ -19,9 +19,13 @@ package org.hsweb.web.mybatis;
|
||||
import org.apache.ibatis.mapping.DatabaseIdProvider;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.TransactionIsolationLevel;
|
||||
import org.apache.ibatis.transaction.Transaction;
|
||||
import org.hsweb.web.mybatis.dynamic.DynamicDataSourceSqlSessionFactoryBuilder;
|
||||
import org.hsweb.web.mybatis.dynamic.DynamicSpringManagedTransaction;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -54,13 +58,20 @@ public class MyBatisAutoConfiguration {
|
||||
@Bean(name = "sqlSessionFactory")
|
||||
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
|
||||
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
|
||||
if (properties.isDynamicDatasource())
|
||||
factory.setSqlSessionFactoryBuilder(new DynamicDataSourceSqlSessionFactoryBuilder());
|
||||
factory.setDataSource(dataSource);
|
||||
factory.setVfs(SpringBootVFS.class);
|
||||
if (StringUtils.hasText(this.properties.getConfig())) {
|
||||
if (properties.isDynamicDatasource()) {
|
||||
factory.setSqlSessionFactoryBuilder(new DynamicDataSourceSqlSessionFactoryBuilder());
|
||||
factory.setTransactionFactory(new SpringManagedTransactionFactory() {
|
||||
@Override
|
||||
public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
|
||||
return new DynamicSpringManagedTransaction();
|
||||
}
|
||||
});
|
||||
}
|
||||
factory.setDataSource(dataSource);
|
||||
if (StringUtils.hasText(this.properties.getConfigLocation())) {
|
||||
factory.setConfigLocation(this.resourceLoader.getResource(this.properties
|
||||
.getConfig()));
|
||||
.getConfigLocation()));
|
||||
}
|
||||
if (this.interceptors != null && this.interceptors.length > 0) {
|
||||
factory.setPlugins(this.interceptors);
|
||||
|
||||
@@ -6,9 +6,11 @@ import org.apache.ibatis.mapping.ResultMap;
|
||||
import org.apache.ibatis.mapping.ResultMapping;
|
||||
import org.hsweb.commons.DateTimeUtils;
|
||||
import org.hsweb.commons.StringUtils;
|
||||
import org.hsweb.ezorm.meta.FieldMetaData;
|
||||
import org.hsweb.ezorm.param.Term;
|
||||
import org.hsweb.ezorm.render.Dialect;
|
||||
import org.hsweb.ezorm.core.param.Param;
|
||||
import org.hsweb.ezorm.core.param.Sort;
|
||||
import org.hsweb.ezorm.core.param.Term;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
|
||||
import org.hsweb.web.bean.common.InsertParam;
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
@@ -19,9 +21,7 @@ import java.sql.JDBCType;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-5-9.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DefaultSqlParamBuilder {
|
||||
|
||||
public Dialect getDialect() {
|
||||
@@ -73,23 +73,23 @@ public class DefaultSqlParamBuilder {
|
||||
|
||||
public KeyWordMapper getKeyWordMapper(String type) {
|
||||
return (paramKey, tableName, term, jdbcType) -> {
|
||||
String termField = term.getField();
|
||||
String termField = term.getColumn();
|
||||
if (termField.contains(".")) {
|
||||
String[] tmp = termField.split("[.]");
|
||||
tableName = tmp[0];
|
||||
termField = tmp[1];
|
||||
}
|
||||
FieldMetaData field = new FieldMetaData();
|
||||
RDBColumnMetaData field = new RDBColumnMetaData();
|
||||
field.setName(termField);
|
||||
field.setJdbcType(jdbcType);
|
||||
return getDialect().wrapperWhere(paramKey, term, field, tableName);
|
||||
return getDialect().buildCondition(paramKey, term, field, tableName).toString();
|
||||
};
|
||||
}
|
||||
|
||||
protected Map<String, Object> createConfig(String resultMapId) {
|
||||
ResultMap resultMaps = ResultMapsUtils.getResultMap(resultMapId);
|
||||
Map<String, Object> fieldConfig = new HashMap<>();
|
||||
List<ResultMapping> resultMappings=new ArrayList<>(resultMaps.getResultMappings());
|
||||
List<ResultMapping> resultMappings = new ArrayList<>(resultMaps.getResultMappings());
|
||||
resultMappings.addAll(resultMaps.getIdResultMappings());
|
||||
resultMappings.forEach(resultMapping -> {
|
||||
if (resultMapping.getNestedQueryId() == null) {
|
||||
@@ -161,7 +161,7 @@ public class DefaultSqlParamBuilder {
|
||||
return javaType;
|
||||
}
|
||||
|
||||
public String buildSelectFields(String resultMapId, String tableName, org.hsweb.ezorm.param.SqlParam param) {
|
||||
public String buildSelectFields(String resultMapId, String tableName, Param param) {
|
||||
Map<String, Object> fieldConfig = createConfig(resultMapId);
|
||||
if (param == null) return "*";
|
||||
Map<String, String> propertyMapper = getPropertyMapper(fieldConfig, param);
|
||||
@@ -219,9 +219,9 @@ public class DefaultSqlParamBuilder {
|
||||
tmp.setSorts(param.getSorts());
|
||||
Map<String, String> propertyMapper = getPropertyMapper(fieldConfig, tmp);
|
||||
if (tmp.getSorts().isEmpty()) return "";
|
||||
Set<org.hsweb.ezorm.param.Sort> sorts = new LinkedHashSet<>();
|
||||
Set<Sort> sorts = new LinkedHashSet<>();
|
||||
param.getSorts().forEach(sort -> {
|
||||
String fieldName = sort.getField();
|
||||
String fieldName = sort.getName();
|
||||
if (StringUtils.isNullOrEmpty(fieldName)) return;
|
||||
if (fieldName.contains("."))
|
||||
fieldName = fieldName.split("[.]")[1];
|
||||
@@ -229,7 +229,7 @@ public class DefaultSqlParamBuilder {
|
||||
if (propertyMapper.get(fieldName) == null) {
|
||||
for (Map.Entry<String, String> entry : propertyMapper.entrySet()) {
|
||||
if (entry.getValue().equals(fieldName)) {
|
||||
sort.setField(entry.getKey());
|
||||
sort.setName(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,17 +239,17 @@ public class DefaultSqlParamBuilder {
|
||||
if (sorts.isEmpty()) return "";
|
||||
String sql = sorts.stream()
|
||||
.map(sort -> {
|
||||
String fieldName = sort.getField();
|
||||
String fieldName = sort.getName();
|
||||
if (fieldName.contains("."))
|
||||
fieldName = fieldName.split("[.]")[1];
|
||||
return new SqlAppender()
|
||||
.add(tableName, ".", fieldName, " ", sort.getDir()).toString();
|
||||
.add(tableName, ".", fieldName, " ", sort.getOrder()).toString();
|
||||
})
|
||||
.reduce((s, s1) -> new SqlAppender().add(s, ",", s1).toString()).get();
|
||||
return " order by ".concat(sql);
|
||||
}
|
||||
|
||||
public Map<String, String> getPropertyMapper(Map<String, Object> fieldConfig, org.hsweb.ezorm.param.SqlParam param) {
|
||||
public Map<String, String> getPropertyMapper(Map<String, Object> fieldConfig, Param param) {
|
||||
Set<String> includes = param.getIncludes(),
|
||||
excludes = param.getExcludes();
|
||||
boolean includesIsEmpty = includes.isEmpty(),
|
||||
@@ -306,11 +306,11 @@ public class DefaultSqlParamBuilder {
|
||||
int index = 0;
|
||||
String prefixTmp = StringUtils.concat(prefix, StringUtils.isNullOrEmpty(prefix) ? "" : ".");
|
||||
for (Term term : terms) {
|
||||
String column = getColumn(fieldConfig, term.getField());
|
||||
if (column != null) term.setField(column);
|
||||
boolean nullTerm = StringUtils.isNullOrEmpty(term.getField());
|
||||
String column = getColumn(fieldConfig, term.getColumn());
|
||||
if (column != null) term.setColumn(column);
|
||||
boolean nullTerm = StringUtils.isNullOrEmpty(term.getColumn());
|
||||
//不是空条件 也不是可选字段
|
||||
if (!nullTerm && !fieldConfig.containsKey(term.getField())) continue;
|
||||
if (!nullTerm && !fieldConfig.containsKey(term.getColumn())) continue;
|
||||
//不是空条件,值为空
|
||||
if (!nullTerm && StringUtils.isNullOrEmpty(term.getValue())) continue;
|
||||
//是空条件,但是无嵌套
|
||||
@@ -318,7 +318,7 @@ public class DefaultSqlParamBuilder {
|
||||
//用于sql预编译的参数名
|
||||
prefix = StringUtils.concat(prefixTmp, "terms[", index++, "]");
|
||||
//JDBC类型
|
||||
JDBCType jdbcType = getFieldJDBCType(term.getField(), fieldConfig);
|
||||
JDBCType jdbcType = getFieldJDBCType(term.getColumn(), fieldConfig);
|
||||
//转换参数的值
|
||||
term.setValue(transformationValue(jdbcType, term.getValue()));
|
||||
//添加类型,and 或者 or
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
package org.hsweb.web.mybatis.builder;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtilsBean;
|
||||
import org.apache.commons.beanutils.PropertyUtilsBean;
|
||||
import org.apache.ibatis.mapping.ResultMap;
|
||||
import org.apache.ibatis.mapping.ResultMapping;
|
||||
import org.hsweb.commons.StringUtils;
|
||||
import org.hsweb.ezorm.core.param.QueryParam;
|
||||
import org.hsweb.ezorm.core.param.Term;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBDatabaseMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.SqlAppender;
|
||||
import org.hsweb.ezorm.rdb.render.SqlRender;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.H2RDBDatabaseMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.MysqlRDBDatabaseMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.OracleRDBDatabaseMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.support.simple.CommonSqlRender;
|
||||
import org.hsweb.ezorm.rdb.render.support.simple.SimpleWhereSqlBuilder;
|
||||
import org.hsweb.web.bean.common.InsertParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.datasource.DatabaseType;
|
||||
import org.hsweb.web.core.exception.BusinessException;
|
||||
import org.hsweb.web.mybatis.plgins.pager.Pager;
|
||||
import org.hsweb.web.mybatis.utils.ResultMapsUtils;
|
||||
|
||||
import java.sql.JDBCType;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
* @TODO
|
||||
*/
|
||||
public class EasyOrmSqlBuilder {
|
||||
|
||||
private static final EasyOrmSqlBuilder instance = new EasyOrmSqlBuilder();
|
||||
protected static final Map<Class, String> simpleName = new HashMap<>();
|
||||
|
||||
protected PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
|
||||
|
||||
public static EasyOrmSqlBuilder getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private EasyOrmSqlBuilder() {
|
||||
}
|
||||
|
||||
static {
|
||||
simpleName.put(Integer.class, "int");
|
||||
simpleName.put(Byte.class, "byte");
|
||||
simpleName.put(Double.class, "double");
|
||||
simpleName.put(Float.class, "float");
|
||||
simpleName.put(Boolean.class, "boolean");
|
||||
simpleName.put(Long.class, "long");
|
||||
simpleName.put(Short.class, "short");
|
||||
simpleName.put(Character.class, "char");
|
||||
simpleName.put(String.class, "string");
|
||||
simpleName.put(int.class, "int");
|
||||
simpleName.put(double.class, "double");
|
||||
simpleName.put(float.class, "float");
|
||||
simpleName.put(boolean.class, "boolean");
|
||||
simpleName.put(long.class, "long");
|
||||
simpleName.put(short.class, "short");
|
||||
simpleName.put(char.class, "char");
|
||||
simpleName.put(byte.class, "byte");
|
||||
}
|
||||
|
||||
public static String getJavaType(Class type) {
|
||||
String javaType = simpleName.get(type);
|
||||
if (javaType == null) javaType = type.getName();
|
||||
return javaType;
|
||||
}
|
||||
|
||||
private final RDBDatabaseMetaData mysql = new MysqlMeta();
|
||||
private final RDBDatabaseMetaData oracle = new OracleMeta();
|
||||
private final RDBDatabaseMetaData h2 = new H2Meta();
|
||||
|
||||
private final ConcurrentMap<RDBDatabaseMetaData, Map<String, RDBTableMetaData>> metaCache = new ConcurrentHashMap<RDBDatabaseMetaData, Map<String, RDBTableMetaData>>() {
|
||||
@Override
|
||||
public Map<String, RDBTableMetaData> get(Object key) {
|
||||
Map<String, RDBTableMetaData> map = super.get(key);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
put((RDBDatabaseMetaData) key, map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
public RDBDatabaseMetaData getActiveDatabase() {
|
||||
DatabaseType type = DataSourceHolder.getActiveDatabaseType();
|
||||
switch (type) {
|
||||
case h2:
|
||||
return h2;
|
||||
case mysql:
|
||||
return mysql;
|
||||
case oracle:
|
||||
return oracle;
|
||||
default:
|
||||
return h2;
|
||||
}
|
||||
}
|
||||
|
||||
protected RDBTableMetaData createMeta(String tableName, String resultMapId) {
|
||||
RDBDatabaseMetaData active = getActiveDatabase();
|
||||
String cacheKey = tableName.concat("-").concat(resultMapId);
|
||||
Map<String, RDBTableMetaData> cache = metaCache.get(active);
|
||||
RDBTableMetaData cached = cache.get(cacheKey);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
RDBTableMetaData rdbTableMetaData = new RDBTableMetaData();
|
||||
rdbTableMetaData.setName(tableName);
|
||||
rdbTableMetaData.setDatabaseMetaData(active);
|
||||
ResultMap resultMaps = ResultMapsUtils.getResultMap(resultMapId);
|
||||
List<ResultMapping> resultMappings = new ArrayList<>(resultMaps.getResultMappings());
|
||||
resultMappings.addAll(resultMaps.getIdResultMappings());
|
||||
resultMappings.forEach(resultMapping -> {
|
||||
if (resultMapping.getNestedQueryId() == null) {
|
||||
RDBColumnMetaData column = new RDBColumnMetaData();
|
||||
column.setJdbcType(JDBCType.valueOf(resultMapping.getJdbcType().name()));
|
||||
column.setName(resultMapping.getColumn());
|
||||
if (!StringUtils.isNullOrEmpty(resultMapping.getProperty()))
|
||||
column.setAlias(resultMapping.getProperty());
|
||||
column.setJavaType(resultMapping.getJavaType());
|
||||
column.setProperty("resultMapping", resultMapping);
|
||||
rdbTableMetaData.addColumn(column);
|
||||
}
|
||||
});
|
||||
cache.put(cacheKey, rdbTableMetaData);
|
||||
return rdbTableMetaData;
|
||||
}
|
||||
|
||||
public String buildUpdateFields(String resultMapId, String tableName, UpdateParam param) {
|
||||
Pager.reset();
|
||||
param.excludes("id");
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
RDBDatabaseMetaData databaseMetaDate = getActiveDatabase();
|
||||
Dialect dialect = databaseMetaDate.getDialect();
|
||||
CommonSqlRender render = (CommonSqlRender) databaseMetaDate.getRenderer(SqlRender.TYPE.SELECT);
|
||||
List<CommonSqlRender.OperationColumn> columns = render.parseOperationField(tableMetaData, param);
|
||||
SqlAppender appender = new SqlAppender();
|
||||
columns.forEach(column -> {
|
||||
RDBColumnMetaData columnMetaData = column.getRDBColumnMetaData();
|
||||
if (columnMetaData.getName().contains(".")) return;
|
||||
if (columnMetaData == null) return;
|
||||
try {
|
||||
Object tmp = propertyUtils.getProperty(param.getData(), columnMetaData.getAlias());
|
||||
if (tmp == null) return;
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
appender.add(",", encodeColumn(dialect, columnMetaData.getName())
|
||||
, "=", "#{data.", columnMetaData.getAlias(),
|
||||
",javaType=", EasyOrmSqlBuilder.getJavaType(columnMetaData.getJavaType()),
|
||||
",jdbcType=", columnMetaData.getJdbcType(),
|
||||
"}");
|
||||
});
|
||||
if (!appender.isEmpty()) appender.removeFirst();
|
||||
return appender.toString();
|
||||
}
|
||||
|
||||
public String encodeColumn(Dialect dialect, String field) {
|
||||
if (field.contains(".")) {
|
||||
String[] tmp = field.split("[.]");
|
||||
return tmp[0] + "." + dialect.getQuoteStart() + (dialect.columnToUpperCase() ? (tmp[1].toUpperCase()) : tmp[1]) + dialect.getQuoteEnd();
|
||||
} else {
|
||||
return dialect.getQuoteStart() + (dialect.columnToUpperCase() ? (field.toUpperCase()) : field) + dialect.getQuoteEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public String buildInsertSql(String resultMapId, String tableName, InsertParam param) {
|
||||
Pager.reset();
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
SqlRender<InsertParam> render = tableMetaData.getDatabaseMetaData().getRenderer(SqlRender.TYPE.INSERT);
|
||||
return render.render(tableMetaData, param).getSql();
|
||||
}
|
||||
|
||||
public String buildUpdateSql(String resultMapId, String tableName, UpdateParam param) {
|
||||
Pager.reset();
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
SqlRender<UpdateParam> render = tableMetaData.getDatabaseMetaData().getRenderer(SqlRender.TYPE.UPDATE);
|
||||
return render.render(tableMetaData, param).getSql();
|
||||
}
|
||||
|
||||
public String buildSelectFields(String resultMapId, String tableName, QueryParam param) {
|
||||
if (param.isPaging() && Pager.get() == null) {
|
||||
Pager.doPaging(param.getPageIndex(), param.getPageSize());
|
||||
}
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
RDBDatabaseMetaData databaseMetaDate = getActiveDatabase();
|
||||
Dialect dialect = databaseMetaDate.getDialect();
|
||||
CommonSqlRender render = (CommonSqlRender) databaseMetaDate.getRenderer(SqlRender.TYPE.SELECT);
|
||||
List<CommonSqlRender.OperationColumn> columns = render.parseOperationField(tableMetaData, param);
|
||||
SqlAppender appender = new SqlAppender();
|
||||
columns.forEach(column -> {
|
||||
RDBColumnMetaData columnMetaData = column.getRDBColumnMetaData();
|
||||
if (columnMetaData == null) return;
|
||||
String cname = columnMetaData.getName();
|
||||
if (!cname.contains(".")) cname = tableName.concat(".").concat(cname);
|
||||
appender.add(",", encodeColumn(dialect, cname)
|
||||
, " AS "
|
||||
, dialect.getQuoteStart()
|
||||
, columnMetaData.getName()
|
||||
, dialect.getQuoteEnd());
|
||||
});
|
||||
param.getIncludes().remove("*");
|
||||
if (appender.isEmpty()) return "*";
|
||||
appender.removeFirst();
|
||||
return appender.toString();
|
||||
}
|
||||
|
||||
public String buildOrder(String resultMapId, String tableName, QueryParam param) {
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
SqlAppender appender = new SqlAppender(" order by ");
|
||||
param.getSorts().stream()
|
||||
.forEach(sort -> {
|
||||
RDBColumnMetaData column = tableMetaData.getColumn(sort.getName());
|
||||
if (column == null)
|
||||
column = tableMetaData.findColumn(sort.getName());
|
||||
if (column == null) return;
|
||||
String cname = column.getName();
|
||||
if (!cname.contains(".")) cname = tableName.concat(".").concat(cname);
|
||||
appender.add(encodeColumn(tableMetaData.getDatabaseMetaData().getDialect(), cname), " ", sort.getOrder(), ",");
|
||||
});
|
||||
if (appender.isEmpty()) return "";
|
||||
appender.removeLast();
|
||||
return appender.toString();
|
||||
}
|
||||
|
||||
public String buildWhereForUpdate(String resultMapId, String tableName, List<Term> terms) {
|
||||
String where = buildWhere(resultMapId, tableName, terms);
|
||||
if (where.trim().isEmpty()) {
|
||||
throw new BusinessException("禁止执行无条件的更新操作");
|
||||
}
|
||||
return where;
|
||||
}
|
||||
|
||||
public String buildWhere(String resultMapId, String tableName, List<Term> terms) {
|
||||
RDBTableMetaData tableMetaData = createMeta(tableName, resultMapId);
|
||||
RDBDatabaseMetaData databaseMetaDate = getActiveDatabase();
|
||||
SimpleWhereSqlBuilder builder = new SimpleWhereSqlBuilder() {
|
||||
@Override
|
||||
public Dialect getDialect() {
|
||||
return databaseMetaDate.getDialect();
|
||||
}
|
||||
};
|
||||
SqlAppender appender = new SqlAppender();
|
||||
builder.buildWhere(tableMetaData, "", terms, appender, new HashSet<>());
|
||||
return appender.toString();
|
||||
}
|
||||
|
||||
class MysqlMeta extends MysqlRDBDatabaseMetaData {
|
||||
public MysqlMeta() {
|
||||
super();
|
||||
renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder());
|
||||
renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.MYSQL));
|
||||
}
|
||||
}
|
||||
|
||||
class OracleMeta extends OracleRDBDatabaseMetaData {
|
||||
public OracleMeta() {
|
||||
super();
|
||||
renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder());
|
||||
renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.MYSQL));
|
||||
}
|
||||
}
|
||||
|
||||
class H2Meta extends H2RDBDatabaseMetaData {
|
||||
public H2Meta() {
|
||||
super();
|
||||
renderMap.put(SqlRender.TYPE.INSERT, new InsertSqlBuilder());
|
||||
renderMap.put(SqlRender.TYPE.UPDATE, new UpdateSqlBuilder(Dialect.MYSQL));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.hsweb.web.mybatis.builder;
|
||||
|
||||
import org.hsweb.ezorm.core.param.InsertParam;
|
||||
import org.hsweb.ezorm.rdb.executor.SQL;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.SqlAppender;
|
||||
import org.hsweb.ezorm.rdb.render.support.simple.SimpleInsertSqlRender;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public class InsertSqlBuilder extends SimpleInsertSqlRender {
|
||||
@Override
|
||||
public SQL render(RDBTableMetaData metaData, InsertParam param) {
|
||||
RDBTableMetaData metaDataNew = metaData.clone();
|
||||
metaDataNew.setDatabaseMetaData(metaData.getDatabaseMetaData());
|
||||
metaDataNew.getColumns().stream()
|
||||
.filter(column -> column.getName().contains("."))
|
||||
.map(RDBColumnMetaData::getName)
|
||||
.forEach(metaDataNew::removeColumn);
|
||||
return super.render(metaDataNew, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlAppender getParamString(String paramName, RDBColumnMetaData rdbColumnMetaData) {
|
||||
return new SqlAppender().add("#{", paramName,
|
||||
",javaType=", EasyOrmSqlBuilder.getJavaType(rdbColumnMetaData.getJavaType()),
|
||||
",jdbcType=", rdbColumnMetaData.getJdbcType(), "}");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package org.hsweb.web.mybatis.builder;
|
||||
|
||||
import org.hsweb.ezorm.render.Dialect;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-5-9.
|
||||
*/
|
||||
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
|
||||
|
||||
@Deprecated
|
||||
public class MysqlParamBuilder extends DefaultSqlParamBuilder {
|
||||
private static MysqlParamBuilder instance = new MysqlParamBuilder();
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.hsweb.web.mybatis.builder;
|
||||
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.datasource.DatabaseType;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
@@ -26,15 +23,16 @@ public class SqlBuilder {
|
||||
private static boolean dynamic;
|
||||
|
||||
public static final Object current() {
|
||||
DatabaseType type = dynamic
|
||||
? DataSourceHolder.getActiveDatabaseType()
|
||||
: DataSourceHolder.getDefaultDatabaseType();
|
||||
switch (type) {
|
||||
case mysql:
|
||||
return MysqlParamBuilder.instance();
|
||||
default:
|
||||
return DefaultSqlParamBuilder.instance();
|
||||
}
|
||||
return EasyOrmSqlBuilder.getInstance();
|
||||
// DatabaseType type = dynamic
|
||||
// ? DataSourceHolder.getActiveDatabaseType()
|
||||
// : DataSourceHolder.getDefaultDatabaseType();
|
||||
// switch (type) {
|
||||
// case mysql:
|
||||
// return MysqlParamBuilder.instance();
|
||||
// default:
|
||||
// return DefaultSqlParamBuilder.instance();
|
||||
// }
|
||||
}
|
||||
|
||||
public static void setDynamic(boolean dynamic) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.hsweb.web.mybatis.builder;
|
||||
|
||||
import org.hsweb.ezorm.core.param.UpdateParam;
|
||||
import org.hsweb.ezorm.rdb.executor.SQL;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBColumnMetaData;
|
||||
import org.hsweb.ezorm.rdb.meta.RDBTableMetaData;
|
||||
import org.hsweb.ezorm.rdb.render.SqlAppender;
|
||||
import org.hsweb.ezorm.rdb.render.dialect.Dialect;
|
||||
import org.hsweb.ezorm.rdb.render.support.simple.SimpleUpdateSqlRender;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public class UpdateSqlBuilder extends SimpleUpdateSqlRender {
|
||||
public UpdateSqlBuilder(Dialect dialect) {
|
||||
super(dialect);
|
||||
}
|
||||
@Override
|
||||
public SQL render(RDBTableMetaData metaData, UpdateParam param) {
|
||||
RDBTableMetaData metaDataNew = metaData.clone();
|
||||
metaDataNew.setDatabaseMetaData(metaData.getDatabaseMetaData());
|
||||
|
||||
metaDataNew.getColumns().stream()
|
||||
.filter(column -> column.getName().contains("."))
|
||||
.map(RDBColumnMetaData::getName)
|
||||
.forEach(metaDataNew::removeColumn);
|
||||
return super.render(metaDataNew, param);
|
||||
}
|
||||
@Override
|
||||
protected SqlAppender getParamString(String paramName, RDBColumnMetaData rdbColumnMetaData) {
|
||||
return new SqlAppender().add("#{", paramName,
|
||||
",javaType=", EasyOrmSqlBuilder.getJavaType(rdbColumnMetaData.getJavaType()),
|
||||
",jdbcType=", rdbColumnMetaData.getJdbcType(), "}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package org.hsweb.web.mybatis.dynamic;
|
||||
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.apache.ibatis.transaction.Transaction;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.utils.ThreadLocalUtils;
|
||||
import org.mybatis.spring.transaction.SpringManagedTransaction;
|
||||
import org.springframework.jdbc.datasource.ConnectionHolder;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* mybatis 同一事务,同一个mapper,动态数据源切换支持
|
||||
*
|
||||
* @author zhouhao
|
||||
*/
|
||||
public class DynamicSpringManagedTransaction implements Transaction {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(SpringManagedTransaction.class);
|
||||
|
||||
private Map<String, TransactionProxy> connectionMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 当前数据源对应的事务代理
|
||||
*
|
||||
* @return {@link TransactionProxy}
|
||||
*/
|
||||
protected TransactionProxy getProxy() {
|
||||
return connectionMap.get(DataSourceHolder.getActiveSourceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个事务代理
|
||||
*
|
||||
* @param proxy
|
||||
*/
|
||||
protected void addProxy(TransactionProxy proxy) {
|
||||
connectionMap.put(DataSourceHolder.getActiveSourceId(), proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有代理
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected Collection<TransactionProxy> getAllProxy() {
|
||||
return connectionMap.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
TransactionProxy proxy = getProxy();
|
||||
if (proxy != null) {
|
||||
return proxy.getConnection();
|
||||
}
|
||||
//根据当前激活的数据源 获取jdbc链接
|
||||
DataSource dataSource = DataSourceHolder.getActiveSource();
|
||||
String dsId = DataSourceHolder.getActiveSourceId();
|
||||
Connection connection = DataSourceUtils.getConnection(dataSource);
|
||||
proxy = new TransactionProxy(dsId, connection, dataSource);
|
||||
addProxy(proxy);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"DataSource (" + DataSourceHolder.getActiveSourceId() + ") JDBC Connection ["
|
||||
+ connection
|
||||
+ "] will"
|
||||
+ (proxy.isConnectionTransactional ? " " : " not ")
|
||||
+ "be managed by Spring");
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
for (TransactionProxy proxy : getAllProxy()) {
|
||||
proxy.commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
for (TransactionProxy proxy : getAllProxy()) {
|
||||
proxy.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
SQLException tmp = null;
|
||||
for (TransactionProxy proxy : getAllProxy()) {
|
||||
try {
|
||||
proxy.close();
|
||||
//保证每个链接都能被释放
|
||||
} catch (SQLException e) {
|
||||
tmp = e;
|
||||
}
|
||||
}
|
||||
connectionMap.clear();
|
||||
if (null != tmp) throw tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTimeout() throws SQLException {
|
||||
return getProxy().getTimeout();
|
||||
}
|
||||
|
||||
class TransactionProxy implements Transaction {
|
||||
Connection connection;
|
||||
DataSource dataSource;
|
||||
boolean isConnectionTransactional;
|
||||
boolean autoCommit;
|
||||
String dataSourceId;
|
||||
|
||||
public TransactionProxy(String dataSourceId, Connection connection, DataSource dataSource) {
|
||||
this.connection = connection;
|
||||
this.dataSource = dataSource;
|
||||
this.dataSourceId = dataSourceId;
|
||||
this.isConnectionTransactional = DataSourceUtils.isConnectionTransactional(connection, dataSource);
|
||||
try {
|
||||
this.autoCommit = connection.getAutoCommit();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
if (this.connection != null && !this.isConnectionTransactional && !this.autoCommit) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Committing DataSource (" + dataSourceId + ") JDBC Connection [" + this.connection + "]");
|
||||
}
|
||||
this.connection.commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
if (this.connection != null && !this.isConnectionTransactional && !this.autoCommit) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Rolling back DataSource (" + dataSourceId + ") JDBC Connection [" + this.connection + "]");
|
||||
}
|
||||
this.connection.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
DataSourceUtils.releaseConnection(connection, dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTimeout() throws SQLException {
|
||||
ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
|
||||
if (holder != null && holder.hasTimeout()) {
|
||||
return holder.getTimeToLiveInSeconds();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.hsweb.web.mybatis.plgins.pager;
|
||||
|
||||
import org.hsweb.web.core.utils.ThreadLocalUtils;
|
||||
|
||||
/**
|
||||
* 分页插件,通过此接口进行分页操作
|
||||
*
|
||||
* @author zhouhao
|
||||
* @see PagerInterceptor
|
||||
*/
|
||||
public interface Pager {
|
||||
int pageIndex();
|
||||
|
||||
int pageSize();
|
||||
|
||||
String threadLocalKey = "nowPager";
|
||||
|
||||
static Pager getAndReset() {
|
||||
try {
|
||||
return get();
|
||||
} finally {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
static Pager get() {
|
||||
return ThreadLocalUtils.get(threadLocalKey);
|
||||
}
|
||||
|
||||
static void reset() {
|
||||
ThreadLocalUtils.remove(threadLocalKey);
|
||||
}
|
||||
|
||||
static void doPaging(int pageIndex, int pageSize) {
|
||||
ThreadLocalUtils.put(threadLocalKey, new Pager() {
|
||||
@Override
|
||||
public int pageIndex() {
|
||||
return pageIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void doPaging(int pageIndex, int pageSize, int total) {
|
||||
doPaging(pageIndex, pageSize);
|
||||
rePaging(total);
|
||||
}
|
||||
|
||||
static void rePaging(int total) {
|
||||
Pager pager = get();
|
||||
int pageIndex = 0;
|
||||
if (pager != null) {
|
||||
// 当前页没有数据后跳转到最后一页
|
||||
if (pager.pageIndex() != 0 && (pager.pageIndex() * pager.pageSize()) >= total) {
|
||||
int tmp = total / pager.pageSize();
|
||||
pageIndex = total % pager.pageSize() == 0 ? tmp - 1 : tmp;
|
||||
}
|
||||
doPaging(pageIndex, pager.pageSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.hsweb.web.mybatis.plgins.pager;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-4-13.
|
||||
*/
|
||||
public interface PagerHelper {
|
||||
|
||||
String getDialect();
|
||||
|
||||
String doPaging(QueryParam param, String sql);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.hsweb.web.mybatis.plgins.pager;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.ParameterMapping;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.apache.ibatis.reflection.SystemMetaObject;
|
||||
@@ -10,12 +11,14 @@ import org.apache.ibatis.session.ResultHandler;
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.mybatis.builder.EasyOrmSqlBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -23,10 +26,6 @@ import java.util.Properties;
|
||||
RowBounds.class, ResultHandler.class})})
|
||||
@Component
|
||||
public class PagerInterceptor implements Interceptor {
|
||||
protected Map<String, PagerHelper> pagerHelperBase = new HashMap<>();
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation target) throws Throwable {
|
||||
@@ -39,14 +38,12 @@ public class PagerInterceptor implements Interceptor {
|
||||
StatementHandler statementHandler = (StatementHandler) target;
|
||||
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
|
||||
String sql = statementHandler.getBoundSql().getSql();
|
||||
Object obj = statementHandler.getParameterHandler().getParameterObject();
|
||||
if (obj instanceof QueryParam) {
|
||||
QueryParam param = (QueryParam) obj;
|
||||
PagerHelper helper = pagerHelperBase.get(getDialect());
|
||||
if (helper != null && param.isPaging() && !sql.contains("count(0)")) {
|
||||
String newSql = helper.doPaging(param, sql);
|
||||
metaStatementHandler.setValue("delegate.boundSql.sql", newSql);
|
||||
}
|
||||
Pager pager = Pager.getAndReset();
|
||||
if (pager != null && sql.trim().toLowerCase().startsWith("select")) {
|
||||
String newSql = EasyOrmSqlBuilder.getInstance()
|
||||
.getActiveDatabase().getDialect()
|
||||
.doPaging(sql, pager.pageIndex(), pager.pageSize());
|
||||
metaStatementHandler.setValue("delegate.boundSql.sql", newSql);
|
||||
}
|
||||
}
|
||||
return Plugin.wrap(target, this);
|
||||
@@ -55,14 +52,4 @@ public class PagerInterceptor implements Interceptor {
|
||||
@Override
|
||||
public void setProperties(Properties properties) {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
Map<String, PagerHelper> helperMap = context.getBeansOfType(PagerHelper.class);
|
||||
helperMap.forEach((name, helper) -> pagerHelperBase.put(helper.getDialect(), helper));
|
||||
}
|
||||
|
||||
public String getDialect() {
|
||||
return DataSourceHolder.getDefaultDatabaseType().name();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.hsweb.web.mybatis.plgins.pager.dialect;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-4-13.
|
||||
*/
|
||||
@Component
|
||||
public class H2PagerHelper extends MysqlPagerHelper {
|
||||
|
||||
@Override
|
||||
public String getDialect() {
|
||||
return "h2";
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package org.hsweb.web.mybatis.plgins.pager.dialect;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.mybatis.plgins.pager.PagerHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.hsweb.commons.StringUtils;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-4-13.
|
||||
*/
|
||||
@Component
|
||||
public class MysqlPagerHelper implements PagerHelper {
|
||||
@Override
|
||||
public String doPaging(QueryParam param, String sql) {
|
||||
StringBuilder builder = new StringBuilder(sql);
|
||||
if (param.isPaging())
|
||||
builder.append(" limit ")
|
||||
.append(param.getPageSize() * param.getPageIndex())
|
||||
.append(",")
|
||||
.append(param.getPageSize() * (param.getPageIndex() + 1));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDialect() {
|
||||
return "mysql";
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.hsweb.web.mybatis.plgins.pager.dialect;
|
||||
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.mybatis.plgins.pager.PagerHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.hsweb.commons.StringUtils;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-4-13.
|
||||
*/
|
||||
@Component
|
||||
public class OraclePagerHelper implements PagerHelper {
|
||||
@Override
|
||||
public String doPaging(QueryParam param, String sql) {
|
||||
if (!param.isPaging()) {
|
||||
return sql;
|
||||
}
|
||||
int startWith = param.getPageSize() * (param.getPageIndex() + 1);
|
||||
StringBuilder builder = new StringBuilder()
|
||||
.append("select * from ( select row_.*, rownum rownum_ from (")
|
||||
.append(sql)
|
||||
.append(") row_ )")
|
||||
.append("where rownum_ <= ")
|
||||
.append(startWith)
|
||||
.append(" and rownum_ > ")
|
||||
.append(param.getPageSize() * param.getPageIndex());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDialect() {
|
||||
return "oracle";
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,8 @@ package org.hsweb.web.mybatis.utils;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by zhouhao on 16-5-9.
|
||||
* @see org.hsweb.ezorm.rdb.render.SqlAppender
|
||||
* @deprecated
|
||||
*/
|
||||
public class SqlAppender extends LinkedList<String> {
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
<sql id="buildWhere">
|
||||
${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildWhere(resultMapId,tableName,#this['_parameter'].terms)}
|
||||
</sql>
|
||||
<sql id="buildWhereForUpdate">
|
||||
${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildWhereForUpdate(resultMapId,tableName,#this['_parameter'].terms)}
|
||||
</sql>
|
||||
|
||||
<!--生成查询字段-->
|
||||
<sql id="buildSelectField">
|
||||
@@ -16,7 +19,7 @@
|
||||
<!--生成修改字段-->
|
||||
<sql id="buildUpdateField">
|
||||
<set>
|
||||
${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildUpdateFields(resultMapId,#this['_parameter'])}
|
||||
${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildUpdateFields(resultMapId,tableName,#this['_parameter'])}
|
||||
</set>
|
||||
</sql>
|
||||
|
||||
@@ -27,48 +30,56 @@
|
||||
|
||||
<!--生成查询sql-->
|
||||
<sql id="buildSelectSql">
|
||||
select
|
||||
<include refid="BasicMapper.buildSelectField"/>
|
||||
from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
</where>
|
||||
<include refid="BasicMapper.buildSortField"/>
|
||||
<trim>
|
||||
select
|
||||
<include refid="BasicMapper.buildSelectField"/>
|
||||
from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
</where>
|
||||
<include refid="BasicMapper.buildSortField"/>
|
||||
</trim>
|
||||
</sql>
|
||||
|
||||
<!--生成删除sql-->
|
||||
<sql id="buildDeleteSql">
|
||||
delete from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
<if test="terms.size()==0">
|
||||
1=2
|
||||
</if>
|
||||
</where>
|
||||
<trim>
|
||||
delete from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhereForUpdate"/>
|
||||
<if test="terms.size()==0">
|
||||
1=2
|
||||
</if>
|
||||
</where>
|
||||
</trim>
|
||||
</sql>
|
||||
|
||||
<!--生成InsertSql-->
|
||||
<sql id="buildInsertSql">
|
||||
insert into ${tableName} ${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildInsertSql(resultMapId,#this['_parameter'])}
|
||||
${@org.hsweb.web.mybatis.builder.SqlBuilder@current().buildInsertSql(resultMapId,tableName,#this['_parameter'])}
|
||||
</sql>
|
||||
|
||||
<!--生成UpdateSql-->
|
||||
<sql id="buildUpdateSql">
|
||||
update ${tableName}
|
||||
<include refid="BasicMapper.buildUpdateField"/>
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
<if test="terms.size()==0">
|
||||
u_id=#{data.id}
|
||||
</if>
|
||||
</where>
|
||||
<trim>
|
||||
update ${tableName}
|
||||
<include refid="BasicMapper.buildUpdateField"/>
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhereForUpdate"/>
|
||||
<if test="terms.size()==0">
|
||||
u_id=#{data.id}
|
||||
</if>
|
||||
</where>
|
||||
</trim>
|
||||
</sql>
|
||||
|
||||
<!--生成查询数量sql-->
|
||||
<sql id="buildTotalSql">
|
||||
select count(0) as "total" from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
</where>
|
||||
<trim>
|
||||
select count(0) as total from ${tableName}
|
||||
<where>
|
||||
<include refid="BasicMapper.buildWhere"/>
|
||||
</where>
|
||||
</trim>
|
||||
</sql>
|
||||
</mapper>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<!--用于动态生成sql所需的配置-->
|
||||
<sql id="config">
|
||||
<bind name="resultMapId" value="'QuartzJobHistoryResultMap'"/>
|
||||
<bind name="tableName" value="'S_QUARTZ_JOB_HIS'"/>
|
||||
<bind name="tableName" value="'s_quartz_job_his'"/>
|
||||
</sql>
|
||||
<insert id="insert" parameterType="org.hsweb.web.bean.common.InsertParam">
|
||||
<include refid="config"/>
|
||||
@@ -48,7 +48,7 @@
|
||||
</update>
|
||||
|
||||
<select id="selectByPk" parameterType="string" resultMap="QuartzJobHistoryResultMap">
|
||||
select * from S_QUARTZ_JOB_HIS where u_id=#{id}
|
||||
select * from s_quartz_job_his where u_id=#{id}
|
||||
</select>
|
||||
|
||||
<select id="select" parameterType="org.hsweb.web.bean.common.QueryParam" resultMap="QuartzJobHistoryResultMap">
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<!--用于动态生成sql所需的配置-->
|
||||
<sql id="config">
|
||||
<bind name="resultMapId" value="'QuartzJobResultMap'"/>
|
||||
<bind name="tableName" value="'S_QUARTZ_JOB'"/>
|
||||
<bind name="tableName" value="'s_quartz_job'"/>
|
||||
</sql>
|
||||
<insert id="insert" parameterType="org.hsweb.web.bean.common.InsertParam">
|
||||
<include refid="config"/>
|
||||
@@ -52,7 +52,7 @@
|
||||
</update>
|
||||
|
||||
<select id="selectByPk" parameterType="string" resultMap="QuartzJobResultMap">
|
||||
select * from S_QUARTZ_JOB where u_id=#{id}
|
||||
select * from s_quartz_job where u_id=#{id}
|
||||
</select>
|
||||
|
||||
<select id="select" parameterType="org.hsweb.web.bean.common.QueryParam" resultMap="QuartzJobResultMap">
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="remark" column="remark" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
|
||||
<collection property="modules" column="u_id" ofType="RoleModule"
|
||||
<collection property="modules" column="u_id" ofType="org.hsweb.web.bean.po.role.RoleModule"
|
||||
select="org.hsweb.web.dao.role.RoleModuleMapper.selectByRoleId"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<result property="roleId" column="role_id" javaType="String" jdbcType="VARCHAR" />
|
||||
<result property="actions" column="actions" javaType="java.util.List" jdbcType="VARCHAR"
|
||||
typeHandler="org.hsweb.web.mybatis.handler.JsonArrayHandler" />
|
||||
<collection property="module" column="module_id" ofType="Module" select="org.hsweb.web.dao.module.ModuleMapper.selectByPk"/>
|
||||
<collection property="module" column="module_id" ofType="org.hsweb.web.bean.po.module.Module" select="org.hsweb.web.dao.module.ModuleMapper.selectByPk"/>
|
||||
</resultMap>
|
||||
|
||||
<!--用于动态生成sql所需的配置-->
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
|
||||
<result property="userId" column="user_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<result property="roleId" column="role_id" javaType="String" jdbcType="VARCHAR"/>
|
||||
<collection property="role" column="role_id" jdbcType="VARCHAR" ofType="Role"
|
||||
<collection property="role" column="role_id" jdbcType="VARCHAR" ofType="org.hsweb.web.bean.po.role.Role"
|
||||
select="org.hsweb.web.dao.role.RoleMapper.selectByPk"></collection>
|
||||
</resultMap>
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<result property="status" column="status" javaType="int" jdbcType="INTEGER"/>
|
||||
<result property="createDate" column="create_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateDate" column="update_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
|
||||
<collection property="userRoles" column="u_id" ofType="UserRole"
|
||||
<collection property="userRoles" column="u_id" ofType="org.hsweb.web.bean.po.role.UserRole"
|
||||
select="org.hsweb.web.dao.role.UserRoleMapper.selectByUserId"/>
|
||||
</resultMap>
|
||||
<!--用于动态生成sql所需的配置-->
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.hsweb.web.mybatis;
|
||||
|
||||
import org.hsweb.ezorm.executor.AbstractJdbcSqlExecutor;
|
||||
import org.hsweb.ezorm.executor.SqlExecutor;
|
||||
import org.hsweb.ezorm.rdb.executor.AbstractJdbcSqlExecutor;
|
||||
import org.hsweb.ezorm.rdb.executor.SqlExecutor;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.datasource.DatabaseType;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
@@ -26,7 +26,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
@@ -38,7 +37,7 @@ import java.sql.SQLException;
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("org.hsweb.web")
|
||||
@MapperScan("org.hsweb.web.dao")
|
||||
@MapperScan({"org.hsweb.web.dao", "org.hsweb.web.mybatis.mappers"})
|
||||
public class SpringApplication {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -16,15 +16,21 @@
|
||||
|
||||
package org.hsweb.web.mybatis.user;
|
||||
|
||||
import org.hsweb.ezorm.core.dsl.Query;
|
||||
import org.hsweb.web.bean.common.DeleteParam;
|
||||
import org.hsweb.web.bean.common.InsertParam;
|
||||
import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
import org.hsweb.web.bean.po.user.User;
|
||||
import org.hsweb.web.dao.form.FormMapper;
|
||||
import org.hsweb.web.dao.user.UserMapper;
|
||||
import org.hsweb.web.mybatis.AbstractTestCase;
|
||||
import org.hsweb.web.mybatis.plgins.pager.Pager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -35,6 +41,9 @@ public class UserMapperTest extends AbstractTestCase {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
protected FormMapper formMapper;
|
||||
|
||||
@Test
|
||||
public void testInsert() {
|
||||
User user = new User();
|
||||
@@ -43,11 +52,22 @@ public class UserMapperTest extends AbstractTestCase {
|
||||
user.setName("test");
|
||||
user.setCreateDate(new Date());
|
||||
int i = userMapper.insert(InsertParam.build(user));
|
||||
userMapper.update(UpdateParam.build(user));
|
||||
userMapper.delete(DeleteParam.build().where("id", "111"));
|
||||
Assert.assertEquals(i, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery() {
|
||||
userMapper.select(QueryParam.build());
|
||||
User user = new User();
|
||||
user.setId("test");
|
||||
user.setUsername("admin");
|
||||
user.setName("test");
|
||||
Pager.doPaging(0, 20);
|
||||
Query.forList(userMapper::select, new QueryParam())
|
||||
.sql("username is not null")
|
||||
.or().sql("username=#{username}", Collections.singletonMap("username", "root"))
|
||||
.fromBean(user)
|
||||
.$like$("username").list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ spring:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
mybatis:
|
||||
config: classpath:mybatis-config.xml
|
||||
configLocation: classpath:mybatis-config.xml
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -16,15 +16,20 @@
|
||||
|
||||
package org.hsweb.web.datasource.dynamic;
|
||||
|
||||
import com.atomikos.icatch.config.UserTransactionService;
|
||||
import com.atomikos.icatch.config.UserTransactionServiceImp;
|
||||
import com.atomikos.icatch.jta.UserTransactionImp;
|
||||
import com.atomikos.icatch.jta.UserTransactionManager;
|
||||
import com.atomikos.jdbc.AtomikosDataSourceBean;
|
||||
import org.hsweb.commons.StringUtils;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.datasource.DynamicDataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.jta.atomikos.AtomikosProperties;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -34,6 +39,7 @@ import org.springframework.transaction.jta.JtaTransactionManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.SystemException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(DynamicDataSource.class)
|
||||
@@ -44,6 +50,17 @@ public class DynamicDataSourceAutoConfiguration {
|
||||
@Autowired
|
||||
private DynamicDataSourceProperties properties;
|
||||
|
||||
@Bean(initMethod = "init", destroyMethod = "shutdownForce")
|
||||
public UserTransactionServiceImp userTransactionService() {
|
||||
AtomikosProperties atomikosProperties = properties.getIcatch();
|
||||
Properties properties = new Properties();
|
||||
properties.putAll(atomikosProperties.asProperties());
|
||||
if (StringUtils.isNullOrEmpty(properties.get("com.atomikos.icatch.service"))) {
|
||||
properties.put("com.atomikos.icatch.service", "com.atomikos.icatch.standalone.UserTransactionServiceFactory");
|
||||
}
|
||||
return new UserTransactionServiceImp(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认数据库链接
|
||||
*/
|
||||
@@ -64,10 +81,12 @@ public class DynamicDataSourceAutoConfiguration {
|
||||
return dynamicXaDataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserTransactionManager userTransactionManager() {
|
||||
@Bean(initMethod = "init", destroyMethod = "close")
|
||||
public UserTransactionManager userTransactionManager(
|
||||
UserTransactionService userTransactionService) {
|
||||
UserTransactionManager transactionManager = new UserTransactionManager();
|
||||
transactionManager.setForceShutdown(true);
|
||||
transactionManager.setStartupTransactionService(false);
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.hsweb.web.core.datasource.DatabaseType;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jta.atomikos.AtomikosProperties;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -56,6 +57,7 @@ public class DynamicDataSourceProperties
|
||||
private Properties properties = null;
|
||||
private ClassLoader classLoader = null;
|
||||
private DatasourceTypeSupport datasourceTypeSupport = null;
|
||||
private AtomikosProperties icatch = new AtomikosProperties();
|
||||
|
||||
public int getTransactionTimeout() {
|
||||
return transactionTimeout;
|
||||
@@ -88,6 +90,14 @@ public class DynamicDataSourceProperties
|
||||
return type;
|
||||
}
|
||||
|
||||
public AtomikosProperties getIcatch() {
|
||||
return icatch;
|
||||
}
|
||||
|
||||
public void setIcatch(AtomikosProperties icatch) {
|
||||
this.icatch = icatch;
|
||||
}
|
||||
|
||||
public void setType(DatabaseType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
|
||||
package org.hsweb.web.datasource.dynamic;
|
||||
|
||||
import org.hsweb.ezorm.executor.AbstractJdbcSqlExecutor;
|
||||
import org.hsweb.ezorm.executor.SQL;
|
||||
import org.hsweb.ezorm.meta.expand.ObjectWrapper;
|
||||
import org.hsweb.ezorm.meta.expand.SimpleMapWrapper;
|
||||
import org.hsweb.ezorm.render.support.simple.SimpleSQL;
|
||||
import org.hsweb.ezorm.core.ObjectWrapper;
|
||||
import org.hsweb.ezorm.rdb.executor.AbstractJdbcSqlExecutor;
|
||||
import org.hsweb.ezorm.rdb.executor.SQL;
|
||||
import org.hsweb.ezorm.rdb.render.support.simple.SimpleSQL;
|
||||
import org.hsweb.web.core.authorize.ExpressionScopeBean;
|
||||
import org.hsweb.web.core.datasource.DataSourceHolder;
|
||||
import org.hsweb.web.core.datasource.DynamicDataSource;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@@ -43,11 +44,20 @@ public class DynamicDataSourceSqlExecutorService extends AbstractJdbcSqlExecutor
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return DataSourceUtils.getConnection(dynamicDataSource.getActiveDataSource());
|
||||
DataSource dataSource = dynamicDataSource.getActiveDataSource();
|
||||
Connection connection = DataSourceUtils.getConnection(dataSource);
|
||||
boolean isConnectionTransactional = DataSourceUtils.isConnectionTransactional(connection, dataSource);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("DataSource ({}) JDBC Connection [{}] will {} be managed by Spring", DataSourceHolder.getActiveSourceId(), connection, (isConnectionTransactional ? "" : "not"));
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(Connection connection) throws SQLException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", DataSourceHolder.getActiveSourceId(), connection);
|
||||
}
|
||||
DataSourceUtils.releaseConnection(connection, dynamicDataSource.getActiveDataSource());
|
||||
}
|
||||
|
||||
@@ -65,59 +75,34 @@ public class DynamicDataSourceSqlExecutorService extends AbstractJdbcSqlExecutor
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> list(SQL sql) throws SQLException {
|
||||
List<Map<String, Object>> data = list(sql, new SimpleMapWrapper());
|
||||
return data;
|
||||
return super.list(sql);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Map<String, Object> single(SQL sql) throws Exception {
|
||||
Map<String, Object> data = single(sql, new SimpleMapWrapper());
|
||||
return data;
|
||||
public Map<String, Object> single(SQL sql) throws SQLException {
|
||||
return super.single(sql);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> list(String sql) throws Exception {
|
||||
List<Map<String, Object>> data = list(create(sql), new SimpleMapWrapper());
|
||||
return data;
|
||||
public List<Map<String, Object>> list(String sql) throws SQLException {
|
||||
return super.list(sql);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Map<String, Object>> list(String sql, Map<String, Object> param) throws Exception {
|
||||
List<Map<String, Object>> data = list(create(sql, param), new SimpleMapWrapper());
|
||||
return data;
|
||||
public List<Map<String, Object>> list(String sql, Object param) throws SQLException {
|
||||
return super.list(sql, param);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Map<String, Object> single(String sql) throws Exception {
|
||||
Map<String, Object> data = single(create(sql));
|
||||
return data;
|
||||
public Map<String, Object> single(String sql) throws SQLException {
|
||||
return super.single(sql);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Map<String, Object> single(String sql, Map<String, Object> param) throws Exception {
|
||||
Map<String, Object> data = single(create(sql, param));
|
||||
return data;
|
||||
public Map<String, Object> single(String sql, Object param) throws SQLException {
|
||||
return super.single(sql, param);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int update(String sql, Map<String, Object> param) throws SQLException {
|
||||
return super.update(new SimpleSQL(sql, param));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int update(String sql) throws SQLException {
|
||||
return super.update(new SimpleSQL(sql));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int delete(String sql, Map<String, Object> param) throws SQLException {
|
||||
return super.delete(new SimpleSQL(sql, param));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int delete(String sql) throws SQLException {
|
||||
return super.delete(new SimpleSQL(sql));
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void exec(String sql) throws SQLException {
|
||||
@@ -130,12 +115,4 @@ public class DynamicDataSourceSqlExecutorService extends AbstractJdbcSqlExecutor
|
||||
super.exec(sql);
|
||||
}
|
||||
|
||||
public SQL create(String sql) {
|
||||
return new SimpleSQL(sql);
|
||||
}
|
||||
|
||||
public SQL create(String sql, Map<String, Object> param) {
|
||||
SimpleSQL sql1 = new SimpleSQL(sql, param);
|
||||
return sql1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,96 @@
|
||||
"name": "hsweb.dynamic-datasource.properties",
|
||||
"type": "java.util.Properties",
|
||||
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch",
|
||||
"type": "org.springframework.boot.jta.atomikos.AtomikosProperties",
|
||||
"sourceType": "org.hsweb.web.datasource.dynamic.DynamicDataSourceProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.service",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.max-timeout",
|
||||
"type": "long",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.default-jta-timeout",
|
||||
"type": "long",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.max-actives",
|
||||
"type": "int",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.enable-logging",
|
||||
"type": "boolean",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.transaction-manager-unique-name",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.serial-jta-transactions",
|
||||
"type": "boolean",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.force-shutdown-on-vm-exit",
|
||||
"type": "boolean",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.log-base-name",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.log-base-dir",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.checkpoint-interval",
|
||||
"type": "long",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.console-log-level",
|
||||
"type": "org.springframework.boot.jta.atomikos.AtomikosLoggingLevel",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.output-dir",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.console-file-name",
|
||||
"type": "String",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.console-file-count",
|
||||
"type": "int",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.console-file-limit",
|
||||
"type": "int",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.threaded-2pc",
|
||||
"type": "boolean",
|
||||
"sourceType": "org.springframework.boot.jta.atomikos.AtomikosProperties"
|
||||
}
|
||||
],
|
||||
"hints": [
|
||||
@@ -115,6 +205,23 @@
|
||||
"description": "use oracle database."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "hsweb.dynamic-datasource.icatch.console-log-level",
|
||||
"values": [
|
||||
{
|
||||
"value": "INFO",
|
||||
"description": "INFO LEVEL."
|
||||
},
|
||||
{
|
||||
"value": "DEBUG",
|
||||
"description": "DEBUG LEVEL."
|
||||
},
|
||||
{
|
||||
"value": "WARN",
|
||||
"description": "ERROR LEVEL."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-oauth2</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-oauth2</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-oauth2</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-oauth2</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -36,5 +36,19 @@
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-web-service-simple</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<artifactId>hsweb-web-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -22,7 +22,6 @@ import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateMapParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
import org.hsweb.web.core.exception.NotFoundException;
|
||||
import org.hsweb.web.core.utils.RandomUtil;
|
||||
import org.hsweb.web.oauth2.dao.OAuth2AccessMapper;
|
||||
import org.hsweb.web.oauth2.dao.OAuth2ClientMapper;
|
||||
import org.hsweb.web.oauth2.po.OAuth2Access;
|
||||
@@ -73,7 +72,7 @@ public class OAuth2ClientServiceImpl extends AbstractServiceImpl<OAuth2Client, S
|
||||
@Override
|
||||
public String refreshSecret(String clientId) {
|
||||
String secret = MD5.encode(UUID.randomUUID().toString() + Math.random());
|
||||
int size = oAuth2ClientMapper.update((UpdateParam) UpdateMapParam.build().set("secret", secret).where("id", clientId));
|
||||
int size = createUpdate().set("secret", secret).where("id", clientId).exec();
|
||||
if (size != 1) throw new NotFoundException("客户端不存在");
|
||||
return secret;
|
||||
}
|
||||
@@ -82,18 +81,18 @@ public class OAuth2ClientServiceImpl extends AbstractServiceImpl<OAuth2Client, S
|
||||
public void enable(String id) {
|
||||
OAuth2Client old = selectByPk(id);
|
||||
assertNotNull(old, "客户端不存在");
|
||||
oAuth2ClientMapper.update((UpdateParam) UpdateMapParam.build().set("status", 1).where("id", id));
|
||||
createUpdate().set("status", 1).where("id", id).exec();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(String id) {
|
||||
OAuth2Client old = selectByPk(id);
|
||||
assertNotNull(old, "客户端不存在");
|
||||
oAuth2ClientMapper.update((UpdateParam) UpdateMapParam.build().set("status", -1).where("id", id));
|
||||
createUpdate().set("status", -1).where("id", id).exec();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(OAuth2Client data) {
|
||||
return getMapper().update(UpdateParam.build(data).excludes("secret","status").where("id", data.getId()));
|
||||
return createUpdate(data).excludes("secret", "status").where("id", data.getId()).exec();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.hsweb.web.bean.common.QueryParam;
|
||||
import org.hsweb.web.bean.common.UpdateParam;
|
||||
import org.hsweb.web.bean.po.user.User;
|
||||
import org.hsweb.web.core.exception.AuthorizeException;
|
||||
import org.hsweb.web.core.exception.BusinessException;
|
||||
import org.hsweb.web.core.exception.NotFoundException;
|
||||
import org.hsweb.web.oauth2.dao.OAuth2AccessMapper;
|
||||
import org.hsweb.web.oauth2.exception.AccessTimeoutException;
|
||||
@@ -96,7 +95,7 @@ public class OAuth2ServiceImpl implements OAuth2Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = AccessTimeoutException.class)
|
||||
@Transactional(noRollbackFor = {AccessTimeoutException.class, AuthorizeException.class})
|
||||
public User getUserByAccessToken(String accessToken) {
|
||||
OAuth2Access auth2Access = null;
|
||||
Cache cache = null;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-oauth2</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-framework</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>hsweb-web-service</artifactId>
|
||||
<groupId>org.hsweb</groupId>
|
||||
<version>2.1-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hsweb-web-service-api</artifactId>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.hsweb.web.service;
|
||||
|
||||
import org.hsweb.ezorm.core.dsl.Delete;
|
||||
import org.hsweb.web.bean.common.DeleteParam;
|
||||
import org.hsweb.web.dao.DeleteMapper;
|
||||
import org.hsweb.web.dao.GenericMapper;
|
||||
|
||||
/**
|
||||
* @author zhouhao
|
||||
*/
|
||||
public interface DeleteService<Pk> {
|
||||
/**
|
||||
* 根据主键删除记录
|
||||
*
|
||||
* @param pk 主键
|
||||
* @return 影响记录数
|
||||
*/
|
||||
int delete(Pk pk);
|
||||
|
||||
Delete createDelete();
|
||||
|
||||
/**
|
||||
* 指定一个dao映射接口,接口需继承{@link GenericMapper}创建dsl数据删除操作对象<br>
|
||||
* 可通过返回的Update对象进行dsl方式操作如:<br>
|
||||
* <code>
|
||||
* createDelete(userMapper).where("id",1).exec();
|
||||
* </code>
|
||||
*
|
||||
* @param mapper dao映射结构
|
||||
* @return {@link Delete}
|
||||
* @see Delete
|
||||
* @see org.hsweb.ezorm.core.Conditional
|
||||
* @since 2.2
|
||||
*/
|
||||
static Delete createDelete(DeleteMapper mapper) {
|
||||
Delete update = new Delete();
|
||||
update.setParam(new DeleteParam());
|
||||
update.setExecutor(param -> mapper.delete(((DeleteParam) param)));
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义一个删除执行器。创建dsl数据删除操作对象
|
||||
*
|
||||
* @param executor 执行器
|
||||
* @return {@link Delete}
|
||||
* @since 2.2
|
||||
*/
|
||||
static Delete createDelete(Delete.Executor<DeleteParam> executor) {
|
||||
Delete update = new Delete();
|
||||
update.setParam(new DeleteParam());
|
||||
update.setExecutor(param -> executor.doExecute(((DeleteParam) param)));
|
||||
return update;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user