日本欧美中文字幕,午夜亚洲成人,在线一区二区视频http://www.aygfsteel.com/zhangzhong1018/category/16373.htmlstudy ruby on railszh-cnThu, 08 Mar 2007 06:37:40 GMTThu, 08 Mar 2007 06:37:40 GMT602007年標(biāo)志設(shè)計趨勢密碼[轉(zhuǎn)]http://www.aygfsteel.com/zhangzhong1018/articles/102563.html天邊一片伴月星天邊一片伴月星Thu, 08 Mar 2007 03:38:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/102563.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/102563.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/102563.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/102563.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/102563.html 2007年標(biāo)志設(shè)計趨勢密碼
2007 Logo Design Trends

2007年1月發(fā)表,1月24日由Quester中文翻譯,原文鏈接:http://logoorange.com/logo-design.php

11 trends that will define Logo design in 2007

Everyone wants to set the curve when it comes to style. No one wants to design out of a book of trends, but nevertheless, they emerge.
Take a peek at the following 11 Logo design trends that we think will define the look of 2007.

11種趨勢將定義2007年的Logo設(shè)計

每個設(shè)計師都想在某一風(fēng)格成為流行前把握它。沒有人愿意自己的設(shè)計和流行趨勢脫節(jié)。但是無論如何,這些趨勢總是會露出端倪。

讓我們一同來窺探一下這11種我們認(rèn)為的2007年標(biāo)志設(shè)計的趨勢密碼。

1. Talk Boxes

This is an outgrowth of last year's trend, even though these boxes have been around a few years now.
We don't quite know who's doing the talking, but whoever it is, their bubble is popping up all over. This Logo symbolizes communication, whether it be from the company or between its customers. LifeLogger, for instance, uses a speech bubble with a smile in it to illustrate how users can communicate through them to friends. They continue the use of three-dimensional speech bubbles in creating avatars for their users, as illustrated to the right.
In this way, the idea of communication represents the person themselves, showing the importance of contact.


1. 對話泡泡

這是一種去年的流行風(fēng)格的衍生,盡管這些泡泡已經(jīng)玩了好幾年了。
我們搞不懂是誰在說話,但管它是誰呢,反正滿處都是冒的這些泡泡。這個符 號象征著溝通,無論是來自企業(yè)還是他們的客戶之間。LifeLogger(生活的記錄者)網(wǎng)站,是一個例證,用泡泡和微笑符號來說話,表明用戶可以用什么 樣的方式和他們的朋友來交流。 他們繼續(xù)使用立體的對話泡泡來為用戶創(chuàng)造神話,就像右邊那個泡泡。
在這里,溝通的想法代表這些人本身,想要展示接觸的重要性。


2. Clouds

Everyone remembers a time when they laid on their back in the grass, staring at the clouds daydreaming or finding images in their puffs.
Clouds are a powerful Logo, conjuring imagery of dreams, creativity and playfulness. Sometimes clouds are combined with thought bubbles to invoke feelings of dreaminess. The clouds can be a 3D bubble or take on a flat feeling. Many of these cloud Logos represent new ideas, hence the thought bubble. Many "clouds" came from new businesses on the internet, certainly a place for dreamers. Some, also include imagery of the sun, which evokes a feeling of a new dawn.


2. 云狀物

每個人都有那些仰面躺在草地上的時候,望著云朵發(fā)白日夢或者從騰云變換中尋找圖案的記憶。
云狀物是一個極有表現(xiàn)力的標(biāo)志,憑空幻化意象,即有創(chuàng)造性,又很好玩。有時候云狀物和“思維泡泡”結(jié)合起來,會產(chǎn)生一種夢幻的感覺。云狀物可以是三維的泡泡或者只是平面的。許多的云狀物L(fēng)ogo用“思維泡泡”來代表一種新思想。
許多的“云朵”來自互聯(lián)網(wǎng)上的新生意,互聯(lián)網(wǎng)確實是個夢想之地。有一些,也包含太陽的圖形,用來形成“新的曙光”的感覺。


3. Reflections

Mirror, mirror, on the wall, what's the hottest trend of all? It might just be reflections. With Apple leading the way, looking like all their graphics were set on a shiny table, others are sure to follow. Dubbed by some as ?the new drop shadow,? reflections are taking over, especially on the web. The reflections might be skewed, such as in the Logo for blinklist, indicating the location of some light source, invisible to the onlooker, but effective in creating even more of a sense of a whole different world the Logo is in.


3. 反射效果(鏡像效果)

魔鏡魔鏡告訴我,什么是最熱的潮流啊? 它可能就是“反射效果”。蘋果最先開始倡導(dǎo)的,把什么東西都弄得好像放在光滑閃亮的桌面上,其他人就開始跟風(fēng)。有人給它起了個綽號叫什么來著?“新的下拉 陰影”(意思和以前的“下拉陰影”效果一樣滿天飛)。 “反射效果”全面霸占,尤其是在網(wǎng)上。反射效果可以是不對稱的,就像 blinklist 的Logo一樣,弄出一些光的效果卻讓你找不到光源,但對于創(chuàng)造擁有更多“完全不同的世界”感覺的Logo是有效而時尚的。


4. Rectangle

In a graphic world where you can do nearly anything, some companies are keeping it simple with shaded rectangles. Their Logo, in a contrasting white, pops out from the background. Shadow boxes have historically been a sign of amateurish design, but this new generation of effective Logos has shown that good design will always be in style. With the popularity of rounded corners, these Logos stand out with (oh no!) sharp edges and right angles. In some occasions, such as with the blurb Logo, the rectangle can represent an image. Blurb used their blue shadow behind their name to symbolize a book, as they are in the book publishing business.


4. 長方形

在圖形世界里,你幾乎可以做任何事情,但有些公司只使用簡單的帶邊框的長方形。他們的Logo,從高反差的白色背景上“跳”出來。相框一樣的長方形 容易給人“業(yè)余設(shè)計水平”的感覺,但是新生的有活力的這些Logo,表明了好的設(shè)計永遠(yuǎn)都是有品味的。與人氣極旺的圓角風(fēng)格同時,這些Logo因有著銳利 的邊緣和適當(dāng)?shù)膬A斜角度而特別顯眼(不是吧?。T谀承﹫龊?,就像 Blurb的Logo,長方形可以用于扮演一個形象。Blurb 用藍(lán)色的圖形放在名字后面來代表一本書,因為他們做的是圖書出版業(yè)務(wù)。

?

5. 3d Puffies

With these new puffed-up Logos, you don't know whether to click on them or bounce on them. Now that the industry has overcome the production issues of gradients, designers seem to prefer air-popped graphics to the flat drawings of yore. Even desktop icons these days seem to have a rounded feel, like you might pop one with one good hard double-click. It's a 2D world out there in Internet land, and these 3D images really make Web pages and Logos jump out of the page, to where you feel you could run your hands over the computer screen and feel their bumps and curves.

5. 立體發(fā)泡物

這些新出現(xiàn)的圓鼓鼓發(fā)泡Logo,讓你搞不懂到底是在上面點擊還是在上面彈跳。自從工業(yè)生產(chǎn)克服了“漸變色”的難題,設(shè)計師們就似乎熱衷于將“立體 彈出”的圖像加到以往的平面圖樣中。甚至桌面圖標(biāo)在最近也看起來有圓乎乎的感覺,就像你用力一點擊它就會彈得老高。二維的世界已經(jīng)從互聯(lián)網(wǎng)走開了,三維的 圖像的確讓網(wǎng)頁和Logo“跳出”頁面,進(jìn)入一個你可以用手指滿屏幕去感覺那些凹凸不平和曲線的新世界。


6. Hot Dogs

These cute little Tic Tacs of color are popping up all over the design world. Like many abstract symbols, the hot dogs can be used to mean many different things. Sometimes they denote movement or sound, such as in the Logo for Snap. These lines, reminiscent of those drawn out of shocked cartoon people by children everywhere, can denote an idea, a feeling or a literal meaning. But no matter how they're used in design, they are a powerful symbol of an upbeat emotion.


6. 熱狗腸

這些色彩和彈出的可愛小把戲遍布了整個設(shè)計界。像許多抽象符號一樣,熱狗腸可以用來表示許多不同的東西。又是他們表示聲音或運動的 警示,就像Snap的Logo里那樣。那些輻射的線條,讓人想起隨處可見的小孩子畫的 大吃一驚的 卡通人物。它能表示一種想法,一種感覺或者只是一種 字面上的意義。但不管它們用在設(shè)計中是為什么,它們都是一種有強(qiáng)烈表現(xiàn)力的符號來象征 樂觀的態(tài)度。


7. Transmission beam

With satellite tv and radio and wireless everything all the rage in the new millennium, a transmission beams are a quick way to show that they are on the cutting edge of technology. Many companies who use this Logo trend deal in internet information. Part of what many of these companies are doing on the internet is taking user (or customer) information and sharing it with the world. The transmission beam, starting with a single dot (to represent the user), shows their ideas spreading out. It's the perfect symbol for publishing companies or blog sites.


7. 發(fā)射電波

衛(wèi)星電視,電臺和無線的東東在新紀(jì)元里遍地開花,用發(fā)射電波是最快捷方式來表明他們是站在科技的最前沿。用這種Logo的許多公司都在做互聯(lián)網(wǎng)信息 生意。他們中間有許多公司做的是在互聯(lián)網(wǎng)上獲取用戶(客戶)資料然后分享給全世界。無線電波,始發(fā)于一個“點”(代表用戶),體現(xiàn)他們的理念在傳播。對于 出版公司和博

?

8. People

AOL's little man has some company, with others creating buddies to include in their Logos. For companies that bring people together, these genderless little people are shown in pairs or groups. They provide a visual indicator of coming together. Others show just one of these symbols, usually as an avatar for their customer. Anyone looking for other people can be sure they've found them when they see a Logo with a buddy.


8. 人形

美國在線的“小人”已有了幾個軍團(tuán),和其他正在創(chuàng)建的好友一起都?xì)w屬在它的Logo旗下。軍團(tuán)將人聚在一起,把這些搞不清性別的人成對或成組排列。 他們?yōu)椤熬墼谝黄稹碧峁┝诉@樣一個視覺指示。有些公司的Logo只展示符號中的一個,這通常作為他們客戶的偶像。任何想找人的人,當(dāng)他們看到有這個 Logo的哥們,就能確信自己可以找到隊伍。


