bbossgroups 31SQLExecutor组件ap使用实例.docx
《bbossgroups 31SQLExecutor组件ap使用实例.docx》由会员分享,可在线阅读,更多相关《bbossgroups 31SQLExecutor组件ap使用实例.docx(25页珍藏版)》请在冰点文库上搜索。
bbossgroups31SQLExecutor组件ap使用实例
bbossgroups3.1SQLExecutor组件api使用实例
Java代码
1./*
2. * Copyright 2008 biaoping.yin
3. *
4. * Licensed under the Apache License, Version 2.0 (the "License");
5. * you may not use this file except in compliance with the License.
6. * You may obtain a copy of the License at
7. *
8. * http:
//www.apache.org/licenses/LICENSE-2.0
9. *
10. * Unless required by applicable law or agreed to in writing, software
11. * distributed under the License is distributed on an "AS IS" BASIS,
12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13. * See the License for the specific language governing permissions and
14. * limitations under the License.
15. */
16.package org.frameworkset.spi.mvc;
17.
18.import java.sql.SQLException;
19.import java.util.ArrayList;
20.import java.util.List;
21.
22.import org.junit.Test;
23.
24.import mon.poolman.Record;
25.import mon.poolman.SQLExecutor;
26.import mon.poolman.handle.NullRowHandler;
27.import mon.poolman.handle.RowHandler;
28.import com.frameworkset.util.ListInfo;
29.
30.public class SimpleApiTest {
31. @Test
32. public void insertOpera()throws SQLException
33. {
34. ListBean lb = new ListBean();
35. lb.setFieldLable("tttt");
36. lb.setFieldName("testttt");
37. lb.setFieldType("int");
38. lb.setIsprimaryKey(false);
39. lb.setRequired(true);
40. lb.setSortorder("ppp");
41. lb.setFieldLength(20);
42. lb.setIsvalidated(6);
43.
44. //用List存放Bean,在某特定的连接池中进行crud操作
45. List beans = new ArrayList();
46. beans.add(lb);
47.
48. String sql = "insert into LISTBEAN(ID,FIELDNAME,FIELDLABLE,FIELDTYPE,SORTORDER,ISPRIMARYKEY,REQUIRED,FIELDLENGTH,ISVALIDATED) " +
49. "values(#[id],#[fieldName],#[fieldLable],#[fieldType],#[sortorder]," +
50. "#[isprimaryKey],#[required],#[fieldLength],#[isvalidated])";
51. SQLExecutor.insertBeans("mysql",sql,beans);
52.
53.
54.
55. SQLExecutor.insertBean("mysql", sql, lb);
56.
57. SQLExecutor.insertBeans("mysql", sql, beans);
58.
59.
60.
61. SQLExecutor.insertBean(sql, lb);
62.
63.
64.
65. sql ="insert into LISTBEAN(ID,FIELDNAME,FIELDLABLE,FIELDTYPE) " +
66. "values(?
?
?
?
)";
67.// SQLExecutor.insert(sql,122,lb.getFieldName(),lb.getFieldLable(),lb.getFieldType());
68.
69.
70.// SQLExecutor.insertWithDBName("mysql", sql,101,"insertOpreation","ttyee","int");
71.
72.
73.
74. }
75.
76. @Test
77. public void updateOpera() throws SQLException
78. {
79. //在某特定的连接池中直接crud对象
80. ListBean bean = new ListBean();
81. bean.setId(88);
82. bean.setFieldLable("tttt");
83. bean.setFieldName("test");
84. bean.setFieldType("int");
85. bean.setIsprimaryKey(false);
86. bean.setRequired(true);
87. bean.setSortorder("ppp");
88. bean.setFieldLength(20);
89. bean.setIsvalidated(6);
90. List beans = new ArrayList();
91. String sql ="";
92. beans.add(bean);
93.
94. sql ="update LISTBEAN set FIELDNAME='yyyy' where ID=#[id]";
95. SQLExecutor.updateBeans("mysql", sql, beans);
96.
97. sql ="update LISTBEAN set FIELDNAME=#[fieldName] where ID=#[id]";
98. SQLExecutor.updateBean(sql,bean);
99.
100. sql ="update LISTBEAN set FIELDNAME=#[fieldName] where ID=#[id]";
101. SQLExecutor.updateBean("mysql",sql,bean);
102.
103.
104. sql ="update LISTBEAN set FIELDNAME=#[fieldName] where ID=#[id]";
105. SQLExecutor.updateBeans(sql,beans);
106.
107. sql = "update LISTBEAN set FIELDNAME=?
where ID=?
";
108. SQLExecutor.update(sql, "mytest",100);
109.
110. sql = "update LISTBEAN set FIELDNAME=?
where ID=?
";
111. SQLExecutor.updateWithDBName("mysql", sql, "zhansans",101);
112.
113.
114. }
115.
116. @Test
117. public void deleteOpera() throws SQLException
118. { //在特定的连接池中对数组对象进行crud
119. ListBean lb = new ListBean();
120. lb.setId(85);
121. lb.setFieldLable("tttt");
122. lb.setFieldName("testttt");
123. lb.setFieldType("int");
124. lb.setIsprimaryKey(false);
125. lb.setRequired(true);
126. lb.setSortorder("ppp");
127. lb.setFieldLength(20);
128. lb.setIsvalidated(6);
129. ListBean lb2 = new ListBean();
130. lb2.setId(15);
131. lb2.setFieldName("this is lb2");
132.
133. List beans = new ArrayList();
134. beans.add(lb);
135. beans.add(lb2);
136. String sql = "";
137.
138. sql = "delete from LISTBEAN where ID=?
";
139. SQLExecutor.delete(sql,68);
140.
141. sql = "delete from LISTBEAN where ID=?
";
142. SQLExecutor.deleteByKeys(sql,67);
143.
144. sql ="delete from LISTBEAN where ID=#[id]";
145. SQLExecutor.deleteBean(sql,lb);
146.
147. sql = "delete from LISTBEAN where ID=#[id]";
148. SQLExecutor.deleteBeans(sql, beans);
149.
150. sql ="delete from LISTBEAN where ID=#[id]";
151. SQLExecutor.deleteBean("mysql",sql,lb);
152.
153. sql ="delete from LISTBEAN where ID=#[id]";
154. SQLExecutor.deleteBeans("mysql",sql,beans);
155.
156. sql = "delete from LISTBEAN where ID=?
";
157. SQLExecutor.deleteWithDBName("mysql", sql, 3);
158.
159. sql = "delete from LISTBEAN where FIELDNAME=?
";
160. SQLExecutor.deleteByKeysWithDBName("mysql", sql,"pppp");
161.
162.
163. }
164.
165.
166. @Test
167. public void queryOprea() throws SQLException{
168. List beans = null;
169.
170. String sql ="select * from LISTBEAN where ID=?
";
171.
172. sql = "select * from LISTBEAN where id=?
";
173. List lbs = (List) SQLExecutor.queryList(ListBean.class, sql,22);
174.
175. sql = "select * from LISTBEAN where fieldName=?
";
176. beans = (List) SQLExecutor.queryListWithDBName(ListBean.class,"mysql",sql,"testttt");
177. for(int i=0;i178. System.out.println(beans.get(i).getId());
179.
180. sql = "select * from LISTBEAN where fieldName=?
";
181. List dbBeans = (List) SQLExecutor.queryListWithDBName(ListBean.class, "mysql", sql, "testttt");
182. for(int i=0;i183. System.out.println(dbBeans.get(i).getFieldName());
184.
185. sql = "select * from LISTBEAN where fieldName=?
and id=?
";
186. ListBean bean = SQLExecutor.queryObject(ListBean.class, sql,"object",22);
187. System.out.println(bean.getId());
188.
189. sql="select * from LISTBEAN where FIELDNAME=?
or id=?
";
190. lbs = (List) SQLExecutor.queryList(ListBean.class, sql, "testttt",100);
191.
192.
193. sql = "select FIELDNAME from LISTBEAN where ID=?
";
194. String lbs1 = SQLExecutor.queryField(sql,2);
195. System.out.println(lbs1);
196.
197. sql="select FIELDNAME from LISTBEAN where ID=?
";
198. String result = SQLExecutor.queryFieldWithDBName("mysql", sql, 100);
199. System.out.println(result);
200.
201. sql = "select * from LISTBEAN where ID=?
";
202. ListBean lb = (ListBean)SQLExecutor.queryObjectWithDBName(ListBean.class,"mysql",sql,20);
203.
204.
205. sql="select * from LISTBEAN where ID
and ID>?
";
206. ListInfo lif = SQLExecutor.queryListInfo(ListBean.class, sql, 0, 10, 20,10);
207. beans = lif.getDatas();
208. for(int i=0;i209. System.out.println(beans.get(i).getFieldName()+".......");
210.
211.
212. bean = new ListBean();
213. bean.setFieldName("testttt");
214. bean.setFieldLable("lisi");
215.
216. sql ="select * from LISTBEAN where ID=?
";
217.
218.
219.// bean = (ListBean)SQLExecutor.queryObjectBean(ListBean.class, sql, bean);
220.
221. sql ="select * from LISTBEAN where FIELDNAME=#[fieldName]";
222. result = SQLExecutor.queryFieldBean(sql, bean);
223. System.out.println(result);
224. result = SQLExecutor.queryFieldBeanWithDBName("mysql", sql, bean);
225. System.out.println(result);
226.
227. beans