面朝大海,春暖花開

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            12 Posts :: 1 Stories :: 3 Comments :: 0 Trackbacks

          2006年4月15日 #

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

          今天在網上閑逛,發現了一本好書,關于JAVA和TDD的,內容介紹如下:

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

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

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

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

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

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

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

          例子,?? 一個常見的 HR 系統:

          using ?System;

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

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

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

          }


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

          }

          現在要求把 Employee 做成 webService HR 系統通過 webService 來調用 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()
          ????
          {
          ????????
          // 對對象創建/訪問的SOAP封裝
          ????
          ?????
          // 發送SOAP數據
          ????
          ?????
          // 如果有返回值,就對SOAP分析,得到C#數據
          ????}

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

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

          }

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

          }

          Proxy 使用的要點:

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

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

          具體的實現可以參考 .NET 中的 WebService 的實現。

          Copy-on-write 技術

          class ?App
          {
          ????
          // 系統在內存中其實是指向同一塊內存
          ???? string ?s1? = ? " Hello " ;? // 不可在修改
          ???? string ?s2? = ? " Hello " ;? // 不可在修改

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

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

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

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

          一、?????????? 數據庫事務概念

          數據庫事務的特征: ACID

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

          二、?????????? 事務的邊界

          數據庫支持 2 種事務模式:自動提交和手動提交。

          JDBC API 的事務邊界

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

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

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

          Hibernate API 聲明事務邊界

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

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

          }

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

          注:一個 session 可以對應多個事務,但是推薦的做法是一個 session 對應一個事務。

          三、 ?????????? 多事務的并發問題

          當多個事務同時訪問相同的數據的時候,程序如果沒有采取適當的隔離措施,就會發生數據庫的并發問題。常見的并發問題有:

          第一類丟失更新:撤消事務的時候,把其他的事務已經提交的數據給覆蓋了;

          臟讀;讀了沒有提交的數據;

          虛讀:一個事務讀到另外一個事務已經提交的新插入的數據;

          不可重復讀:一個事務讀到另外一個事務已經提交的更新的數據;

          第二類丟失更新:一個事務覆蓋另外一個事務已經提交的更新數據。?
          四、??????????

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

          有一點要關注的是:鎖的粒度越大,隔離性越好,并發性越差。

          按照鎖的程度來分有:

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

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

          更新鎖:執行 update 的時候,加鎖。

          死瑣:多是事務分別鎖定了一個資源,又請求鎖定對方已經鎖定的資源,就造成了請求環。

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

          五、 ?????????? 數據庫的事務隔離級別

          數據庫提供 4 種事務隔離級別:

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

          Repeatable Read :可重復讀; 2

          Read Commited :讀已提交數據; 4

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

          Hiberate 中的隔離級別的設置

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

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

          從應用程序的角度來看,鎖分為悲觀鎖和樂觀鎖。

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

          Select ……. For update;

          Hibernate 中的代碼

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

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

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

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

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

          主站蜘蛛池模板: 云安县| 南漳县| 鄂伦春自治旗| 滁州市| 溧水县| 师宗县| 普陀区| 兰州市| 邮箱| 卫辉市| 水城县| 广平县| 普陀区| 牡丹江市| 溆浦县| 普定县| 钟祥市| 宜川县| 松潘县| 巴南区| 井冈山市| 来宾市| 东山县| 金华市| 孟连| 永德县| 抚州市| 博客| 东兰县| 沈阳市| 广东省| 成安县| 濮阳市| 宝兴县| 磐石市| 南阳市| 马尔康县| 时尚| 西乌珠穆沁旗| 沁水县| 民乐县|