Selaa lähdekoodia

添加修改注释

liutong3 5 vuotta sitten
vanhempi
commit
7b0d2cf530

+ 4 - 0
ipu-db-example/pom.xml

@ -32,6 +32,7 @@
32 32
33 33
    <dependencies>
34 34
        <!-- ipu-database -->
35
        <!-- ipu-sql-mgmt依赖了ipu-database,故移除 -->
35 36
        <!--<dependency>-->
36 37
            <!--<groupId>com.ai.ipu</groupId>-->
37 38
            <!--<artifactId>ipu-database</artifactId>-->
@ -42,6 +43,7 @@
42 43
            <groupId>com.ai.ipu</groupId>
43 44
            <artifactId>ipu-sql-parse</artifactId>
44 45
            <version>${ipu}</version>
46
            <!-- ipu-sql-mgmt依赖了ipu-database,故移除 -->
45 47
            <exclusions>
46 48
                <exclusion>
47 49
                    <groupId>com.ai.ipu</groupId>
@ -57,12 +59,14 @@
57 59
            <scope>system</scope>
58 60
            <systemPath>${project.basedir}/libs/ipu-sql-mgmt-3.2-SNAPSHOT.jar</systemPath>
59 61
        </dependency>
62
        <!-- 测试模块 -->
60 63
        <dependency>
61 64
            <groupId>junit</groupId>
62 65
            <artifactId>junit</artifactId>
63 66
            <version>${junit}</version>
64 67
            <scope>compile</scope>
65 68
        </dependency>
69
        <!-- 日志 -->
66 70
        <dependency>
67 71
            <groupId>log4j</groupId>
68 72
            <artifactId>log4j</artifactId>

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

@ -5,6 +5,7 @@ import com.ai.ipu.data.impl.JsonMap;
5 5
import com.ai.ipu.database.conn.SqlSessionManager;
6 6
import com.ai.ipu.sql.mgmt.ISqlMgmtDao;
7 7
import com.ai.ipu.sql.mgmt.SqlMgmtDaoFactory;
8
import org.junit.Before;
8 9
import org.junit.Test;
9 10
10 11
import java.util.List;
@ -16,11 +17,12 @@ import java.util.Map;
16 17
 * @date 2019/10/12 14:44
17 18
 */
18 19
public class IpuSqlMgmtExample {
19
    //通过数据库获取sql并查询
20
    private String connName = "db_druid";
21
22
    //通过数据库获取sql并执行
20 23
    @Test
21 24
    public void testGetSqlByDb() {
22 25
        try {
23
            String connName = "db_druid";
24 26
            ISqlMgmtDao dao = SqlMgmtDaoFactory.createDbSqlMgmtDao(connName);
25 27
            JMap params = new JsonMap();
26 28
            params.put("pk", 0);
@ -33,10 +35,10 @@ public class IpuSqlMgmtExample {
33 35
        }
34 36
    }
35 37
38
    //通过xml文件获取sql并执行,路径为resource/sql/com/ai/ipu/ipu-db-demo/ipu-db-demo.xml
36 39
    @Test
37 40
    public void testGetSqlByFile() {
38 41
        try {
39
            String connName = "db_druid";
40 42
            ISqlMgmtDao dao = SqlMgmtDaoFactory.createFileSqlMgmtDao(connName);
41 43
            JMap params = new JsonMap();
42 44
            params.put("pk", 0);

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

@ -11,7 +11,7 @@ import java.util.*;
11 11
 * @author liutong3
12 12
 * @team IPU
13 13
 * @date 2019/10/15 16:10
14
 * @desc dao层,根据sql调用ipu-database的execute方法连接数据库
14
 * @desc dao层示例,根据sql调用ipu-database的execute方法连接数据库
15 15
 */
16 16
public class IpuDbDemoDao extends AbstractBizDao {
17 17
    public IpuDbDemoDao(String connName) throws IOException {

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

@ -10,13 +10,13 @@ import java.util.List;
10 10
 * @author liutong3
11 11
 * @team IPU
12 12
 * @date 2019/10/15 17:02
13
 * @desc service层,绑定dao
13
 * @desc service层示例,绑定dao
14 14
 */
15 15
public class IpuDbDemoService {
16 16
    private IpuDbDemoDao dao;
17 17
18 18
    /**
19
     * 获取test的dao
19
     * 获取db_druid的dao
20 20
     */
21 21
    public IpuDbDemoService() throws Exception {
22 22
        dao = IpuDaoManager.takeDao(IpuDbDemoDao.class, "db_druid");

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

@ -1,219 +0,0 @@
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>