123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.customer.mapper.TableInfoMapper">
-
- <resultMap id="mysqlTableInfoResult" type="com.customer.pojo.TableInfo">
- <result property="fieldName" column="fieldName"></result>
- <result property="fieldType" column="fieldType"></result>
- <result property="isNull" column="isNull" javaType="boolean"></result>
- <result property="isPrimary" column="isPrimary" javaType="boolean"></result>
- <result property="fieldDescription" column="fieldDescription"></result>
- <result property="fieldLength" column="fieldLength"></result>
- <result property="isAuto" column="isAuto" javaType="boolean"></result>
- </resultMap>
- <update id="useDataBase">
- use ${dataBaseName}
- </update>
- <update id="createMysqlDataBase">
- CREATE database IF NOT EXISTS `${dataBaseName}`;
- CREATE TABLE IF NOT EXISTS `${dataBaseName}`.`${tableName}`
- (
- <foreach collection="filedList" item="filed" separator=",">
- ${filed}
- </foreach>
- );
- </update>
- <select id="mysqlDataBaseExist" resultType="int">
- SELECT count(1) FROM information_schema.SCHEMATA where SCHEMA_NAME= #{dataBaseName};
- </select>
- <select id="mysqlTableExist" resultType="int">
- SELECT count(1) FROM information_schema.TABLES t, information_schema.SCHEMATA n WHERE t.table_name = #{tableName} AND n.SCHEMA_NAME = #{dataBaseName};
- </select>
- <select id="tableInfoList" resultType="com.customer.vo.TableInfoVO">
- select table_name tableName,create_time createTime,table_comment tableComment from information_schema.tables where table_schema=#{databaseName}
- </select>
- <!-- <select id="selectDataCount" resultType="int">-->
- <!-- SELECT table_rows FROM information_schema.tables-->
- <!-- WHERE TABLE_SCHEMA = #{dataBaseName}-->
- <!-- and table_name = #{tableName}-->
- <!-- </select>-->
- <select id="selectDataCount" resultType="int">
- select count(1) from ${tableName}
- </select>
- <delete id="dropMysqlTable">
- DROP TABLE IF EXISTS ${tableName};
- </delete>
- <update id="updateMysqlTable">
- DROP TABLE IF EXISTS ${dataBaseName}.${tableName};
- CREATE TABLE IF NOT EXISTS `${dataBaseName}`.`${tableName}`
- (
- <foreach collection="filedList" item="filed" separator=",">
- ${filed}
- </foreach>
- );
- </update>
- <select id="mysqlTableFieldInfo" resultMap="mysqlTableInfoResult">
- SELECT
- column_name fieldName,
- IF
- ( is_nullable = 'NO', TRUE, FALSE ) isNull,
- data_type fieldType,
- character_maximum_length fieldLength,
- IF
- ( column_key = 'PRI', TRUE, FALSE ) isPrimary,
- column_comment fieldDescription ,
- if(extra='auto_increment',true,false) isAuto
- FROM
- information_schema.COLUMNS
- WHERE
- table_name = #{tableName}
- AND table_schema = #{dataBaseName};
- </select>
- <select id="sqlServerTableExist" resultType="int">
- select count(1) from sysobjects where id = object_id(#{tableName})
- </select>
- <update id="createSqlServerDataBase">
- IF DB_ID ( <![CDATA[ N'${dataBaseName}' ]]>) IS NULL
- CREATE DATABASE ${dataBaseName};
- </update>
- <update id="createSqlServerTable">
- use ${dataBaseName};
- create table ${tableName}
- (
- <foreach collection="filedList" item="filed" separator=",">
- ${filed}
- </foreach>
- );
- <foreach collection="descriptionList" item="description" separator=";">
- ${description}
- </foreach>
- </update>
- <select id="existOrNot" resultType="int">
- select count(1) From master.dbo.sysdatabases where name = #{dataBaseName}
- </select>
- <select id="dmTableExist" resultType="int">
- select count(1) from dba_segments where dba_segments.OWNER=#{dataBaseName} and SEGMENT_NAME=#{tableName}
- </select>
- <select id="dmDataBaseExist" resultType="int">
- select COUNT(1) from sysobjects where NAME=#{dataBaseName} and SUBTYPE$ is null
- </select>
- <update id="createDmDataBase">
- CREATE SCHEMA ${databaseName}
- </update>
- <update id="useDmDataBase">
- set schema ${dataBaseName};
- </update>
- <update id="createDmTable">
- create table ${tableName}
- (
- <foreach collection="filedList" item="filed" separator=",">
- ${filed}
- </foreach>
- );
- </update>
- <update id="addTableDescription">
- ${description}
- </update>
- <update id="createOracleUser">
- CREATE USER ${username} IDENTIFIED BY ${password} DEFAULT TABLESPACE users QUOTA unlimited ON users
- </update>
- <update id="assignAuthority">
- GRANT ALL PRIVILEGES TO ${username}
- </update>
- <select id="oracleTableExist" resultType="int">
- select count(1) from user_tables where table_name=upper(#{tableName})
- </select>
- <update id="createOracleTable">
- create table ${tableName}
- (
- <foreach collection="filedList" item="filed" separator=",">
- ${filed}
- </foreach>
- )
- </update>
- <update id="addOracleTableDescription">
- ${description}
- </update>
- </mapper>
|