0516_1

          1. Update make a detached object persistent.
          2. Config mapping relating in mapping files make query as object oriented.
          3. For many-to-many relation relationship, middle table store link to two tables.
          4. Key element is identify the column of middle table.
          5. Db operation happend at the end of a unit work ---- session flush.
          6. For value type, "element" will replace "many-to-many" in set element(acturally, for all java object, hibernate take it as a value type), value type can not shared by more than one instance.
          7. All bi-directional associations need one side as inverse. bi-direction means both sides of mapping mentain relations of middle table, inverse side is a mirror of the other side, during save or update, the other side will handle.

          posted @ 2007-05-16 08:52 Sheldon Sun 閱讀(167) | 評論 (0)編輯 收藏

          session

          1. batch insert/update session.flush session.clear
          2. statlesssession

          posted @ 2007-05-15 13:34 Sheldon Sun 閱讀(82) | 評論 (0)編輯 收藏

          Mapping for inheritance

          There are three main kinds of mapping for inheritance:
          1. table per class hirachy, for each subclass, use discriminator to distinguish different data, subclass specific property can not be null, only one table.
          2. table per subclass, there is a common table for super class, subclass table reference to super table through primary key, add relationship between tables.
          3. table per concrete class, generate too much redandance data, pk was generated by super class.


          some mix mapping is available.



          posted @ 2007-05-14 13:41 Sheldon Sun 閱讀(135) | 評論 (0)編輯 收藏

          hibernate ref1

          1. Entity name: can be used query.
          2. Way of define mapping: xml, xdoclet, annotation.
          3. Gerated properties: timestamp, version, and property can be generated. Types as follows :
          never: default value.
          always: generated when insert and update.
          insert: only geneated when create data, won't change when updated it later.
          4. Create db schema can be written in xml file.

          posted @ 2007-05-14 10:20 Sheldon Sun 閱讀(113) | 評論 (0)編輯 收藏

          Hibernate reference

          1. lite archetecture: application handle connection and transaction, use niminum hibernate api.
          2. full scream architecture: application will ingore underlying jdbc, jta apis, hibernate hold it.
          3. Persistent object stats: persistence, transient and detached.
          4. Session factory: a cache of compiled configuration files for single db, thread-safed, factory of session and client of connectionProvider, an optional cache of data for process, cluster layer.
          5. Session: represent a conversation between application and db, factory of transaction. wrapped conncetion.
          6. Transatcion: specify automic unit of work.
          7. Context session: hibernateUtil class, for certain application, the scope of current is different, have different context concept. (need more research!)
          8. Configration: store xml to java, can got it through specify xml, java class and proeprties.
          9. Hibernate mapping: mapping java type to SQL type.
          10. Custome mapping type: implement UserType or CompsiteUserType, can define short name, chould get certain value of property by key value.(useless)
          11. Entity and Value: entity can be shared by more than one persistent class as reference.


          posted @ 2007-05-14 09:45 Sheldon Sun 閱讀(249) | 評論 (0)編輯 收藏

          再論Singleton模式

          Singleton模式可能是應用最廣泛的模式之一了, 但有些錯誤的應用。
          ?Singleton的實現: 有兩種方式, 如下:
          1. class Test { public static final Test instance = new Test(); private Test() {} }
          ?2. class Test { private static final Test instance = new Test(); private Test() {} public static Test getInstance() { return instance; } } 這兩種方法都要求構造器是私有的, 這樣就可以防止該類外的對象創建新的TEST對象。 但相對而言, 推薦使用第二種方法, 因為其更具有靈活性,當我們改變創建對象的方式的時候, 不需要改動客戶代碼。 第一種方法較第二種有一點完全可以忽略不計的效率的提高。
          ?但應避免如下代碼實現Singleton: class Test { private static Test singleton = null; private Test() {} public Test getSingleton() { if(singleton == null) { singleton = new Test(); } return singleton; } } 因為嚴格上講, 這并不能完全實現Singleton模式,而且會導致程序出錯, 這同著名的線程問題--DCL實效的原理是完全一樣的:
          JVM創建對象的過程可以分為幾個步驟:創建空間, 把所有的變量賦值位默認值, 初始化。。。 當有兩個線程A和B同事進入該方法, A先執行, A創建Test實例的空間, 這時,因為CPU的指令流機制,時間片段正好輪到B線程, 這時B判斷singleton是否為NULL, 因為A已經為Test的實例分配了空間, 所以JVM認為實例已經創建了, B繼續執行, 更糟糕的是B調用了singleton, 這時因為他并沒有初始化完全, 所以拋出NullPointerException, 太糟糕了!

          posted @ 2006-10-30 14:10 Sheldon Sun 閱讀(189) | 評論 (0)編輯 收藏

          Bridge模式 和Composite模式

          Bridge:主要實現的原理就是把接口 和實現分離開來, 保證他們再兩個不同的類層次結構。

          用Bridge而不是直接繼承實現主要有兩個好處:
          1。 二進制兼容。 假設我們的應用程序需要用到format功能, 我們可能有要引用兩個第三方JAR包, formatInterface.JAR And formatImp.jar, 我們程序可能只引用了formatInterface.jar中的接口, 而formatImpl.jar里是什么我們根本不需要關心, 因為他是formatInterface的實現, 所以當他改變的時候, 我們的應用程序完全不用重新修改代碼, 編譯。可能我在LINUX下用LINUXFormatImpl.jar, 再WINDOW下use WindowFormatImpl.jar, but Application will never care about it.
          ?2. 接口與實現的分離, 實現不一定實現接口的內容, 就是說實現同接口之間不是一一對應的, 實現可能完成最原子的操作, 而接口通過持有一個實現的應用, 組裝這些操作來實現接口。 比如說接口是createRectangle(), 實現可能只完成了createLine的操作, 然后有接口來組裝。


          ?Composite模式則要從全局的角度考慮對象之間的關系是否滿足“樹枝” 與 “樹葉”的關系, 如果滿足, 則需要定義一個樹枝與樹葉的集合接口Tree, 既包含樹枝接口add(tree)和樹葉接口getColor()。

          posted @ 2006-10-26 19:46 Sheldon Sun 閱讀(156) | 評論 (0)編輯 收藏

          Synchronize 與 JAVA 內存模型

          每個JAVA對象都有一把所, 當有多個線程同時訪問共享資源的時候, 需要Synchronize 來控制安全性, synchronize 分 synchronize 方法 和synchronize快,使用synchronize塊時, 一定要顯示的獲得該對象的鎖(如synchronize(object))而方法則不需要。

          ?JAVA 的內存模型是對每一個進程有一個主內存, 每個線程有自己的內存, 他們從主內存中取數據, 然后計算, 再存入主內存中。

          ?并發問題如下:如果多個線程同事操作同一數據, A線程從主內存中取的I的值為1, 然后進行加1操作, 這時B線程也取I的值, 進行加2操作, 然后A存入2到主內存中, B也存入, 這樣就覆蓋了A的值(同數據庫中的并發問題一樣)。 解決辦法是用synchronize, 如用synchronized(I)。被synchronize 修飾的方法(塊)把以下三步操作當成一個原子操作:取數據, 操作數據, 存數據。 我們知道原子操作是不可以被打斷的, 所以其保證了數據一致性, 這樣同一時間只有一個線程再執行, 對性能有一定的影響。這也是synchronize的第二個作用:保證統一時間只有一個線程再運行。 當實現SOCKET連接的時候經常用到.

          ?JAVA中規定對非FLOAT, LONG的原始類型的取和存操作為原子操作。 其實就是對一個字(32位)的取,存位原始操作, 因為FLOAT, LONG為兩個字節的長度, 所以其取, 存為非原子操作。 如果想把他們也變為原子操作, 可以用VOLATILE關鍵字來修飾。

          posted @ 2006-10-26 19:19 Sheldon Sun 閱讀(412) | 評論 (0)編輯 收藏

          java seriliazable

          1. serializable default serialize all field and object net.
          2. Externalizable default deserialize all fields and use writeExternal and readExternal to serialize object. should provide public construct.
          3. serializable interface use private writeObject and private readOjbect to implemnets the same fucntion as Extenalizable interface. (writeDefautObject and readDefaultObject).
          4. Externalizable extends serializable

          posted @ 2006-10-23 20:09 Sheldon Sun 閱讀(165) | 評論 (0)編輯 收藏

          從學習JAVA看學習語言

          學習java也有幾年的時間了, 大學開始就一直沒有斷過, 工作后有專門學習了java。 由于對原理型的知識比較看重, 所以JAVA基礎學的比較多, 至今精通不敢說, 但至少也應該算是熟悉了吧! 我認為語言的學習最簡單的就是文法學習, 估計一般學習一周 到兩周就可以使用這種語言編寫程序, 對于初級程序員這樣也就足夠了, 但要對語言有很深的了解:就是對這個語言的特性的了解, 把JAVA做例子, 他的所有類繼承自OBJECT(他的所有方法用途, 作用等等), CLONABLE接口, SERIALIZABEL接口改變了方法的行為,synchronized等等, 這些都是JAVA語言定義的自己的特征, 包括JAVA的性能, 要能高效率的運用JAVA, 必須對對這些特性有比較深的了解, 還要對其主要的庫有一定的了解,比如說容器庫, 輸入輸出流。。如果了解這些的話最少也要花費1--2年的學習, 還不一定掌握精髓。 估計掌握這些知識的人怎么也應該是高級程序員了。 JAVA學習的最高境界應該是對其類庫的無比熟悉, 能清楚其內在的實現, 如容器類散列桶的實現方法等等, 以及他們實現的優劣。 能達到這個程度的人應該寥寥無幾, 這樣的人一般是有10年JAVA工作經驗的資深JAVA程序員了。 個人認為學習語言也不過這三個階段:熟悉語法, 熟悉語言的特性, 精通類庫。一個語言成熟與否的標志就是他是否有一個設計良好的全面的類庫。

          posted @ 2006-10-23 11:24 Sheldon Sun 閱讀(199) | 評論 (0)編輯 收藏

          僅列出標題
          共5頁: 上一頁 1 2 3 4 5 下一頁 
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統計

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 溧阳市| 瓦房店市| 潜江市| 贵定县| 黄浦区| 达日县| 元江| 安宁市| 恩平市| 绍兴市| 遂昌县| 曲麻莱县| 修文县| 杭锦后旗| 大洼县| 三亚市| 繁昌县| 山阳县| 社旗县| 中宁县| 石阡县| 定日县| 泗阳县| 韶山市| 三穗县| 南通市| 洛阳市| 祁阳县| 家居| 武邑县| 舒兰市| 太原市| 页游| 高碑店市| 焉耆| 颍上县| 三明市| 贺兰县| 黄平县| 诸城市| 胶南市|