9. Transparency

Transparency is still hot. Again, many may gasp as the mere though of using a shadow, but this updated version is nothing like the shadow boxes that have plagued generic design. These Logos invoke images of blending together. Some, like the two transmission bubbles that seem to be popping out the little people in the BlueDot Logo, can symbolize communication, or a sort of overlapping and blending of ideas. Others are a Venn diagram, showing where the company fits, such as Zopa.


9. 透明效果

透明效果仍舊熱門。強(qiáng)調(diào)一下,很多人的需求只不過是加上個相框樣的東東,但是這個“升級版”一點都不象相框那樣是令人厭倦的普通設(shè)計。這些Logo 讓圖像混合在一起。有些,象是兩個傳送的泡泡,它們看起來象是要把“小人”彈出來(見BlueDot的Logo),它可以象征溝通,或者 觀念的混合 和 重疊的排序。另外的看起來象“交集圖”(Venn diagram),展現(xiàn)出什么是公司的業(yè)務(wù)范圍,就像 Zopa。


10. Outlines

(I think this is another way to add sophistication, 3d effect to a Logo)
Many are finding that nothing brings a Logo to the next level like a professionally done outline. These surrounding lines or shades can simply run around the text or seem to encapsulate it in a bubble, as seen in the picturecloud.com Logo. These outlines can take text and make it seem as though it's one unit. Nicely done, these effects add sophistication and a third dimension to Logos.

?

10. 輪廓線

(我想這是另外一個方法來錦上添花,弄點立體效果到Logo上。)
很多人發(fā)現(xiàn),沒有什么比用輪廓線更能使Logo看起來顯得專業(yè)。這些環(huán)繞 著的線或者框可以直接用在文字的周圍或是看起來象塑封在一個泡泡里,就像在picturecloud.com 的Logo里一樣。這些輪廓線能讓文字看起來就像是一個整體。干得漂亮,這些效果的確給Logo錦上添花并有了立體感。


11. Punctuation

From smiley faces to complex illustrations, every day punctuation has gained a new life in the tech typing world of the internet. While some used to only be used to denote the f-word, they're now used in the young on-line world on instant messaging, e-mailing and teen-speak in general. Now, these symbols have jumped out of instant messaging and onto billboards as of late, with their meanings left to the imagination of customers.


11. 標(biāo)點符號

從笑臉圖案到復(fù)雜插圖,在互聯(lián)網(wǎng)的文字輸入世界里,標(biāo)點符號每天都會獲得新生。當(dāng)某些人習(xí)慣于只用 F-word(粗俗語言,F(xiàn)xxk字頭的詞匯)來表達(dá)時,它們現(xiàn)在就被年輕人用在即時聊天,E-Mail和小青年們的日常對話里?,F(xiàn)在這些符號從即時聊天 軟件和聊天室里蹦出來,帶著它們的涵義留給用戶無限的想像空間。



