提交 a39061a2 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 扫描时length为null。

上级 c8ac74d4
......@@ -11,6 +11,7 @@ import com.tykj.workflowcore.model_layer.entity.vo.*;
import com.tykj.workflowcore.model_layer.entity.*;
import com.tykj.workflowcore.model_layer.myEnum.ModelType;
import com.tykj.workflowcore.model_layer.service.ModelService;
import com.tykj.workflowcore.model_layer.utils.CreateTableUtil;
import com.tykj.workflowcore.model_layer.utils.SessionUtil;
import com.tykj.workflowcore.model_layer.utils.SqlUtil;
import io.swagger.annotations.ApiModel;
......@@ -136,8 +137,7 @@ public class ModelImpl implements ModelService {
sessionUtil.addXml(xmlMapping);
Session session = sessionUtil.getSession();
// CreateTableUtil creatTableUtil = new CreateTableUtil();
// Session session = creatTableUtil.getSession(entityManagerFactory, xmlMapping);
List<ColumnVO> dataList = tableVO.getDataList();
TableInfo tableInfo = new TableInfo();
......@@ -222,10 +222,9 @@ public class ModelImpl implements ModelService {
* @Date 16:17 2021/3/5
**/
public void insertValue(String tableName, Map map) {
/*
CreateTableUtil createTableUtil = new CreateTableUtil();
Session newSession = createTableUtil.getSession(entityManagerFactory, xml);
*/
Session newSession = sessionUtil.getSession();
......@@ -341,10 +340,10 @@ public class ModelImpl implements ModelService {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setFieldName(columnVO.getFieldName());
columnInfo.setFieldType(columnVO.getFieldType());
columnInfo.setFieldLength(columnVO.getFieldLength());
columnInfo.setFieldLength(setLength(genericType.toString()));
columnInfo.setFieldTitle(columnVO.getFieldTitle());
columnInfo.setPrimaryKey(columnVO.getPrimaryKey());
setLength(columnInfo, genericType.toString());
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
......
package com.tykj.workflowcore.model_layer.utils;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
/**
* @ClassName ClassTypeLength
* @Description TODO
......@@ -11,23 +9,22 @@ import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
* @Version 1.0
*/
public class ClassTypeLength {
public static String STRING="class java.lang.String";
public static String Integer="class java.lang.Integer";
public static String Double="class java.lang.Double";
public static void setLength(ColumnInfo columnInfo , String genericType){
public static String STRING = "class java.lang.String";
public static String Integer = "class java.lang.Integer";
public static String Double = "class java.lang.Double";
public static int setLength(String genericType) {
int length ;
if (STRING.equals(genericType)){
columnInfo.setFieldLength(255);
if (STRING.equals(genericType)) {
length = 255;
} else if (Integer.equals(genericType)) {
columnInfo.setFieldLength(11);
length = 11;
} else if (Double.equals(genericType)) {
columnInfo.setFieldLength(10);
}
else {
columnInfo.setFieldLength(0);
length = 10;
} else {
length = 0;
}
return length;
}
}
package com.tykj.workflowcore.model_layer.utils;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.entity.vo.ColumnVO;
import com.tykj.workflowcore.model_layer.entity.vo.TableVO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
import sun.rmi.runtime.NewThreadAction;
import javax.persistence.EntityManagerFactory;
import java.io.ByteArrayInputStream;
import java.util.EnumSet;
import java.util.List;
/**
......@@ -55,26 +44,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);
sessionFactory.getSessionFactoryOptions();
metadataSources.addInputStream(new ByteArrayInputStream(xml.getBytes()));
Metadata metadata = metadataSources.buildMetadata();
//更新数据库Schema,如果不存在就创建表,存在就更新字段,不会影响已有数据
SchemaUpdate schemaUpdate = new SchemaUpdate();
schemaUpdate.execute(EnumSet.of(TargetType.DATABASE), metadata, serviceRegistry);
metadata = metadataSources.buildMetadata();
//创建会话工厂
SessionFactory newSessionFactory = metadata.buildSessionFactory();
//保存对象
Session newSession = newSessionFactory.openSession();
return newSession;
}
public static String getClassName(String aClass) {
......
......@@ -478,14 +478,14 @@ class WorkflowCoreApplicationTests {
// }
@Test
public void testJSON() {
String xml = tableInfoExDao.findById(3).get().getXml();
String xml = tableInfoExDao.findById(4).get().getXml();
sessionUtil.addXml(xml);
Session session = sessionUtil.getSession();
List list = session.createQuery("from people_car").list();
List list = session.createQuery("from student_teacher_ref").list();
System.out.println(list);
String jsonExample = modelHelper.getJsonExample(2);
System.out.println(jsonExample);
// String jsonExample = modelHelper.getJsonExample(2);
// System.out.println(jsonExample);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论