123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- package com.yihu.hos.system.service;
- import com.yihu.hos.web.framework.model.ActionResult;
- import com.yihu.hos.web.framework.model.DataGridResult;
- import com.yihu.hos.system.dao.intf.IDatasourceDao;
- import com.yihu.hos.system.model.SystemDatasource;
- import com.yihu.hos.system.service.intf.IDatasourceManager;
- import com.yihu.hos.common.Services;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.List;
- import java.util.Map;
- /**
- * Created by hzp on 2016/1/11.
- */
- @Service(Services.Datasource)
- @Transactional
- public class DatasourceManager implements IDatasourceManager {
- @Autowired
- private IDatasourceDao datasourceDao;
- /**
- * 测试连接
- */
- private boolean testDB(String type, String config)
- {
- try {
- datasourceDao.testDatasource(type,config);
- return true;
- } catch (Exception e) {
- return false;
- }
- }
- /**
- * 根据ID获取数据源信息
- * @return
- */
- @Override
- public SystemDatasource getDatasourcegById(String id) throws Exception
- {
- return datasourceDao.getEntity(SystemDatasource.class, id);
- }
- /**
- * 获取数据源列表
- * @param page
- * @param rows
- * @return
- * @throws Exception
- */
- @Override
- public DataGridResult getDatasource(Map<String, Object> conditionMap, int page, int rows) throws Exception{
- return datasourceDao.getDatasource(conditionMap,page,rows);
- }
- /**
- * 根据组织ID获取据源列表
- */
- @Override
- public DataGridResult getDatasourceByOrg(String orgId) throws Exception{
- return datasourceDao.getDatasourceByOrg(orgId);
- }
- /**
- * 测试数据源
- * @param dataSource
- * @param config
- * @return
- */
- @Override
- public ActionResult testDatasource(String dataSource, String config) {
- try {
- boolean re = testDB(dataSource, config);
- if(re)
- return new ActionResult(true,"测试成功!");
- else
- return new ActionResult(false,"测试失败!");
- }
- catch (Exception e)
- {
- System.out.print(e.getMessage());
- return new ActionResult(false,"测试失败!");
- }
- }
- /**
- * 新增数据源
- * @param obj
- * @return
- */
- @Override
- @Transactional
- public ActionResult addDatasource(SystemDatasource obj) {
- try{
- datasourceDao.saveEntity(obj);
- return new ActionResult(true,"新增成功!");
- }
- catch (Exception ex)
- {
- return new ActionResult(false,"新增失败!");
- }
- }
- /**
- * 修改数据源
- * @param obj
- * @return
- */
- @Override
- @Transactional
- public ActionResult updateDatasource(SystemDatasource obj) {
- try{
- datasourceDao.updateEntity(obj);
- return new ActionResult(true,"修改成功!");
- }
- catch (Exception ex)
- {
- return new ActionResult(false,"修改失败!");
- }
- }
- /**
- * 删除数据源
- */
- @Override
- @Transactional
- public ActionResult deleteDatasource(String id)
- {
- try{
- datasourceDao.deleteEntity(SystemDatasource.class,id);
- return new ActionResult(true,"删除成功!");
- }
- catch (Exception ex)
- {
- return new ActionResult(false,"删除失败!");
- }
- }
- @Override
- public List<SystemDatasource> getDatasources(String orgId) {
- try {
- return datasourceDao.getDatasources(orgId);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }
|