添加数据集管理基本页面

This commit is contained in:
datagear 2019-12-17 19:02:32 +08:00
parent 0c57376d2e
commit eefa164c26
21 changed files with 833 additions and 45 deletions

View File

@ -28,6 +28,11 @@
<artifactId>datagear-persistence</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.datagear</groupId>
<artifactId>datagear-analysis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.management.domain;
import java.sql.Connection;
import org.datagear.connection.ConnectionSource;
import org.datagear.management.util.SchemaConnectionSupport;
import org.datagear.util.JdbcUtil;
import org.datagear.util.resource.ConnectionFactory;
/**
* 封装{@linkplain Schema}{@linkplain ConnectionFactory}
*
* @author datagear@163.com
*
*/
public class SchemaConnectionFactory extends SchemaConnectionSupport implements ConnectionFactory
{
private ConnectionSource connectionSource;
private Schema schema;
public SchemaConnectionFactory()
{
super();
}
public SchemaConnectionFactory(ConnectionSource connectionSource, Schema schema)
{
super();
this.connectionSource = connectionSource;
this.schema = schema;
}
public ConnectionSource getConnectionSource()
{
return connectionSource;
}
public void setConnectionSource(ConnectionSource connectionSource)
{
this.connectionSource = connectionSource;
}
public Schema getSchema()
{
return schema;
}
public void setSchema(Schema schema)
{
this.schema = schema;
}
@Override
public Connection get() throws Exception
{
return super.getSchemaConnection(this.connectionSource, this.schema);
}
@Override
public void release(Connection resource) throws Exception
{
JdbcUtil.closeConnection(resource);
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.management.domain;
import java.util.Date;
import org.datagear.analysis.DataSetParams;
import org.datagear.analysis.support.SqlDataSetFactory;
import org.datagear.util.resource.ConnectionFactory;
/**
* {@linkplain SqlDataSetFactoryEntity}实体
*
* @author datagear@163.com
*
*/
public class SqlDataSetFactoryEntity extends SqlDataSetFactory
implements CreateUserEntity<String>, DataPermissionEntity<String>
{
private static final long serialVersionUID = 1L;
/** 授权资源类型 */
public static final String AUTHORIZATION_RESOURCE_TYPE = "SqlDataSetFactoryEntity";
/** 名称 */
private String name;
/** 创建用户 */
private User createUser;
/** 创建时间 */
private Date createTime;
/** 权限 */
private int dataPermission = PERMISSION_NOT_LOADED;
public SqlDataSetFactoryEntity()
{
super();
this.createTime = new Date();
}
public SqlDataSetFactoryEntity(String id, DataSetParams dataSetParams, SchemaConnectionFactory connectionFactory,
String sql, String name, User createUser)
{
super(id, dataSetParams, connectionFactory, sql);
this.name = name;
this.createTime = new Date();
}
@Override
public SchemaConnectionFactory getConnectionFactory()
{
return (SchemaConnectionFactory) super.getConnectionFactory();
}
@Override
public void setConnectionFactory(ConnectionFactory connectionFactory)
{
if (!(connectionFactory instanceof SchemaConnectionFactory))
throw new IllegalArgumentException();
super.setConnectionFactory(connectionFactory);
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public User getCreateUser()
{
return createUser;
}
@Override
public void setCreateUser(User createUser)
{
this.createUser = createUser;
}
public Date getCreateTime()
{
return createTime;
}
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
@Override
public int getDataPermission()
{
return dataPermission;
}
@Override
public void setDataPermission(int dataPermission)
{
this.dataPermission = dataPermission;
}
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.management.service;
import org.datagear.management.domain.SqlDataSetFactoryEntity;
/**
* {@linkplain SqlDataSetFactoryEntity}业务服务接口
*
* @author datagear@163.com
*
*/
public interface SqlDataSetFactoryEntityService extends EntityService<String, SqlDataSetFactoryEntity>
{
}

View File

@ -102,6 +102,7 @@ public abstract class AbstractMybatisEntityService<ID, T extends Entity<ID>> ext
params.put("id", id);
T entity = selectOneMybatis("getById", params);
postProcessSelect(entity);
return entity;
}

View File

@ -210,6 +210,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
params.put("param", param);
T entity = selectOneMybatis("get", params);
postProcessSelect(entity);
return entity;
}
@ -251,7 +252,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
addQueryaram(params, query);
List<T> list = selectListMybatis(statement, params);
postProcessSelectList(list);
postProcessSelects(list);
return list;
}
@ -301,7 +302,7 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
addPagingQueryParams(params, startIndex, pagingData.getPageSize());
List<T> list = selectListMybatis(statement, params);
postProcessSelectList(list);
postProcessSelects(list);
pagingData.setItems(list);
@ -328,14 +329,29 @@ public abstract class AbstractMybatisService<T> extends SqlSessionDaoSupport
/**
* 后置处理查询结果列表
*
* @param list
*/
protected void postProcessSelects(List<T> list)
{
if (list == null)
return;
for (T e : list)
postProcessSelect(e);
}
/**
* 后置处理读取结果
* <p>
* 默认为空方法子类可以重写已实现特定的查询结果处理逻辑
* </p>
*
* @param list
* @param obj
*/
protected void postProcessSelectList(List<T> list)
protected void postProcessSelect(T obj)
{
}
/**

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.management.service.impl;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSessionFactory;
import org.datagear.connection.ConnectionSource;
import org.datagear.management.domain.SchemaConnectionFactory;
import org.datagear.management.domain.SqlDataSetFactoryEntity;
import org.datagear.management.domain.User;
import org.datagear.management.service.AuthorizationService;
import org.datagear.management.service.PermissionDeniedException;
import org.datagear.management.service.SchemaService;
import org.datagear.management.service.SqlDataSetFactoryEntityService;
import org.mybatis.spring.SqlSessionTemplate;
/**
* {@linkplain SqlDataSetFactoryEntityService}实现类
*
* @author datagear@163.com
*
*/
public class SqlDataSetFactoryEntityServiceImpl
extends AbstractMybatisDataPermissionEntityService<String, SqlDataSetFactoryEntity>
implements SqlDataSetFactoryEntityService
{
protected static final String SQL_NAMESPACE = SqlDataSetFactoryEntity.class.getName();
private ConnectionSource connectionSource;
private SchemaService schemaService;
private AuthorizationService authorizationService;
public SqlDataSetFactoryEntityServiceImpl()
{
super();
}
public SqlDataSetFactoryEntityServiceImpl(SqlSessionFactory sqlSessionFactory, ConnectionSource connectionSource,
SchemaService schemaService, AuthorizationService authorizationService)
{
super(sqlSessionFactory);
this.connectionSource = connectionSource;
this.schemaService = schemaService;
this.authorizationService = authorizationService;
}
public SqlDataSetFactoryEntityServiceImpl(SqlSessionTemplate sqlSessionTemplate, ConnectionSource connectionSource,
SchemaService schemaService, AuthorizationService authorizationService)
{
super(sqlSessionTemplate);
this.connectionSource = connectionSource;
this.schemaService = schemaService;
this.authorizationService = authorizationService;
}
public ConnectionSource getConnectionSource()
{
return connectionSource;
}
public void setConnectionSource(ConnectionSource connectionSource)
{
this.connectionSource = connectionSource;
}
public SchemaService getSchemaService()
{
return schemaService;
}
public void setSchemaService(SchemaService schemaService)
{
this.schemaService = schemaService;
}
public AuthorizationService getAuthorizationService()
{
return authorizationService;
}
public void setAuthorizationService(AuthorizationService authorizationService)
{
this.authorizationService = authorizationService;
}
@Override
public String getResourceType()
{
return SqlDataSetFactoryEntity.AUTHORIZATION_RESOURCE_TYPE;
}
@Override
public SqlDataSetFactoryEntity getByStringId(User user, String id) throws PermissionDeniedException
{
return super.getById(user, id);
}
@Override
protected boolean deleteById(String id, Map<String, Object> params)
{
boolean deleted = super.deleteById(id, params);
if (deleted)
this.authorizationService.deleteByResource(SqlDataSetFactoryEntity.AUTHORIZATION_RESOURCE_TYPE, id);
return deleted;
}
@Override
protected void postProcessSelects(List<SqlDataSetFactoryEntity> list)
{
// XXX 查询操作仅用于展示不必完全加载
// super.postProcessSelects(list);
}
@Override
protected void postProcessSelect(SqlDataSetFactoryEntity obj)
{
if (obj == null)
return;
SchemaConnectionFactory connectionFactory = obj.getConnectionFactory();
connectionFactory.setSchema(this.schemaService.getById(connectionFactory.getSchema().getId()));
connectionFactory.setConnectionSource(this.connectionSource);
}
@Override
protected void addDataPermissionParameters(Map<String, Object> params, User user)
{
addDataPermissionParameters(params, user, getResourceType(), false, true);
}
@Override
protected String getSqlNamespace()
{
return SQL_NAMESPACE;
}
}

View File

@ -101,7 +101,7 @@ public class UserServiceImpl extends AbstractMybatisEntityService<String, User>
}
@Override
protected void postProcessSelectList(List<User> list)
protected void postProcessSelects(List<User> list)
{
if (list == null)
return;

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.management.util;
import java.sql.Connection;
import org.datagear.connection.ConnectionOption;
import org.datagear.connection.ConnectionSource;
import org.datagear.connection.ConnectionSourceException;
import org.datagear.connection.DriverEntity;
import org.datagear.management.domain.Schema;
/**
* {@linkplain Schema}数据库连接支持类
*
* @author datagear@163.com
*
*/
public class SchemaConnectionSupport
{
public SchemaConnectionSupport()
{
}
/**
* 获取指定{@linkplain Schema}{@linkplain Connection}
*
* @param connectionSource
* @param schema
* @return
* @throws ConnectionSourceException
*/
public Connection getSchemaConnection(ConnectionSource connectionSource, Schema schema)
throws ConnectionSourceException
{
Connection cn = null;
ConnectionOption connectionOption = ConnectionOption.valueOf(schema.getUrl(), schema.getUser(),
schema.getPassword());
if (schema.hasDriverEntity())
{
DriverEntity driverEntity = schema.getDriverEntity();
cn = connectionSource.getConnection(driverEntity, connectionOption);
}
else
{
cn = connectionSource.getConnection(connectionOption);
}
return cn;
}
}

View File

@ -163,3 +163,26 @@ ALTER TABLE DATAGEAR_SQL_HISTORY ADD FOREIGN KEY (SQLHIS_SCHEMA_ID) REFERENCES D
--version[1.5.0], DO NOT EDIT THIS LINE!
-----------------------------------------
CREATE TABLE DATAGEAR_SQL_DATA_SET_FACTORY
(
DSF_ID VARCHAR(50) NOT NULL,
DSF_NAME VARCHAR(100) NOT NULL,
DSF_SCHEMA_ID VARCHAR(50) NOT NULL,
DSF_SQL VARCHAR(50) NOT NULL,
DSF_CREATE_USER_ID VARCHAR(50),
DSF_CREATE_TIME TIMESTAMP,
PRIMARY KEY (DSF_ID)
);
CREATE TABLE DATAGEAR_SQL_DATA_SET_FACTORY_PAR
(
DSFP_DSF_ID VARCHAR(50) NOT NULL,
DSFP_NAME VARCHAR(100) NOT NULL,
DSFP_TYPE VARCHAR(100) NOT NULL,
DSFP_REQUIRED VARCHAR(10),
DSFP_DEFAULT_VALUE VARCHAR(200)
);
ALTER TABLE DATAGEAR_SQL_DATA_SET_FACTORY_PAR ADD FOREIGN KEY (DSFP_DSF_ID) REFERENCES DATAGEAR_SQL_DATA_SET_FACTORY (DSF_ID) ON DELETE CASCADE;
ALTER TABLE DATAGEAR_SQL_DATA_SET_FACTORY_PAR ADD CONSTRAINT UK_DSFP_DSF_ID_NAME UNIQUE (DSFP_DSF_ID, DSFP_NAME);

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.datagear.management.domain.SqlDataSetFactoryEntity">
<insert id="insert">
INSERT INTO DATAGEAR_SQL_DATA_SET_FACTORY
(
DSF_ID, DSF_NAME, DSF_SCHEMA_ID, DSF_SQL, DSF_CREATE_USER_ID,
DSF_CREATE_TIME
)
VALUES
(
#{entity.id}, #{entity.name}, #{entity.connectionFactory.schema.id}, #{entity.sql}, #{entity.createUser.id},
#{entity.createTime}
)
</insert>
<update id="update">
UPDATE DATAGEAR_SQL_DATA_SET_FACTORY SET
DSF_NAME = #{entity.name},
DSF_SCHEMA_ID = #{entity.connectionFactory.schema.id},
DSF_SQL = #{entity.sql}
WHERE
DSF_ID = #{entity.id}
</update>
<delete id="deleteById">
DELETE FROM DATAGEAR_SQL_DATA_SET_FACTORY
WHERE
DSF_ID = #{id}
</delete>
<select id="getById" resultType="org.datagear.management.domain.SqlDataSetFactoryEntity">
SELECT
T.*
FROM
(<include refid="queryViewDataPermission" />) T
WHERE
T.${_iq_}id${_iq_} = #{id}
</select>
<select id="getDataIdPermissions" resultType="org.datagear.management.domain.DataIdPermission">
SELECT
T.DATA_ID as ${_iq_}dataId${_iq_},
T.DATA_PERMISSION as ${_iq_}dataPermission${_iq_}
FROM
(
<include refid="commonDataPermission.dataIdPermissionQueryViewHead" />
<include refid="queryViewDataPermissionId" />
<include refid="commonDataPermission.dataIdPermissionQueryViewFoot" />
) T
WHERE
<foreach item="item" collection="ids" separator=" OR ">T.DATA_ID = #{item}</foreach>
</select>
<select id="query" resultType="org.datagear.management.domain.SqlDataSetFactoryEntity">
SELECT
T.*
FROM
(<include refid="queryViewDataPermission" />) T
WHERE
<include refid="queryCondition" />
<include refid="common.queryOrder" />
</select>
<select id="pagingQueryCount" resultType="int">
SELECT
COUNT(*)
FROM
(<include refid="queryViewDataPermission" />) T
WHERE
<include refid="queryCondition" />
</select>
<select id="pagingQuery" resultType="org.datagear.management.domain.SqlDataSetFactoryEntity">
<include refid="common.pagingQueryHead" />
SELECT
T.*
FROM
(<include refid="queryViewDataPermission" />) T
WHERE
<include refid="queryCondition" />
<include refid="common.queryOrder" />
<include refid="common.pagingQueryFoot" />
</select>
<sql id="queryViewDataPermission">
<choose><when test="DP_CURRENT_USER == null">
<include refid="queryView" />
</when><otherwise>
SELECT
T0.*,
T1.DATA_PERMISSION as ${_iq_}dataPermission${_iq_}
FROM
(<include refid="queryView" />) T0
INNER JOIN
(
<include refid="commonDataPermission.dataIdPermissionQueryViewHead" />
<include refid="queryViewDataPermissionId" />
<include refid="commonDataPermission.dataIdPermissionQueryViewFoot" />
) T1
ON
T0.${_iq_}id${_iq_} = T1.DATA_ID
WHERE
T1.DATA_PERMISSION >= ${DP_MIN_READ_PERMISSION}
</otherwise></choose>
</sql>
<sql id="queryViewDataPermissionId">
SELECT
A.DSF_ID AS DP_AUTH_DATA_ID,
A.DSF_CREATE_USER_ID AS DP_AUTH_DATA_CREATOR_ID
FROM
DATAGEAR_SQL_DATA_SET_FACTORY A
</sql>
<sql id="queryView">
SELECT
A.DSF_ID AS ${_iq_}id${_iq_},
A.DSF_NAME AS ${_iq_}name${_iq_},
B.SCHEMA_ID AS ${_iq_}connectionFactory.schema.id${_iq_},
B.SCHEMA_TITLE AS ${_iq_}connectionFactory.schema.title${_iq_},
A.DSF_SQL AS ${_iq_}sql${_iq_},
<include refid="common.fieldsForCreateUser"></include>
A.DSF_CREATE_USER_ID AS ${_iq_}createUser.id${_iq_},
A.DSF_CREATE_TIME AS ${_iq_}createTime${_iq_}
FROM
DATAGEAR_SQL_DATA_SET_FACTORY A
INNER JOIN
DATAGEAR_SCHEMA B
ON
A.DSF_SCHEMA_ID = B.SCHEMA_ID
LEFT JOIN
DATAGEAR_USER USR
ON
A.DSF_CREATE_USER_ID = USR.USER_ID
</sql>
<sql id="queryCondition">
1 = 1
<if test="queryKeyword != null">
AND
(
${_iq_}name${_iq_} LIKE #{queryKeyword}
OR ${_iq_}connectionFactory.schema.title${_iq_} LIKE #{queryKeyword}
OR ${_iq_}createUser.name${_iq_} LIKE #{queryKeyword}
OR ${_iq_}createUser.realName${_iq_} LIKE #{queryKeyword}
)
</if>
<include refid="common.queryCondition" />
</sql>
</mapper>

View File

@ -21,4 +21,13 @@
ORDER BY ${queryOrder}
</if>
</sql>
<!-- 带有createUser属性的查询字段用于表的别名必须为USR -->
<sql id="fieldsForCreateUser">
USR.USER_NAME AS ${_iq_}createUser.name${_iq_},
USR.USER_REAL_NAME AS ${_iq_}createUser.realName${_iq_},
(CASE WHEN USR.USER_IS_ADMIN IS NULL THEN '0' ELSE USR.USER_IS_ADMIN END) AS ${_iq_}createUser.admin${_iq_},
(CASE WHEN USR.USER_ID IS NULL THEN '1' ELSE '0' END) AS ${_iq_}createUser.anonymous${_iq_},
USR.USER_CREATE_TIME AS ${_iq_}createUser.createTime${_iq_},
</sql>
</mapper>

View File

@ -44,6 +44,11 @@
<artifactId>datagear-dataexchange</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.datagear</groupId>
<artifactId>datagear-analysis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.datagear</groupId>
<artifactId>datagear-util</artifactId>

View File

@ -14,14 +14,13 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.datagear.connection.ConnectionOption;
import org.datagear.connection.ConnectionSource;
import org.datagear.connection.ConnectionSourceException;
import org.datagear.connection.DriverEntity;
import org.datagear.management.domain.Schema;
import org.datagear.management.domain.User;
import org.datagear.management.service.PermissionDeniedException;
import org.datagear.management.service.SchemaService;
import org.datagear.management.util.SchemaConnectionSupport;
import org.datagear.util.JdbcUtil;
import org.datagear.web.convert.ClassDataConverter;
import org.datagear.web.util.WebUtils;
@ -42,6 +41,8 @@ public abstract class AbstractSchemaConnController extends AbstractController
@Autowired
private ConnectionSource connectionSource;
private SchemaConnectionSupport schemaConnectionSupport = new SchemaConnectionSupport();
public AbstractSchemaConnController()
{
super();
@ -75,6 +76,16 @@ public abstract class AbstractSchemaConnController extends AbstractController
this.connectionSource = connectionSource;
}
public SchemaConnectionSupport getSchemaConnectionSupport()
{
return schemaConnectionSupport;
}
public void setSchemaConnectionSupport(SchemaConnectionSupport schemaConnectionSupport)
{
this.schemaConnectionSupport = schemaConnectionSupport;
}
/**
* 获取指定用户有读权限的{@linkplain Schema}
*
@ -127,23 +138,7 @@ public abstract class AbstractSchemaConnController extends AbstractController
*/
protected Connection getSchemaConnection(Schema schema) throws ConnectionSourceException
{
Connection cn = null;
ConnectionOption connectionOption = ConnectionOption.valueOf(schema.getUrl(), schema.getUser(),
schema.getPassword());
if (schema.hasDriverEntity())
{
DriverEntity driverEntity = schema.getDriverEntity();
cn = this.connectionSource.getConnection(driverEntity, connectionOption);
}
else
{
cn = this.connectionSource.getConnection(connectionOption);
}
return cn;
return this.schemaConnectionSupport.getSchemaConnection(this.connectionSource, schema);
}
protected void checkReadTableDataPermission(Schema schema, User user)

View File

@ -0,0 +1,71 @@
/*
* Copyright 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.web.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.datagear.management.domain.SqlDataSetFactoryEntity;
import org.datagear.management.service.SqlDataSetFactoryEntityService;
import org.datagear.persistence.PagingData;
import org.datagear.persistence.PagingQuery;
import org.datagear.web.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 数据集控制器
*
* @author datagear@163.com
*
*/
@Controller
@RequestMapping("/analysis/dataSet")
public class DataSetController extends AbstractController
{
@Autowired
private SqlDataSetFactoryEntityService sqlDataSetFactoryEntityService;
public DataSetController()
{
super();
}
public DataSetController(SqlDataSetFactoryEntityService sqlDataSetFactoryEntityService)
{
super();
this.sqlDataSetFactoryEntityService = sqlDataSetFactoryEntityService;
}
public SqlDataSetFactoryEntityService getSqlDataSetFactoryEntityService()
{
return sqlDataSetFactoryEntityService;
}
public void setSqlDataSetFactoryEntityService(SqlDataSetFactoryEntityService sqlDataSetFactoryEntityService)
{
this.sqlDataSetFactoryEntityService = sqlDataSetFactoryEntityService;
}
@RequestMapping("/pagingQuery")
public String pagingQuery(HttpServletRequest request, org.springframework.ui.Model model)
{
return "/analysis/dataSet/dataSet_grid";
}
@RequestMapping(value = "/pagingQueryData", produces = CONTENT_TYPE_JSON)
@ResponseBody
public PagingData<SqlDataSetFactoryEntity> pagingQueryData(HttpServletRequest request, HttpServletResponse response,
final org.springframework.ui.Model springModel) throws Exception
{
PagingQuery pagingQuery = getPagingQuery(request, WebUtils.COOKIE_PAGINATION_SIZE);
PagingData<SqlDataSetFactoryEntity> pagingData = this.sqlDataSetFactoryEntityService.pagingQuery(pagingQuery);
return pagingData;
}
}

View File

@ -19,16 +19,15 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.cometd.bayeux.server.ServerChannel;
import org.datagear.connection.ConnectionOption;
import org.datagear.connection.ConnectionSource;
import org.datagear.connection.ConnectionSourceException;
import org.datagear.connection.DriverEntity;
import org.datagear.dbmodel.DatabaseModelResolver;
import org.datagear.dbmodel.ModelSqlSelectService;
import org.datagear.dbmodel.ModelSqlSelectService.ModelSqlResult;
import org.datagear.management.domain.Schema;
import org.datagear.management.domain.User;
import org.datagear.management.service.SqlHistoryService;
import org.datagear.management.util.SchemaConnectionSupport;
import org.datagear.model.Model;
import org.datagear.util.IDUtil;
import org.datagear.util.JdbcUtil;
@ -59,6 +58,8 @@ public class SqlpadExecutionService
private SqlPermissionChecker sqlPermissionChecker = new SqlPermissionChecker();
private SchemaConnectionSupport schemaConnectionSupport = new SchemaConnectionSupport();
private ExecutorService _executorService = Executors.newCachedThreadPool();
private ConcurrentMap<String, SqlpadExecutionRunnable> _sqlpadExecutionRunnableMap = new ConcurrentHashMap<String, SqlpadExecutionRunnable>();
@ -150,6 +151,16 @@ public class SqlpadExecutionService
this.sqlPermissionChecker = sqlPermissionChecker;
}
public SchemaConnectionSupport getSchemaConnectionSupport()
{
return schemaConnectionSupport;
}
public void setSchemaConnectionSupport(SchemaConnectionSupport schemaConnectionSupport)
{
this.schemaConnectionSupport = schemaConnectionSupport;
}
/**
* 提交SQL执行
*
@ -234,23 +245,7 @@ public class SqlpadExecutionService
*/
protected Connection getSchemaConnection(Schema schema) throws ConnectionSourceException
{
Connection cn = null;
ConnectionOption connectionOption = ConnectionOption.valueOf(schema.getUrl(), schema.getUser(),
schema.getPassword());
if (schema.hasDriverEntity())
{
DriverEntity driverEntity = schema.getDriverEntity();
cn = this.connectionSource.getConnection(driverEntity, connectionOption);
}
else
{
cn = this.connectionSource.getConnection(connectionOption);
}
return cn;
return this.schemaConnectionSupport.getSchemaConnection(this.connectionSource, schema);
}
/**

View File

@ -304,6 +304,13 @@
</property>
</bean>
<bean id="sqlDataSetFactoryEntityService" class="org.datagear.management.service.impl.SqlDataSetFactoryEntityServiceImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="connectionSource" ref="connectionSource" />
<property name="schemaService" ref="schemaService" />
<property name="authorizationService" ref="authorizationService" />
</bean>
<bean id="sqlHistoryService" class="org.datagear.management.service.impl.SqlHistoryServiceImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

View File

@ -600,4 +600,12 @@ authorization.resourceMeta.DATA_SOURCE.fillPatternLabel.desc=\u53EF\u5728[\u6570
authorization.resourceMeta.DATA_SOURCE.permission.READ.desc=\u4EC5\u53EF\u6D4F\u89C8\u6570\u636E\uFF0C\u6267\u884CSELECT SQL\u8BED\u53E5
authorization.resourceMeta.DATA_SOURCE.permission.EDIT.desc=\u53EF\u6D4F\u89C8\u3001\u7F16\u8F91\u6570\u636E\uFF0C\u6267\u884CSELECT\u3001UPDATE SQL\u8BED\u53E5
authorization.resourceMeta.DATA_SOURCE.permission.DELETE.desc=\u53EF\u6D4F\u89C8\u3001\u7F16\u8F91\u3001\u5220\u9664\u6570\u636E\uFF0C\u6267\u884C\u6240\u6709SQL\u8BED\u53E5
authorization.resourceMeta.DATA_SOURCE.permission.NONE.desc=\u4E0D\u53EF\u8BBF\u95EE
authorization.resourceMeta.DATA_SOURCE.permission.NONE.desc=\u4E0D\u53EF\u8BBF\u95EE
#Data Set
dataSet.dataSet=\u6570\u636E\u96C6
dataSet.name=\u540D\u79F0
dataSet.dataSource=\u6570\u636E\u6E90
dataSet.sql=SQL\u8BED\u53E5
dataSet.createUser=\u521B\u5EFA\u7528\u6237
dataSet.createTime=\u521B\u5EFA\u65F6\u95F4

View File

@ -0,0 +1,84 @@
<#include "../../include/import_global.ftl">
<#include "../../include/html_doctype.ftl">
<html>
<head>
<#include "../../include/html_head.ftl">
<title><#include "../../include/html_title_app_name.ftl"><@spring.message code='dataSet.dataSet' /></title>
</head>
<body class="fill-parent">
<#if !isAjaxRequest>
<div class="fill-parent">
</#if>
<div id="${pageId}" class="page-grid page-grid-data-set">
<div class="head">
<div class="search">
<#include "../../include/page_obj_searchform.html.ftl">
</div>
<div class="operation">
<input name="addButton" type="button" value="<@spring.message code='add' />" />
<input name="editButton" type="button" value="<@spring.message code='edit' />" />
<input name="viewButton" type="button" value="<@spring.message code='view' />" />
<input name="deleteButton" type="button" value="<@spring.message code='delete' />" />
</div>
</div>
<div class="content">
<table id="${pageId}-table" width="100%" class="hover stripe">
</table>
</div>
<div class="foot">
<div class="pagination-wrapper">
<div id="${pageId}-pagination" class="pagination"></div>
</div>
</div>
</div>
<#if !isAjaxRequest>
</div>
</#if>
<#include "../../include/page_js_obj.ftl">
<#include "../../include/page_obj_searchform_js.ftl">
<#include "../../include/page_obj_pagination.ftl">
<#include "../../include/page_obj_grid.ftl">
<script type="text/javascript">
(function(po)
{
$.initButtons(po.element(".operation"));
po.url = function(action)
{
return "${contextPath}/analysis/dataSet/" + action;
};
po.buildTableColumValueOption = function(title, data)
{
var option =
{
title : title,
data : data,
render: function(data, type, row, meta)
{
return data;
},
defaultContent: "",
};
return option;
};
var tableColumns = [
po.buildTableColumValueOption("<@spring.message code='dataSet.name' />", "name"),
po.buildTableColumValueOption("<@spring.message code='dataSet.dataSource' />", "connectionFactory.schema.title"),
po.buildTableColumValueOption("<@spring.message code='dataSet.sql' />", "sql"),
po.buildTableColumValueOption("<@spring.message code='dataSet.createUser' />", "createUser.realName"),
po.buildTableColumValueOption("<@spring.message code='dataSet.createTime' />", "createTime"),
];
po.initPagination();
var tableSettings = po.buildDataTableSettingsAjax(tableColumns, po.url("pagingQueryData"));
tableSettings.order=[[1,"desc"]];
po.initDataTable(tableSettings);
})
(${pageId});
</script>
</body>
</html>

View File

@ -972,11 +972,12 @@
var tabId = "dataAnalysis-";
var tabName = $node.text();
var tabUrl = "${contextPath}/about";
var tabUrl = "${contextPath}/analysis/";
if($node.hasClass("item-dataset"))
{
tabId += "dataset";
tabUrl += "dataSet/pagingQuery";
}
else if($node.hasClass("item-chart"))
{

View File

@ -88,6 +88,7 @@
<url-pattern>/resetPasswordRequestHistory/*</url-pattern>
<url-pattern>/globalSetting/*</url-pattern>
<url-pattern>/notification/*</url-pattern>
<url-pattern>/analysis/*</url-pattern>
</servlet-mapping>
<servlet>