天邊一片伴月星 2007-03-08 11:38 發(fā)表評論
]]>
轉(zhuǎn)compass (http://www.agilejava.org/space/?108/action_viewspace_itemid_172.html)http://www.aygfsteel.com/zhangzhong1018/articles/96567.html天邊一片伴月星天邊一片伴月星Mon, 29 Jan 2007 10:21:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/96567.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/96567.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/96567.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/96567.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/96567.htmlCompass是一流的開放源碼JAVA搜索引擎框架,對于你的應(yīng)用修飾,搜索引擎語義更具有能力。依靠頂級的Lucene搜索引擎,Compass 結(jié)合了,像 Hibernate和 Sprin的流行的框架,為你的應(yīng)用提供了從數(shù)據(jù)模型和數(shù)據(jù)源同步改變的搜索力.并且添加了2方面的特征,事物管理和快速更新優(yōu)化. Compass的目標(biāo)是:把java應(yīng)用簡單集成到搜索引擎中.編碼更少,查找數(shù)據(jù)更便捷。
??? 下面以一個應(yīng)用場景分步驟講解如何利用compass實現(xiàn)搜索引擎:
1.?這里我們有一個Article表,希望利用compass實現(xiàn)對它的搜索。
??Article的結(jié)構(gòu)如下:
??CREATE TABLE `article` (
??? `ArticleID` bigint(20) NOT NULL,
??? `PersonInfoID` bigint(20) default NULL,
??? `ArticleTitle` varchar(200) default NULL,
??? `PublishDate` datetime default NULL,
??? `Summary` text,
??? `Content` longtext,
??? `KeyList` text,
??? PRIMARY KEY? (`ArticleID`),
??? KEY `PersonInfoArticle_FK` (`PersonInfoID`)
??) ENGINE=InnoDB DEFAULT CHARSET=utf8;
??我們希望利用compass對它的ArticleTitle、Summary、Content和KeyList進(jìn)行全文檢索。下面開始行動吧。
??
2.?首先到http://www.opensymphony.com/compass/download.action 上下載一個compass的發(fā)布版,我們下載的是Version 1.0.0的With Dependencies 。這樣就可能省去尋找相關(guān)信賴庫的麻煩了。

3.?將compass1.0解壓到一個合適的目錄,我們的工作目錄是d:\develop\compass1.0

4.?我們是在eclipse環(huán)境下實現(xiàn)當(dāng)前要求的,所以建議你也安裝一個eclipse 3.2。

5.?首先我們在eclipse中建立了一個java工程,名為mycompass。

6.?然后我們在工程目錄中建立了一個lib目錄,用來存放本次工程所需要的所有compass和其它相關(guān)的庫文件,并將他們設(shè)置為當(dāng)前工程構(gòu)建路徑中需要的庫文件。所有這些文件可以在compass的安裝目錄的lib目錄找到。

??下面是我們的庫文件列表:
?
7.?建立了Article表的pojo類。
??package com.darkhe.sample.mycompass;
??
??// Generated 2006-8-2 10:57:06 by Hibernate Tools 3.2.0.beta6a
??
??import java.util.Date;
??
??/**
?? * Article generated by hbm2java
?? */
??public class Article implements java.io.Serializable {
??
???// Fields???
??
???private long articleId;
??
???private Long personInfoId;
??
???private String articleTitle;
??
???private Date publishDate;
??
???private String summary;
??
???private String content;
??
???private String keyList;
??
???// Constructors
??
???/** default constructor */
???public Article() {
???}
??
???/** minimal constructor */
???public Article(long articleId) {
????this.articleId = articleId;
???}
??
???/** full constructor */
???public Article(long articleId, Long personInfoId, String articleTitle,
?????Date publishDate, String summary, String content, String keyList) {
????this.articleId = articleId;
????this.personInfoId = personInfoId;
????this.articleTitle = articleTitle;
????this.publishDate = publishDate;
????this.summary = summary;
????this.content = content;
????this.keyList = keyList;
???}
??
???// Property accessors
???public long getArticleId() {
????return this.articleId;
???}
??
???public void setArticleId(long articleId) {
????this.articleId = articleId;
???}
??
???public Long getPersonInfoId() {
????return this.personInfoId;
???}
??
???public void setPersonInfoId(Long personInfoId) {
????this.personInfoId = personInfoId;
???}
??
???public String getArticleTitle() {
????return this.articleTitle;
???}
??
???public void setArticleTitle(String articleTitle) {
????this.articleTitle = articleTitle;
???}
??
???public Date getPublishDate() {
????return this.publishDate;
???}
??
???public void setPublishDate(Date publishDate) {
????this.publishDate = publishDate;
???}
??
???public String getSummary() {
????return this.summary;
???}
??
???public void setSummary(String summary) {
????this.summary = summary;
???}
??
???public String getContent() {
????return this.content;
???}
??
???public void setContent(String content) {
????this.content = content;
???}
??
???public String getKeyList() {
????return this.keyList;
???}
??
???public void setKeyList(String keyList) {
????this.keyList = keyList;
???}
??
??}


8.?建立hibernate的pojo到數(shù)據(jù)表映射文件
?<?xml version="1.0"?>
?<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
?"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
?<!-- Generated 2006-8-2 10:57:07 by Hibernate Tools 3.2.0.beta6a -->
?<hibernate-mapping>
??? <class name="com.darkhe.sample.mycompass.Article" table="article" catalog="freedom">
??????? <comment></comment>
??????? <id name="articleId" type="long">
??????????? <column name="ArticleID" />
??????????? <generator class="assigned" />
??????? </id>
??????? <property name="personInfoId" type="java.lang.Long">
??????????? <column name="PersonInfoID">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??????? <property name="articleTitle" type="string">
??????????? <column name="ArticleTitle" length="200">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??????? <property name="publishDate" type="timestamp">
??????????? <column name="PublishDate" length="19">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??????? <property name="summary" type="string">
??????????? <column name="Summary" length="65535">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??????? <property name="content" type="string">
??????????? <column name="Content">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??????? <property name="keyList" type="string">
??????????? <column name="KeyList" length="65535">
??????????????? <comment></comment>
??????????? </column>
??????? </property>
??? </class>
?</hibernate-mapping>


9.?開始配置compass,首先是compass的系統(tǒng)配置文件 mycompass.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<compass-core-config
?xmlns="http://www.opensymphony.com/compass/schema/core-config"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://www.opensymphony.com/compass/schema/core-config
?????????? http://www.opensymphony.com/compass/schema/compass-core-config.xsd">

?<compass name="default"> <!—這個名字隨你取了,但它是必須的-->

??<connection>
???<file path="target" /> <!—這里是索引文件的存放路徑,我們設(shè)置的是當(dāng)前工程的相對路徑target-?
??</connection>

??<searchEngine>
??? <!-- 因是使用自己的分詞算法,所以這里的類型必須是CustomAnalyzer -->
????????? <analyzer name="MMAnalyer" type="CustomAnalyzer" analyzerClass="jeasy.analysis.MMAnalyzer">
????????????? <stopWords>
????????????????? <stopWord value="test" />
????????????? </stopWords>
????????? </analyzer>
????? </searchEngine>

?</compass>
</compass-core-config>
?在上面的配置中,我們使用的我們選用的一個中文分詞算法庫,你可以用compass自帶的。具體compass提供了哪些分詞算法,請查閱compass的手冊。


10.?然后是mycompass.cmd.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE compass-core-meta-data PUBLIC
??? "-//Compass/Compass Core Meta Data DTD 1.0//EN"
??? "http://www.opensymphony.com/compass/dtd/compass-core-meta-data.dtd">

<compass-core-meta-data>

<!-- 定義一個實體和字段組-->
??? <meta-data-group id="mycompass" displayName="My Compass">
???
??????? <descrīption>Mycompass Meta Data</descrīption>??????
??????? <uri>http://com/darkhe/sample/mycompass</uri>
???
???????
<!-- 申明所有需要檢索的實體-->???????
??????? <alias id="Article" displayName="Article">
??????????? <descrīption>Article alias</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/Article</uri>
??????????? <name>Article</name>
??????? </alias>
???????
?<!-- 申明所有需要檢索的屬性或者字段,而不管這些屬性或者字段是哪個實體的 -->???????
??????? <meta-data id="ArticleTitle" displayName="ArticleTitle">
??????????? <descrīption>ArticleTitle</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/ArticleTitle</uri>
??????????? <name>ArticleTitle</name>
??????? </meta-data>
???????
??????? <meta-data id="PublishDate" displayName="PublishDate">
??????????? <descrīption>PublishDate</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/PublishDate</uri>
??????????? <name format="yyyy-MM-dd hh:mm:ss">date</name>
??????? </meta-data>
???????
??????? <meta-data id="Summary" displayName="Summary">
??????????? <descrīption>Summary</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/Summary</uri>
??????????? <name>Summary</name>
??????? </meta-data>
???????
??????? <meta-data id="Content" displayName="Content">
??????????? <descrīption>Content</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/Content</uri>
??????????? <name>Content</name>
??????? </meta-data>

??????? <meta-data id="KeyList" displayName="KeyList">
??????????? <descrīption>KeyList</descrīption>
??????????? <uri>http://com/darkhe/sample/mycompass/alias/KeyList</uri>
??????????? <name>KeyList</name>
??????? </meta-data>???????
???????????????????????
??? </meta-data-group>
???
</compass-core-meta-data>


11.?再是mycompass.cpm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE compass-core-mapping PUBLIC
??? "-//Compass/Compass Core Mapping DTD 1.0//EN"
??? "http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd">

<!-- 這里的包名必須和pojo的包名一致 -->
<compass-core-mapping package="com.darkhe.sample.mycompass">

<!-- 定義實體及其字段的對應(yīng)關(guān)系 -->

<!-- 注意實體及其字段的名稱的大小寫應(yīng)當(dāng)與pojo對象一致,而不是與數(shù)據(jù)庫一致
? 關(guān)于pojo與數(shù)據(jù)庫的對應(yīng)表的一致性關(guān)系由hibernate的映謝文件定義,而不是這個文件
? 當(dāng)前映射文件只定義compass與hibernate的關(guān)系 -->

?<class name="Article" alias="${mycompass.Article}">
??<id name="ArticleId" />
??
??<property name="ArticleTitle">
???<meta-data>${mycompass.ArticleTitle}</meta-data>
??</property>

??<property name="PublishDate">
???<meta-data>${mycompass.PublishDate}</meta-data>
??</property>

??<property name="Summary">
???<meta-data>${mycompass.Summary}</meta-data>
??</property>

??<property name="Content">
???<meta-data>${mycompass.Content}</meta-data>
??</property>

??<property name="KeyList">
???<meta-data>${mycompass.KeyList}</meta-data>
??</property>
?</class>
?</compass-core-mapping>


12.?log4j.properties
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %c - %m%n
log4j.logger.org.compass=INFO


13.?jdbc.properties
# Properties file with JDBC-related settings.
# Applied by PropertyPlaceholderConfigurer from "applicationContext-*.xml".
# Targeted at system administrators, to avoid touching the context XML files.
jdbc.driverClassName=com.mysql.jdbc.Driver
#jdbc.driverClassName=org.hsqldb.jdbcDriver
#jdbc.url=jdbc:hsqldb:hsql://localhost:9001
jdbc.url=jdbc:mysql://localhost:3306/testdb
jdbc.username=test
jdbc.password=test
# Property that determines the Hibernate dialect
# (only applied with "applicationContext-hibernate.xml")
#hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect

14.?最后是applicationContext-hibernate.xml,這里集中配置了compass如何與spring與hibernate結(jié)合的。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
?- Application context definition for Petclinic on Hibernate.
-->
<beans>
?<!-- ========================= RESOURCE DEFINITIONS ========================= -->
?<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
?<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
?<bean id="propertyConfigurer"
??class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
??<property name="location">
???<value>classpath:jdbc.properties</value>
??</property>
?</bean>
?<!-- Local DataSource that works in any environment -->
?<!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->
?<!-- See JPetStore for an example of using Commons DBCP BasicDataSource as alternative -->
?<!-- See Image Database for an example of using C3P0 ComboPooledDataSource as alternative -->
?<bean id="dataSource"
??class="org.springframework.jdbc.datasource.DriverManagerDataSource">
??<property name="driverClassName">
???<value>${jdbc.driverClassName}</value>
??</property>
??<property name="url">
???<value>${jdbc.url}</value>
??</property>
??<property name="username">
???<value>${jdbc.username}</value>
??</property>
??<property name="password">
???<value>${jdbc.password}</value>
??</property>
?</bean>
?<!-- JNDI DataSource for J2EE environments -->
?<!--
??<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
??<property name="jndiName"><value>java:comp/env/jdbc/petclinic</value></property>
??</bean>
?-->
?<!-- Hibernate SessionFactory -->
?<bean id="sessionFactory"
??class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
??<property name="dataSource">
???<ref local="dataSource" />
??</property>
??<property name="mappingResources">
???<list>
????<value>
?????com/darkhe/sample/mycompass/Article.hbm.xml <!-- 這里是hibernate里需要的數(shù)據(jù)映射文件 -->
????</value>
???</list>
??</property>
??<property name="hibernateProperties">
???<props>
????<prop key="hibernate.dialect">
?????${hibernate.dialect}
????</prop>
????<prop key="hibernate.show_sql">false</prop>
????<prop key="hibernate.generate_statistics">true</prop>
???</props>
??</property>
??<property name="eventListeners">
???<map>
????<entry key="merge">
?????<bean
??????class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
????</entry>
???</map>
??</property>
?</bean>


?<!-- COMPASS START -->
?<bean id="compass" class="org.compass.spring.LocalCompassBean">
??<property name="resourceLocations">
???<list>
????<value>classpath:mycompass.cmd.xml</value>?<!-- 這里是compass所需要的兩個關(guān)于數(shù)據(jù)項的配置文件 -->
????<value>classpath:mycompass.cpm.xml</value>
???</list>
??</property>
??<property name="configLocation">
???<value>classpath:mycompass.cfg.xml</value>?<!-- 這里是compass的系統(tǒng)配置文件的路徑 -->
??</property>
??<!--???????? <property name="compassSettings">
???<props>
???<prop key="compass.engine.connection">file://d:/target</prop>
???<prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop>
???</props>
???</property>-->

??<property name="transactionManager">
???<ref local="transactionManager" />
??</property>
?</bean>


?<bean id="hibernateGpsDevice"
??class="org.compass.spring.device.hibernate.SpringHibernate3GpsDevice">
??<property name="name">
???<value>hibernateDevice</value>
??</property>
??<property name="sessionFactory">
???<ref local="sessionFactory" />
??</property>
?</bean>
?<bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps"
??init-method="start" destroy-method="stop">
??<property name="compass">
???<ref bean="compass" />
??</property>
??<property name="gpsDevices">
???<list>
????<bean
?????class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">
?????<property name="gpsDevice" ref="hibernateGpsDevice" />
????</bean>
???</list>
??</property>
?</bean>
?<!-- COMPASS END -->
</beans>

15.?注意上面的所以配置文件,根據(jù)我們上面的配置,都應(yīng)當(dāng)放到classpath的根路徑。
16.?建立工具類,用來進(jìn)行spring引擎的初始化工作。
/**
?* <p>@(#) IOC.java 2006-2-1 0:08:23</p>
?* <p>Copyright (c) 2005-2006 ???????????????????</p>
?*/
package com.darkhe.sample.mycompass;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
?*
?*
?* @version 1.0 2006-2-1
?* @author darkhe
?*/
public class IOC {
?private static ApplicationContext context = null;

?private static boolean isInit = false;

?private IOC() {
??super();
?}

?private static void init() {
?
??if (isInit == false) {
???String[] xmlfilenames = { "applicationContext-hibernate.xml" };

???context = new ClassPathXmlApplicationContext(xmlfilenames);

???isInit = true;
??}
?}

?/**
? *?
? * @return
? */
?public static ApplicationContext getContext() {
??if (context == null || isInit == false) {
???init();
??}
??return context;
?}

?/**
? *
? * @param name
? * @return
? */
?public static Object getBean(String name) {
??return getContext().getBean(name);
?}

}


17.?建立索引程序,用來數(shù)據(jù)庫中的建立索引
/*
?* Copyright (c) 2005-2006
?* ChongQing Man-Month Technology Development Co. ,Ltd
?*
?* ---------------------------------------------------------------------------------
?* @(#) Inder.java, 2006-8-1 下午09:01:14
?* ---------------------------------------------------------------------------------
?*/
package com.darkhe.sample.mycompass;

import java.io.FileNotFoundException;

import org.compass.gps.CompassGps;
import org.springframework.context.ApplicationContext;

/**
?* @author darkhe
?*
?*/
public class Indexer {

?/**
? * @param args
? * @throws FileNotFoundException
? */
?public static void main(String[] args) throws FileNotFoundException {

???// 加裁自定義詞典
??DictionaryUtils.loadCustomDictionary();

??ApplicationContext context = IOC.getContext();

??// 得到spring環(huán)境中已經(jīng)配置和初始化好的compassGps對象
??CompassGps compassGps = (CompassGps) context.getBean("compassGps");
??// 調(diào)用index方法建立索引
??compassGps.index();

?}

}

18.?建立搜索程序,檢證compass的應(yīng)用。
/*
?* Copyright (c) 2005-2006
?* ChongQing Man-Month Technology Development Co. ,Ltd
?*
?* ---------------------------------------------------------------------------------
?* @(#) Searcher.java, 2006-8-1 下午09:36:29
?* ---------------------------------------------------------------------------------
?*/

package com.darkhe.sample.mycompass;

import java.io.FileNotFoundException;

import org.compass.core.Compass;
import org.compass.core.CompassCallbackWithoutResult;
import org.compass.core.CompassException;
import org.compass.core.CompassHits;
import org.compass.core.CompassSession;
import org.compass.core.CompassTemplate;
import org.compass.core.Resource;
import org.springframework.context.ApplicationContext;

/**
?* @author darkhe
?*
?*/
public class Searcher {

?/**
? * @param args
? * @throws FileNotFoundException
? */
?public static void main(String[] args) throws FileNotFoundException {

??// 加裁自定義詞典
??DictionaryUtils.loadCustomDictionary();

??ApplicationContext context = IOC.getContext();

??Compass compass = (Compass) context.getBean("compass");

??CompassTemplate template = new CompassTemplate(compass);

??template.execute(new CompassCallbackWithoutResult() {
???protected void doInCompassWithoutResult(CompassSession session)
?????throws CompassException {
????CompassHits hits = session.find("大頭人");

????System.out.println("Found [" + hits.getLength()
??????+ "] hits for [大頭人] query");
????System.out
??????.println("======================================================");
????for (int i = 0; i < hits.getLength(); i++) {
?????print(hits, i);
????}

????hits.close();
???}
??});

?}

?public static void print(CompassHits hits, int hitNumber) {
??Object value = hits.data(hitNumber);
??Resource resource = hits.resource(hitNumber);
??System.out.println("ALIAS [" + resource.getAlias() + "]? SCORE ["
????+ hits.score(hitNumber) + "]");
??System.out.println(":::: " + value);
??System.out.println("");
?}
}


19.?工具類DictionaryUtils是用來管理我們自己采用的中文分詞算法的加載自定義詞典的。
/**
?* Copyright (c) 2005-2006 重慶人月科技發(fā)展有限公司
?*
?* ------------------------------------------------------------------------------
?* @(#) DictionaryUtils.java, 2006-8-2 下午04:55:22
?* ------------------------------------------------------------------------------
?*/
package com.darkhe.sample.mycompass;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import jeasy.analysis.MMAnalyzer;

/**
?*
?* @author darkhe
?* @version 1.0.0
?*/
public class DictionaryUtils {
?// 靜態(tài)變量
?private static boolean isInit = false;

?// 靜態(tài)初始化

?// 靜態(tài)方法
?public static void loadCustomDictionary() throws FileNotFoundException {

??if (isInit == false) {

???// 添加我們自己的詞典
???FileReader fr = new FileReader(new File("dict.txt"));
???MMAnalyzer.addDictionary(fr);
???
???//System.out.println("添加我們自己的詞典");

???isInit = true;
??}
?}
}
20.?執(zhí)行Indexer,再執(zhí)行Seracher后控制臺信息如下:

Found [1] hits for [大頭人] query
================================================
ALIAS [Article] SCORE [0.3988277]
:::: com.darkhe.sample.mycompass.Article@bla4e2


具體結(jié)果和你的數(shù)據(jù)表中的內(nèi)容有別。

21.?這樣,我們便實現(xiàn)了如何利用compass構(gòu)建我們自己的搜索引擎的一個簡單實現(xiàn)。



天邊一片伴月星 2007-01-29 18:21 發(fā)表評論
]]>
COMPASS應(yīng)用(轉(zhuǎn))http://www.aygfsteel.com/zhangzhong1018/articles/96564.html天邊一片伴月星天邊一片伴月星Mon, 29 Jan 2007 10:12:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/96564.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/96564.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/96564.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/96564.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/96564.html
一個簡單的COMPASS應(yīng)用

