Skip to content

Commit

Permalink
Merge branch 'master' of github.com:/hs-web/hsweb-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jul 21, 2017
2 parents 380f172 + 6953c07 commit 5009a13
Show file tree
Hide file tree
Showing 25 changed files with 749 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ public void assertAuthorized(Annotation a) throws AuthorizationException {
.stream()
.filter(authorizeConfig.action::contains)
.collect(Collectors.toList());

if (actions.isEmpty()) return false;

//如果 控制逻辑是or,则只要过滤结果数量不为0.否则过滤结果数量必须和配置的数量相同
return logicalIsOr ? actions.size() > 0 : permission.getActions().containsAll(actions);
}).collect(Collectors.toList());
access = logicalIsOr ? permissions.size() > 0 : permissions.size() == authorizeConfig.permission.size();
access = logicalIsOr ?
permissions.size() > 0 :
//权限数量和配置的数量相同
permissions.size() == authorizeConfig.permission.size();
}
//控制角色
if (!authorizeConfig.role.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.hswebframework.web.commons.entity.RecordCreationEntity;
import org.hswebframework.web.dao.CrudDao;
import org.hswebframework.web.id.IDGenerator;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.validator.group.CreateGroup;
import org.hswebframework.web.validator.group.UpdateGroup;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -58,18 +58,21 @@ public GenericEntityService() {

@Override
public int deleteByPk(PK pk) {
Assert.notNull(pk, "parameter can not be null");
return createDelete()
.where(GenericEntity.id, pk)
.exec();
}

@Override
public int updateByPk(PK pk, E entity) {
Assert.notNull(pk, "primary key can not be null");
Assert.notNull(entity, "entity can not be null");
entity.setId(pk);
tryValidate(entity, UpdateGroup.class);
return createUpdate(entity)
//如果是RecordCreationEntity则不修改creator_id和creator_time
.when(ClassUtils.instanceOf(getEntityType(), RecordCreationEntity.class),
.when(entity instanceof RecordCreationEntity,
update -> update.and().excludes(RecordCreationEntity.creatorId, RecordCreationEntity.createTime))
.where(GenericEntity.id, pk)
.exec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@
*/
@Transactional(rollbackFor = Throwable.class)
public class DefaultJdbcExecutor extends AbstractJdbcSqlExecutor {

@Override
public Connection getConnection() {
return DataSourceUtils.getConnection(DataSourceHolder.currentDataSource().getNative());
DataSource dataSource = DataSourceHolder.currentDataSource().getNative();
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.switcher().currentDataSourceId(), connection, (isConnectionTransactional ? "" : "not "));
}
return connection;
}

@Override
public void releaseConnection(Connection connection) throws SQLException {
if (logger.isDebugEnabled()) {
logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", DataSourceHolder.switcher().currentDataSourceId(), connection);
}
DataSourceUtils.releaseConnection(connection, DataSourceHolder.currentDataSource().getNative());
}

Expand Down
6 changes: 6 additions & 0 deletions hsweb-datasource/hsweb-datasource-jta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

Expand All @@ -20,11 +21,20 @@
public class JtaJdbcSqlExecutor extends AbstractJdbcSqlExecutor {
@Override
public Connection getConnection() {
return DataSourceUtils.getConnection(DataSourceHolder.currentDataSource().getNative());
DataSource dataSource = DataSourceHolder.currentDataSource().getNative();
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.switcher().currentDataSourceId(), connection, (isConnectionTransactional ? "" : "not "));
}
return connection;
}

@Override
public void releaseConnection(Connection connection) throws SQLException {
if (logger.isDebugEnabled()) {
logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", DataSourceHolder.switcher().currentDataSourceId(), connection);
}
DataSourceUtils.releaseConnection(connection, DataSourceHolder.currentDataSource().getNative());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-template</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>hsweb-system-template-controller</artifactId>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-template-service-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-controller</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.hswebframework.web.controller.tempalte;

import org.hswebframework.web.authorization.annotation.Authorize;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.entity.tempalte.TemplateEntity;
import org.hswebframework.web.logging.AccessLogger;
import org.hswebframework.web.service.tempalte.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 模板
*
* @author hsweb-generator-online
*/
@RestController
@RequestMapping("${hsweb.web.mappings.template:template}")
@Authorize(permission = "template")
@AccessLogger("模板")
public class TempalteController implements SimpleGenericEntityController<TemplateEntity, String, QueryParamEntity> {

private TemplateService templateService;

@Autowired
public void setTemplateService(TemplateService templateService) {
this.templateService = templateService;
}

@Override
public TemplateService getService() {
return templateService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-template-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>hsweb-system-template-dao-api</artifactId>

<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-template-entity</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-dao-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.hswebframework.web.dao.tempalte;

import org.hswebframework.web.dao.CrudDao;
import org.hswebframework.web.entity.tempalte.TemplateEntity;

/**
* 模板 DAO接口
* @author hsweb-generator-online
*/
public interface TemplateDao extends CrudDao<TemplateEntity,String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-template-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>hsweb-system-template-dao-mybatis</artifactId>

<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-template-dao-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-dao-mybatis</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.hswebframework.web.dao.tempalte.TemplateDao">
<resultMap id="TemplateResultMap" type="org.hswebframework.web.entity.tempalte.TemplateEntity">
<id property="id" column="u_id" javaType="string" jdbcType="VARCHAR"/>
<result property="name" column="name" javaType="String" jdbcType="VARCHAR"/>
<result property="type" column="type" javaType="String" jdbcType="VARCHAR"/>
<result property="template" column="template" javaType="String" jdbcType="CLOB"/>
<result property="config" column="config" javaType="String" jdbcType="CLOB"/>
<result property="version" column="version" javaType="Long" jdbcType="DECIMAL"/>
<result property="classified" column="classified" javaType="String" jdbcType="VARCHAR"/>
</resultMap>

<!--用于动态生成sql所需的配置-->
<sql id="config">
<bind name="resultMapId" value="'TemplateResultMap'"/>
<bind name="tableName" value="'s_template'"/>
</sql>

<insert id="insert" parameterType="org.hswebframework.web.entity.tempalte.TemplateEntity">
<include refid="config"/>
<include refid="BasicMapper.buildInsertSql"/>
</insert>

<delete id="deleteByPk" parameterType="String">
delete from s_template where u_id =#{id}
</delete>

<delete id="delete" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildDeleteSql"/>
</delete>

<update id="update" parameterType="org.hswebframework.web.commons.entity.Entity">
<include refid="config"/>
<include refid="BasicMapper.buildUpdateSql"/>
</update>

<select id="query" parameterType="org.hswebframework.web.commons.entity.Entity" resultMap="TemplateResultMap">
<include refid="config"/>
<include refid="BasicMapper.buildSelectSql"/>
</select>

<select id="count" parameterType="org.hswebframework.web.commons.entity.Entity" resultType="int">
<include refid="config"/>
<include refid="BasicMapper.buildTotalSql"/>
</select>
</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-template</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>hsweb-system-template-dao</artifactId>
<packaging>pom</packaging>
<modules>
<module>hsweb-system-template-dao-api</module>
<module>hsweb-system-template-dao-mybatis</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hsweb-system-template</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>hsweb-system-template-entity</artifactId>

<dependencies>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-commons-entity</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 5009a13

Please sign in to comment.