TableInfoMapper.xml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.customer.mapper.TableInfoMapper">
  4. <resultMap id="mysqlTableInfoResult" type="com.customer.pojo.TableInfo">
  5. <result property="fieldName" column="fieldName"></result>
  6. <result property="fieldType" column="fieldType"></result>
  7. <result property="isNull" column="isNull" javaType="boolean"></result>
  8. <result property="isPrimary" column="isPrimary" javaType="boolean"></result>
  9. <result property="fieldDescription" column="fieldDescription"></result>
  10. <result property="fieldLength" column="fieldLength"></result>
  11. <result property="isAuto" column="isAuto" javaType="boolean"></result>
  12. </resultMap>
  13. <update id="useDataBase">
  14. use ${dataBaseName}
  15. </update>
  16. <update id="createMysqlDataBase">
  17. CREATE database IF NOT EXISTS `${dataBaseName}`;
  18. CREATE TABLE IF NOT EXISTS `${dataBaseName}`.`${tableName}`
  19. (
  20. <foreach collection="filedList" item="filed" separator=",">
  21. ${filed}
  22. </foreach>
  23. );
  24. </update>
  25. <select id="mysqlDataBaseExist" resultType="int">
  26. SELECT count(1) FROM information_schema.SCHEMATA where SCHEMA_NAME= #{dataBaseName};
  27. </select>
  28. <select id="mysqlTableExist" resultType="int">
  29. SELECT count(1) FROM information_schema.TABLES t, information_schema.SCHEMATA n WHERE t.table_name = #{tableName} AND n.SCHEMA_NAME = #{dataBaseName};
  30. </select>
  31. <select id="tableInfoList" resultType="com.customer.vo.TableInfoVO">
  32. select table_name tableName,create_time createTime,table_comment tableComment from information_schema.tables where table_schema=#{databaseName}
  33. </select>
  34. <!-- <select id="selectDataCount" resultType="int">-->
  35. <!-- SELECT table_rows FROM information_schema.tables-->
  36. <!-- WHERE TABLE_SCHEMA = #{dataBaseName}-->
  37. <!-- and table_name = #{tableName}-->
  38. <!-- </select>-->
  39. <select id="selectDataCount" resultType="int">
  40. select count(1) from ${tableName}
  41. </select>
  42. <delete id="dropMysqlTable">
  43. DROP TABLE IF EXISTS ${tableName};
  44. </delete>
  45. <update id="updateMysqlTable">
  46. DROP TABLE IF EXISTS ${dataBaseName}.${tableName};
  47. CREATE TABLE IF NOT EXISTS `${dataBaseName}`.`${tableName}`
  48. (
  49. <foreach collection="filedList" item="filed" separator=",">
  50. ${filed}
  51. </foreach>
  52. );
  53. </update>
  54. <select id="mysqlTableFieldInfo" resultMap="mysqlTableInfoResult">
  55. SELECT
  56. column_name fieldName,
  57. IF
  58. ( is_nullable = 'NO', TRUE, FALSE ) isNull,
  59. data_type fieldType,
  60. character_maximum_length fieldLength,
  61. IF
  62. ( column_key = 'PRI', TRUE, FALSE ) isPrimary,
  63. column_comment fieldDescription ,
  64. if(extra='auto_increment',true,false) isAuto
  65. FROM
  66. information_schema.COLUMNS
  67. WHERE
  68. table_name = #{tableName}
  69. AND table_schema = #{dataBaseName};
  70. </select>
  71. <select id="sqlServerTableExist" resultType="int">
  72. select count(1) from sysobjects where id = object_id(#{tableName})
  73. </select>
  74. <update id="createSqlServerDataBase">
  75. IF DB_ID ( <![CDATA[ N'${dataBaseName}' ]]>) IS NULL
  76. CREATE DATABASE ${dataBaseName};
  77. </update>
  78. <update id="createSqlServerTable">
  79. use ${dataBaseName};
  80. create table ${tableName}
  81. (
  82. <foreach collection="filedList" item="filed" separator=",">
  83. ${filed}
  84. </foreach>
  85. );
  86. <foreach collection="descriptionList" item="description" separator=";">
  87. ${description}
  88. </foreach>
  89. </update>
  90. <select id="existOrNot" resultType="int">
  91. select count(1) From master.dbo.sysdatabases where name = #{dataBaseName}
  92. </select>
  93. <select id="dmTableExist" resultType="int">
  94. select count(1) from dba_segments where dba_segments.OWNER=#{dataBaseName} and SEGMENT_NAME=#{tableName}
  95. </select>
  96. <select id="dmDataBaseExist" resultType="int">
  97. select COUNT(1) from sysobjects where NAME=#{dataBaseName} and SUBTYPE$ is null
  98. </select>
  99. <update id="createDmDataBase">
  100. CREATE SCHEMA ${databaseName}
  101. </update>
  102. <update id="useDmDataBase">
  103. set schema ${dataBaseName};
  104. </update>
  105. <update id="createDmTable">
  106. create table ${tableName}
  107. (
  108. <foreach collection="filedList" item="filed" separator=",">
  109. ${filed}
  110. </foreach>
  111. );
  112. </update>
  113. <update id="addTableDescription">
  114. ${description}
  115. </update>
  116. <update id="createOracleUser">
  117. CREATE USER ${username} IDENTIFIED BY ${password} DEFAULT TABLESPACE users QUOTA unlimited ON users
  118. </update>
  119. <update id="assignAuthority">
  120. GRANT ALL PRIVILEGES TO ${username}
  121. </update>
  122. <select id="oracleTableExist" resultType="int">
  123. select count(1) from user_tables where table_name=upper(#{tableName})
  124. </select>
  125. <update id="createOracleTable">
  126. create table ${tableName}
  127. (
  128. <foreach collection="filedList" item="filed" separator=",">
  129. ${filed}
  130. </foreach>
  131. )
  132. </update>
  133. <update id="addOracleTableDescription">
  134. ${description}
  135. </update>
  136. </mapper>