首先你要下載Compass framework: Download Compass.
你需要在你的class path 中添加4個jarcompass-x/modules/core/compass-core-x.jar, compass/modules/core/lib/commons-logging-x.jar, compass-x/modules/core/lib/log4j-x.jar, compass-x/modules/core/lib/lucene-core-x-rc1-dev.jar.
在你的項目中創(chuàng)建下面的目錄(可以根據(jù)自己的定義來改動):

log4j.properties
- org
?? - compassframework
???? - sample
?????? - example
?????????? alias.cmd.xml
?????????? compass.cfg.xml
?????????? CompassExample.java
?????????? Phrase.cpm.xml
?????????? Phrase.java
下面說一下幾個重要的配置文件

?compass.cfg.xmlcode

指定的target/index?是一個存儲目錄放索引文件的

(這個類必須有個無參數(shù)的構(gòu)造和id屬性)

xml 代碼
  1. <!--CTYPE?compass-core-configuration?PUBLIC"-//Compass/Compass?Core?Configuration?DTD?1.0//EN"? ??</sp-->
  2. ??
  3. ??
  4. "http://static.compassframework.org/dtd/compass-core-configuration-1.0.dtd" > ? ??
  5. ??
  6. ??
  7. ??
  8. < ??
  9. ??
  10. compass-core-configuration > ? ??
  11. < compass > ??
  12. ??
  13. < setting ? name = "compass.engine.connection" > target/index setting > ??
  14. ??
  15. < meta-data ? resource = "org/compassframework/sample/example/alias.cmd.xml" ? /> ??
  16. ??
  17. compass > ??
  18. ??
  19. compass-core-configuration > ??
  20. ??

?alias.cmd.xml:

xml 代碼
  1. <!--sp-->??
  2. ??
  3. xml ? version = "1.0" ?> ? ??
  4. <!--CTYPE?compass-core-meta-data?PUBLIC? ??</sp-->
  5. "-//Compass/Compass?Core?Meta?Data?DTD?1.0//EN"? ??
  6. "http://static.compassframework.org/dtd/compass-core-meta-data-1.0.dtd" > ? ??
  7. < compass-core-meta-data > ? ??
  8. < meta-data-group ? id = "example" ? displayName = "Example?Meta?Data" > ??
  9. ??
  10. < description > Example?Meta?Data description > ??
  11. ??
  12. < uri > http://compass/example uri > ??
  13. ??
  14. ??
  15. < alias ? id = "phrase" ? displayName = "Phrase" > ??
  16. ??
  17. < description > Phrase?alias description > ??
  18. ??
  19. < uri > http://compass/example/phrase uri > ??
  20. ??
  21. < name > phrase name > ??
  22. ??
  23. alias > ??
  24. ??
  25. < meta-data ? id = "author" ? displayName = "Author" > ??
  26. ??
  27. < description > Author?alias description > ??
  28. ??
  29. < uri > http://compass/example/author uri > ??
  30. ??
  31. < name > author name > ??
  32. ??
  33. meta-data > ??
  34. ??
  35. < meta-data ? id = "text" ? displayName = "Text" > ??
  36. ??
  37. < description > Text?alias description > ??
  38. ??
  39. < uri > http://compass/example/text uri > ??
  40. ??
  41. < name > text name > ??
  42. ??
  43. meta-data > ??
  44. ??
  45. meta-data-group > ??
  46. ??
  47. compass-core-meta-data > ??

Phrase.java

java 代碼
  1. package ?org.compassframework.sample.example; ??
  2. ??
  3. public ? class ?Phrase?{ ??
  4. ??
  5. ? private ?String?author; ??
  6. ??
  7. ? private ?String?text; ??
  8. ??
  9. ? private ?Long?id; ??
  10. ??
  11. ? public ?Phrase()?{ ??
  12. ??
  13. ?} ??
  14. ??
  15. ? public ?String?getAuthor()?{ ??
  16. ????? return ?author; ??
  17. ?} ??
  18. ??
  19. ? public ? void ?setAuthor(String?author)?{ ??
  20. ????? this .author?=?author; ??
  21. ?} ??
  22. ??
  23. ? public ?String?getText()?{ ??
  24. ????? return ?text; ??
  25. ?} ??
  26. ??
  27. ? public ? void ?setText(String?text)?{ ??
  28. ????? this .text?=?text; ??
  29. ?} ??
  30. ??
  31. ? public ?Long?getId()?{ ??
  32. ????? return ?id; ??
  33. ?} ??
  34. ??
  35. ? public ? void ?setId(Long?id)?{ ??
  36. ????? this .id?=?id; ??
  37. ?} ??
  38. ??
  39. ? public ?String?toString()?{ ??
  40. ??
  41. ????? return ?text; ??
  42. ?} ??
  43. ??
  44. }? ??
Phrase.cpm.xml

?

xml 代碼
  1. <!--sp-->xml?version="1.0"?>? ??
  2. <!--CTYPE?compass-core-mapping?PUBLIC? ??</sp-->
  3. "-//Compass/Compass?Core?Mapping?DTD?1.0//EN"? ??
  4. "http://static.compassframework.org/dtd/compass-core-mapping-1.0.dtd" > ? ??
  5. < compass-core-mapping ? package = "org.compassframework.sample.example" > ? ??
  6. < class ? name = "Phrase" ? alias = "${example.phrase}" > ??
  7. ??
  8. < id ? name = "id" ? /> ??
  9. ??
  10. < property ? name = "author" > ??
  11. ??
  12. < meta-data > ${example.author} meta-data > ??
  13. ??
  14. property > ??
  15. ??
  16. < property ? name = "text" > ??
  17. ??
  18. < meta-data > ${example.text} meta-data > ??
  19. ??
  20. property > ??
  21. ??
  22. class > ??
  23. ??
  24. compass-core-mapping > ??
CompassExample.java

