面朝大海,春暖花開

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            12 Posts :: 1 Stories :: 3 Comments :: 0 Trackbacks

          2006年4月10日 #

          馬上要做新項目了,項目不大,準備用ajax來練練手,HOHO!
          posted @ 2006-06-05 22:09 面朝大海 閱讀(162) | 評論 (0)編輯 收藏

          今天在網(wǎng)上閑逛,發(fā)現(xiàn)了一本好書,關(guān)于JAVA和TDD的,內(nèi)容介紹如下:

          Master Java 5.0 and TDD Together: Build More Robust, Professional Software

          Master Java 5.0, object-oriented design, and Test-Driven Development (TDD) by learning them together. Agile Java weaves all three into a single coherent approach to building professional, robust software systems. Jeff Langr shows exactly how Java and TDD integrate throughout the entire development lifecycle, helping you leverage today's fastest, most efficient development techniques from the very outset.

          Langr writes for every programmer, even those with little or no experience with Java, object-oriented development, or agile methods. He shows how to translate oral requirements into practical tests, and then how to use those tests to create reliable, high-performance Java code that solves real problems. Agile Java doesn't just teach the core features of the Java language: it presents coded test examples for each of them. This TDD-centered approach doesn't just lead to better code: it provides powerful feedback that will help you learn Java far more rapidly. The use of TDD as a learning mechanism is a landmark departure from conventional teaching techniques.

          • Presents an expert overview of TDD and agile programming techniques from the Java developer's perspective

          • Brings together practical best practices for Java, TDD, and OO design

          • Walks through setting up Java 5.0 and writing your first program

          • Covers all the basics, including strings, packages, and more

          • Simplifies object-oriented concepts, including classes, interfaces, polymorphism, and inheritance

          • Contains detailed chapters on exceptions and logging, math, I/O, reflection, multithreading, and Swing

          • Offers seamlessly-integrated explanations of Java 5.0's key innovations, from generics to annotations

          • Shows how TDD impacts system design, and vice versa

          • Complements any agile or traditional methodology, including Extreme Programming (XP)


          E文不算太難,一般都應(yīng)該可以看懂,為什么好書都是老外寫的呢?
          我想把書傳上來,但是.Text對文件的大小好象是有限制,書的名字叫
          Agile Java Crafting Code with Test-Driven Development,想要的同學(xué)可以留下EMAIL

          posted @ 2006-05-12 19:17 面朝大海 閱讀(440) | 評論 (2)編輯 收藏

          很早就聽說過Castle的大名了,但是一直沒有時間去研究。一方面也是自己的惰性,另一方面也關(guān)于Castle的分析文章太少了。但是不管怎么說,面對這這么優(yōu)秀的項目沒有一睹芳容,真是。現(xiàn)在好了,在博客園找到了一個關(guān)于Castle的系列文章,先收藏個連接,51在休息的空隙,還可以抽出點時間好好研究好東東,
          http://www.cnblogs.com/Terrylee/archive/2006/04/28/387503.html
          posted @ 2006-04-28 22:04 面朝大海 閱讀(269) | 評論 (0)編輯 收藏

          近來很忙,一直沒寫 blog 了,今天晚上有點時間,聽了節(jié) MSDN 上面的一節(jié) webCast ,講的就是 Proxy 模式,本就就是這節(jié)課的筆記。

          學(xué)習(xí)設(shè)計模式也有段時間了,很早也見過 Proxy 模式的,記得最開始接觸 Proxy 模式還是在著名的 JIVE 論壇( JIVE 中用 Proxy 來做權(quán)限控制)。今天算是一遍復(fù)習(xí)吧。

          對復(fù)雜的軟件系統(tǒng),人們常常用的一種處理手法是在系統(tǒng)增加一層間接層,得到對系統(tǒng)靈活的、滿足特殊要求的解決方案。

          使用 Proxy 模式的動機:在 OO 的開發(fā)過程中,某些對象的開銷很大(如: new 的開銷大、某些對象因為安全的原因不能被客戶直接的調(diào)用等),如果直接操作這些對象會破壞系統(tǒng)結(jié)構(gòu)。那么,我們就用代理對象來控制對象的訪問。

          例子,?? 一個常見的 HR 系統(tǒng):

          using ?System;

          class ?Employee
          {
          ????
          public ? double ?GetSalary()
          ????
          {
          ????????..
          ????}

          ????
          public ? void ?Report()
          ????
          {
          ????????.
          ????}

          ????
          public ? void ?ApplyVacation()
          ????
          {
          ????????
          ????}

          }


          class ?HrSys
          {
          ????
          public ? void ?ProcessEmployee
          ????????(Employee?employee
          /* 該對象和HR系統(tǒng)在同一個地址空間中 */ )
          ????
          {
          ????????employee.Report();
          ????????..
          ????????employee.ApplyVacation();
          ????}

          }

          現(xiàn)在要求把 Employee 做成 webService HR 系統(tǒng)通過 webService 來調(diào)用 Employee 對象,代碼修改如下:

          using ?System;

          interface ?IEmployee
          {
          ????
          public ? double ?GetSalary();
          ????
          public ? void ?Report();
          ????
          public ? void ?ApplyVacation();
          }

          // 運行在internet上面的某臺機器
          class ?Employee?:?IEmployee
          {
          ????
          public ? double ?GetSalary()
          ????
          {
          ????????..
          ????}

          ????
          public ? void ?Report()
          ????
          {
          ????????.
          ????}

          ????
          public ? void ?ApplyVacation()
          ????
          {
          ????????
          ????}

          }

          // 運行在本地的程序中
          class ?EmployeeProxy?:?IEmployee
          {
          ????
          public ? double ?GetSalary()
          ????
          {
          ????????
          // 對對象創(chuàng)建/訪問的SOAP封裝
          ????
          ?????
          // 發(fā)送SOAP數(shù)據(jù)
          ????
          ?????
          // 如果有返回值,就對SOAP分析,得到C#數(shù)據(jù)
          ????}

          ????
          ????
          public ? void ?Report()
          ????
          {
          ????????
          // 對對象創(chuàng)建/訪問的SOAP封裝
          ????
          ?????
          // 發(fā)送SOAP數(shù)據(jù)
          ????
          ?????
          // 如果有返回值,就對SOAP分析,得到C#數(shù)據(jù)
          ????}

          ????
          ????
          public ? void ?ApplyVacation()
          ????
          {
          ????????
          // 對對象創(chuàng)建/訪問的SOAP封裝
          ????
          ?????
          // 發(fā)送SOAP數(shù)據(jù)
          ????
          ?????
          // 如果有返回值,就對SOAP分析,得到C#數(shù)據(jù)
          ????}

          }

          class ?HrSys
          {
          ????
          public ? void ?ProcessEmployee(IEmployee?employeeProxy)
          ????
          {
          ????????employeeProxy.Report();
          ????????..
          ????????employeeProxy.ApplyVacation();
          ????}

          }

          Proxy 使用的要點:

          1 、“增加一層間接層”,是軟件系統(tǒng)中常用的手段之一。

          2 、具體的實現(xiàn)中, Proxy 有很大差別,有的是簡單的“ copy-on-write ”,有的是對組件模塊的抽象代理。在 JAVA 中常見的 SSH 架構(gòu)模式中( struts+spring+hibernate )中,我們可以把 spring 所在的服務(wù)層看成對 hiberate 的代理。

          具體的實現(xiàn)可以參考 .NET 中的 WebService 的實現(xiàn)。

          Copy-on-write 技術(shù)

          class ?App
          {
          ????
          // 系統(tǒng)在內(nèi)存中其實是指向同一塊內(nèi)存
          ???? string ?s1? = ? " Hello " ;? // 不可在修改
          ???? string ?s2? = ? " Hello " ;? // 不可在修改

          ????
          // s1.ToUpper();? // s1不會產(chǎn)生任何改變

          ????stringBulider?sb1?
          = ? new ?stringBulider( " Hello " );
          ????stringBulider?sb2?
          = ? new ?stringBulider( " Hello " );
          ????
          ????sb1.replace(
          " H " , " L " );? // 可以修改成功
          }

          sb1.replace("H","L"); 系統(tǒng)做的動作是, sb1 的代理對象先拷貝 ”Hello” 字符串,然后用“ L ”替換“ H ”, sb1 的代理對象重新指向新的對象。

          posted @ 2006-04-27 20:33 面朝大海 閱讀(300) | 評論 (0)編輯 收藏

          一、?????????? 數(shù)據(jù)庫事務(wù)概念

          數(shù)據(jù)庫事務(wù)的特征: ACID

          Atomic (原子性)、 Consistency (一致性)、 Isolation (隔離性)和 Durability (持久性)。 DBMS 用日志來保證數(shù)據(jù)的原子性、一致性和持久性;用鎖的機制來保證數(shù)據(jù)的隔離性。

          二、?????????? 事務(wù)的邊界

          數(shù)據(jù)庫支持 2 種事務(wù)模式:自動提交和手動提交。

          JDBC API 的事務(wù)邊界

          try
          {
          ????Connection?conn?
          = ?java.sql.DriverManager,.getConnection(dbUrl,dbUser,dbPwd);
          ????conn.setAutoCommit(
          false );? // 設(shè)置成手動模式
          ????stmt? = ?conn.createStatement();
          ????stmt.executeUpdate(
          " . " );? // 數(shù)據(jù)庫更新1
          ????stmt.executeUpdate( " . " );? // 數(shù)據(jù)庫更新2
          ????
          ????conn.commit();
          }

          catch (Exception?e)
          {
          ????conn.rollback();
          }

          finally
          {
          ????stmt.close();
          ????conn.close();
          }

          Hibernate API 聲明事務(wù)邊界

          Session?session? = ?factory.openSession();
          Transaction?tx;
          try ?
          {
          ????tx?
          = ?session.beginTransaction();? // 開始事務(wù)
          ????
          // 執(zhí)行操作
          ????。。。。。
          ????
          ????tx.commit();
          }

          catch ?(Exception?e)
          {
          ????
          if ?(tx != null )
          ????
          {
          ????????tx.rollback();
          ????}

          }

          finally
          {
          ????session.close();
          }

          注:一個 session 可以對應(yīng)多個事務(wù),但是推薦的做法是一個 session 對應(yīng)一個事務(wù)。

          三、 ?????????? 多事務(wù)的并發(fā)問題

          當(dāng)多個事務(wù)同時訪問相同的數(shù)據(jù)的時候,程序如果沒有采取適當(dāng)?shù)母綦x措施,就會發(fā)生數(shù)據(jù)庫的并發(fā)問題。常見的并發(fā)問題有:

          第一類丟失更新:撤消事務(wù)的時候,把其他的事務(wù)已經(jīng)提交的數(shù)據(jù)給覆蓋了;

          臟讀;讀了沒有提交的數(shù)據(jù);

          虛讀:一個事務(wù)讀到另外一個事務(wù)已經(jīng)提交的新插入的數(shù)據(jù);

          不可重復(fù)讀:一個事務(wù)讀到另外一個事務(wù)已經(jīng)提交的更新的數(shù)據(jù);

          第二類丟失更新:一個事務(wù)覆蓋另外一個事務(wù)已經(jīng)提交的更新數(shù)據(jù)。?
          四、??????????

          一般地,大型的 DBMS 都會自動的管理鎖定機制,但是在對數(shù)據(jù)的安全性、完整性和一致性有特殊要求的地方,可以由事務(wù)本身來管理瑣的機制。

          有一點要關(guān)注的是:鎖的粒度越大,隔離性越好,并發(fā)性越差。

          按照鎖的程度來分有:

          共享鎖:用讀操作,非獨占的,其他事務(wù)可以讀,但是不能更新,并發(fā)性好;

          獨占鎖:用與 insert update delete 等語句,其他事務(wù)不能讀,也不能改,并發(fā)性差;

          更新鎖:執(zhí)行 update 的時候,加鎖。

          死瑣:多是事務(wù)分別鎖定了一個資源,又請求鎖定對方已經(jīng)鎖定的資源,就造成了請求環(huán)。

          降低死鎖的最好辦法是使用短事務(wù)。

          五、 ?????????? 數(shù)據(jù)庫的事務(wù)隔離級別

          數(shù)據(jù)庫提供 4 種事務(wù)隔離級別:

          Serializable :串行化;(隔離級別最高) 1

          Repeatable Read :可重復(fù)讀; 2

          Read Commited :讀已提交數(shù)據(jù); 4

          Read Uncommited :讀未提交數(shù)據(jù);(隔離級別最低) 8

          Hiberate 中的隔離級別的設(shè)置

          Hibernate 的配置文件中 hibernate.connection.isolation=2

          六、 ?????????? 悲觀鎖和樂觀瑣

          從應(yīng)用程序的角度來看,鎖分為悲觀鎖和樂觀鎖。

          悲觀鎖:顯示的為程序加鎖,但是降低并發(fā)性。

          Select ……. For update;

          Hibernate 中的代碼

          Session.get(Account.class,net Long(1),LockMode.UPGRADE) // 程序采用悲觀鎖

          樂觀鎖:依靠 DBMS 來管理鎖,程序依靠版本控制來避免并發(fā)問題。

          在對象 - 關(guān)系映射的文件中,用 <version> 或者 <timestamp> 可以管理并發(fā)。樂觀瑣比悲觀瑣有更好的并發(fā)性,優(yōu)先考慮樂觀瑣。 ?

          posted @ 2006-04-22 17:12 面朝大海 閱讀(883) | 評論 (0)編輯 收藏

               摘要: 1. 你們的項目組使用源代碼管理工具了么? ??? 應(yīng)該用。 VSS 、 CVS 、 PVCS 、 ClearCase 、 CCC/Harvest 、 FireFly 都可以。我的選擇是 VSS 。 ...  閱讀全文
          posted @ 2006-04-15 20:38 面朝大海 閱讀(187) | 評論 (0)編輯 收藏

          在JAVA的老巢找到的這本書,不用多說了,這本書就是JAVA權(quán)威了,SUN提供了PDF下載和在線瀏覽:http://java.sun.com/docs/books/jls/
          posted @ 2006-04-12 21:07 面朝大海 閱讀(591) | 評論 (1)編輯 收藏

          1.長相不令人討厭,如果長得不好,就讓自己有才氣;如果才氣也沒有,那就總是微笑。
          ?  
          ?  2.氣質(zhì)是關(guān)鍵。如果時尚學(xué)不好,寧愿純樸。
          ?  
          ?  3.與人握手時,可多握一會兒。真誠是寶。
          ?  
          ?  4.不必什么都用“我”做主語。
          ?  
          ?  5.不要向朋友借錢。
          ?  
          ?  6.不要“逼”客人看你的家庭相冊。
          ?  
          ?  7.與人打“的”時,請搶先坐在司機旁。
          ?  
          ?  8.堅持在背后說別人好話,別擔(dān)心這好話傳不到當(dāng)事人耳朵里。
          ?  
          ?  9.有人在你面前說某人壞話時,你只微笑。
          ?  
          ?  10.自己開小車,不要特地停下來和一個騎自行車的同事打招呼。人家會以為你在炫耀。
          ?  
          ?  11.同事生病時,去探望他。很自然地坐在他病床上,回家再認真洗手。
          ?  
          ?  12.不要把過去的事全讓人知道。
          ?  
          ?  13.尊重不喜歡你的人。
          ?  
          ?  14.對事不對人;或?qū)κ聼o情,對人要有情;或做人第一,做事其次。
          ?  
          ?  15.自我批評總能讓人相信,自我表揚則不然。
          ?  
          ?  16.沒有什么東西比圍觀者們更能提高你的保齡球的成績了。所以,平常不要吝惜你的喝彩聲。
          ?  
          ?  17.不要把別人的好,視為理所當(dāng)然。要知道感恩。
          ?  
          ?  18.榕樹上的“八哥”在講,只講不聽,結(jié)果亂成一團。學(xué)會聆聽。
          ?  
          ?  19.尊重傳達室里的師傅及搞衛(wèi)生的阿姨。
          ?  
          ?  20.說話的時候記得常用“我們”開頭。
          ?  
          ?  21.為每一位上臺唱歌的人鼓掌。
          ?  
          ?  22.有時要明知故問:你的鉆戒很貴吧!有時,即使想問也不能問,比如:你多大了?
          ?  
          ?  23.話多必失,人多的場合少說話。
          ?  
          ?  24.把未出口的“不”改成:“這需要時間”、“我盡力”、“我不確定”、“當(dāng)我決定后,會給你打電話”……
          ?  
          ?  25.不要期望所有人都喜歡你,那是不可能的,讓大多數(shù)人喜歡就是成功的表現(xiàn)。
          ?  
          ?  26.當(dāng)然,自己要喜歡自己。?  
          ?  
          ?  ps:27.如果你在表演或者是講演的時候,如果只要有一個人在聽也要用心的繼續(xù)下去,即使沒有人喝采也要演,因為這是你成功的道路,是你成功的搖籃,你不要看的人成功,而是要你成功。
          ?  
          ?  28.如果你看到一個貼子還值得一看的話,那么你一定要回復(fù),因為你的回復(fù)會給人繼續(xù)前進的勇氣,會給人很大的激勵,同時也會讓人感激你!
          posted @ 2006-04-12 20:58 面朝大海 閱讀(174) | 評論 (0)編輯 收藏

          Hibernate 提供了 3 種檢索策略:

          l??????? 延遲檢索;

          l??????? 立即檢索;

          l??????? 迫切左外連接;

          Hibernate 提供 2 種方式來確定檢索策略,一中是在配置文件當(dāng)中,另外一種是在程序種設(shè)置。當(dāng)然,如果你在程序中設(shè)置了檢索策略,那么你在配置文件中的設(shè)置也就無效了。另外的一種情況是 HQL 會忽略配置文件的設(shè)置,而總是采用迫切左外連接。

          一、 類級別的檢索

          可以選擇的檢索策略是立即檢索和延遲檢索,默認的是立即檢索。用配置文件中的 <class> 節(jié)點的 lazy 來控制。

          注意:不管你在配置 class lazy true 還是 false ,對 get() create Criteria () 方法都不起作用,只有對 load() 方法起作用。

          當(dāng)你使用的檢索策略是 lazy 的時候,當(dāng)你執(zhí)行

          Customer customer = (Customer)session.load(Customer.class,new Long(1));

          的時候, Hibernate 不從數(shù)據(jù)庫檢索數(shù)據(jù),而只是產(chǎn)生一個代理類,只有當(dāng)你執(zhí)行

          Customer.getName();

          的時候, Hibernate 才到數(shù)據(jù)庫取數(shù)據(jù)。所以,如下的代碼是會被拋出異常的:

          Session?session? = ?sessionFactory.openSession();
          transaction?tx?
          = ? null ;
          tx?
          = ?session.beginTransaction();
          ? Customer?customer?
          = ?(Customer)session.load(Customer. class , new ?Long( 1 ));
          tx.commit();
          ? session.close();
          customer.getName();

          get() 方法總是用的立即檢索,如果和它相關(guān)聯(lián)的類也是用的立即檢索,那么也會把相關(guān)聯(lián)的數(shù)據(jù)也檢索出來。

          二、 一對和多對多關(guān)聯(lián)檢索

          一般地,為了有減少對數(shù)據(jù)庫的訪問,我們往往用延遲檢索的策略。所以,我們優(yōu)先使用如下方式;

          <set class=”order” inverse=”true’ lazy=”true” >

          但是,我們在檢索“多”的一方的時候, Hibernate 不能為我們產(chǎn)生代理類。由此,我們就要用 betch-size 的配置來減少 SQL 語句。

          當(dāng)我們使用 outer-join 屬性的時候,我們就沒有必要使用 lazy 屬性了。 Outer-join 會一次將“一”方和與之相關(guān)的“多”方用左外連接的方式檢索出來。

          Session session = sessionFactory.openSession();

          ????????????? ?????? Transaction tx = null;

          ????????????? ????? ?tx = session.beginTransaction();

          ????????????? ????? Customer customer = (Customer)session.get(Customer.class,new Long(1));

          產(chǎn)生的 SQL 語句如下:

          Hibernate: select customer0_.ID as ID1_, customer0_.NAME as NAME2_1_, orders1_.CUSTOMER_ID as CUSTOMER3_3_, orders1_.ID as ID3_, orders1_.ID as ID0_, orders1_.ORDER_NUMBER as ORDER2_1_0_, orders1_.CUSTOMER_ID as CUSTOMER3_1_0_ from sampledb.customers customer0_ left outer join sampledb.orders orders1_ on customer0_.ID=orders1_.CUSTOMER_ID where customer0_.ID=?

          posted @ 2006-04-10 20:44 面朝大海 閱讀(276) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 隆子县| 阳信县| 陇川县| 陵川县| 依兰县| 双峰县| 右玉县| 阿城市| 麟游县| 莎车县| 和龙市| 勃利县| 东安县| 博兴县| 建宁县| 东台市| 阳朔县| 新昌县| 聊城市| 平遥县| 麻江县| 遂川县| 二连浩特市| 五寨县| 克拉玛依市| 南江县| 兴业县| 东台市| 清涧县| 资溪县| 马龙县| 榆社县| 上思县| 青海省| 长兴县| 靖安县| 鄂州市| 信阳市| 丰都县| 平顺县| 顺义区|