33import java .io .Serializable ;
44import java .util .List ;
55
6+ import openthinks .libs .sql .dao .BaseDao ;
67import openthinks .libs .sql .data .Row ;
78import openthinks .libs .sql .dhibernate .support .query .Query ;
89import openthinks .libs .sql .entity .Entity ;
1415
1516/**
1617 * 与数据库会话接口
17- *
18+ * <p>Include high level and low level ways to access database<BR>
19+ * <B>High level DAO API - auto generate SQL</B>
20+ * <ul>
21+ * <li>{@link #createQuery(Class)}
22+ * <li>{@link #load(Class, Serializable)}
23+ * <li>{@link #save(Object)}
24+ * <li>{@link #update(Object)}
25+ * <li>{@link #delete(Object)}
26+ * <li>{@link #list(Class)}
27+ * </ul>
28+ * <B>Low level DAO API - manual generate SQL</B>
29+ * <ul>
30+ * <li>{@link #add(Condition)} {@link #add(String)} {@link #add(String, String[])}
31+ * <li>{@link #createCondition()}
32+ * <li>{@link #delete(Condition)} {@link #delete(String)} {@link #delete(String, String[])}
33+ * <li>{@link #get(Class, Condition)} {@link #get(Class, String)} {@link #get(Class, String, String[])}
34+ * <li>{@link #list(Condition)} {@link #list(String)} {@link #list(String, String[])}
35+ * <li>{@link #list(Class, Condition)} {@link #list(Class, String)} {@link #list(Class, String, String[])}
36+ * <li>{@link #update(Condition)} {@link #update(String)} {@link #update(String, String[])}
37+ * </ul>
38+ * </p>
1839 * @author dmj
1940 * @version 2010/11/19
2041 *
2142 */
2243public interface Session {
2344
45+ /**
46+ * 开启事务
47+ *
48+ * @throws TransactionException
49+ * 事务异常
50+ */
51+ public void beginTransaction () throws TransactionException ;
52+
53+ /**
54+ * 提交事务
55+ *
56+ * @throws TransactionException
57+ * 事务异常
58+ */
59+ public void commit () throws TransactionException ;
60+
61+ /**
62+ * 回滚事务
63+ *
64+ * @throws TransactionException
65+ * 事务异常
66+ */
67+ public void rollback () throws TransactionException ;
68+
69+ /**
70+ * 关闭与数据库会话
71+ */
72+ public void close ();
73+
74+ /**
75+ * 取得日志记录器 logger
76+ *
77+ * @return 日志记录器logger
78+ */
79+ public Logger getLogger ();
80+
81+ /**
82+ * 取得数据库连接配置器 configurator
83+ *
84+ * @return 数据库连接配置器configurator
85+ */
86+ public Configurator getConfigurator ();
87+
88+ /**
89+ * judge database connection is auto-close after execute DML
90+ * @return Boolean
91+ */
92+ public Boolean isAutoClose ();
93+
94+ /**
95+ * controller database connection auto-close when after execute DML
96+ *
97+ */
98+ public void enableAutoClose ();
99+
100+ public void disableAutoClose ();
101+
102+ /*==========================================================================================
103+ * High level DAO API, recommend
104+ */
24105 /**
25106 * create a {@link Query} for this given entity class
26107 * @param clz Class<T> entity class type
@@ -30,10 +111,9 @@ public interface Session {
30111
31112 /**
32113 * 根据id值获取clz类型的实体对象
33- *
34114 * @param clz
35115 * 实体类型clz<BR>
36- * 1.{@link Entity}子类默认第一个属性为ID列<BR>
116+ * 1.{@link Entity}子类默认第一个属性为ID列,类名需与表名一致 <BR>
37117 * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
38118 * @param id Serializable
39119 * 主键值
@@ -44,79 +124,97 @@ public interface Session {
44124 /**
45125 * 持久化对象,进行Insert
46126 *
47- * @param object
127+ * @param object T
128+ * 实体类型T<BR>
129+ * 1.{@link Entity}子类默认第一个属性为ID列,类名需与表名一致<BR>
130+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
48131 */
49132 public <T > void save (T object );
50133
51134 /**
52135 * 持久化对象,根据持久化的对象主键进行Update
53- *
54- * @param object
136+ * 实体类型T<BR>
137+ * 1.{@link Entity}子类默认第一个属性为ID列,类名需与表名一致<BR>
138+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
139+ * @param object T
55140 */
56141 public <T > void update (T object );
57142
58143 /**
59- *
60- * @param object
144+ * 删除对象,根据持久化的对象主键进行Delete
145+ * 实体类型T<BR>
146+ * 1.{@link Entity}子类默认第一个属性为ID列,类名需与表名一致<BR>
147+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
148+ * @param object T
61149 */
62150 public <T > void delete (T object );
63151
152+ /**
153+ * 返回所有相应实体类的集合列表<br>
154+ *
155+ * @param clz
156+ * 查询的实体Class类型,<span style=color:red>可以不是Entity的子类</span><BR>
157+ * 1.{@link Entity}子类子类默认第一个属性为ID列,类名需与表名一致<BR>
158+ * 2.JPA注解方式
159+ * @since 2010/11/17
160+ * @return List<E> 任何实体类的集合列表
161+ */
162+ public <T > List <T > list (Class <T > clz );
163+
164+ /*==========================================================================================
165+ * Low level DAO API, recommend
166+ */
167+
64168 /**
65169 * 根据查询语句获取clz类型的实体对象
66170 *
67171 * @param clz
68- * 实体类型clz
172+ * 实体类型clz<BR>
173+ * 1.{@link Entity}子类<BR>
174+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
69175 * @param sql
70- * 标准查询语句 ,<span style=color:red;>不支持多表查询语句</span>
176+ * 完整标准查询语句 ,<span style=color:red;>不支持多表查询语句</span>
71177 * @return Object 数据库表所对应的实体对象
72178 */
73179 public <T > T get (Class <T > clz , String sql );
74180
75- public <T extends Entity > T get (Entity entity , String sql );
181+ // @Deprecated
182+ // public <T extends Entity> T get(Entity entity, String sql);
76183
77184 /**
78185 * 根据查询语句获取clz类型的实体对象
79- *
80186 * @param clz
81- * 实体类型clz
187+ * 实体类型clz<BR>
188+ * 1.{@link Entity}子类<BR>
189+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
82190 * @param sql
83- * 标准查询语句 ,<span style=color:red;>不支持多表查询语句</span>
191+ * 完整标准查询语句 ,<span style=color:red;>不支持多表查询语句</span>
84192 * @param params
85193 * sql语句依赖的参数数组
86194 * @return Object 数据库表所对应的实体对象
87195 */
88196 public <T > T get (Class <T > clz , String sql , String [] params );
89197
90- public < T extends Entity > T get ( Entity entity , String sql , String [] params );
91-
198+ // @Deprecated
199+ // public <T extends Entity> T get(Entity entity, String sql, String[] params);
92200 /**
93201 * 根据查询语句获取clz类型的实体对象
94202 *
95203 * @param clz
96- * 实体类型clz
204+ * 实体类型clz<BR>
205+ * 1.{@link Entity}子类<BR>
206+ * 2.JPA标注的实体类标准 {@link javax.persistence.Id}
97207 * @param condition
98- * 专用于生成带条件的sql语句的对象 ,<span style=color:red;>不支持多表查询</span>
208+ * 专用于生成带条件的完整查询语句的对象 ,<span style=color:red;>不支持多表查询</span>
99209 * @return Object 数据库表所对应的实体对象
100210 */
101211 public <T > T get (Class <T > clz , Condition condition );
102212
103- public <T extends Entity > T get (Entity entity , Condition condition );
104-
105- /**
106- * 返回所有相应实体类的集合列表<br>
107- *
108- * @param clz
109- * 查询的实体Class类型,<span style=color:red>可以不是Entity的子类</span><BR>
110- * 1.{@link Entity}子类<BR>
111- * 2.JPA注解方式
112- * @since 2010/11/17
113- * @return List<E> 任何实体类的集合列表
114- */
115- public <T > List <T > list (Class <T > clz );
116-
213+ // @Deprecated
214+ // public <T extends Entity> T get(Entity entity, Condition condition);
117215 /**
118216 * 根据查询语句获取clz类型的实体对象对象列表
119- *
217+ * @see Session#list(Class, String, String[])
120218 * @param clz
121219 * 实体类型clz
122220 * @param sql
@@ -127,7 +225,7 @@ public interface Session {
127225
128226 /**
129227 * 根据查询语句获取clz类型的实体对象对象列表
130- *
228+ * @see BaseDao#list(Class, String, String[])
131229 * @param clz
132230 * 实体类型clz
133231 * @param sql
@@ -272,61 +370,4 @@ public interface Session {
272370 */
273371 public int delete (Condition condition );
274372
275- /**
276- * 开启事务
277- *
278- * @throws TransactionException
279- * 事务异常
280- */
281- public void beginTransaction () throws TransactionException ;
282-
283- /**
284- * 提交事务
285- *
286- * @throws TransactionException
287- * 事务异常
288- */
289- public void commit () throws TransactionException ;
290-
291- /**
292- * 回滚事务
293- *
294- * @throws TransactionException
295- * 事务异常
296- */
297- public void rollback () throws TransactionException ;
298-
299- /**
300- * 关闭与数据库会话
301- */
302- public void close ();
303-
304- /**
305- * 取得日志记录器 logger
306- *
307- * @return 日志记录器logger
308- */
309- public Logger getLogger ();
310-
311- /**
312- * 取得数据库连接配置器 configurator
313- *
314- * @return 数据库连接配置器configurator
315- */
316- public Configurator getConfigurator ();
317-
318- /**
319- * judge database connection is auto-close after execute DML
320- * @return Boolean
321- */
322- public Boolean isAutoClose ();
323-
324- /**
325- * controller database connection auto-close when after execute DML
326- *
327- */
328- public void enableAutoClose ();
329-
330- public void disableAutoClose ();
331-
332373}
0 commit comments