TableInfoMapper.xml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. <update id="useDataBase">
  5. use ${dataBaseName}
  6. </update>
  7. <update id="createMysqlDataBase">
  8. CREATE database IF NOT EXISTS `${dataBaseName}`;
  9. use `${dataBaseName}`;
  10. CREATE TABLE IF NOT EXISTS `${tableName}`
  11. (
  12. <foreach collection="filedList" item="filed" separator=",">
  13. ${filed}
  14. </foreach>
  15. );
  16. </update>
  17. <select id="mysqlDataBaseExist" resultType="int">
  18. SELECT count(1) FROM information_schema.SCHEMATA where SCHEMA_NAME= #{dataBaseName};
  19. </select>
  20. <select id="mysqlTableExist" resultType="int">
  21. SELECT count(1) FROM information_schema.TABLES t, information_schema.SCHEMATA n WHERE t.table_name = #{tableName} AND n.SCHEMA_NAME = #{dataBaseName};
  22. </select>
  23. <select id="sqlServerTableExist" resultType="int">
  24. select count(1) from sysobjects where id = object_id(#{tableName})
  25. </select>
  26. <update id="createSqlServerDataBase">
  27. IF DB_ID ( <![CDATA[ N'${dataBaseName}' ]]>) IS NULL
  28. CREATE DATABASE ${dataBaseName};
  29. </update>
  30. <update id="createSqlServerTable">
  31. use ${dataBaseName};
  32. create table ${tableName}
  33. (
  34. <foreach collection="filedList" item="filed" separator=",">
  35. ${filed}
  36. </foreach>
  37. );
  38. <foreach collection="descriptionList" item="description" separator=";">
  39. ${description}
  40. </foreach>
  41. </update>
  42. <select id="existOrNot" resultType="int">
  43. select count(1) From master.dbo.sysdatabases where name = #{dataBaseName}
  44. </select>
  45. <select id="dmTableExist" resultType="int">
  46. select count(1) from dba_segments where dba_segments.OWNER=#{dataBaseName} and SEGMENT_NAME=#{tableName}
  47. </select>
  48. <select id="dmDataBaseExist" resultType="int">
  49. select COUNT(1) from sysobjects where NAME=#{dataBaseName} and SUBTYPE$ is null
  50. </select>
  51. <update id="createDmDataBase">
  52. CREATE SCHEMA ${databaseName}
  53. </update>
  54. <update id="useDmDataBase">
  55. set schema ${dataBaseName};
  56. </update>
  57. <update id="createDmTable">
  58. create table ${tableName}
  59. (
  60. <foreach collection="filedList" item="filed" separator=",">
  61. ${filed}
  62. </foreach>
  63. );
  64. </update>
  65. <update id="addTableDescription">
  66. ${description}
  67. </update>
  68. <select id="oracleTableExist" resultType="int">
  69. select count(1) from user_tables where table_name=upper(#{tableName})
  70. </select>
  71. <update id="createOracleTable">
  72. create table ${tableName}
  73. (
  74. <foreach collection="filedList" item="filed" separator=",">
  75. ${filed}
  76. </foreach>
  77. )
  78. </update>
  79. <update id="addOracleTableDescription">
  80. ${description}
  81. </update>
  82. </mapper>