提交 722775bf authored 作者: ww1xhqc's avatar ww1xhqc

model layer 代码规约检查

上级 b237fd37
...@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Import; ...@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Import;
import java.lang.annotation.*; import java.lang.annotation.*;
/**
* @author HASEE
*/
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE}) @Target({ElementType.TYPE})
@Documented @Documented
......
...@@ -15,5 +15,4 @@ import java.lang.annotation.Target; ...@@ -15,5 +15,4 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface WorkFlowCoreNoScan { public @interface WorkFlowCoreNoScan {
String desc ="工作流核心不扫描!";
} }
...@@ -4,6 +4,7 @@ package com.tykj.workflowcore.model_layer.controller; ...@@ -4,6 +4,7 @@ package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.base.result.ResultUtil; import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.model_layer.model.QueryCondition; import com.tykj.workflowcore.model_layer.model.QueryCondition;
import com.tykj.workflowcore.model_layer.model.SearchTableInfoVo;
import com.tykj.workflowcore.model_layer.model.TableInfo; import com.tykj.workflowcore.model_layer.model.TableInfo;
import com.tykj.workflowcore.model_layer.model.TableVO; import com.tykj.workflowcore.model_layer.model.TableVO;
import com.tykj.workflowcore.model_layer.service.ModelService; import com.tykj.workflowcore.model_layer.service.ModelService;
...@@ -11,6 +12,7 @@ import io.swagger.annotations.Api; ...@@ -11,6 +12,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -43,11 +45,10 @@ public class ModelController { ...@@ -43,11 +45,10 @@ public class ModelController {
**/ **/
@ApiOperation("得到所有数据表信息") @ApiOperation("得到所有数据表信息")
@RequestMapping("/getAllEntity") @RequestMapping("/getAllEntity")
public ResponseEntity getAllEntity() { public ResponseEntity getAllEntity(SearchTableInfoVo searchTableInfoVo) {
Page<TableInfo> tableInfos = null;
List<TableInfo> tableInfos = null;
try { try {
tableInfos = modelService.ListAllEntities(); tableInfos = modelService.listAllEntities(searchTableInfoVo);
} catch (SQLException throwables) { } catch (SQLException throwables) {
throwables.printStackTrace(); throwables.printStackTrace();
} }
...@@ -80,16 +81,14 @@ public class ModelController { ...@@ -80,16 +81,14 @@ public class ModelController {
**/ **/
@ApiOperation("新增数据模型") @ApiOperation("新增数据模型")
@PostMapping("/addModel") @PostMapping("/addModel")
//入参使用VO直接接收即可
//jsonStr -> TableVo
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception { public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
List<TableInfo> tableInfos = modelService.ListAllEntities(); List<TableInfo> tableInfos = modelService.listAllEntities();
for (TableInfo tableInfo : tableInfos) { for (TableInfo tableInfo : tableInfos) {
if (tableVO.getModelName().equals(tableInfo.getName())) { if (tableVO.getModelName().equals(tableInfo.getName())) {
return ResultUtil.failed("表已经存在!"); return ResultUtil.failed("表已经存在!");
} }
} }
modelService.NewTable(tableVO); modelService.newTable(tableVO);
return ResultUtil.success("","新建成功"); return ResultUtil.success("","新建成功");
} }
......
...@@ -24,7 +24,10 @@ public class ColumnInfo { ...@@ -24,7 +24,10 @@ public class ColumnInfo {
@Column(name = "id") @Column(name = "id")
private long id; private long id;
//0是,1否
/**
* 0是,1否
*/
@Column(name = "primary_key") @Column(name = "primary_key")
private Integer primarykey; private Integer primarykey;
@Column(name = "name") @Column(name = "name")
......
...@@ -18,7 +18,7 @@ public class ColumnVO { ...@@ -18,7 +18,7 @@ public class ColumnVO {
private String filedType; private String filedType;
private String fieldName; private String fieldName;
private String filedDescription; private String filedDescription;
private int filedLength; private Integer filedLength;
private Integer primarykey=1; private Integer primarykey=1;
} }
...@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor; ...@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* @author HASEE
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
......
package com.tykj.workflowcore.model_layer.model;
import com.tykj.workflowcore.base.page.JpaCustomPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName SearchTableInfoVo
* @Description TODO
* @Author WWW
* @Date 2021/3/11 16:06
* @Version 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SearchTableInfoVo extends JpaCustomPage {
private String tableName;
}
...@@ -42,7 +42,10 @@ public class TableInfo implements Serializable { ...@@ -42,7 +42,10 @@ public class TableInfo implements Serializable {
@Column(name = "description") @Column(name = "description")
private String desc; private String desc;
//0是扫描,1是自建
/**
*0是扫描,1是自建
*/
@Column(name = "type") @Column(name = "type")
private Integer type; private Integer type;
...@@ -51,7 +54,7 @@ public class TableInfo implements Serializable { ...@@ -51,7 +54,7 @@ public class TableInfo implements Serializable {
@Lob @Lob
@Column(name = "xml") @Column(name = "xml")
private String XML; private String xml;
@Column(name = "update_time") @Column(name = "update_time")
private Date updateTime; private Date updateTime;
......
...@@ -3,10 +3,8 @@ package com.tykj.workflowcore.model_layer.service; ...@@ -3,10 +3,8 @@ package com.tykj.workflowcore.model_layer.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.tykj.workflowcore.model_layer.model.ColumnInfo; import com.tykj.workflowcore.model_layer.model.*;
import com.tykj.workflowcore.model_layer.model.QueryCondition; import org.springframework.data.domain.Page;
import com.tykj.workflowcore.model_layer.model.TableInfo;
import com.tykj.workflowcore.model_layer.model.TableVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -22,24 +20,67 @@ import java.util.Map; ...@@ -22,24 +20,67 @@ import java.util.Map;
* @Date 2021/2/26 13:36 * @Date 2021/2/26 13:36
* @Version 1.0 * @Version 1.0
*/ */
@Transactional
@Service @Service
public interface ModelService { public interface ModelService {
List<TableInfo> ListAllEntities() throws SQLException; /**
* 分页查询
* @param searchTableInfoVo
* @return
* @throws SQLException
*/
Page<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo) throws SQLException;
/**
* 方法重载不分页查询
* @return
* @throws SQLException
*/
List<TableInfo> listAllEntities() throws SQLException;
List<ColumnInfo> showModelFields(String ModelName);
TableVO addModel(String tableVO) throws JsonProcessingException; /**
* 根据表名查询所有字段信息
* @param modelName
* @return
*/
List<ColumnInfo> showModelFields(String modelName);
TableVO NewTable(TableVO tableVO);
/**
* 新建模型
* @param tableVO
* @return
*/
TableVO newTable(TableVO tableVO);
/**
* 根据表名插入数据
* @param map
* @return
*/
int putValueByEntityName(Map<String, Object> map); int putValueByEntityName(Map<String, Object> map);
/**
* 扫描
* @param classList
*/
void swaggerScan(List<Class<?>> classList); void swaggerScan(List<Class<?>> classList);
/**
* 根据表名查询所有
* @param name
* @return
* @throws SQLException
*/
List findAllByName(String name) throws SQLException; List findAllByName(String name) throws SQLException;
/**
* 复杂查询
* @param tableName
* @param queryConditions
* @return
*/
List complexQuery(String tableName, List<QueryCondition> queryConditions); List complexQuery(String tableName, List<QueryCondition> queryConditions);
} }
package com.tykj.workflowcore.model_layer.service.impl; package com.tykj.workflowcore.model_layer.service.impl;
import cn.hutool.db.Db; import cn.hutool.db.Db;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan; import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao; import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao; import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
...@@ -23,6 +22,7 @@ import org.hibernate.type.StringType; ...@@ -23,6 +22,7 @@ import org.hibernate.type.StringType;
import org.hibernate.type.TimestampType; import org.hibernate.type.TimestampType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -51,7 +51,7 @@ import static com.tykj.workflowcore.model_layer.utils.HqlUtil.createQuery; ...@@ -51,7 +51,7 @@ import static com.tykj.workflowcore.model_layer.utils.HqlUtil.createQuery;
* @Date 2021/2/26 13:39 * @Date 2021/2/26 13:39
* @Version 1.0 * @Version 1.0
*/ */
@Transactional
@Service @Service
@Slf4j @Slf4j
public class ModelImpl implements ModelService { public class ModelImpl implements ModelService {
...@@ -74,48 +74,34 @@ public class ModelImpl implements ModelService { ...@@ -74,48 +74,34 @@ public class ModelImpl implements ModelService {
* @Date 16:14 2021/3/5 * @Date 16:14 2021/3/5
**/ **/
@Override @Override
public List<TableInfo> ListAllEntities() { public Page<TableInfo> listAllEntities( SearchTableInfoVo searchTableInfoVo) {
List<TableInfo> all = tableInfoDao.findAll(); PredicateBuilder<TableInfo> and = Specifications.and();
return all; and.eq(searchTableInfoVo.getTableName()!=null,"name",searchTableInfoVo.getTableName());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
} }
/** /**
* @param TableName * @param tableName
* @return java.util.List<com.tykj.workflowcore.model_layer.model.ColumnInfo> * @return java.util.List<com.tykj.workflowcore.model_layer.model.ColumnInfo>
* @Author WWW * @Author WWW
* @Description 根据表名得到所有字段名 * @Description 根据表名得到所有字段名
* @Date 16:15 2021/3/5 * @Date 16:15 2021/3/5
**/ **/
@Override @Override
public List<ColumnInfo> showModelFields(String TableName) { public List<ColumnInfo> showModelFields(String tableName) {
Specification specification = (Specification) (root, criteriaQuery, criteriaBuilder) -> { Specification specification = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Path db_name = root.get("dbName"); Path dbName = root.get("dbName");
Predicate equal = criteriaBuilder.equal(db_name, TableName); Predicate equal = criteriaBuilder.equal(dbName, tableName);
return equal; return equal;
}; };
List<ColumnInfo> all = columnInfoDao.findAll(specification); List<ColumnInfo> all = columnInfoDao.findAll(specification);
return all; return all;
} }
/**
* @param jsonStr
* @return com.tykj.workflowcore.model_layer.model.TableVO
* @Author WWW
* @Description 将json字符串转换实体类
* @Date 16:15 2021/3/5
**/
@Override
public TableVO addModel(String jsonStr) {
ObjectMapper mapper = new ObjectMapper();
TableVO tableVO = null;
try {
tableVO = mapper.readValue(jsonStr, TableVO.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return tableVO;
}
/** /**
* @param tableVO * @param tableVO
...@@ -125,17 +111,17 @@ public class ModelImpl implements ModelService { ...@@ -125,17 +111,17 @@ public class ModelImpl implements ModelService {
* @Date 16:16 2021/3/5 * @Date 16:16 2021/3/5
**/ **/
@Override @Override
public TableVO NewTable(TableVO tableVO) { public TableVO newTable(TableVO tableVO) {
String XML_MAPPING = CreatTable(tableVO); String xmlMapping = creatTable(tableVO);
CreatTableUtil creatTableUtil = new CreatTableUtil(); CreatTableUtil creatTableUtil = new CreatTableUtil();
Session session = creatTableUtil.getSession(entityManagerFactory, XML_MAPPING); Session session = creatTableUtil.getSession(entityManagerFactory, xmlMapping);
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
TableInfo tableInfo = new TableInfo(); TableInfo tableInfo = new TableInfo();
tableInfo.setName(tableVO.getModelName()+"_"); tableInfo.setName(tableVO.getModelName()+"_");
tableInfo.setCnName(tableVO.getModelTitle()); tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(XML_MAPPING); tableInfo.setXml(xmlMapping);
tableInfo.setType(2); tableInfo.setType(2);
tableInfoDao.save(tableInfo); tableInfoDao.save(tableInfo);
...@@ -181,12 +167,12 @@ public class ModelImpl implements ModelService { ...@@ -181,12 +167,12 @@ public class ModelImpl implements ModelService {
Object values = map.get(tableName); Object values = map.get(tableName);
if (values instanceof Map) { if (values instanceof Map) {
//插入数据 //插入数据
insertValue(tableInfo.getName(), tableInfo.getXML(), (Map) values); insertValue(tableInfo.getName(), tableInfo.getXml(), (Map) values);
} else { } else {
//循环插入数据 //循环插入数据
List valuesList = (List) values; List valuesList = (List) values;
for (int i = 0; i < valuesList.size(); i++) { for (int i = 0; i < valuesList.size(); i++) {
insertValue(tableInfo.getName(), tableInfo.getXML(), (Map) valuesList.get(i)); insertValue(tableInfo.getName(), tableInfo.getXml(), (Map) valuesList.get(i));
} }
} }
} }
...@@ -230,7 +216,7 @@ public class ModelImpl implements ModelService { ...@@ -230,7 +216,7 @@ public class ModelImpl implements ModelService {
} }
if (propertyType instanceof StringType) { if (propertyType instanceof StringType) {
//然后调用强转方法 //然后调用强转方法
propertyNames[i] = propertyNames[i] + ""; propertyNames[i] = propertyNames[i];
map.put(propertyNames[i], propertyNames[i]); map.put(propertyNames[i], propertyNames[i]);
} }
} }
...@@ -253,16 +239,16 @@ public class ModelImpl implements ModelService { ...@@ -253,16 +239,16 @@ public class ModelImpl implements ModelService {
//获得类中文描述 //获得类中文描述
if (aClass.isAnnotationPresent(ApiModel.class)) { if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class); ApiModel annotation = aClass.getAnnotation(ApiModel.class);
StringBuilder APiModelDocument = new StringBuilder(); StringBuilder apiModelDocument = new StringBuilder();
if (annotation.value() != null && !annotation.value().equals("")) { if (annotation.value() != null && !"".equals(annotation.value())) {
APiModelDocument.append(annotation.value() + "|"); apiModelDocument.append(annotation.value() + "|");
} }
if (annotation.description() != null && !annotation.description().equals("")) { if (annotation.description() != null && !"".equals(annotation.description())) {
APiModelDocument.append(annotation.description() + "|"); apiModelDocument.append(annotation.description() + "|");
} }
tableVO.setModelTitle(APiModelDocument.toString()); tableVO.setModelTitle(apiModelDocument.toString());
} else { } else {
tableVO.setModelTitle(""); tableVO.setModelTitle("");
} }
...@@ -284,25 +270,25 @@ public class ModelImpl implements ModelService { ...@@ -284,25 +270,25 @@ public class ModelImpl implements ModelService {
//获得属性中文描述 //获得属性中文描述
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) { if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class); ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder ApiModelPropertyDocument = new StringBuilder(); StringBuilder apiModelPropertyDocument = new StringBuilder();
if (annotation.value() != null && !annotation.value().equals("")) { if (annotation.value() != null && !"".equals(annotation.value())) {
ApiModelPropertyDocument.append(annotation.value() + "|"); apiModelPropertyDocument.append(annotation.value() + "|");
} }
if (annotation.example() != null && !annotation.example().equals("")) { if (annotation.example() != null && !"".equals(annotation.example())) {
ApiModelPropertyDocument.append(annotation.example() + "|"); apiModelPropertyDocument.append(annotation.example() + "|");
} }
columnVO.setFiledDescription(ApiModelPropertyDocument.toString()); columnVO.setFiledDescription(apiModelPropertyDocument.toString());
} else { } else {
columnVO.setFiledDescription("无描述"); columnVO.setFiledDescription("无描述");
} }
list.add(columnVO); list.add(columnVO);
} }
tableVO.setDataList(list); tableVO.setDataList(list);
String xml = CreatTable(tableVO); String xml = creatTable(tableVO);
tableInfo.setName(tableVO.getModelName()); tableInfo.setName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle()); tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(xml); tableInfo.setXml(xml);
tableInfo.setType(0); tableInfo.setType(0);
//判断是否存在 //判断是否存在
if (checkRepeat(realName)){ if (checkRepeat(realName)){
...@@ -316,12 +302,12 @@ public class ModelImpl implements ModelService { ...@@ -316,12 +302,12 @@ public class ModelImpl implements ModelService {
columnInfo.setCnName(columnVO.getFiledDescription()); columnInfo.setCnName(columnVO.getFiledDescription());
columnInfo.setPrimarykey(columnVO.getPrimarykey()); columnInfo.setPrimarykey(columnVO.getPrimarykey());
//暂定 简单类型 //暂定 简单类型
if (genericType.toString().equals("class java.lang.String")) { if ("class java.lang.String".equals(genericType.toString())){
columnInfo.setLength(255); columnInfo.setLength(255);
} else if (genericType.toString().equals("class java.lang.Integer")&&genericType.toString().equals("int")) { } else if ("class java.lang.Integer".equals(genericType.toString())) {
columnInfo.setLength(11); columnInfo.setLength(11);
} else if (genericType.toString().equals("class java.lang.Double")) { } else if ("class java.lang.Double".equals(genericType.toString())) {
columnInfo.setLength(10); columnInfo.setLength(10);
} }
else { else {
...@@ -386,7 +372,7 @@ public class ModelImpl implements ModelService { ...@@ -386,7 +372,7 @@ public class ModelImpl implements ModelService {
@Override @Override
public List complexQuery(String tableName, List<QueryCondition> queryConditions) { public List complexQuery(String tableName, List<QueryCondition> queryConditions) {
List<cn.hutool.db.Entity> list=null; List<cn.hutool.db.Entity> list=null;
if (!tableName.equals("")){ if (!"".equals(tableName)){
String query = createQuery(tableName, queryConditions); String query = createQuery(tableName, queryConditions);
try { try {
list = Db.use().query(query); list = Db.use().query(query);
...@@ -400,4 +386,8 @@ public class ModelImpl implements ModelService { ...@@ -400,4 +386,8 @@ public class ModelImpl implements ModelService {
return list ; return list ;
} }
@Override
public List<TableInfo> listAllEntities() {
return tableInfoDao.findAll();
}
} }
package com.tykj.workflowcore.model_layer.utils; package com.tykj.workflowcore.model_layer.utils;
import cn.hutool.json.XML;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan; import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import com.tykj.workflowcore.model_layer.model.ColumnVO; import com.tykj.workflowcore.model_layer.model.ColumnVO;
import com.tykj.workflowcore.model_layer.model.TableInfo; import com.tykj.workflowcore.model_layer.model.TableInfo;
...@@ -32,38 +33,38 @@ import java.util.List; ...@@ -32,38 +33,38 @@ import java.util.List;
* @Version 1.0 * @Version 1.0
*/ */
public class CreatTableUtil { public class CreatTableUtil {
public static String CreatTable(TableVO tableVO){ public static String creatTable(TableVO tableVO){
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
String XML_MAPPING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + String xmlMapping = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE hibernate-mapping PUBLIC\n" + "<!DOCTYPE hibernate-mapping PUBLIC\n" +
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" + " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" + " \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
"<hibernate-mapping>\n" + "<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n"; " <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n";
XML_MAPPING += " <id name=\"id\" type=\"java.lang.Long\" length=\"64\" unsaved-value=\"null\">\n" + xmlMapping += " <id name=\"id\" type=\"java.lang.Long\" length=\"64\" unsaved-value=\"null\">\n" +
" <generator class=\"identity\" />\n" + " <generator class=\"identity\" />\n" +
" </id>"; " </id>";
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
XML_MAPPING += xmlMapping +=
" <property type=\"" + columnVO.getFiledType() + "\" name=\"" + columnVO.getFieldName() + " <property type=\"" + columnVO.getFiledType() + "\" name=\"" + columnVO.getFieldName() +
"\" column=\"" + columnVO.getFieldName() + "\"/>\n"; "\" column=\"" + columnVO.getFieldName() + "\"/>\n";
} }
XML_MAPPING += " </class>" + xmlMapping += " </class>" +
"</hibernate-mapping>"; "</hibernate-mapping>";
return XML_MAPPING; return xmlMapping;
} }
public Session getSession(EntityManagerFactory entityManagerFactory,String XML){ public Session getSession(EntityManagerFactory entityManagerFactory,String xml){
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry(); StandardServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
MetadataSources metadataSources = new MetadataSources(serviceRegistry); MetadataSources metadataSources = new MetadataSources(serviceRegistry);
sessionFactory.getSessionFactoryOptions(); sessionFactory.getSessionFactoryOptions();
metadataSources.addInputStream(new ByteArrayInputStream(XML.getBytes())); metadataSources.addInputStream(new ByteArrayInputStream(xml.getBytes()));
Metadata metadata = metadataSources.buildMetadata(); Metadata metadata = metadataSources.buildMetadata();
//更新数据库Schema,如果不存在就创建表,存在就更新字段,不会影响已有数据 //更新数据库Schema,如果不存在就创建表,存在就更新字段,不会影响已有数据
SchemaUpdate schemaUpdate = new SchemaUpdate(); SchemaUpdate schemaUpdate = new SchemaUpdate();
...@@ -79,13 +80,13 @@ public class CreatTableUtil { ...@@ -79,13 +80,13 @@ public class CreatTableUtil {
} }
//处理.
public static String getClassName(String aClass){ public static String getClassName(String aClass){
int i = aClass.lastIndexOf("."); int i = aClass.lastIndexOf(".");
String substring = aClass.substring(i+1); String substring = aClass.substring(i+1);
return substring; return substring;
} }
// 处理带空格的class
public static String getTypeName(String aClass){ public static String getTypeName(String aClass){
return aClass.replace("class ", ""); return aClass.replace("class ", "");
......
...@@ -5,6 +5,9 @@ import com.tykj.workflowcore.model_layer.model.QueryCondition; ...@@ -5,6 +5,9 @@ import com.tykj.workflowcore.model_layer.model.QueryCondition;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
/**
* @author HASEE
*/
public class HqlUtil { public class HqlUtil {
public static String createQuery(String tableName, List<QueryCondition> conditions) { public static String createQuery(String tableName, List<QueryCondition> conditions) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论