增加DDL对于达梦数据库的适配(细节问题还需调整),目前简单可用
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.ddl.mapper; |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.ResultType; |
| | | import org.apache.ibatis.annotations.Update; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | /** |
| | | * è¾¾æ¢¦æ°æ®åºçæä½æ§è¡å¨ |
| | | */ |
| | | @Repository |
| | | public interface DdlDmMapper extends DdlMapper{ |
| | | |
| | | /** |
| | | * å é¤è¡¨æ ¼ä¸çå |
| | | * @param tableName 表åç§° |
| | | * @param columnName ååç§° |
| | | * @return åå½±åçè¡æ° |
| | | */ |
| | | @Update("alter table ${tableName} DROP COLUMN ${columnName}") |
| | | @Override |
| | | int dropTableColumn(@Param("tableName")String tableName, @Param("columnName")String columnName); |
| | | |
| | | /** |
| | | * å é¤è¡¨æ ¼ |
| | | * @param tableName è¡¨æ ¼åç§° |
| | | * @return å½±åçè¡æ° |
| | | */ |
| | | @Update("drop table if exists ${tableName}") |
| | | @ResultType(Integer.class) |
| | | @Override |
| | | int dropTable(@Param("tableName") String tableName); |
| | | |
| | | /** |
| | | * æ¹éä¿®æ¹æ°æ®åºè¡¨çåæ®µ |
| | | * @param tableName è¡¨æ ¼çåç§° |
| | | * @param attributeSql ä¿®æ¹ç屿§çsql |
| | | * @return å½±åçè¡æ° |
| | | */ |
| | | @Update("alter table ${tableName} modify ( ${attributeSql} ) ") |
| | | @ResultType(Integer.class) |
| | | @Override |
| | | int modifyTableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql); |
| | | |
| | | /** |
| | | * åæ°æ®åºè¡¨ä¸æ¹éæ·»å åæ®µ |
| | | * @param tableName è¡¨æ ¼çåç§° |
| | | * @param attributeSql è¦æ·»å çæ°çsql |
| | | * @return å½±åçè¡æ° |
| | | */ |
| | | @Update("alter table ${tableName} add ( ${attributeSql} )") |
| | | @ResultType(Integer.class) |
| | | @Override |
| | | int addColumn2TableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.ddl.mapper; |
| | | |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | /** |
| | | * è¾¾æ¢¦æ°æ®åºçæä½æ§è¡å¨ |
| | | */ |
| | | @Repository |
| | | public interface DllDmMapper extends DllMapper{ |
| | | |
| | | } |
| | |
| | | package com.vci.ubcs.ddl.mapper; |
| | | |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.ResultType; |
| | | import org.apache.ibatis.annotations.Select; |
| | | import org.apache.ibatis.annotations.Update; |
| | | |
| | | /** |
| | | * Description: |
| | | * |
| | |
| | | */ |
| | | public interface DllMapper { |
| | | |
| | | int createViewBySql(String viewCreateSql); |
| | | @Update({"${viewCreateSql}"}) |
| | | int createViewBySql(@Param("viewCreateSql") String viewCreateSql); |
| | | |
| | | int createTableBySql(String tableName,String attributeSql); |
| | | @Update({"create table ${tableName} ( ${attributeSql} )"}) |
| | | int createTableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql); |
| | | |
| | | int checkTableExist(String tableName); |
| | | @Update({"COMMENT ON TABLE ${tableName} IS '${comment}' "}) |
| | | int commentTable(@Param("tableName") String tableName, @Param("comment") String comment); |
| | | |
| | | int countAll(String tableName); |
| | | @Update({"COMMENT ON column ${tableName}.${columnName} IS '${comment}' "}) |
| | | int commentColumnTable(@Param("tableName") String tableName, @Param("columnName") String columnName, @Param("comment") String comment); |
| | | |
| | | int commentTable(String tableName, String comment); |
| | | @Update({"alter table ${tableName} modify ( ${attributeSql} ) "}) |
| | | int modifyTableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql); |
| | | |
| | | int commentColumnTable(String tableName, String columnName, String comment); |
| | | @Update({"alter table ${tableName} add ( ${attributeSql} )"}) |
| | | int addColumn2TableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql); |
| | | |
| | | int modifyTableBySql(String tableName, String attributeSql); |
| | | @Update({"drop table if exists ${tableName}"}) |
| | | int dropTable(@Param("tableName") String tableName); |
| | | |
| | | int addColumn2TableBySql(String tableName, String attributeSql); |
| | | @Select({"select count(table_name) from user_tables where upper(table_name) = upper(#{tableName,jdbcType=VARCHAR})"}) |
| | | int checkTableExist(@Param("tableName") String tableName); |
| | | |
| | | int dropTable(String tableName); |
| | | @Select({"select count(*) from ${tableName}"}) |
| | | @ResultType(Integer.class) |
| | | int countAll(@Param("tableName") String tableName); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.ddl.processor.ddl; |
| | | |
| | | import com.vci.ubcs.ddl.mapper.DdlDmMapper; |
| | | import com.vci.ubcs.ddl.mapper.DdlMapper; |
| | | import com.vci.ubcs.starter.util.VciSpringUtil; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * è¾¾æ¢¦æ°æ®åºæ§è¡è¡¨æä½sqlçå¤çå¨ |
| | | */ |
| | | @Component |
| | | public class DdlDmMapperProcessor extends DdlMapperProcessor{ |
| | | |
| | | private static final DdlMapper MAPPER = VciSpringUtil.getBean(DdlDmMapper.class); |
| | | |
| | | public DdlDmMapperProcessor() { |
| | | super(MAPPER); |
| | | System.out.println("-----------------"); |
| | | if (MAPPER != null){ |
| | | System.out.println("[success]::å è½½è¾¾æ¢¦æ°æ®åºDDLæä½æå¡æå"); |
| | | }else { |
| | | System.out.println("[fail]::å è½½è¾¾æ¢¦æ°æ®åºDDLæä½æå¡å¤±è´¥"); |
| | | } |
| | | } |
| | | @Override |
| | | public void modifyTableBySqlBase(String tableName, String attributeSql) { |
| | | modifyTableBySql(tableName,attributeSql); |
| | | } |
| | | |
| | | @Override |
| | | boolean support(String url) { |
| | | return "dm.jdbc.driver.DmDriver".equals(url); |
| | | } |
| | | } |
| | |
| | | import com.vci.ubcs.starter.util.VciSpringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | * @author LiHang |
| | | * @date 2023/4/24 |
| | | */ |
| | | @Component |
| | | public class DdlMapperProcessStrategy { |
| | | |
| | | @Value("${spring.datasource.driver-class-name}") |
| | | private static final String DATABASE_DRIVER = ""; |
| | | private String DATABASE_DRIVER; |
| | | |
| | | private final static List<DdlMapperProcessor> PROCESSORS = Lists.newArrayList(); |
| | | |
| | |
| | | PROCESSORS.add(VciSpringUtil.getBean(DdlOracleMapperProcessor.class)); |
| | | PROCESSORS.add(VciSpringUtil.getBean(DdlMySqlMapperProcessor.class)); |
| | | PROCESSORS.add(VciSpringUtil.getBean(DdlMsMapperProcessor.class)); |
| | | PROCESSORS.add(VciSpringUtil.getBean(DdlDmMapperProcessor.class)); |
| | | } |
| | | |
| | | public static DdlMapperProcessor getProcessor(){ |
| | | @Bean("ddlMapper") |
| | | public DdlMapperProcessor getProcessor(){ |
| | | for (DdlMapperProcessor processor : PROCESSORS) { |
| | | if (processor.support(DATABASE_DRIVER)){ |
| | | System.out.println("==========================================="); |
| | | System.out.println("è·åDDLæä½ç±»æåï¼" + processor.getClass().getName()); |
| | | return processor; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.ddl.processor.dll; |
| | | |
| | | import com.vci.ubcs.ddl.bo.DdlFieldMappingAttrBO; |
| | | import com.vci.ubcs.ddl.mapper.DllDmMapper; |
| | | import com.vci.ubcs.ddl.mapper.DllMapper; |
| | | import com.vci.ubcs.starter.util.VciSpringUtil; |
| | | import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; |
| | | import org.apache.commons.collections4.BidiMap; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Description: åºç¨äºè¾¾æ¢¦æ°æ®ï¼çæå建表æä½sqlçå¤çå¨ |
| | | * |
| | | * @author LiHang |
| | | * @date 2023/4/24 |
| | | */ |
| | | @Component |
| | | public class DllDmMapperProcessor extends DllMapperProcessor{ |
| | | |
| | | private static final DllMapper MAPPER = VciSpringUtil.getBean(DllDmMapper.class); |
| | | |
| | | private static final BidiMap<VciFieldTypeEnum, DdlFieldMappingAttrBO> FIELD_MAP = getMappingMapCopy(); |
| | | |
| | | static { |
| | | // éè¦éæ°æ å°çåæ®µç±»åå¨è¿éå |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTDouble,new DdlFieldMappingAttrBO("DOUBLE",26,8,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTInteger,new DdlFieldMappingAttrBO("NUMBER",22,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTLong,new DdlFieldMappingAttrBO("BIGINT",22,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTBoolean,new DdlFieldMappingAttrBO("VARCHAR",5,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTDate,new DdlFieldMappingAttrBO("DATE",null,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTDateTime,new DdlFieldMappingAttrBO("TIMESTAMP",null,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTTime,new DdlFieldMappingAttrBO("TIME",null,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTFilePath,new DdlFieldMappingAttrBO("TEXT",null,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTClob,new DdlFieldMappingAttrBO("CLOB",100,null,true,null)); |
| | | FIELD_MAP.put(VciFieldTypeEnum.VTString,new DdlFieldMappingAttrBO("VARCHAR",255,null,true,null)); |
| | | } |
| | | |
| | | public DllDmMapperProcessor() { |
| | | super(MAPPER); |
| | | System.out.println("-----------------"); |
| | | if (MAPPER != null){ |
| | | System.out.println("[success]::å è½½è¾¾æ¢¦æ°æ®åºDLLæä½æå¡æå"); |
| | | }else { |
| | | System.out.println("[fail]::å è½½è¾¾æ¢¦æ°æ®åºDLLæä½æå¡å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean support(String url) { |
| | | return "dm.jdbc.driver.DmDriver".equals(url); |
| | | } |
| | | |
| | | @Override |
| | | protected DdlFieldMappingAttrBO getMappingBO(VciFieldTypeEnum fieldTypeEnum) { |
| | | return getMappingBOInMap(fieldTypeEnum,FIELD_MAP); |
| | | } |
| | | |
| | | /** |
| | | * ææ°æ®åºå段类åå举ææçVCIåæ®µç±»å |
| | | * |
| | | * @param columnStr æ°æ®åºå段类å |
| | | * @return VCIåæ®µç±»å |
| | | */ |
| | | @Override |
| | | public List<VciFieldTypeEnum> listFieldByColumnStr(String columnStr) { |
| | | return listFieldInMapByColumnStr(columnStr,FIELD_MAP); |
| | | } |
| | | |
| | | @Override |
| | | public VciFieldTypeEnum getFieldTypeByColumnStr(String columnStr, Integer length) { |
| | | return getFieldTypeBeColumnStrInMap(columnStr,length,FIELD_MAP); |
| | | } |
| | | } |
| | |
| | | import com.vci.ubcs.ddl.mapper.DllOracleMapper; |
| | | import com.vci.ubcs.ddl.mapper.DllSqlLiteMapper; |
| | | import com.vci.ubcs.starter.util.VciSpringUtil; |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | |
| | | * @author LiHang |
| | | * @date 2023/4/24 |
| | | */ |
| | | @Component |
| | | public class DllMapperProcessorStrategy { |
| | | |
| | | @Value("${spring.datasource.driver-class-name}") |
| | | private static final String DATABASE_DRIVER = ""; |
| | | private String DATABASE_DRIVER; |
| | | |
| | | public static List<DllMapperProcessor> processors = Lists.newArrayList(); |
| | | |
| | |
| | | processors.add(VciSpringUtil.getBean(DllSqlLiteMapperProcessor.class)); |
| | | processors.add(VciSpringUtil.getBean(DllMySqlMapperProcessor.class)); |
| | | processors.add(VciSpringUtil.getBean(DllOracleMapperProcessor.class)); |
| | | processors.add(VciSpringUtil.getBean(DllDmMapperProcessor.class)); |
| | | } |
| | | |
| | | public static DllMapperProcessor getProcessor(){ |
| | | @Bean("dllMapper") |
| | | public DllMapperProcessor getProcessor(){ |
| | | for (DllMapperProcessor processor : processors) { |
| | | if (processor.support(DATABASE_DRIVER)){ |
| | | System.out.println("==========================================="); |
| | | System.out.println("è·åDLLæä½ç±»æåï¼" + processor.getClass().getName()); |
| | | return processor; |
| | | } |
| | | } |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | /** |
| | | * ddlæ°æ®æä½æå¡ |
| | | */ |
| | | private final DdlMapperProcessor ddlMapper = DdlMapperProcessStrategy.getProcessor(); |
| | | @Autowired |
| | | private DdlMapperProcessor ddlMapper; |
| | | |
| | | |
| | | /** |
| | | * dllæ°æ®æä½æå¡ |
| | | */ |
| | | private final DllMapperProcessor dllMapper = DllMapperProcessorStrategy.getProcessor(); |
| | | @Autowired |
| | | private DllMapperProcessor dllMapper; |
| | | |
| | | private static final String YES = "Y"; |
| | | |