java 代碼
  1. package ?org.compassframework.sample.example; ??
  2. ??
  3. import ?org.apache.log4j.Logger; ??
  4. ??
  5. import ?org.compassframework.core.Compass; ??
  6. import ?org.compassframework.core.Compass; ??
  7. import ?org.compassframework.core.CompassSession; ??
  8. import ?org.compassframework.core.CompassTransaction; ??
  9. import ?org.compassframework.core.config.CompassConfiguration; ??
  10. ??
  11. public ? class ?CompassExample?{ ??
  12. ??
  13. ? private ? static ? final ?Logger?logger?=?Logger.getLogger(CompassExample. class ); ??
  14. ? ??
  15. ? private ?compasscompass; ??
  16. ? ??
  17. ? public ? static ? void ?main(String[]?args){ ??
  18. ????? new ?CompassExample().process(); ??
  19. ?} ??
  20. ? ??
  21. ? private ? void ?process(){ ??
  22. ?????CompassConfiguration?config?=? new ?CompassConfiguration(); ??
  23. ?????config.configure( "org/compassframework/sample/example/compass.cfg.xml" ); ??
  24. ?????config.addClass(Phrase. class ); ??
  25. ?????compass?=?config.buildCompass(); ??
  26. ?????compass.getSearchEngineIndexManager().deleteIndex(); ??
  27. ?????compass.getSearchEngineIndexManager().createIndex(); ??
  28. ?? ??
  29. ?????createIndex(); ??
  30. ?????search( "mule?AND?crazy" ); ??
  31. ?????search( "Marisol?OR?Ramon" ); ??
  32. ?} ??
  33. ? ??
  34. ? private ? void ?createIndex(){ ??
  35. ??CompassSession?session?=?compass.openSession(); ??
  36. ?????CompassTransaction?tx?=?session.beginTransaction(); ??
  37. ?????Phrase?phrase?=? new ?Phrase(); ??
  38. ?????phrase.setAuthor( "Joe" ); ??
  39. ?????phrase.setText( "I?don't?think?it's?nice?you?laughing.?" ?+? ??
  40. ???????????? "You?see?my?mule?don't?like?people?laughing.?" ?+? ??
  41. ???????????? "He?gets?the?crazy?idea?you're?laughing?at?him.?" ?+? ??
  42. ???????????? "Now?if?you?apologize?like?I?know?you're?going?to,?" ?+? ??
  43. ???????????? "I?might?convince?him?that?you?really?didn't?mean?it..." ); ??
  44. ?????phrase.setId( new ?Long( 1 )); ??
  45. ?????session.save(phrase); ??
  46. ?????tx.commit(); ??
  47. ?????session.close(); ??
  48. ?} ??
  49. ? ??
  50. ? private ? void ?search(String?query){ ??
  51. ?????CompassSession?session?=?compass.openSession(); ??
  52. ?????CompassTransaction?tx?=?session.beginTransaction(); ??
  53. ?????Compass?hits?=?session.find(query); ??
  54. ????? if ?(logger.isDebugEnabled())?{ ??
  55. ????????logger.debug( "search()?-?Found?" ?+?hits.getLength()+ "?hits?for?\"" +query+ "\"" ); ??
  56. ?????} ??
  57. ????? for ?( int ?i?=? 0 ;?i?<?hits.getLength();?i++)?{ ??
  58. ????????print(hits,?i); ??
  59. ?????} ??
  60. ?????hits.close(); ??
  61. ?????tx.commit(); ??
  62. ?????session.close(); ??
  63. ?????compass.close(); ??
  64. ?} ??
  65. ? ??
  66. ? private ? void ?print(Compass?hits,? int ?hitNumber)?{ ??
  67. ?????Phrase?value?=?(Phrase)hits.data(hitNumber); ??
  68. ????? if ?(logger.isDebugEnabled())?{ ??
  69. ?????????logger.debug( "print()?-?Phrase?by?" ?+?value.getAuthor()?+? ":?" ??
  70. ?????????????+?value.getText()); ??
  71. ?????} ??
  72. ?} ??
  73. ??
  74. } ??
  75. ??

?

為了保證能打印出我們的測試,需要加入log4j.properties
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p %c - %m%n
log4j.logger.org.compassframework.sample.example=DEBUG


下面是打印出來的測試結(jié)果:
search() - Found 1 hits for "mule AND crazy"
print() - Phrase by Joe: I don't think it's nice you laughing...
search() - Found 0 hits for "Marisol OR Ramon"



天邊一片伴月星 2007-01-29 18:12 發(fā)表評論
]]>
Compasshttp://www.aygfsteel.com/zhangzhong1018/articles/96563.html天邊一片伴月星天邊一片伴月星Mon, 29 Jan 2007 10:11:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/96563.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/96563.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/96563.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/96563.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/96563.html

下面闡述Compass的一些名詞:

1:Resource,Compass對Lucene的Document的抽象,與Alias聯(lián)系在一起。

2:Property,Compass對Lucene的Field的抽象。通過Compass Converter framework將不是String類型的對象轉(zhuǎn)換為可以索引的Property。

3:RSEM:Resource/Search Engine Mapping,資源搜索引擎影射。

4:Lucene采用IndexReader、Searcher、IndexWriter三個類完成索引搜索的功能。而Compass只有一個簡單的接口,能夠通過該接口實現(xiàn)所有的操作。

5:事務(wù)索引和集成:lucene是非事務(wù)性的。無法和事務(wù)型的系統(tǒng)進(jìn)行結(jié)合。Compass提供兩種提交事務(wù):read_committed 和 serializable。

6:快速更新:lucene中,執(zhí)行更新必須先刪除舊的Document,然后再新建一個Document。由于Compass支持事務(wù)索引,因此每個要保存的Resource都必須有一個唯一標(biāo)識。這樣更新的效率會更高。

7: All 支持:在lucene中,沒有辦法對一個Document的所有的字段進(jìn)行搜索,要對所有字段進(jìn)行搜索,必須創(chuàng)建一個包含所有field的一個 "all"field。compass默認(rèn)地建立一個"all"屬性,并且該"all"屬性充當(dāng)默認(rèn)的搜索Field,當(dāng)然,"all"property 可以設(shè)置成enabled或disabled、重命名或者不充當(dāng)默認(rèn)的搜索Property,也可以排除all中的某些屬性。

8:索引分塊,

來源:http://bbs.xml.org.cn/blog/more.asp?name=lhwork&id=18505

作者: 地獄男爵

compass官方網(wǎng)站: http://www.compassframework.org/

Compass是一流的JAVA搜索框架,可以快速修飾你的應(yīng)用,使其具備Searchable的能力。

在沒有Compass,單純用Lucene的環(huán)境里,一般做法是定期遍歷數(shù)據(jù)庫,編碼將里面的內(nèi)容轉(zhuǎn)為索引。

而Compass通過與 Hibernate和 Spring的結(jié)合,簡單的為Domain Object提供了到Lucene引擎的映射,而且索引庫能夠隨Domain Object同步更新(Data Mirror)。

?

1?Quick Start

2?對象/搜索引擎映射(OSEM)



天邊一片伴月星 2007-01-29 18:11 發(fā)表評論
]]>
cocoon xsp http://www.aygfsteel.com/zhangzhong1018/articles/96114.html天邊一片伴月星天邊一片伴月星Fri, 26 Jan 2007 04:02:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/96114.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/96114.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/96114.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/96114.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/96114.htmlXSP (eXtensible Server Page )作為Cocoon的一個重要的組成部分可以為Cocoon的pipeline生成XML文件。XSP文件本身是XML文件,遵循XML的規(guī)范,但是支持在XML文件中包含程序代碼。XSP借助Bean Scripting Framework支持多種語言,包括Java,Javascript,Python 等。

XSP文件的根元素為<page>,通常使用xsp名字空間(<xsp:page>)。
一個簡單的例子如:

1: <?xml version="1.0"?>
2: <?cocoon-process type=”xsp”?>
3:
4: <xsp:page
5: language=”java”
6: xmlns:xsp=”http://apache.org/xsp”>
7:
8: <date>
9: <xsp:expr>new java.util.Date().toString()</xsp:expr>
10: </date>
11: </xsp:page>

2004年出版的Professional XML Development with Apache Tools: Xerces, Xalan, FOP, Cocoon, Axis, Xindice一書稱2行是必須的,但是我在Cocoon 2.1.9下測試發(fā)現(xiàn),其中的第2行聲明可以去掉。

下面看一個在XSP里定義一個函數(shù)的例子:

1: <?xml version="1.0"?>
2: <?cocoon-process type=”xsp”?>
3:
4: <xsp:page
5: language=”java”
6: xmlns:xsp=”http://apache.org/xsp”>
7:
8: <xsp:structure>
9: <xsp:include>java.util.Date</xsp:include>
10: </xsp:structure>
11:
12: <xsp:logic>
13: String getDate() {
14: Date d = new Date();
15: return d.toString();
16: }
17: </xsp:logic>
18:
19: <date>
20: <xsp:expr>getDate()</xsp:expr>
21: </date>
22: </xsp:page>

可以看到,定義函數(shù)的代碼被放在了<xsp:logic>元素里,另外使用<xsp:structure>和其子元素<xsp:include>元素可以導(dǎo)入Java的類。

