亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Designing “query by criteria”(hibernate 2.1)

2019-11-18 13:56:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  Designing "query by criteria" 01. Dec 2003, 14:47
by gavin@hibernate.org Link 16 comments
One of the great imPRovements in Hibernate 2.1 is that we finally have a mature Criteria query API. For a very long time I let this feature languish because I just wasn´t sure what it should really look like. Every QBC API I´ve looked at is designed differently and there is certainly nothing like a standard API to learn from. I´ve seen everything from this:

new Criteria(Project.class)
.addEq("name", "Hibernate")
.addLike("descr .execute();


to this:

Criteria crit = new Criteria(Project.class)
crit.getProperty("name").eq("Hibernate);
crit.getProperty("description).like("%ORM%");
crit.execute();


I don´t like either of these approaches because the addition of new types of criterion requires the uncontrolled growth of a single central interface (Criteria, in the first case; Property in the second).

I like the second approach even less because it is very difficult to chain method calls. What should the eq() method return? Well, it seems most reasonable that it would return the receiving object (ie. the property). But it is very unusual to apply multiple criteria to the same property! So we would really prefer it to return the Criteria if we wanted to chain method calls. Well, I don´t know about you, but I think that any API that returned the receiver from two calls ago might not be considered "intuitive". So we are stUCk with that evil temp variable.

I´d seriously consider improving this second approach to look like this:

new Criteria(Project.class)
.getProperty("name").eq("Hibernate)
.and()
.getProperty("description).like("%ORM%");
.execute();



Which is actually very clean. Unfortunately, the interfaces themselves are quite bizzare: and() is an
Operation defined by .... Criterion? The and() method returns .... the Criteria? This doesn´t feel like a very natural OO design. And I think it would confuse new users. I´ll come back to another reason why "and" and "or" should not be operations at all.

As a variation upon the first approach, I have seen the following:

new Criteria(Project.class)
.add( new Equals("name", "Hibernate") )
.add( new Like("description", "%ORM%") )
.execute();


This avoids the problem of the Criteria interface growing out of control. But I hate java constructors almost as much as I hate temp variables! The problem with constructors in Java is that they cannot be given meaningful names. We can´t call a constructor EqualsIgnoreCase() if the class is named Equals. Secondly, once we start using constructors, we pretty much permanently nail down the Criterion class hierarchy. We tie client code directly to the concrete classes. I can´t change my mind later and decide that Equals and EqualsIgnoreCase should be different classes.

Eventually I ended up being most influenced by the Cayenne query API (whch I presume was in turn influenced by Apple´s WebObjects). Cayenne uses a class with static factory methods to create Criterion instances. Actually, Cayenne misnames the criterion class EXPression and I stupidly inherited this misnaming in our (Hibernate) factory class. So, we ended up with:

session.createCriteria(Project.class)
.add( Expression.eq("name", "Hibernate") )
.add( Expression.like("description", "%ORM%") )
.list();


Notice that this code does not use any concrete classes other than the static factory class - its all interfaces!

The downside of this design is that there are more characters in "add( Expression.eq())" than in "add( new Eq())" or "addEq()". So it is certainly more verbose. It is also noisy. What stands out in the code above is the two occurrences of "Expression". But they are the least important thing in the code.

Fortunately for me, JDK1.5 will come along and give us static imports. Static imports have been very unfairly maligned in the past, so let me try to set the record straight. If I add "import net.sf.hibernate.expression.Expression.*", the code example above becomes:

session.createCriteria(Project.class)
.add( eq("name", "Hibernate") )
.add( like("description", "%ORM%") )
.list();


This is now less verbose and more readable than the version that used constructors. I´m halfway done.

A second problem is the logical combination of criterions. "and" and "or" are each associative, but a string of both "and"s and "or"s is certainly not associative. So it seemed critically important to me that the precedence of the logical operators is crystal clear from the structure of the code. I hate the following:

session.createCriteria(Project.class)
.addAnd( eq("name", "Hibernate") )
.addAnd( like("description", "%ORM%") )
.addOr( like("description", "%object/relational%") )
.list();


I´ve seen a number of APIs like this and I still don´t have a clue how the previous code is intended to be read. The same problem applies to this variation:

new Criteria(Project.class)
.getProperty("name").eq("Hibernate)
.and()
.getProperty("description).like("%ORM%")
.or()
.getProperty("description).like("%object/relational%")
.execute();


OK, OK, I actually do know that conjunction usually has a higher precendence than disjunction - but I would never, ever write code that depended upon this. It just isn´t readable. And we certainly can´t always rely upon operator precedence - we do need some way to express grouping. Anyway, I think this problem would affect any API which offers and() and or() as methods. So let´s not make and() and or() be operations at all.

By the way, worst of all is this:

new Criteria(Project.class)
.getProperty("name").eq("Hibernate)
.and( crit.getProperty("description).like("%ORM%") )
.execute();


"And" is a symmetrical operation! This symmetry should be obvious.

The solution is to treat Conjunction and Disjunction in exactly the same way as atomic Criterions. Make them Criterions, not operations.

session.createCriteria(Project.class)
.add( Expression.disjunction()
.add( eq("name", "Hibernate") )
.add( like("description", "%ORM%") )
)
.list();


Well, that´s a couple too many parentheses for my taste. I´m considering supporting something like the following in Hibernate:

session.createCriteria(Project.class)
.createDisjunction()
.add( eq("name", "Hibernate") )
.add( like("description", "%ORM%") )
.list();


My big problem here is that createDisjunction() would need to return a new instance of Criteria (wrapping a Disjunction) just so that we can call list() without needing a new temp variable. I´m not sure if I like this. Currently Expression.disjunction() just returns an instance of Disjunction directly - and Disjunction implements only the Criterion interface. I guess we´re still searching for perfection...

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
你懂得在线网址| 丰满湿润大白屁股bbw按摩| 日韩精品在线观看av| 日本在线高清视频一区| 在线看视频不卡| 久久韩国免费视频| 亚洲小说春色综合另类电影| 久久久久久久性潮| 第四色成人网| 在线观看18视频网站| 香蕉视频成人在线| 欧美激情乱人伦一区| 亚洲午夜激情免费视频| 黄色片视频免费观看| 91麻豆精品一二三区在线| 国产福利片在线| 欧美性猛交一区二区三区| 国产精品久久久av久久久| 国产精品51麻豆cm传媒| 久久资源av| 欧美激情va永久在线播放| 91欧美精品午夜性色福利在线| 精品亚洲视频在线| 国产午夜精品在线观看| 国产探花一区二区| 99久久综合| 在线看日本不卡| 日韩欧美一区二区视频在线播放| 999精品免费视频| 精品人妻一区二区三区免费看| av高清不卡| 中文字幕在线视频一区二区三区| 日韩高清国产一区在线| 亚洲精品视频99| 日韩国产在线| 黄在线观看在线播放720p| 日韩黄色免费网站| 一区二区三区视频在线观看免费| 日韩亚洲一区在线| 国产一区视频免费观看| 男人av在线| 久久久久国产精品免费免费搜索| 欧美78videosex性欧美| 91精品国产一区二区三区蜜臀| 亚洲九九在线| 国产精品r级在线| 亚洲第一区第二区第三区| 99国产高清| 成人综合专区| 重囗味另类老妇506070| 性开放的欧美大片| 日韩中文字幕亚洲一区二区va在线| 污视频网站免费观看| 国产传媒第一页| 久久婷婷综合中文字幕| 久久综合成人精品亚洲另类欧美| 又粗又大的机巴好爽欧美| 欧美美女被草| 四色永久网址| 亚洲成人资源在线| 91美女高潮出水| 国产欧美自拍视频| 天天干天天玩天天操| 亚洲欧美国产一本综合首页| 亚洲天堂网在线观看视频| 在线精品视频一区二区三四| 韩日成人影院| 成人黄色免费网| 精品久久久久久中文字幕一区奶水| 国产91色在线|| 丰满少妇又爽又紧又丰满电影| 无码粉嫩虎白一线天在线观看| 久久人妻无码aⅴ毛片a片app| 九色视频在线观看免费| 日韩精品极品| 丝袜美腿成人在线| 日韩av在线电影网| 国产精品麻豆免费版现看视频| 91啪亚洲精品| 国产黄色片免费看| 成人午夜激情网| 青青青视频在线免费观看| 91大神福利视频| 亚洲午夜精品国产| 欧美视频在线观看一区二区| 国产+成+人+亚洲欧洲| 污污视频网站在线| 日韩一级视频| 免费在线欧美视频| 日本a级片免费| 91精品福利观看| 黄色网在线免费看| 国产精品91视频| 国产精品一区二区婷婷| 在线精品视频一区| 麻豆久久久久久久| 欧美视频中文在线看| 欧美一级欧美三级| 91传媒视频在线播放| 粉嫩av一区二区三区免费观看| 欧美日韩激情视频8区| 欧美丰满少妇xxxbbb| 成人美女视频在线看| 中文字幕观看在线| 亚洲乱码日产精品bd| 欧美最猛黑人xxxx| 91视频在线网站| 加勒比海盗1在线观看免费国语版| 成人av在线网| 日本免费看黄| 国产成人精品实拍在线| 激情综合自拍| 亚洲成人精品视频在线观看| 中文字幕视频观看| 成人久久久精品乱码一区二区三区| 日韩av一卡二卡三卡| 中文字幕精品无| 欧美激情福利视频在线观看免费| 天堂av免费在线观看| 国产免费999| 国产亚洲精品久久777777| 精品成人在线| 欧美日韩中文不卡| av网站网址| 国产精品入口麻豆原神| 中文字幕第80页| 在线不卡一区二区三区| 波多野结衣在线一区| 午夜在线观看视频18| 欧美熟乱第一页| 亚洲人成网站777色婷婷| 麻豆精品一区二区av白丝在线| 欧美成人性网| 国产精品欧美一区二区三区奶水| 五月激情综合色| 日本少妇高潮喷水xxxxxxx| 亚洲热在线观看| 国产一级片儿| av之家在线观看| 亚洲精品电影网站| 国产在线视频2019最新视频| 国产亚洲精品女人久久久久久| 成人av动漫在线观看| 老熟妇仑乱视频一区二区| 国产福利免费观看| 美国毛片一区二区| 国产一二三区在线| 91超碰在线播放| 奇米影视第四色7777| 亚洲三级网页| av不卡在线观看| 精品综合久久久久久97| av一区二区在线观看| 一级片在线免费看| 麻豆疯狂做受xxxx高潮视频| 日本一区免费视频| 1pondo在线播放免费| www成人免费观看| 国产一区av在线| 欧洲一区二区视频| 日韩h在线观看| 国产精品av免费观看| 精品成人国产| 国产精品www爽爽爽| 亚洲日本精品一区| 国产成人免费av一区二区午夜| 岛国一区二区在线观看| 国产99久久久精品| 久久精品视频在线观看榴莲视频| 国产美女高潮在线观看| jizz欧美| 欧美精品三级在线观看| 亚洲欧洲三级电影| 欧美激情亚洲视频| va视频在线观看| 日韩精品一区二区三区中文在线| 26uuu精品一区二区| www.黄色片| 午夜爽爽视频| 亚洲综合爱爱久久网| 欧美三级三级三级爽爽爽| 国产精品777一区二区| 五月婷婷深深爱| 亚洲专区第一页| avhd101老司机| 欧美做受高潮中文字幕| 视频一区二区在线播放| 欧美偷拍一区二区三区| 亚洲黄网在线观看| 精品一级少妇久久久久久久| 精品无人区麻豆乱码久久久| 看全色黄大色黄女片18| 一级欧洲+日本+国产| 精品欧美国产一区二区三区| 日韩免费观看视频| 日韩欧美少妇| 91网址在线观看精品| 久久99久久99小草精品免视看| 亚洲精品国产美女| 欧美精品亚洲二区| 日韩精品在线电影| 葵司免费一区二区三区四区五区| 亚洲日产av中文字幕| 日韩av免费网站| 在线观看免费高清完整| 野外性xxxxfreexxxxx欧美| 国产在线精品一区免费香蕉| 欧美三级 欧美一级| 亚洲三级在线看| 一本色道久久综合亚洲精品不卡| 亚洲成av人片在线| 久久九九精品99国产精品| 欧美专区第一页| 久久艹精品视频| 欧美tk丨vk视频| 日本h片久久| 日韩影院精彩在线| 亚洲巨乳在线观看| 波多野结衣在线网站| 妺妺窝人体色WWW精品| 国内免费精品视频| a√资源在线| 在线性视频日韩欧美| 九色综合日本| 午夜精品成人av| 欧美日韩黄色网| 人人妻人人玩人人澡人人爽| 国产成人久久精品77777最新版本| 久草综合在线视频| 91jq激情在线观看| 色妹子一区二区| 91麻豆精品国产91久久久久久| 国产一线二线在线观看| 中文字幕9999| 在线视频欧美亚洲| 日韩大陆毛片av| 久久久久99| 四虎影成人精品a片| 色妹子一区二区| 色婷婷av金发美女在线播放| 亚洲视频综合在线| 欧美日韩xxx| 午夜剧场免费看| 日日干日日操| 五月天婷婷视频| 99精品国产一区二区三区不卡| 国产一区私人高清影院| 久久伊伊香蕉| 亚洲国产欧美在线| 国产精品va无码一区二区三区| 337p粉嫩大胆噜噜噜噜噜91av| 黄色片子免费看| 国产精品福利在线观看播放| 精品中文字幕一区二区三区四区| 日韩一级免费观看| 国产精品扒开腿做| 麻豆九一精品爱看视频在线观看免费| 久久国产精品99久久久久久老狼| 欧美成人se01短视频在线看| 国内毛片久久| 欧美日韩国产丝袜美女| 制服丝袜av在线| 色婷婷激情综合| 久久久噜噜噜久久久| 亚洲男女毛片无遮挡| 亚洲女娇小黑人粗硬| 亚洲欧美在线磁力| 日本v片在线免费观看| 日韩美女av在线| 一区二区三区欧美| 国产香蕉精品| 亚洲少妇自拍| 久久综合中文色婷婷| 高清无码一区二区在线观看吞精| 欧美精品一二三| 日韩高清一二三区| 中文字幕一区久久| 久久精品这里只有精品| 公交车强行挺进岳身体| 亚洲福利视频在线| 国产精品免费视频二三区| 久久av在线| 国产黄色片视频| chien国产乱露脸对白| 国产午夜精品一区理论片飘花| 久久激情网站| 疯狂撞击丝袜人妻| 久久99精品久久久久久久久久| 国产高清精品网站| 永久免费在线观看| 国产精品密蕾丝视频下载| 亚洲国产中文在线二区三区免| 成人网男人的天堂| 色悠悠在线视频| 色菇凉天天综合网| 午夜久久福利| 欧美成aaa人片在线观看蜜臀| 啦啦啦啦免费高清视频在线观看1| 东北一级毛片| 狠狠操精品视频| 色拍拍在线精品视频8848| 在线看的毛片| 久久久久久婷婷| 美女国内精品自产拍在线播放| 亚洲综合丝袜美腿| 亚洲日本黄色| 精品国产凹凸成av人网站| 欧美专区福利在线| 日韩妆和欧美的一区二区| 欧美激情影音先锋| 潘金莲一级淫片aaaaaa播放1| 亚洲图片欧美色图| 久久久久久国产| 免费在线中文字幕| 亚洲一区二区欧美日韩| 中文字幕资源网在线观看| 国产99久久精品一区二区| www.99色.com| 永久免费在线观看| 欧美日韩加勒比精品一区| 久久精品一区中文字幕| 一区二区在线播放视频| 日韩美女写真福利在线观看| 懂色一区二区三区av片| 精品久久久久久久久久久久久久久久久久| 日韩精品成人免费观看视频| 欧美图片一区二区三区| 久久99国产精品久久久久久久久|