<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sun
    是選擇你愛的人還是愛你的人?
    posts - 8,comments - 14,trackbacks - 0

    JPOX requires that all classes that are persisted implement PersistenceCapable, an interface defined by JDO. Why should we do this, Hibernate/TopLink dont need it ?. Well thats a simple question really

    • JPOX uses this PersistenceCapable interface, and adds it using bytecode enhancement techniques so that you never need to actually change your classes. This means that you get transparent persistence, and your classes always remain your classes. ORM tools that use a mix of reflection and/or proxies are not totally transparent.
    • JPOX' use of PersistenceCapable provides transparent change tracking. When any change is made to an object the change creates a notification to JPOX allowing it to be optimally persisted. ORM tools that dont have access to such change tracking have to use reflection to detect changes. The performance of this process will break down as soon as you read a large number of objects, but modify just a handful, with these tools having to compare all object states for modification at transaction commit time.

    In a JDO-enabled application there are 3 categories of classes. These are PersistenceCapable, PersistenceAware and normal classes. The Meta-Data defines which classes fit into these categories. To give an example for JDO, we have 3 classes. The class A is to be persisted in the datastore. The class B directly updates the fields of class A but doesn't need persisting. The class C is not involved in the persistence process. We would define JDO MetaData for these classes like this

    1 <class name="A" persistence-modifier="persistence-capable">
    2     <field name="myField">
    3         
    4     </field>
    5     
    6 </class>
    7 <class name="B" persistence-modifier="persistence-aware">
    8 </class>


     

    So our MetaData is mainly for those classes that are PersistenceCapable and are to be persisted to the datastore (we don't really need the persistence-modifier for thse classes since this is the default). For PersistenceAware classes we simply notate that the class knows about persistence. We don't define MetaData for any class that has no knowledge of persistence.

    JDO requires that all classes to be persisted must implement the PersistenceCapable interface . Users could manually do this themselves but this would impose work on them. JDO permits the use of a byte-code enhancer that converts the users normal classes to implement this interface. JPOX provides its own byte-code enhancer (this can be found in the jpox-enhancer.jar). This section describes how to use this enhancer with JPOX. The JPOX enhancer fully implements JDO2 and so is the recommended choice when persisting using the JDO2 API. The enhancement process adds the necessary methods to the users class in order to implement PersistenceCapable.



    The example above doesn't show all PersistenceCapable methods, but demonstrates that all added methods and fields are prefixed with "jdo" to distinguish them from the users own methods and fields. Also each persistent field of the class will be given a jdoGetXXX, jdoSetXXX method so that accesses of these fields are intercepted so that JDO can manage their "dirty" state.

    The MetaData defines which classes are required to be persisted, and also defines which aspects of persistence each class requires. For example if a class has the detachable attribute set to true, then that class will be enhanced to also implement Detachable



    Again, the example above doesn't show all methods added for the Detachable interface but the main thing to know is that the detached state (object id of the datastore object, the version of the datastore object when it was detached, and which fields were detached is stored in "jdoDetachedState"). Please see the JDO spec for more details.

    If the MetaData is changed in any way during development, the classes should always be recompiled and re-enhanced afterwards.

    Byte-Code Enhancement Myths

    Some groups (e.g Hibernate) perpetuated arguments against "byte-code enhancement" saying that it was somehow 'evil'. The most common were :-

    • Slows down the code-test cycle. This is erroneous since you only need to enhance just before test and the provided plugins for Ant, Eclipse and Maven all do the enhancement job automatically and rapidly.
    • Is less "lazy" than the proxy approach since you have to load the object as soon as you get a pointer to it. In a 1-1 relation you have to load the object then since you would cause issues with null pointers otherwise. With 1-N relations you load the elements of the collection/map only when you access them and not the collection/map. Hardly an issue then is it!
    • Fail to detect changes to public fields unless you enhance your client code. Firstly very few people will be writing code with public fields since it is bad practice in an OO design, and secondly, this is why we have "PersistenceAware" classes.

    So as you can see, there are no valid reasons against byte-code enhancement, and the pluses are that runtime detection of dirty events on objects is much quicker, hence your persistence layer operates faster without any need for iterative reflection-based checks. The fact is that Hibernate itself also now has a mode whereby you can do bytecode enhancement although not the default mode of Hibernate. So maybe it wasn't so evil after all ?

     

    posted on 2010-05-08 23:57 .Sun 閱讀(2575) 評論(1)  編輯  收藏 所屬分類: 隨筆

    FeedBack:
    # re: 關(guān)于 字節(jié)碼增強(qiáng) 摘要[未登錄]
    2010-05-11 08:29 | sunny
    hahahhaha  回復(fù)  更多評論
      
    主站蜘蛛池模板: 中国性猛交xxxxx免费看| 国产精品视_精品国产免费 | 国产国产人免费视频成69大陆| 久久精品国产亚洲AV嫖农村妇女| 一级有奶水毛片免费看| 国产精品亚洲综合专区片高清久久久| 香港特级三A毛片免费观看| 四虎影视永久免费观看地址 | 激情无码亚洲一区二区三区 | 免费一级毛片在线播放视频免费观看永久 | 亚洲A∨无码一区二区三区| a级在线观看免费| 国产精品国产亚洲精品看不卡| 成人久久免费网站| 亚洲欧洲日本精品| 女人毛片a级大学毛片免费| 亚洲成av人片在www鸭子| 国产无遮挡又黄又爽免费视频| 国产精品成人亚洲| 青青草原亚洲视频| 免费不卡在线观看AV| 亚洲a∨无码男人的天堂| 国产三级免费电影| 久久国产精品免费一区二区三区| 久久精品夜色国产亚洲av| 美女隐私免费视频看| 国产亚洲欧洲Aⅴ综合一区 | 亚洲精品网站在线观看你懂的| 四虎在线视频免费观看视频| 亚洲国产欧美日韩精品一区二区三区| 日韩亚洲精品福利| 亚洲自偷自偷在线成人网站传媒 | 青青草a免费线观a| 国产成人 亚洲欧洲| 亚洲国产精品乱码一区二区| 久久受www免费人成_看片中文| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 亚洲第一福利视频| 成年18网站免费视频网站| 一级毛片在线完整免费观看| 亚洲黄色中文字幕|