完整的XSP元素列表如下:

  • <?cocoon-process?> This processing instruction (PI) tells Cocoon how to process this file. You may have multiple cocoon-process PIs because Cocoon can process an XSP page in two different ways. It can process the document as an XSP file, causing the language code to be executed. To indicate this style of processing, specify “xsp” as the value of the type pseudo-attribute. Cocoon can also use an XSL stylesheet to transform the document. This can occur either before or after the XSP processing. The processing order is determined by the order in which the PIs appear in the document. To use a stylesheet with an XSP document, specify “xslt” as the value of the type pseudo-attribute. If you use a stylesheet with the document, you need to supply an XML stylesheet processing instruction that tells where to find the stylesheet. (See the next item.)

  • <?xml-stylesheet?> This PI is defined by the W3C’s Associating Style Sheets with XML Documents recommendation. Associating a stylesheet is easy; you supply two pseudo-attributes. The href pseudo-attribute contains the URI for the stylesheet, and the type pseudo-attribute contains the MIME type of the stylesheet, which should be “text/xsl” for XSLT stylesheets.

  • <xsp:page> The root element of an XSP page is <xsp:page>. It takes a language attribute that allows you to specify the programming language being used in the XSP. You’ll probably also define some namespace prefixes on this element. The minimum would be for you to define the xsp prefix. The <xsp:page> must contain at least one user-defined element that’s used as the root element of the XSP result.

  • <xsp:structure> This element is a container for <xsp:include> elements.

  • <xsp:include> XSP uses the <xsp:include> element to import type definitions that are needed by the rest of the XSP. In Java, these are specified either as fully qualified classnames or in wildcarded package style, like java.util.*.

  • <xsp:logic> The implementation of the logic of an XSP should be the content of the <xsp:logic> element. For Java-based XSPs, this includes member fields and methods.

  • <xsp:expr> An <xsp:expr> element invokes logic in the <xsp:logic> to return a string valued expression. In Java, this is through method calls, field accesses, or string literals. Java string literals that appear as the content of an <xsp:expr> tag must be inside double quotes (”").

  • <xsp:element> This element allows you to dynamically create an element in the output XML. The <xsp:element> element takes a name attribute whose value is the name of the element to be created. You can nest these elements to create element subtrees dynamically. You can also insert literal XML elements and character data as part of the content of this element.

  • <xsp:attribute> The <xsp:attribute> element should appear as the child of either an <xsp:element> element or a literal XML element. It allows you to dynamically create an attribute by supplying a name attribute for the name of the new attribute. The value of the new attribute is the content of the <xsp:attribute> element.

  • <xsp:comment> To create a comment in the XSP output, use the <xsp:comment> element and make the content of the element the text of your comment.

  • <xsp:pi> The <xsp:pi> element allows you to create processing instructions. You supply a target attribute that defines the PI target name. If you wish to create pseudo-attributes, you do so via <xsp:expr> elements in the content of the <xsp:pi> element. So, to create a PI that looks like <?xml-stylesheet href=”sheet.xsl” type=”text/xsl”?>, your <xsp:pi> element would look like this:

    <xsp:pi target="xml-stylesheet">    <xsp:expr>"href=\"sheet.xsl\" type=\"text/xsl\""</xsp:expr>  </xsp:pi>
  • <xsp:content> You can use the <xsp:content> element inside an <xsp:logic> element to insert the Java code for an XSP fragment at that point on the program. This is particularly useful for inserting an XSP fragment that is to be output as the body of a loop.
  • xsp:page — XSP 文檔的根元素,它必須只包含一個用戶元素
  • xsp:structure、xsp:include — 允許將附加的 Java 類導(dǎo)入到 XSP 的已編譯版本中
  • xsp:logic — 允許在 XSP 的已編譯版本中包含附加的編程代碼塊;這可以包含成員變量、方法或應(yīng)用程序邏輯
  • xsp:expr — 允許對 Java 表達(dá)式求值,并將它們的值添加到文檔
  • xsp:element — 允許 XSP 動態(tài)創(chuàng)建元素;這些元素可以用任意名稱創(chuàng)建,并且可以與任何名稱空間和前綴關(guān)聯(lián)
  • xsp:attribute — 允許將屬性動態(tài)地添加到元素;這些屬性可以用任意名稱和值創(chuàng)建,并且可以與任何名稱空間關(guān)聯(lián)
  • xsp:comment — 允許將注釋添加到已生成的文檔
  • xsp:pi — 允許動態(tài)創(chuàng)建處理指令,并將之添加到已生成的文檔
  • xsp:parameter — 允許為元素或?qū)傩陨擅Q

通過使用 xsp:element,還可以動態(tài)地創(chuàng)建元素,如:

<xsp:element>
<xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
Element content
</xsp:element>

這個示例顯示了用動態(tài)生成名稱創(chuàng)建元素涉及使用 xsp:element 和 xsp:param 元素。xsp:param定義了一個參數(shù),在本例中是元素的名稱,其值是一個用于計算元素名稱的表達(dá)式。

上面的代碼將生成 XML 輸出

<myElementName>Element content</myElementName>

用這種方式創(chuàng)建的元素還可以與一個特定的名稱空間和前綴關(guān)聯(lián),如下例所示。請注意:這兩個名稱空間和前綴參數(shù)都是必需的;否則將產(chǎn)生錯誤。

<xsp:element prefix="my" uri="http://www.examples.org">
<xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
Element content
</xsp:element>

這個示例生成了以下 XML 輸出:

<my:myElementName xmlns:my="http://www.examples.org">Element content</my:myElementName>

如同元素一樣,可以在 XSP 頁面中動態(tài)創(chuàng)建屬性。xsp:attribute 元素的工作原理類似于 xsp:element,它允許動態(tài)創(chuàng)建屬性的名稱及其值:

<xsp:element>
<xsp:param name="name"><xsp:expr>"myElementName"</xsp:expr></xsp:param>
<xsp:attribute name="myAttribute">myAttributeValue</xsp:attribute>
Element content
</xsp:element>

這個屬性的名稱定義在 name 屬性內(nèi),盡管是用與 xsp:element 類似的方法定義的,但它還能通過使用 xsp:param 子元素來定義。屬性值被指定成元素內(nèi)容。這可以是一個簡單文本值或更有效地由 xsp:expr 元素生成。

而 xsp:attribute 標(biāo)記不必與 xsp:element 結(jié)合使用。它可以被放置在任何用戶元素內(nèi),而且可以用相同的方法添加屬性。例如,可以通過使用調(diào)用定義在 XSP 頁面別處的方法的表達(dá)式來動態(tài)創(chuàng)建 image 元素的 URL。

<image>
<xsp:attribute name="href"><xsp:expr>calculateImageURL()</xsp:expr></xsp:attribute>
</image>

如果生成的屬性與特定的名稱空間關(guān)聯(lián),那么這可以通過使用附加的 prefix 和 uri 屬性或 xsp:param 元素來表示,它類似于用于 xsp:element 的方法。同樣,如果只定義了其中的一個,則是一個錯誤。

創(chuàng)建注釋和處理指令

xsp:comment 和 xsp:pi 元素用于創(chuàng)建注釋和處理指令。

創(chuàng)建注釋十分簡單。任何作為 xsp:comment 元素的子元素而提供的文本都變成了 XML 注釋:

<xsp:comment>This is a comment</xsp:comment>

然后這個注釋變成:

<!-- This is a comment -->

創(chuàng)建處理指令類似于創(chuàng)建動態(tài)元素或?qū)傩?。xsp:pi 元素應(yīng)該有一個標(biāo)識處理指令目標(biāo)的嵌套參數(shù)。照例對 xsp:pi 元素的剩余內(nèi)容求值。這里是一個簡單示例:

<xsp:pi target="myApplication">
<xsp:expr>"param1=value, param2=value, generatorTimestamp=" +
System.currentTimeMillis()</xsp:expr>
</xsp:pi>

輸出如下:

<?myApplication param1=value, param2=value, generatorTimestamp=1017407796870?>

還可以通過在 xsp:param 元素內(nèi)創(chuàng)建處理指令的目標(biāo)來自動生成它,如同以下示例演示的那樣:

<xsp:pi>
<xsp:param name="target"><xsp:expr>"myApplication"</xsp:expr></xsp:param>
<xsp:expr>"param1=value, param2=value, generatorTimestamp=" +
System.currentTimeMillis()</xsp:expr>
</xsp:pi>



天邊一片伴月星 2007-01-26 12:02 發(fā)表評論
]]>
hibernate Q&A (often)http://www.aygfsteel.com/zhangzhong1018/articles/78307.html天邊一片伴月星天邊一片伴月星Tue, 31 Oct 2006 08:16:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/78307.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/78307.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/78307.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/78307.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/78307.html ?。?、到底在哪用cascade="..."?
  
  cascade屬性并不是多對多關(guān)系一定要用的,有了它只是讓我們在插入或刪除對像時更方便一些,
??? 只要在cascade的源頭上插入或是刪除,所有cascade的關(guān)系就會被自己動的插入或是刪除。
??? 便是為了能正確的cascade,unsaved-value是個很重要的屬性。
??? Hibernate通過這個屬性來判斷一個對象應(yīng)該save還是update,如果這個對象的id是unsaved-value的話,
??? 那說明這個對象不是persistence object要save(insert);如果id是非unsaved-value的話,
??? 那說明這個對象是persistence object(數(shù)據(jù)庫中已存在),只要update就行了。saveOrUpdate方法用的也是這個機(jī)制。
  
 ?。?、到底在哪用inverse="ture"?
  
  inverse屬性默認(rèn)是false的,就是說關(guān)系的兩端都來維護(hù)關(guān)系。這個意思就是說,
??? 如有一個Student, Teacher和TeacherStudent表,Student和Teacher是多對多對多關(guān)系,
??? 這個關(guān)系由TeacherStudent這個表來表現(xiàn)。那么什么時候插入或刪除TeacherStudent表中的記錄來維護(hù)關(guān)系呢?
??? 在用hibernate時,我們不會顯示的對TeacherStudent表做操作。對TeacherStudent的操作是hibernate幫我們做的。
??? hibernate就是看hbm文件中指定的是"誰"維護(hù)關(guān)系,那個在插入或刪除"誰"時,就會處發(fā)對關(guān)系表的操作。
??? 前提是"誰"這個對象已經(jīng)知道這個關(guān)系了,就是說關(guān)系另一頭的對象已經(jīng)set或是add到"誰"這個對象里來了。
??? 前面說過inverse默認(rèn)是false,就是關(guān)系的兩端都維護(hù)關(guān)系,對其中任一個操作都會處發(fā)對表系表的操作。
??? 當(dāng)在關(guān)系的一頭,如Student中的bag或set中用了inverse="true"時,那就代表關(guān)系是由另一關(guān)維護(hù)的(Teacher)。
??? 就是說當(dāng)這插入Student時,不會操作TeacherStudent表,即使Student已經(jīng)知道了關(guān)系。
??? 只有當(dāng)Teacher插入或刪除時才會處發(fā)對關(guān)系表的操作。所以,當(dāng)關(guān)系的兩頭都用inverse="true"是不對的,
??? 就會導(dǎo)致任何操作都不處發(fā)對關(guān)系表的操作。當(dāng)兩端都是inverse="false"或是default值是,
??? 在代碼對關(guān)系顯示的維護(hù)也是不對的,會導(dǎo)致在關(guān)系表中插入兩次關(guān)系。
  
  在一對多關(guān)系中inverse就更有意義了。在多對多中,在哪端inverse="true"效果差不多(在效率上)。
??? 但是在一對多中,如果要一方維護(hù)關(guān)系,就會使在插入或是刪除"一"方時去update"多"方的每一個與這個"一"的對象有關(guān)系的對象。
??? 而如果讓"多"方面維護(hù)關(guān)系時就不會有update操作,因為關(guān)系就是在多方的對象中的,直指插入或是刪除多方對象就行了。
??? 當(dāng)然這時也要遍歷"多"方的每一個對象顯示的操作修關(guān)系的變化體現(xiàn)到DB中。不管怎樣說,還是讓"多"方維護(hù)關(guān)系更直觀一些。
  
 ?。场ascade和inverse有什么區(qū)別?
  
  可以這樣理解,cascade定義的是關(guān)系兩端對象到對象的級聯(lián)關(guān)系;而inverse定義的是關(guān)系和對象的級聯(lián)關(guān)系。
  
  4、net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by
