提交 265a73d1 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 去掉hutool工具

上级 d632f671
......@@ -72,7 +72,7 @@ public interface ModelService {
* @return
* @throws SQLException
*/
List findAllByName(String name) throws SQLException;
List<Map<String, Object>> findAllByName(String name) throws SQLException;
/**
......@@ -81,7 +81,7 @@ public interface ModelService {
* @param queryConditions
* @return
*/
List complexQuery(String tableName, List<QueryCondition> queryConditions);
List<Map<String, Object>> complexQuery(String tableName, List<QueryCondition> queryConditions);
......
package com.tykj.workflowcore.model_layer.service.impl;
import cn.hutool.db.Db;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
......@@ -26,8 +24,8 @@ import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
......@@ -70,6 +68,9 @@ public class ModelImpl implements ModelService {
@Autowired
private ColumnInfoDao columnInfoDao;
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* @param
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
......@@ -361,32 +362,23 @@ public class ModelImpl implements ModelService {
* @Date 10:51 2021/3/11
**/
@Override
public List findAllByName(String name) {
public List<Map<String, Object>> findAllByName(String name) {
if (name != null && name != "") {
try {
return Db.use().findAll(name);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
String sql="select * from "+name;
return jdbcTemplate.queryForList(sql);
}
return null;
}
@Override
public List complexQuery(String tableName, List<QueryCondition> queryConditions) {
List<cn.hutool.db.Entity> list = null;
public List<Map<String, Object>> complexQuery(String tableName, List<QueryCondition> queryConditions) {
if (!"".equals(tableName)) {
String query = createQuery(tableName, queryConditions);
try {
list = Db.use().query(query);
} catch (SQLException throwables) {
throwables.printStackTrace();
return jdbcTemplate.queryForList(query);
}
} else {
return null;
}
return list;
}
@Override
public List<TableInfo> listAllEntities() {
return tableInfoDao.findAll();
......@@ -450,11 +442,8 @@ public class ModelImpl implements ModelService {
private void UpdateColumnName(String tableName, String oldColumnName, String newColumnName) {
// ALTER TABLE stu rename column name to name2;
if (""!=tableName&&tableName!=null){
try {
Db.use().execute(" ALTER TABLE " + tableName + " rename column " + oldColumnName + " to " + newColumnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
jdbcTemplate.execute(" ALTER TABLE " + tableName + " rename column " + oldColumnName + " to " + newColumnName + ";");
}
else {
log.info("列名:{}或者新列名:{}不合法!",oldColumnName,newColumnName);
......@@ -469,11 +458,7 @@ public class ModelImpl implements ModelService {
*/
private void delOneColumn(String tableName, String columnName) {
// ALTER TABLE fab2 DROP test1;
try {
Db.use().execute("ALTER TABLE " + tableName + " DROP " + columnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
jdbcTemplate.execute("ALTER TABLE " + tableName + " DROP " + columnName + ";");
}
/**
......@@ -484,11 +469,7 @@ public class ModelImpl implements ModelService {
*/
private void addOneColumn(String tableName, String columnName, String type) {
// alter table fab2 add test1 varchar(10) not Null;
try {
Db.use().execute(" alter table "+tableName+" add "+columnName+" "+type);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
jdbcTemplate.execute(" alter table "+tableName+" add "+columnName+" "+type);
}
}
......@@ -50,7 +50,6 @@ public class CreateTableUtil {
public Session getSession(EntityManagerFactory entityManagerFactory,String xml){
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
......@@ -68,6 +67,7 @@ public class CreateTableUtil {
Session newSession = newSessionFactory.openSession();
return newSession;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论