浏览代码

junit的@Test读取的是test里面的配置文件。统一配置文件。

liutong3 5 年之前
父节点
当前提交
e37fa2693a

+ 2 - 2
ipu-db-example/src/main/java/com/ai/ipu/example/db/IpuSqlMgmtExample.java

@ -20,7 +20,7 @@ public class IpuSqlMgmtExample {
20 20
    @Test
21 21
    public void testGetSqlByDb() {
22 22
        try {
23
            String connName = "test";
23
            String connName = "db_druid";
24 24
            ISqlMgmtDao dao = SqlMgmtDaoFactory.createDbSqlMgmtDao(connName);
25 25
            JMap params = new JsonMap();
26 26
            params.put("pk", 0);
@ -36,7 +36,7 @@ public class IpuSqlMgmtExample {
36 36
    @Test
37 37
    public void testGetSqlByFile() {
38 38
        try {
39
            String connName = "test";
39
            String connName = "db_druid";
40 40
            ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
41 41
            JMap params = new JsonMap();
42 42
            params.put("pk", 0);

+ 1 - 1
ipu-db-example/src/main/java/com/ai/ipu/example/db/IpuSqlParseExample.java

@ -29,7 +29,7 @@ public class IpuSqlParseExample {
29 29
     */
30 30
    @Test
31 31
    public void testParseWithConnName() {
32
        SqlParser sqlParser = new SqlParser("test", "select string_type, int_type from ipu_db_demo where pk = '1'");
32
        SqlParser sqlParser = new SqlParser("db_druid", "select string_type, int_type from ipu_db_demo where pk = '1'");
33 33
        System.out.println("sql语句类型:" + sqlParser.getType());
34 34
        System.out.println("查询的表是:" + sqlParser.getTableName());
35 35
        System.out.println("查询条件是:" + sqlParser.getWhere());

+ 4 - 4
ipu-db-example/src/main/java/com/ai/ipu/example/db/dao/IpuDbDemoDao.java

@ -24,9 +24,9 @@ public class IpuDbDemoDao extends AbstractBizDao {
24 24
        List<IpuDbDemoDto> list = new ArrayList<IpuDbDemoDto>();
25 25
        for (Map<String, Object> obj : result) {
26 26
            IpuDbDemoDto ipuDbDemoDto = new IpuDbDemoDto();
27
            ipuDbDemoDto.setPk((int) obj.get("pk"));
27
            ipuDbDemoDto.setPk((Integer) obj.get("pk"));
28 28
            ipuDbDemoDto.setString_type((String) obj.get("string_type"));
29
            ipuDbDemoDto.setInt_type((int) obj.get("int_type"));
29
            ipuDbDemoDto.setInt_type((Integer) obj.get("int_type"));
30 30
            ipuDbDemoDto.setDecimal_type((BigDecimal) obj.get("decimal_type"));
31 31
            ipuDbDemoDto.setDate_type((Date) obj.get("date_type"));
32 32
            ipuDbDemoDto.setDatetime_type((Date) obj.get("datetime_type"));
@ -46,9 +46,9 @@ public class IpuDbDemoDao extends AbstractBizDao {
46 46
        } else {
47 47
            Map<String, Object> obj = result.get(0);
48 48
            IpuDbDemoDto ipuDbDemoDto = new IpuDbDemoDto();
49
            ipuDbDemoDto.setPk((int) obj.get("pk"));
49
            ipuDbDemoDto.setPk((Integer) obj.get("pk"));
50 50
            ipuDbDemoDto.setString_type((String) obj.get("string_type"));
51
            ipuDbDemoDto.setInt_type((int) obj.get("int_type"));
51
            ipuDbDemoDto.setInt_type((Integer) obj.get("int_type"));
52 52
            ipuDbDemoDto.setDecimal_type((BigDecimal) obj.get("decimal_type"));
53 53
            ipuDbDemoDto.setDate_type((Date) obj.get("date_type"));
54 54
            ipuDbDemoDto.setDatetime_type((Date) obj.get("datetime_type"));

+ 1 - 1
ipu-db-example/src/main/java/com/ai/ipu/example/db/service/IpuDbDemoService.java

@ -19,7 +19,7 @@ public class IpuDbDemoService {
19 19
     * 获取test的dao
20 20
     */
21 21
    public IpuDbDemoService() throws Exception {
22
        dao = IpuDaoManager.takeDao(IpuDbDemoDao.class, "test");
22
        dao = IpuDaoManager.takeDao(IpuDbDemoDao.class, "db_druid");
23 23
    }
24 24
25 25
    public List<IpuDbDemoDto> select() throws Exception {

+ 0 - 41
ipu-db-example/src/main/resources/ipu-mybatis-config.xml

@ -1,41 +0,0 @@
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE configuration
3
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
5
6
<configuration>
7
    <settings>
8
		<setting name="defaultFetchSize" value="1000" /> <!-- 结果集获取数量提示值,分批传输 -->
9
	</settings>
10
    <plugins>
11
        <!--&lt;!&ndash; 分页插件,可根据参数定制化 &ndash;&gt;-->
12
	    <!--<plugin interceptor="com.github.pagehelper.PageInterceptor">-->
13
	        <!--&lt;!&ndash; config params as the following &ndash;&gt;-->
14
		<!--</plugin>-->
15
		<plugin interceptor="com.ai.ipu.sql.mgmt.mybatis.SqlMgmtPlugin">
16
        </plugin>
17
	</plugins>
18
	<environments default="test">
19
        <environment id="test">
20
            <transactionManager type="JDBC" />
21
            <dataSource type="com.ai.ipu.database.datasource.DruidDataSourceFactory">
22
                <property name="driverClass" value="com.mysql.jdbc.Driver" />
23
                <property name="url" value="jdbc:mysql://47.105.160.21:3307/test" />
24
                <property name="username" value="iputest" />
25
                <property name="password" value="iputest@321" />
26
				<!-- 连接池用完时,等待获取新连接的时间 (毫秒) -->
27
				<property name="maxWait" value="5000" />
28
				<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
29
				<!--<property name="acquireRetryAttempts" value="5" />-->
30
				<!--两次连接中间隔时间,单位毫秒。Default: 1000 -->
31
				<!--<property name="acquireRetryDelay" value="1000" />-->
32
				<property name="initialSize" value="3" />
33
				<property name="minIdle" value="3" />
34
				<property name="maxActive" value="3" />
35
				<!--<property name="maxIdleTime" value="600" />-->
36
				<!--<property name="idleConnectionTestPeriod" value="60" />-->
37
				<property name="validationQuery" value="SELECT 1" />
38
            </dataSource>
39
        </environment>
40
	</environments>
41
</configuration>

+ 0 - 40
ipu-db-example/src/main/resources/sql_mgmt_mybatis.xml

@ -1,40 +0,0 @@
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE configuration
3
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
5
<!-- <!DOCTYPE configuration SYSTEM "mybatis-ipu-3-config.dtd"> -->
6
7
<configuration>
8
    <settings>
9
		<setting name="defaultFetchSize" value="1000" /> <!-- 结果集获取数量提示值,分批传输 -->
10
	</settings>
11
    <plugins>
12
        <!-- 分页插件,可根据参数定制化 -->
13
	    <plugin interceptor="com.github.pagehelper.PageInterceptor">
14
	        <!-- config params as the following -->
15
		</plugin>
16
	</plugins>
17
	<environments default="ipu_sql_mgmt">
18
		<environment id="ipu_sql_mgmt">
19
			<transactionManager type="JDBC" />
20
			<dataSource type="com.ai.ipu.database.datasource.DruidDataSourceFactory">
21
				<property name="driverClass" value="com.mysql.jdbc.Driver" />
22
				<property name="url" value="jdbc:mysql://47.105.160.21:3307/ipu_sql_mgmt" />
23
				<property name="username" value="iputest" />
24
				<property name="password" value="iputest@321" />
25
				<!-- 连接池用完时,等待获取新连接的时间 (毫秒) -->
26
				<property name="maxWait" value="5000" />
27
				<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
28
				<!--<property name="acquireRetryAttempts" value="5" />-->
29
				<!--两次连接中间隔时间,单位毫秒。Default: 1000 -->
30
				<!--<property name="acquireRetryDelay" value="1000" />-->
31
				<property name="initialSize" value="3" />
32
				<property name="minIdle" value="3" />
33
				<property name="maxActive" value="3" />
34
				<!--<property name="maxIdleTime" value="600" />-->
35
				<!--<property name="idleConnectionTestPeriod" value="60" />-->
36
				<property name="validationQuery" value="SELECT 1" />
37
			</dataSource>
38
		</environment>
39
	</environments>
40
</configuration>

+ 1 - 1
ipu-db-example/src/test/java/com/ai/ipu/example/db/mgmt/SqlMgmtDaoExample.java

@ -18,7 +18,7 @@ public class SqlMgmtDaoExample {
18 18
        try{
19 19
            JMap params = new JsonMap();
20 20
            ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
21
            List<Map<String, Object>> dataResult = dao.executeSelect("com.ai.ipu.example.db.ipu_db_demo","select_all_ipu_db_demo", params);
21
            List<Map<String, Object>> dataResult = dao.executeSelect("com.ai.ipu.ipu-db-demo.ipu-db-demo","select", params);
22 22
            System.out.println(dataResult);
23 23
        }catch(Exception e){
24 24
            e.printStackTrace();

+ 27 - 10
ipu-db-example/src/test/resources/ipu-mybatis-config.xml

@ -1,23 +1,40 @@
1 1
<?xml version="1.0" encoding="UTF-8" ?>
2 2
<!DOCTYPE configuration
3
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
3
		PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
4
		"http://mybatis.org/dtd/mybatis-3-config.dtd">
5 5

6 6
<configuration>
7
    <settings>
7
	<settings>
8 8
		<setting name="defaultFetchSize" value="1000" /> <!-- 结果集获取数量提示值,分批传输 -->
9 9
	</settings>
10
    <plugins>
11
	    <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin> <!-- 分页插件,可根据参数定制化 -->
12
	    <plugin interceptor="com.ai.ipu.sql.mgmt.mybatis.SqlMgmtPlugin"></plugin>
10
	<plugins>
11
		<!-- 分页插件,可根据参数定制化 -->
12
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
13
			<!-- config params as the following -->
14
		</plugin>
15
		<plugin interceptor="com.ai.ipu.sql.mgmt.mybatis.SqlMgmtPlugin">
16
		</plugin>
13 17
	</plugins>
14 18
	<environments default="db_druid">
15 19
		<environment id="db_druid">
16
			<transactionManager type="jdbc" />
20
			<transactionManager type="JDBC" />
17 21
			<dataSource type="com.ai.ipu.database.datasource.DruidDataSourceFactory">
18
				<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://47.105.160.21:3307/test" />
19
				<property name="username" value="ipu" />
20
				<property name="password" value="ipu@321" />
22
				<property name="driverClass" value="com.mysql.jdbc.Driver" />
23
				<property name="url" value="jdbc:mysql://47.105.160.21:3307/test" />
24
				<property name="username" value="iputest" />
25
				<property name="password" value="iputest@321" />
26
				<!-- 连接池用完时,等待获取新连接的时间 (毫秒) -->
27
				<property name="maxWait" value="5000" />
28
				<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
29
				<!--<property name="acquireRetryAttempts" value="5" />-->
30
				<!--两次连接中间隔时间,单位毫秒。Default: 1000 -->
31
				<!--<property name="acquireRetryDelay" value="1000" />-->
32
				<property name="initialSize" value="3" />
33
				<property name="minIdle" value="3" />
34
				<property name="maxActive" value="3" />
35
				<!--<property name="maxIdleTime" value="600" />-->
36
				<!--<property name="idleConnectionTestPeriod" value="60" />-->
37
				<property name="validationQuery" value="SELECT 1" />
21 38
			</dataSource>
22 39
		</environment>
23 40
	</environments>

+ 0 - 10
ipu-db-example/src/test/resources/sql/com/ai/ipu/example/db/ipu_db_demo.xml

@ -1,10 +0,0 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<sqls>
3
	<sql name="select_all_ipu_db_demo">
4
		<![cdata[
5
		<select id="select" resultType="java.util.Map" useCache="true">
6
	        select * from ipu_db_demo
7
		</select>
8
		]]>
9
	</sql>
10
<sqls>

+ 219 - 0
ipu-db-example/src/test/resources/sql/com/ai/ipu/ipu-db-demo/ipu-db-demo.xml

@ -0,0 +1,219 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<sqls>
3
	<sql name="select">
4
		<![CDATA[
5
		<select id="select" parameterType="ai.ipu.data.JMap" resultType="java.util.Map" useCache="true">
6
	        select pk, string_type, int_type, decimal_type, date_type, datetime_type, null_type from ipu_db_demo
7
	        <where>
8
	            <if test="pk != null">
9
	                pk = #{pk}
10
	            </if>
11
	            <if test="string_type != null">
12
	                string_type = #{string_type}
13
	            </if>
14
	            <if test="int_type != null">
15
	                int_type = #{int_type}
16
	            </if>
17
	            <if test="decimal_type != null">
18
	                decimal_type = #{decimal_type}
19
	            </if>
20
	            <if test="date_type != null">
21
	                date_type = #{date_type}
22
	            </if>
23
	            <if test="datetime_type != null">
24
	                datetime_type = #{datetime_type}
25
	            </if>
26
	            <if test="null_type != null">
27
	            	<if test="null_type == true">
28
	                	null_type is null
29
	                </if>
30
	                <if test="null_type == false">
31
	                	null_type is not null
32
	                </if>
33
	            </if>
34
	        </where>
35
		</select>
36
		]]>
37
	</sql>
38
39
	<sql name="select_javabean">
40
		<![CDATA[
41
		<select id="select" parameterType="com.ai.ipu.sql.mgmt.IpuDbDemoBean" resultType="com.ai.ipu.sql.mgmt.IpuDbDemoBean" useCache="true" >
42
	        select pk, string_type, int_type, decimal_type, date_type, datetime_type, null_type from ipu_db_demo
43
	        <where>
44
	            <if test="pk != null">
45
	                pk = #{pk}
46
	            </if>
47
	            <if test="string_type != null">
48
	                string_type = #{string_type}
49
	            </if>
50
	            <if test="int_type != null">
51
	                int_type = #{int_type}
52
	            </if>
53
	            <if test="decimal_type != null">
54
	                decimal_type = #{decimal_type}
55
	            </if>
56
	            <if test="date_type != null">
57
	                date_type = #{date_type}
58
	            </if>
59
	            <if test="datetime_type != null">
60
	                datetime_type = #{datetime_type}
61
	            </if>
62
	            <if test="null_type != null">
63
	            	<if test="null_type == true">
64
	                	null_type is null
65
	                </if>
66
	                <if test="null_type == false">
67
	                	null_type is not null
68
	                </if>
69
	            </if>
70
	        </where>
71
		</select>
72
		]]>
73
	</sql>
74
75
	<sql name="simple_select">
76
		<![CDATA[
77
        select pk, string_type, int_type, decimal_type, date_type, datetime_type, null_type from ipu_db_demo where
78
            1 = 1
79
            <if test="pk != null">
80
	            and pk = #{pk}
81
	        </if>
82
	        <if test="string_type != null">
83
                and string_type = #{string_type}
84
	        </if>
85
	        <if test="int_type != null">
86
                and int_type = #{int_type}
87
	        </if>
88
	        <if test="decimal_type != null">
89
                and decimal_type = #{decimal_type}
90
            </if>
91
            <if test="date_type != null">
92
                and date_type = #{date_type}
93
            </if>
94
            <if test="datetime_type != null">
95
                and datetime_type = #{datetime_type}
96
            </if>
97
            <if test="null_type != null">
98
            	<if test="null_type == true">
99
                	and null_type is null
100
                </if>
101
                <if test="null_type == false">
102
                	and null_type is not null
103
                </if>
104
            </if>
105
		]]>
106
	</sql>
107
108
	<sql name="update">
109
		<![CDATA[
110
		<update id="update" parameterType="ai.ipu.data.JMap">
111
		update ipu_db_demo
112
			<set>
113
				<if test="string_type != null">
114
					string_type = #{string_type},
115
				</if>
116
				<if test="int_type != null">
117
					int_type = #{int_type},
118
				</if>
119
				<if test="decimal_type != null">
120
					decimal_type = #{decimal_type},
121
				</if>
122
				<if test="date_type != null">
123
					date_type = #{date_type},
124
				</if>
125
				<if test="datetime_type != null">
126
					datetime_type = #{datetime_type},
127
				</if>
128
				<if test="null_type != null">
129
					<if test="null_type == true">
130
						null_type = null
131
					</if>
132
					<if test="null_type == false">
133
						null_type = ''
134
					</if>
135
				</if>
136
			</set>
137
			where
138
				pk = #{pk}
139
		</update>
140
		]]>
141
	</sql>
142
143
	<sql name="simple_update">
144
		<![CDATA[
145
		update ipu_db_demo
146
		<set>
147
			<if test="string_type != null">
148
					string_type = #{string_type},
149
				</if>
150
			<if test="int_type != null">
151
				int_type = #{int_type},
152
			</if>
153
			<if test="decimal_type != null">
154
				decimal_type = #{decimal_type},
155
			</if>
156
			<if test="date_type != null">
157
				date_type = #{date_type},
158
			</if>
159
			<if test="datetime_type != null">
160
				datetime_type = #{datetime_type},
161
			</if>
162
			<if test="null_type != null">
163
				<if test="null_type == true">
164
					null_type = null
165
				</if>
166
				<if test="null_type == false">
167
					null_type = ''
168
				</if>
169
			</if>
170
		</set>
171
		where
172
		pk = #{pk}
173
		]]>
174
	</sql>
175
176
	<sql name="insert">
177
		<![CDATA[
178
		<insert id="insert" parameterType="ai.ipu.data.JMap">
179
			insert into ipu_db_demo (pk, string_type, int_type, decimal_type, date_type, datetime_type, null_type)
180
			values (#{pk}, #{string_type}, #{int_type}, #{decimal_type}, #{date_type}, #{datetime_type},
181
			<if test="null_type == true">
182
				null
183
			</if>
184
			<if test="null_type == false">
185
				''
186
			</if>
187
			)
188
		</insert>
189
		]]>
190
	</sql>
191
192
	<sql name="simple_insert">
193
		<![CDATA[
194
		insert into ipu_db_demo (pk, string_type, int_type, decimal_type, date_type, datetime_type, null_type)
195
		values (#{pk}, #{string_type}, #{int_type}, #{decimal_type}, #{date_type}, #{datetime_type},
196
		<if test="null_type == true">
197
			null
198
		</if>
199
		<if test="null_type == false">
200
			''
201
		</if>
202
		)
203
		]]>
204
	</sql>
205
206
	<sql name="delete">
207
		<![CDATA[
208
		<delete id="delete" parameterType="ai.ipu.data.JMap">
209
			delete from ipu_db_demo where pk = #{pk}
210
		</delete>
211
		]]>
212
	</sql>
213
214
	<sql name="simple_delete">
215
		<![CDATA[
216
			delete from ipu_db_demo where pk = #{pk}
217
		]]>
218
	</sql>
219
</sqls>

+ 15 - 3
ipu-db-example/src/test/resources/sql_mgmt_mybatis.xml

@ -19,9 +19,21 @@
19 19
			<transactionManager type="JDBC" />
20 20
			<dataSource type="com.ai.ipu.database.datasource.DruidDataSourceFactory">
21 21
				<property name="driverClass" value="com.mysql.jdbc.Driver" />
22
				<property name="jdbcUrl" value="jdbc:mysql://121.42.183.206:3307/ipu_sql_mgmt" />
23
				<property name="username" value="ipu" />
24
				<property name="password" value="ipumysql" />
22
				<property name="url" value="jdbc:mysql://47.105.160.21:3307/ipu_sql_mgmt" />
23
				<property name="username" value="iputest" />
24
				<property name="password" value="iputest@321" />
25
				<!-- 连接池用完时,等待获取新连接的时间 (毫秒) -->
26
				<property name="maxWait" value="5000" />
27
				<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
28
				<!--<property name="acquireRetryAttempts" value="5" />-->
29
				<!--两次连接中间隔时间,单位毫秒。Default: 1000 -->
30
				<!--<property name="acquireRetryDelay" value="1000" />-->
31
				<property name="initialSize" value="3" />
32
				<property name="minIdle" value="3" />
33
				<property name="maxActive" value="3" />
34
				<!--<property name="maxIdleTime" value="600" />-->
35
				<!--<property name="idleConnectionTestPeriod" value="60" />-->
36
				<property name="validationQuery" value="SELECT 1" />
25 37
			</dataSource>
26 38
		</environment>
27 39
	</environments>