???? cascade (remove deleted object from associations): 2, of class: Xxxxx

  這個問題出現(xiàn)在要刪除關(guān)系的一頭時。如,要刪除一個已經(jīng)和Student有關(guān)系的Teacher。當(dāng)tx.commit();
??? 時才會拋出這個異常。這時一個在關(guān)系另一頭的Student對象中的Set或是List中把這個Teacher對象顯示的remove掉,
??? 再session.delete(這個teacher);。這是為了防止在Student端有cascade時把這個Teacher對象再存回DB。
??? 所以,這個異常的只有在Student的關(guān)系定義中有cascade="...",而且沒有像上面說的顯示的解除關(guān)系時才會出現(xiàn)。
??? 所以防止出現(xiàn)這個異常的方法就是:1,在Student端不用cascade;2,或是用cascade的話,就顯示的刪除對像中的關(guān)系。
??? 3,在Teacher端要用cascade
  
  5、net.sf.hibernate.HibernateException: identifier of an instance of my.MyObject altered from N to N
  
  這個異常其時不是多對多中常遇到的,但是這個異常的提示不make sense,所以提一下,
??? 是因為id的java對象中的type和hbm文件中定義的不一樣,如:java中用long,而hbm中用type="integer",
??? 并且generator用的是identity時就會出現(xiàn)



天邊一片伴月星 2006-10-31 16:16 發(fā)表評論
]]>
hibernate summarizehttp://www.aygfsteel.com/zhangzhong1018/articles/78306.html天邊一片伴月星天邊一片伴月星Tue, 31 Oct 2006 08:14:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/78306.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/78306.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/78306.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/78306.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/78306.html  A.hibernate.cfg.xml和B.hibernate.properties
  
  A中可含映射文件的配置,而B中hard codes加映射文件。
  
  A.Configuration config=new Configuration().config();
  B. Configuration config=new Configuration();
  config.addClass(TUser.class);
  
  2.你不必一定用hibernate.cfg.xml或hibernate.properties這兩文件名,你也不一定非得把配置文件放在Classes下,  File file=new File("c:\\sample\\myhibernate.xml");  Configuration config=new Configuration().config(file);
  
  3. session.Flush() 強(qiáng)制數(shù)據(jù)庫立即同步,當(dāng)用事務(wù)時,不必用flush,事務(wù)提交自動調(diào)用flush在session關(guān)閉時也會調(diào)用flush
  
  4. Hibernate總是使用對象類型作為字段類型
  
  5. XDoclet專門建立了hibernate doclet,就是在java代碼上加上一些java docTag,后來再讓XDoclet分析該java代碼,生成映射文件;
  
  6.HQL子句本身大小寫無關(guān),但是其中出現(xiàn)的類名和屬性名必須注意大小寫區(qū)分。
  
  7.關(guān)系:  Constrained : 約束,表明主控表的主鍵上是否存在一個外鍵(foreigh key)對其進(jìn)行約束。
  
  property-ref:關(guān)聯(lián)類中用于與主控類相關(guān)聯(lián)的屬性名,默認(rèn)為關(guān)聯(lián)類的主鍵屬性名
  
  單向一對多需在一方配置,雙向一對多需在雙方進(jìn)行配置
  
  8.lazy=false:被動方的記錄由hibernate負(fù)責(zé)記取,之后存放在主控方指定的Collection類型屬性中
  
  9. java.util.Set或net.sof.hibernate.collecton.Bag類型的Collection
  
  10.重要:inverse:用于標(biāo)識雙向關(guān)聯(lián)中的被動方一端。
  
  inverse=false的一方(主控方)負(fù)責(zé)維護(hù)關(guān)聯(lián)關(guān)系.默認(rèn)值:false
  
  11.batch-size:采用延遲加載特征時,一次讀入的數(shù)據(jù)數(shù)昨。
  
  12.一對多通過主控方更新(主控方為一方時)
  
  user.getAddresses().add(addr);
  
  session.save(user);//通過主控對象級聯(lián)更新
  
  13.在one-to-many 關(guān)系中,將many 一方設(shè)為主動方(inverse=false)將有助性能的改善。在一方設(shè)置關(guān)系時,inverse=true,即將主控權(quán)交給多方,  這樣多方可主動從一方獲得foreign key,然后一次insert即可完工。
  
  addr.setUser(user);//設(shè)置關(guān)聯(lián)的TUser對象
  
  user.getAddresses().add(addr);
  
  session.save(user);//級聯(lián)更新
  
  14.只有設(shè)為主控方的一方才關(guān)心(訪問)對方的屬性,被動方是不關(guān)心對方的屬性的。
  
  15.one-to-many與many-to-one節(jié)點的配置屬性不同:
  
  一對多關(guān)系多了lazy和inverse兩個屬性多對多節(jié)點屬性:
  
  column:中間映射表中,關(guān)聯(lián)目標(biāo)表的關(guān)聯(lián)字段
  
  class:類名,關(guān)聯(lián)目標(biāo)類
  
  outer-join:是否使用外聯(lián)接
  
  注意:access是設(shè)置屬性值的讀取方式。
  
  column是設(shè)置關(guān)聯(lián)字段。
  
  16.多對多,注意兩方都要設(shè)置inverse和lazy,cascade只能設(shè)為insert-update
  
  多對多關(guān)系中,由于關(guān)聯(lián)關(guān)系是兩張表相互引用,因此在保存關(guān)系狀態(tài)時必須對雙方同時保存。
  
  group1.getRoles().add(role1);  role1.getGroups().add(group1);
  
  session.save(role1);  session.save(group1);
  
  17.關(guān)于vo和po  vo經(jīng)過hibernate容量處理,就變成了po(該vo的引用將被容器保存,并且在session關(guān)閉時flush,因此po如果再傳到其它地方改變了,就危險了)    vo和po相互轉(zhuǎn)換:BeanUtils.copyProperties(anotherUser,user);
  
  18.對于save操作而言,如果對象已經(jīng)與Session相關(guān)聯(lián)(即已經(jīng)被加入Session的實體容器中),則無需進(jìn)行具體的操作。因為之后的Session.flush過程中,Hibernate 會對此實體容器中的對象進(jìn)行遍歷,查找出發(fā)生變化的實體,生成并執(zhí)行相應(yīng)的update 語句。
  
  19.如果我們采用了延遲加載機(jī)制,但希望在一些情況下,實現(xiàn)非延遲加 載時的功能,也就是說,我們希望在Session關(guān)閉后,依然允許操作user的addresses 屬性 Hibernate.initialize方法可以通過強(qiáng)制加載關(guān)聯(lián)對象實現(xiàn)這一功能: 這也正是我們?yōu)槭裁丛诰帉慞OJO時,必須用JDK Collection接口(如Set,Map), 而非特定的JDK Collection實現(xiàn)類(如HashSet、HashMap)申明Collection屬性的 原因。
  
  20.事務(wù):從sessionFactory獲得session,其自動提交屬性就已經(jīng)關(guān)閉(AutoCommit=false),此時若執(zhí)行了jdbc操作,如果不顯式調(diào)用session.BeginTransaction(),是不會執(zhí)行事務(wù)操作的。
  
  jdbc transaction:基于同一個session(就是同一個connection)的事務(wù);
  
  jta transaction:跨session(跨connection)事務(wù).
  
  對于jta事務(wù),有三種實現(xiàn)方法:
  
  A。UserTransaction tx=new InitialContext().lookup("...");
  tx.commit();
  
  B. 使用hibernate封裝的方法:(不推薦)
  
  Transaction tx=session.beginTransaction();
  tx.commit();
  C. 使用ejb之sessionBean的事務(wù)技持方法,你只要在把需要在發(fā)布描述符中,把需要jta事務(wù)的方法聲明為require即可
  
  21.悲觀鎖,樂觀鎖:  樂觀鎖一般通過version來實現(xiàn),注意version節(jié)點必須出現(xiàn)在id后。
  
  22.Hibernate中,可以通過Criteria.setFirstResult和Criteria.setFetchSize方法設(shè)定分頁范圍。
  
  Query接口中也提供了與其一致的方法,hibernate主要在dialect類中實現(xiàn)在這個功能。
  
  23.cache
  
   ……
  
  net.sf.ehcache.hibernate.Provider 

  
  還需對ecache本身進(jìn)配置
  
   

  
  之后在映射文件中指定各個映射實體的cache策略
  
  
  ....
  
  
  ....
  

  
  ***************************************************** Query.list()跟Query.iterate()的不同: 對于query.list()總是通過一條sql語句獲取所有記錄,然后將其讀出,填入pojo返回; 但是query.iterate(),則是首先通過一條Select SQL 獲取所有符合查詢條件的記錄的 id,再對這個id 集合進(jìn)行循環(huán)操作,通過單獨的Select SQL 取出每個id 所對應(yīng)的記 錄,之后填入POJO中返回。
  
  也就是說,對于list 操作,需要一條SQL 完成。而對于iterate 操作,需要n+1 條SQL。,list方法將不會從Cache中讀取數(shù)據(jù)。iterator卻會。
  
  24.ThreadLocal:它會為每個線程維護(hù)一個私有的變量空間。實際上, 其實現(xiàn)原理是在JVM 中維護(hù)一個Map,這個Map的key 就是當(dāng)前的線程對象,而value則是 線程通過ThreadLocal.set方法保存的對象實例。當(dāng)線程調(diào)用ThreadLocal.get方法時, ThreadLocal會根據(jù)當(dāng)前線程對象的引用,取出Map中對應(yīng)的對象返回。
  
  這樣,ThreadLocal通過以各個線程對象的引用作為區(qū)分,從而將不同線程的變量隔離開來。
  
  25.Hibernate官方開發(fā)手冊標(biāo)準(zhǔn)示例:
  
  public class HibernateUtil { private static SessionFactory sessionFactory;
  static { try { // Create the SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
  } catch (HibernateException ex) { throw new RuntimeException( "Configuration problem: " + ex.getMessage(), ex );
  } } public static final ThreadLocal session = new ThreadLocal();
  public static Session currentSession() throws HibernateException { Session s = (Session) session.get();
  // Open a new Session, if this Thread has none yet if (s == null) { s = sessionFactory.openSession();
  session.set(s);
  } return s;
  } public static void closeSession() throws HibernateException { Session s = (Session) session.get();
  session.set(null);
  if (s != null) s.close();
  } }
  
  26.通過filter實現(xiàn)session的重用:
  
  public class PersistenceFilter implements Filter { protected static ThreadLocal hibernateHolder = new ThreadLocal();
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { hibernateHolder.set(getSession());
  try { …… chain.doFilter(request, response);
  …… } finally { Session sess = (Session)hibernateHolder.get();
  if (sess != null) { hibernateHolder.set(null);
  try { sess.close(); } catch (HibernateException ex) { throw new ServletException(ex);
  } } } } ……}<>


天邊一片伴月星 2006-10-31 16:14 發(fā)表評論
]]>
hibernate many-to-many casehttp://www.aygfsteel.com/zhangzhong1018/articles/78297.html天邊一片伴月星天邊一片伴月星Tue, 31 Oct 2006 07:47:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/78297.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/78297.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/78297.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/78297.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/78297.html SQL(MY SQL):
create table tgroup (
? group_id int not null auto_increment,
? name varchar(16) not null default ′′,
? primary key? (group_id)
) type=innodb;

create table trole (
? role_id int not null auto_increment,
? name varchar(16) not null default ′′,?
? primary key? (role_id)
) type=innodb;

create table tgroup_role (
? group_id int not null,
? role_id int not null,
? primary key(group_id, role_id),
? index (group_id),
? foreign key (group_id) references tgroup(group_id),
? index (role_id),
? foreign key (role_id) references trole(role_id)
) type=innodb;

Group 類:
package ivan.hibernate.many2many;
public class Group {
? ?private int id;
? ?private String name;
? ?private Set roles = new HashSet();
?? ...
}

Group.hbm.xml:
<hibernate-mapping>
??? <class name="ivan.hibernate.many2many.Group" table="tgroup">
??????? <id name="id" column="group_id" unsaved-value="0">
??????????? <generator class="increment"/>
??????? </id>
??????? <property name="name" type="string"/>??????
??????? <set name="roles"
???????????? table="tgroup_role"
???????????? cascade="save-update">????????????
???????????? <key column="group_id"/>
???????????? <many-to-many class="ivan.hibernate.many2many.Role"
?????????????????????????? column="role_id"/>
?????? </set>
??? </class>
</hibernate-mapping>

Role 類:
package ivan.hibernate.many2many;
public class Role {
?? private int id;
? ?private String name;
? ?private Set groups = new HashSet();
?? ...
}

Role.hbm.xml:
<hibernate-mapping>
??? <class name="ivan.hibernate.many2many.Role" table="trole">
??????? <id name="id" column="role_id" unsaved-value="0">
??????????? <generator class="increment"/>
??????? </id>
??????? <property name="name" type="string"/>??????
??????? <set name="groups"
???????????? table="tgroup_role"
????????????
inverse="true"
???????????? cascade="save-update">????????????
???????????? <key column="role_id"/>
???????????? <many-to-many class="ivan.hibernate.many2many.Group"
?????????????????????????? column="group_id"/>
??</set>
??? </class>
</hibernate-mapping>

hibernate.cfg.xml 同前面的例子差不多。

public class Test {
?
?public static void main(String[] args) throws HibernateException {
????
??Role role1 = new Role();?
??role1.setName("Role1");
??Role role2 = new Role();
??role2.setName("Role2");
??Role role3 = new Role();
??role3.setName("Role3");
??Group group1 = new Group();
??group1.setName("group1");
??Group group2 = new Group();
??group2.setName("group2");
??Group group3 = new Group();
??group3.setName("group3");
??group1.getRoles().add(role1);
??group1.getRoles().add(role2);
??group2.getRoles().add(role2);
??group2.getRoles().add(role3);
??group3.getRoles().add(role1);
??group3.getRoles().add(role3);
??role1.getGroups().add(group1);
??role1.getGroups().add(group3);
??role2.getGroups().add(group1);
??role2.getGroups().add(group2);
??role3.getGroups().add(group2);
??role3.getGroups().add(group3);
?
??SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
??Session session = sessionFactory.openSession();
??Transaction tx= session.beginTransaction();
??session.save(role1);
??session.save(role2);
??session.save(role3);
??session.save(group1);
??session.save(group2);
??session.save(group3);
??tx.commit();
??session.close();
??sessionFactory.close();
?}
}



天邊一片伴月星 2006-10-31 15:47 發(fā)表評論
]]>
用cocoon call webservice 生成 html,excel http://www.aygfsteel.com/zhangzhong1018/articles/75830.html天邊一片伴月星天邊一片伴月星Wed, 18 Oct 2006 02:11:00 GMThttp://www.aygfsteel.com/zhangzhong1018/articles/75830.htmlhttp://www.aygfsteel.com/zhangzhong1018/comments/75830.htmlhttp://www.aygfsteel.com/zhangzhong1018/articles/75830.html#Feedback0http://www.aygfsteel.com/zhangzhong1018/comments/commentRss/75830.htmlhttp://www.aygfsteel.com/zhangzhong1018/services/trackbacks/75830.htmlxsp 代碼
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsp:page language="java"
? xmlns:xsp="? xmlns:xsp-request="? xmlns:xscript="? xmlns:soap="?
? <page>
????? <content>
????? <xsp:logic>

?????? String cFCType= request.getParameter("cFCType");
???????String cPFrom= request.getParameter("cPFrom");
?<para>
????????<xsp:expr>iStartYear</xsp:expr>
?</para>
?<para>
?? <soap:call url="
???? <ns1:getcurrforecast xmlns:ns1="urn:www.gpe.com:forecast:forecast">
???? <soap:enc/>
???? ?<cFCType xsi:type="xsd:string" xmlns:xsi="
>
???? </ns1:getcurrforecast>
?? </soap:call>
?</para>

????? </xsp:logic>
????? </content>
? </page>
?
</xsp:page>

xml2html 代碼

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
???? xmlns:xsl="
???? xmlns:sql="<xsl:output method="html"/>

<xsl:template match="/">
<xsl:variable name="s" select="number(//fp_id_12)"/>
<table border="0" width="100%" height="50">
<tr>
<td width="30%" align="left">
<img border="0" src="
</td>
<td width="40%" align="center" style="font-size: 30pt"><b><u>Forecast Report</u></b></td>
<td width="30%" align="right" style="font-size: 14pt">
<SCRIPT>
document.write(Date());
</SCRIPT>
</td>
</tr>
</table>
<table border="0" bgcolor="#66CCFF" width="100%" style="border: 1px #66CCFF" cellspacing="1" cellpadding="1">
?<tr bgcolor="#66CCFF">
?? <th style="font-size: 9pt"><nobr>Part No</nobr></th>
?? <th style="font-size: 9pt"><nobr>Description</nobr></th>
?</tr>
?<xsl:for-each select="http://Item">
??<tr bgcolor="#FFFFFF">
??<td style="font-size: 9pt"><nobr><xsl:value-of select="product_code"/></nobr></td>
??<td style="font-size: 9pt"><nobr><xsl:value-of select="description"/></nobr></td>
?</xsl:for-each>
</table>

</xsl:template>

</xsl:stylesheet>

xml2xls 代碼
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
????????????????????????????? xmlns:sql="???????????????????????????? xmlns:gmr="? <xsl:output method="xml" />
? <xsl:template match="/">
?<gmr:Workbook xmlns:gmr="
????? <gmr:SheetNameIndex>
??????? <gmr:SheetName>Sheet 1</gmr:SheetName>
????? </gmr:SheetNameIndex>
????? <gmr:Sheets>
??????? <gmr:Sheet>
????????? <gmr:Name>Sheet 1</gmr:Name>

????????? <gmr:Styles>
??????????? <gmr:StyleRegion startRow="0" endRow="0" startCol="0" endCol="99">
?????????????? <gmr:Style HAlign="8" VAlign="4" WrapText="0" Orient="1"
???????????????????????? Shade="0" Indent="0" Locked="1" Hidden="0"
???????????????????????? Fore="0:0:0" Back="FFFF:FFFF:FFFF"
???????????????????????? PatternColor="0:0:0" Format="General">
??????????????? <gmr:Font Unit="10" Bold="1" Italic="0" Underline="0" StrikeThrough="0">
????????????????? Helvetica
??????????????? </gmr:Font>
????????????? </gmr:Style>
??????????? </gmr:StyleRegion>
????????? </gmr:Styles>

????????? <gmr:Cells>
?????? <xsl:call-template name="headerrow"/>
??????????? <xsl:apply-templates select="http://Item"/>
????????? </gmr:Cells>
??????? </gmr:Sheet>
????? </gmr:Sheets>
??? </gmr:Workbook>
</xsl:template>
<xsl:template name="headerrow">
??? ??<gmr:Cell Row="0" Col="0" ValueType="60">Part No</gmr:Cell>
??<gmr:Cell Row="0" Col="1" ValueType="60">Description</gmr:Cell>
</xsl:template>
<xsl:template match="Item">
??? <xsl:variable name="row" select="position()"/>
??? <gmr:Cell Row="{$row}" Col="0" ValueType="60">
????? <xsl:value-of select="product_code"/>
??? </gmr:Cell>
??? <gmr:Cell Row="{$row}" Col="1" ValueType="60">
????? <xsl:value-of select="description"/>
??? </gmr:Cell>
</xsl:template>
</xsl:stylesheet>



天邊一片伴月星 2006-10-18 10:11 發(fā)表評論
]]>
主站蜘蛛池模板: 册亨县| 肥城市| 澜沧| 松潘县| 怀安县| 建宁县| 桐柏县| 浏阳市| 明水县| 德昌县| 吉安市| 繁峙县| 大理市| 黎平县| 宁安市| 治多县| 句容市| 彩票| 长泰县| 印江| 西华县| 清水县| 诸暨市| 海丰县| 和平区| 浦城县| 黔江区| 中宁县| 台东市| 金寨县| 怀集县| 桂东县| 汨罗市| 鹿邑县| 夏邑县| 方山县| 固原市| 宁津县| 科技| 榕江县| 即墨市|