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

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

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

    Duran's technical life
    踏踏實實學技術,認認真真做研究。

    2005年5月19日

    從MySql5中運行本地腳本創建數據庫,當插入中文字段時發生“data too long for column”錯誤。上網一查,發現多字節用戶大都碰到了這種情況。google搜索網上的解決方法大都是要將數據庫的編碼方式為GBK或UTF8,可我在安裝MySql時就選擇了UTF8格式。原來錯誤原因是本地的腳本文件不是UTF8編碼的,用記事本或UltraEdit將編碼轉為UTF8后問題解決。再次強調,JSP頁面,數據庫聯接接方式,數據庫創建,…,都須一致使用UTF8編碼!

    BTW,MySql最近借著Web2.0的浪潮風頭很勁啊,techn orati(好像這幾天被GFW filter了),flickr,del.icio.us等一批網站都是用了MySql。MySql還專門在首頁開了一大塊來炫耀。
    posted @ 2006-07-14 19:12 Duran's technical life 閱讀(9186) | 評論 (4)編輯 收藏
     
    Installed JDK6 (Mustang) beta and Eclipse3.2 . As Sun promised , Swing library, especially the?WindowsLookAndFeel feels much better. It’s hard to tell the difference between a Swing drawn window and a WINXP native window. Developing Java desktop applications is worth considering. Mattise, a free easy-to-use WYSIWYG Swing UI designer, is the only reason for many to use the tedious NetBeans. Recently, Genuitec provided Matisse4Eclipse, which is?an implementation of Matisse that integrates its functionality into MyEclipse Workbench to enable the easy creation of Swing applications with Eclipse. So the only reason to use NetBeans has gone.
    posted @ 2006-07-13 22:17 Duran's technical life 閱讀(1037) | 評論 (0)編輯 收藏
     
    去年7月決定考研后暫停了對Java技術的學習。錄研上后專心開發導師負責的項目,到4月份從深圳出差回來后又忙著做畢設。快一年的時間沒跟新這,幾乎都要abandon了。百度剛開放了百度空間的注冊,不過看起來不咋的。選國外的BSP會面臨隨時偉大的GFW過濾掉的后果。總的來說,BlogJava還是很適合post技術方面的東西,優點是流量大,被google收錄快;缺點就是沒有trackback。前幾天下午跑到圖書館看了看上半年的程序員,新鮮玩意并不多。SOA,這個被預測為06年最熱點的技術,并沒有什么有趣的文章,或許這個名詞還是沒有個明確的含義和應用。在學校里,IBM的SOA大賽倒是舉辦的風風火火。JavaEE5,JDK 6的發布還是給Java界帶來不少有趣又實用的新東東,比如annotation,persistence API和script supporting。得跟上技術前進的步伐了,以后技術的筆記還是發這里,平日的雜想就寫在我的MSN space上。
    posted @ 2006-07-13 22:14 Duran's technical life 閱讀(329) | 評論 (0)編輯 收藏
     

    @title [筆記]事務處理

    #1 Transaction Propagation Behavior
    Required:Excute within a current tx, create a new one if none exists.
    Supports: Excute within a current tx, execute without a tx if none exsits.
    Mandatory: Excute within a current tx, throw an exception if none exists.
    Requires New: Create a new tx and excute within the tx, suspend the current tx if one exists.
    Not Supported: Excute without a tx, suspend the current tx if none exsits.
    Never: Excute without a tx, throw an exception if a tx exsits.

    #2 Transaction Isolation Level[1]
    #2.1 Concurrent Problem
    Dirty Reads: 臟讀(臟數據指已更新,還沒提交的數據)。事務T1讀取到事務T2中的臟數據。

    Unrepeatable Reads: 不可重復讀。事務T1檢索到某行后,事務T2更新并提交了該行,若事務T2再次檢索該行,則會看到不一樣的結果。

    Phantom Reads: 虛讀。事務T1檢索到符合某條件的行集后,事務T2插入并提交了滿足該條件的新行,若事務T2再次按該條件檢索,則會看到以前不存在的行“Phantom”。

    #2.2 Isolation Level
    +---------------+-------+------------------+-----------+
    |Isolation Level|Phantom|Unrepeatable Reads|Dirty Reads|
    +---------------+-------+------------------+-----------+
    |Read Uncommited|   Y   |         Y        |     Y     |
    +---------------+-------+------------------+-----------+
    |Read Commited  |   Y   |         Y        |     N     |
    +---------------+-------+------------------+-----------+
    |Repeatable Read|   Y   |         N        |     N     |
    +---------------+-------+------------------+-----------+
    |Serializable   |   N   |         N        |     N     |
    +---------------+-------+------------------+-----------+

    #3 Timeout

    #4 ReadOnly Transaction
    只讀事務保證了多條查詢SQL的在事務級別的讀一致性。JDBC和數據庫會對只讀事務做一些優化。

    [1] C.J.Date, An Introduction to Database Systems 7th.

    posted @ 2005-09-09 13:09 Duran's technical life 閱讀(715) | 評論 (1)編輯 收藏
     

    iteration::two Cairngorm 0.99 開發指南
    @author sakis
    @version 0.1

    #0
    MXML優點:使用方便,XML代碼簡潔易懂
    缺點:事件、函數、界面描混在一起。程序規模大了難于開發維護。

    #1
    Cairngorm框架是iterationtwo推出的號稱基于JEE Best Practice的Flex程序開發的light-weight framework。(恩,light-weight這個詞還真是流行呢)。目前最新版本為0.99。

    Cairngorm的結構如下:
    org
    └─nevis
        └─cairngorm
            ├─application
            │      CairngormApplication.as
            │
            ├─business
            │      Responder.as
            │      ServiceLocator.as
            │
            ├─commands
            │      Command.as
            │      SequenceCommand.as
            │
            ├─control
            │      Event.as
            │      EventBroadcaster.as
            │      FrontController.as
            │
            ├─model
            │      ModelLocator.as
            │
            ├─view
            │      ViewHelper.as
            │      ViewLocator.as
            │
            └─vo
                    ValueObject.as


    #2
    下面給大家簡單介紹Cairngorm的實現思路。

    #2.1
    Command/FrontController將Event與Viwe分離。
    FrontController實現Singleton模式(以下簡寫為SP)。所有自定義的Command在要在FrontController構造函數中實例化并以關聯數組的方式注冊FrontController#addCommand(eventType:String, commandInstance:Command)。EventBroadcaster實現SP。Event類的結構為{type:eventType, data:eventData}。我們通過EventBroadcaster#broadcastEvent(eventType:String, eventData:Object)發布Event。Event發布后,與eventType對應的command instance執行Command#execute(event:Event)。

    BTW:在Cairngorm的源碼中,eventType、commandName、eventName混用,我統一用eventType。

    #2.2
    ServiceLocator將Remote Service聲明與View分離。
    ServiceLocator實現SP。在Cairngorm的demo中,又通過Delegate對象解除Command/Responder和ServiceLocator之間的依賴。這個Delegate做的事情其實意義不大,就是調用ServiceLocator中的Method,設置莫個Responder為相應遠程方法的handler。個人覺得無謂地增加了代碼量,而且Delegate對象也沒實現SP,也就是說我們每次調用一次Remote Service中的Method,都要new一個Delegate對象,實在浪費。

    #2.3
    ViewLocator/ViewHelper將View(MXML)中夾雜的function與View分離。
    ViewHelper有點意思,當一個ViewHelper在某個MXML頁面中聲明時,如<view:LoginViewHelper id="loginViewHelper" />。ViewHelper能自動取得所在MXML對象的引用,并通過ViewLocator#register(id, this:ViewHelper)將自身注冊到ViewLocator中。ViewLocator實現SP。借助ViewLocator/ViewHelper,我們就可以方便的調用不同MXML頁面中的方法。

    #2.4
    ModelLocator是一個marker interface,程序中Model可以放在某個ModelLocator方便調用。

    #2.5
    ValueObject也是一個marker interface, 基本不需要。

    #3
    Cairngorm.99給我們開發Flex程序提供了很不錯的架構模式,M/V/C/Remote之間可以做到完全解構。但在實際開發時沒有必要死扣,代碼結構清晰有活力就好。

    posted @ 2005-09-07 21:49 Duran's technical life 閱讀(883) | 評論 (0)編輯 收藏
     

    Hibernate一對一關聯實用介紹

    #0
    書和文檔上寫的都不是特清楚的。自己記下來。

    #1 Using a PK association

    #1.1 POJO with XDolclet annotation
    public class Customer {
     /**
      * @return Returns the shoppingCart.
      * @hibernate.many-to-one cascade="delete" column="shopping_cart_id"
      *  unique="true" foreign-key="FK_SHOPPING_CART__CUSTOMER"
      */
     public ShoppingCart getShoppingCart() {
      return shoppingCart;
     }
    }

    public class ShoppingCart {
     /**
      * @return Returns the customer.
      * @hibernate.one-to-one property-ref="shoppingCart"
      */
     public Customer getCustomer() {
      return customer;
     }
    }

    property-ref="shoppingCart" 告訴Hibernate ShoppingCart#customer和Customer#shoppingCart是反向的關系。所以Hibernate知道如何從ShoppingCart#getCustomer中檢索到相應的customer對象。取出某個Customer對象時,Hibernate會生成DEBUG SQL:324 - 3中的SQL語句。

    #1.2 HBM
    Customer.hbm.xml
    <many-to-one
        name="shoppingCart"
        class="ShoppingCart"
        cascade="delete"
        outer-join="auto"
        foreign-key="FK_SHOPPING_CART__CUSTOMER"
        column="shopping_cart_id"
    />

    ShoppingCart.hbm.xml
    <one-to-one
        name="customer"
        class="Customer"
        cascade="none"
        outer-join="auto"
        constrained="false"
        property-ref="shoppingCart"
    />

    #1.3 SCHEMA SQL
    create table CUSTOMER (
        ID bigint generated by default as identity (start with 1),
        SHOPPING_CART_ID bigint,
        primary key (ID)
    )

    create table SHOPPING_CART (
        ID bigint generated by default as identity (start with 1)
        primary key (ID)
    )

    alter table CUSTOMER
        add constraint FK_SHOPPING_CART__CUSTOMER
        foreign key (SHOPPING_CART_ID)
        references SHOPPING_CART

    #1.4 Query SQL
    DEBUG SQL:324 - 1
    select customer0_.ID as ID, customer0_.SHOPPING_CART_ID as SHOPPING2_3_, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_
    from CUSTOMER customer0_
    where customer0_.USERNAME=? and customer0_.PWD=?

    DEBUG SQL:324 - 2
    select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_
    from SHOPPING_CART shoppingca0_
    where shoppingca0_.ID=?

    DEBUG SQL:324 - 3
    select customer0_.ID as ID1_, customer0_.SHOPPING_CART_ID as SHOPPING2_3_1_, customer0_.USERNAME as USERNAME3_1_, customer0_.PWD as PWD3_1_, shoppingca1_.ID as ID0_, shoppingca1_.TOTAL as TOTAL8_0_
    from
     CUSTOMER customer0_
     left outer join
     SHOPPING_CART shoppingca1_
     on customer0_.SHOPPING_CART_ID=shoppingca1_.ID
    where customer0_.SHOPPING_CART_ID=?


    #2 Using a FK association

    #2.1 POJO with XDolclet annotation
    public class Customer {
     /**
      * @return Returns the shoppingCart.
      * @hibernate.one-to-one cascade="delete"
      */
     public ShoppingCart getShoppingCart() {
      return shoppingCart;
     }
    }

    public class ShoppingCart {
     /**
      * @return Returns the id.
      * @hibernate.id generator-class="foreign"
      * @hibernate.generator-param name="property" value="customer"
      */
     public Long getId() {
      return id();
     }

     /**
      * @return Returns the customer.
      * @hibernate.one-to-one constrained="true" foreign-key="FK_CUSTOMER__SHOPPING_CART"
      */
     public Customer getCustomer() {
      return customer;
     }
    }

    constrained="true" 告訴Hibernate ShoppingCart的PK還應該是一個FK,這個FK引用Customer的PK。還需要多做一點工作,聲明ShoppingCart的PK生成策略是foreign,對應ShoppingCart#customer。這和上面一句話不是一個意思嘛,FT~~

    #2.2 HBM
    Customer.hbm.xml
    <one-to-one
        name="shoppingCart"
        class="ShoppingCart"
        cascade="delete"
        outer-join="auto"
        constrained="false"
    />

    ShoppingCart.hbm.xml
    <id
        name="id"
        column="id"
        type="java.lang.Long"
    >
        <generator class="foreign">
     <param name="property">customer</param>
        </generator>
    </id>

    <one-to-one
        name="customer"
        class="Customer"
        cascade="none"
        outer-join="auto"
        constrained="true"
    />

    #2.3 SCHEMA SQL
    create table CUSTOMER (
        ID bigint generated by default as identity (start with 1),
        primary key (ID)
    )

    create table SHOPPING_CART (
        ID bigint not null,
        TOTAL integer,
        primary key (ID)
    )

    alter table SHOPPING_CART
        add constraint FK_CUSTOMER__SHOPPING_CART
        foreign key (ID)
        references CUSTOMER

    #2.4 Query SQL
    DEBUG SQL:324 -
    select customer0_.ID as ID, customer0_.USERNAME as USERNAME3_, customer0_.PWD as PWD3_
    from CUSTOMER customer0_
    where customer0_.USERNAME=? and customer0_.PWD=?

    DEBUG SQL:324 -
    select shoppingca0_.ID as ID0_, shoppingca0_.TOTAL as TOTAL8_0_
    from SHOPPING_CART shoppingca0_
    where shoppingca0_.ID=?

    這個“真正”的one-to-one的好處是少條關聯SQL語句,看到了嗎?

    posted @ 2005-09-06 13:16 Duran's technical life 閱讀(4193) | 評論 (2)編輯 收藏
     
    1  Open the Apache Tomcat configuration app in sys tray, and on the "Java" tab, bump up the initial memory pool size and the maximum memory pool size to 512 Initial and 768 Max, click Ok.
    2  In \Program Files\Apache software Foundation\Tomcat 5.0\bin\catalina.bat, in the last section immediately after "rem Execute Java with the applicable properties", insert this line, set CATALINA_OPTS=-mx1024m. Save the file.
    posted @ 2005-08-12 17:38 Duran's technical life 閱讀(1597) | 評論 (0)編輯 收藏
     

    在google里敲了“HelloWolrd”,再點“手氣不錯”,出來了這樣一個頁面:http://www2.latech.edu/~acm/HelloWorld.shtml

    Hello World!

    Welcome to the ACM "Hello World" project. Everyone has seen the Hello World program used as a first exposure to a new language or environment. We are attempting to collect examples for as many languages and related programming environments (shells etc.) as possible.


    Aproximate number of examples:204     <----wow~~~
    This page has been accessed 33274 times.
    Last updated: January 20, 2005   


    看看C的,經典HelloWorld
    #include <stdio.h>
    main()
    {
      for(;;)
          {
              printf ("Hello World!\n");
          }
    }


    這也是HelloWolrd?!
    a 1986 entry from Bruce Holloway:

    #include "stdio.h"
    #define e 3
    #define g (e/e)
    #define h ((g+e)/2)
    #define f (e-g-h)
    #define j (e*e-g)
    #define k (j-h)
    #define l(x) tab2[x]/h
    #define m(n,a) ((n&(a))==(a))

    long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
    int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };

    main(m1,s) char *s; {
        int a,b,c,d,o[k],n=(int)s;
        if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
        else switch(m1-=h){
            case f:
                a=(b=(c=(d=g)<<g)<'<g)<<g;
                return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
            case h:
                for(a=f;a=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
                return(o[b-g]%n+k-h);
            default:
                if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
                for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
            }
    }

    曾經最短的HelloWorld(Jari.Arkko@lmf.eua.ericsson.se
    jar.1.c
    char*_="Hello world.\n";

    ln -s /dev/tty jar.1.o
    cc -c jar.1.c



    現在最短的HelloWorld (Jyrki Holopainen)
    ";main(){puts("Hello World!");}char*C=".c  
    char*_=__FILE__;

    posted @ 2005-08-09 09:38 Duran's technical life 閱讀(625) | 評論 (0)編輯 收藏
     

    抵達深圳

    在中國改革開放的貞操牌坊,更加強烈感受了GCD領導下的中國特色的社會主義和諧社會。羅湖區1w的小套間,隨處可見benz和BMW。晚上去吃海鮮,一盤盤的叫不上名來,味道倒是鮮美:-)

    實習第一天

    XX信息公司研發部實習員工登記,領工卡,認識組員,了解項目情況,做了一天需求分析,easy。在公司里寫程序的感覺和學校不大一樣,一邊寫一邊就能聽到boss在隔壁辦公室訓斥某人。小小的不滿:液晶顯示器不多,自然輪不到我。小小小的不滿:QQ不能用就算了,msn好像都不能用。

    posted @ 2005-07-14 18:07 Duran's technical life 閱讀(627) | 評論 (0)編輯 收藏
     

    性能比較:Java全面超越C++?
    這樣的八卦炒作貼也能在java.csdn.net上置頂,真是無語了~我只想對csdn說:“你太差了!”
    《程序員》每期都會買,是因為我沒的選擇。作為一本技術刊物,《程序員》不是保持中立,而是摻雜了太多的商業立場和利益。高水平的文章也有,但遠遠不夠。該雜志一主編感嘆沒有對手,說《DDJ China》“幾乎是一個合格的對手了”。說的極端和刻薄一點,《DDJ》是軟件開發的學術刊物,csdn、《程序員》只能算是程序員的娛樂新聞雜志。

    這是一個署名“周星星”的同學對原文的評論。
    周星星 發表于2005-06-16 5:01 PM 
    “很明顯,C++的編譯器不如java的JIT和HotSpot編譯器,因為JIT和HotSpot編譯器能針對CPU指令集進行人優化、能在運行時根據使用頻率對method進行內聯和優化。而C++的靜態編譯器永遠也做不到這些”
    --- 無知了吧,現存于世的C++編譯器,無論是VC++,還是Intel C++,還是g++,都能針對特定CPU進行優化;而Java的所謂動態優化只是做了部分(不是全部)C++靜態優化的工作;事實上,真正的動態優化不是任何一個高級語言所能做到的,C++不能,C不能,Java更不能,必須內嵌匯編才能做到這一點。

    “JDK1.0時,java的速度是C++的20到40分之一。而到了jdk1.4時,java的性能則是C++的三分之一到2倍(通常C++是java的1.2倍到1.5倍)。可惜這分報告沒有jdk1.4以后的數據,而后面的報告我們將看到在jdk1.4.2時,java性能全面超過C++。”
    --- 有個10歲的小孩子對她30母親說:“9年前我的年齡是妳的1/21,我現在的年齡是妳的1/3,隨著這種趨勢的發展,在未來我的年齡就可以超過妳。”
    Java的速度也許可以接近C++,但永遠不可能達到C++一樣快,更不可能超過C++,因為解釋程序必須要求原生程序來解釋執行,所以永遠達不到一樣的速度。

    “Java寫的數據庫的性能是C++寫的數據庫性能的近600倍!”
    --- 天方夜譚,如果真的這樣,MS SQL為什么不用Java來編寫,Oracle為什么不用Java來編寫,MySQL為什么不用Java來編寫?

    “伯克利大學和Lawrence伯克利國家實驗室的一份報告證明:IBM的JDK比GCC更快”
    --- 伯克利大學真的有這個報告嗎?真是玷污伯克利的威名,把JDK和GCC放在一起比,如同把“長度”和“重量”這兩種不同性質的東西放在一起比。

    “用純java寫的JDK底層要比用C++寫JDK底層要快”
    --- 暈,“純java寫的JDK”,教你Java的老師被你氣跳樓了。

    posted @ 2005-06-17 12:31 Duran's technical life 閱讀(730) | 評論 (1)編輯 收藏
     

    環境:Hibernate 2.1.7 + MySQL4.1(MySQL的編碼已設置為utf8)
    問題:通過Hibernate向MySQL寫入中文后,通過Hibernate取回數據,在console中打印java對象顯示正常。但在MySQL Query Browser中看到的是亂碼,傳給前端的Flex也是亂碼。
    原因:Hibernate的基礎還是JDBC,所以一樣需要設置characterEncoding!
    解決方法
    在hibernate.cfg.xml中應該這樣寫

    <property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8</property>
    如果用hibernate.properties
    #hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

    ps:處理中文的話,characterEncoding用GBK一樣可以。
    但字節編碼問題最好的解決方法還是統一使用UTF-8!!!
    posted @ 2005-06-10 21:35 Duran's technical life 閱讀(15935) | 評論 (13)編輯 收藏
     
    Degrees and what they mean:
     BS  I can code, do basic technical work
     MS  More design responsibility and more independence
    PhD  Research, teaching, or architecting/design
    posted @ 2005-06-10 12:35 Duran's technical life 閱讀(527) | 評論 (0)編輯 收藏
     
    GUI編程太繁瑣,而且感覺相對而言“技術含量”不高。討厭也得學啊,畢竟寫的程序要通過GUI暴露給用戶。
    有的人笑話java的跨平臺是幌子,一次編寫,到處調試。我倒想問,怎樣該被稱做“幌子”。不同的操作系統之間的差異本來就很大,做到完全統一從原理上就是永遠不可能的。就像寫的再好的模擬器也只能達到99%的模擬程度!Swing其實已經不錯了,隨著jdk更新的每個版本都能有所改進。但是仍然遠沒達到讓人滿意的地步。一是表現力仍然很差,看Swing做的軟件Together、NetBeans……界面真的好丑!也看了一些第三方公司自己擴展Swing做出的demo,效果還不錯。要價幾k美刀,也不知開發效率如何。二就是開發效率仍然過低。“鄙視”vb、pb這樣的RAD工具,寫出來的代碼混亂沒架構,但是它們做GUI的效率很高。
    最期待的表現層技術還是M$的Avalon,M$雖然討厭,但它的開發環境對程序員是最友善的。
    說說Flex。Flex學習曲線不大,各種UI Component超好用。不爽的ActionScript語法好別扭,不習慣。現有的官方reference文檔太少了,更新又慢,例子也少得很。做東西時沒有pattern模仿,自己摸蠻痛苦而且寫出來的代碼也覺得有些cuo。
    posted @ 2005-06-07 23:18 Duran's technical life 閱讀(565) | 評論 (0)編輯 收藏
     

    Martin Fowler是ThoughtWorks的首席科學家。從80年代開始,他就一直從事軟件開發的工作。在80年代中期,他對面向對象開發這個新領域發生了興趣。他擅長在商業信息系統中加入面向對象的思想。時至21世紀,他又在UML推廣普及、領域建模、企業應用開發和敏捷方法等方面建樹卓著,被稱為軟件開發的教父。

    可惜他只去上海、北京,眼巴巴地看著啊。

    posted @ 2005-06-01 23:31 Duran's technical life 閱讀(287) | 評論 (0)編輯 收藏
     
    以前沒人考研的時候都是開考研動員大會,現在人招多了輔導員又開始勸大家條件不好的就盡量去找工作,呵呵。看上一屆就業單位名單里居然連“安利(中國)日用品有限公司”都有,真是暈菜死。
    posted @ 2005-06-01 23:24 Duran's technical life 閱讀(289) | 評論 (0)編輯 收藏
     
    考試周,明天晚上GF來,忙~~~自習去了。
    posted @ 2005-05-26 07:45 Duran's technical life 閱讀(380) | 評論 (1)編輯 收藏
     
         摘要: 參考package EDU.oswego.cs.dl.util.concurrent 1public interface Sync {2    public void acquire();3    public void release();4...  閱讀全文
    posted @ 2005-05-19 09:54 Duran's technical life 閱讀(1047) | 評論 (0)編輯 收藏
     
         廬山回來后就沒寫過blog了,不過每天晚上跑步倒是一直在堅持。寫blog的目的是對自己學習成長的記錄、反省和促進,貴在堅持。上個星期用java寫了個評估項目CPM的小程序,實踐了hibernate、xDoclet,練習了反復Refactor+TDD的開發方式,感覺很爽。當做到PERT計算功能時發現需要查正態分布表,google查了查沒找到第三方的java數學運算包。直到在圖書管看書時才發現用編程進行復雜的函數運算的方法是屬于《計算方法》課的,奇怪我們專業為什么不開這門課。發現自己知識結構上的一個空白。

        前幾天做操作系統作業,順便看了看《Concurrent Programming in Java: Design Principles and Patterns》,確信《程序員》第三期上關于Mutex的一段代碼完全是錯誤的,又給《程序員》編輯發了mail(上次發了mail后了無音訊)。沒想很快到過了收到編輯和作者的回復,確認了錯誤。倒不是說出了錯就說明作者水平不高,java相關技術太多了,軟件開發相關技術就更多了。我想說的的是搞軟件開發雖然是個智力活動,但終究談不上需要極高的天賦才行(不像數學這樣的基礎理論學科)。作者也是人,當然也會犯錯誤。國外的那些軟件大牛也是人,他們也是一步一步成長起來的,其實并不是在神壇上高不可攀。那為什么國內高手少呢?環境所致。記得好像是在白云上看過有個人說“Linus好牛,20歲就搞出了linux,我們20歲能干嗎”,下面有個人回帖說“那是他在Stanford,要是把你丟在那,你說不定也能做出個XXX來”。

        HeadStorm是我很欽佩的一位程序員,工作了幾年后憑著不停的學習、實踐對j2ee應用開發技術有了較高的造詣。在圈內取得一定成績后又及時地認清了自己的目標,做一個全面的技術高手,要“往下走”,而不是安于“j2ee架構師”這個名頭。說到“往上走”和“往下走”之爭,想到兩個不好笑的小笑話。第一個是有天聽到幾個同學談論開發軟件,一個同學說開發mis沒意思,另一個同學就說:“那你去寫匯編啊,寫底層驅動啊,那個有技術含量。”第二個是有次聽武大計算機系某老師說:“java有什么了不起,我用c一樣可以實現多態、繼承。”第一個笑話不加評論。第二個笑話讓我想起以前一直流傳的一句話:“學程序,什么語言都一樣。”個人覺得這句話是帶有很大的誤導成分的。語法層面上,基本的順序、選擇、循環語句是差不多;但要你實際做開發應用呢,你還能說用啥都一樣嗎。不同的語言,設計者在最初設計語言特性時就決定了該語言最有效的應用領域。Ruby之類的動態語言現在大放光彩也是有其理由的。在“向上走”的時候也要注意提醒自己“勿筑高臺于浮沙”。技術無盡的,時間是有限的,要學習什么,學到什么程度,得有清醒的頭腦。

        說到學習技術,決定開始研究Flex了,看了兩天,感覺還不錯。這才是程序員需要的表現層方案,拖放好控件,再編寫用戶交互的script就完了,至于很cool的頁面表現效果的是如何做到的,那是Macromedia的事情。什么struts、webWork之流都是自娛自樂,并不能給用戶帶來多大的使用體驗。JSF想法還不錯,可有多少人支持呢。你說你表現層框架技術再先進,可表現出來的交互界面像yts一樣,對用戶來說還不如回到c/s的懷抱。js的登頂之作也就是Bindows了,還不就那樣。一句話,非常看好Flex!Laszlo也還行,但終究沒有Flex感覺好,而且是開源的,技術支持也沒Flex強。Flex還有一個很好的可視化開發工具——FlexBuilder,大大加快了開發效率。

    posted @ 2005-05-19 09:47 Duran's technical life 閱讀(442) | 評論 (1)編輯 收藏
     
    Suppose we start with a simple <one-to-many> association from Parent to Child.
     1<hibernate-mapping package="org.hibernate.auction.model">
     2 <class name="Parent" table="PARENT">
     3  <id name="id" column="PARENT_ID" type="long">
     4   <generator class="native"></generator>
     5  </id>
     6  <set name="children">
     7   <key column="MY_PARENT_ID" />
     8   <one-to-many class="org.hibernate.auction.model.Child" />
     9  </set>
    10 </class>
    11 <class name="Child" table="CHILD">
    12  <id name="id" column="CHILD_ID" type="long">
    13   <generator class="native"></generator>
    14  </id>
    15  <property name="name" column="NAME" type="string" />
    16 </class>
    17</hibernate-mapping>

    If we were to execute the following code

     1Parent p = new Parent(new HashSet()); 
     2Child c1 = new Child(new String("c1"
    ));
     3

     4try 
    {
     5    session =
     sessionFactory.openSession();            
     6    tx =
     session.beginTransaction();           
     7
        session.save(p);
     8    Long pid =
     p.getId();
     9
        tx.commit();
    10
        session.close();
    11
        
    12    session =
     sessionFactory.openSession();
    13    tx =
     session.beginTransaction();
    14    Parent pp = (Parent) session.load(Parent.class
    , pid); 
    15
        pp.getChildren().add(c1);        
    16
        session.save(c1);
    17
        session.flush();
    18
        tx.commit();
    19

    20}
     catch (HibernateException e) {
    21}

    Hibernate would issue two SQL statements:
    - an INSERT to create the record for c
    - an UPDATE to create the link from p to c

    Hibernate: insert into PARENT values ( )
    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_ from CHILD children0_ where children0_.MY_PARENT_ID=?

    - Hibernate: insert into CHILD (NAME) values (?)
    - Hibernate: update CHILD set MY_PARENT_ID=? where CHILD_ID=?

    This is not only inefficient, but also violates any NOT NULL constraint on the
    MY_PARENT_ID column.

    **********1
    The underlying cause is that the link (the foreign key parent_id) from p to c is not considered part of the state of the Child object and is therefore not created in the INSERT. So the solution is to make the link part of the Child mapping.
    **********1

     <many-to-one name="my_parent"
      class
    ="org.hibernate.auction.model.Parent" column="MY_PARENT_ID"
      not-null
    ="true">
     
    </many-to-one>

    **********2
    Now that the Child entity is managing the state of the link, we tell the collection not to update the link. We use the inverse attribute.
    **********2

     <set name="children" inverse="true">
      
    <key column="MY_PARENT_ID" />
      
    <one-to-many class="org.hibernate.auction.model.Child" />
     
    </set>

    The following code would be used to add a new Child

    1Parent pp = (Parent) session.load(Parent.class, pid); 
    2
    pp.getChildren().add(c1);
    3c1.setMy_parent(pp); //the link is part of the Child object's state. @see***1 

    4session.save(c1);

    And now, only one SQL INSERT would be issued!
    To tighten things up a bit, we could create an addChild() method of Parent.

    1public void addChild(Child c) {
    2  c.setParent(this
    );
    3
      children.add(c);
    4}

    Now, the code to add a Child looks like

    1Parent p = (Parent) session.load(Parent.class, pid);
    2Child c = new
     Child();
    3p.addChild(c);  // 1.let both side of the association knows each other.

    4session.save(c); // 2.save the non-verse side

    =========================================================================================
    CONCLUSION:
    1.The non-inverse(inverse="false") side is responsible to save the in-memory representation (object) to the database .
    --- you should save the child: session.save(c);
    2.Changes made only to the inverse end of the association are not persisted.
    --- you needn't update the parent: //session.update(p);

     1session = sessionFactory.openSession();
     2tx =
     session.beginTransaction();
     3Parent pp = (Parent) session.load(Parent.classnew Long(1
    )); 
     4pp.getChildren().add(c1); //the parent(pp) now knowns about the relationship

     5c1.setMy_parent(pp); //the child(c1) now knows about the relationship
     6

     7//
     when cascade="save-update", update(p) will cause all p's
     8//
     referencing children become persistence(cascade 
     9//
     saveOrUpdate() operation to parent's all children).
    10//
     So, it's same as you explicitly call session.save(c1).
    11

    12//
     when cascade="none"(default), update(p) will just cause
    13//
     p become persistence.
    14//
     And inverse="true", update(p) just persists p, but not 
    15// persists the link between p and c1. @see ***2

    16session.update(pp);  
    17//session.save(c1);  

    18session.flush();
    19
    tx.commit();
    20


    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?

     1session = sessionFactory.openSession();
     2tx =
     session.beginTransaction();
     3Parent pp = (Parent) session.load(Parent.classnew Long(1
    )); 
     4
    pp.getChildren().add(c1);
     5
    c1.setMy_parent(pp);
     6//
    session.update(pp);
     7

     8//
     when save(c1), because c1 holds a reference to its Parent
     9// (my_parent), so p become persistence too.

    10session.save(c1);  //The relationship will be saved. @see ***1
    11session.flush();
    12
    tx.commit();
    13


    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?
    Hibernate: insert into CHILD (NAME, MY_PARENT_ID) values (?, ?)


     

    posted @ 2005-05-19 09:28 Duran's technical life 閱讀(582) | 評論 (0)編輯 收藏
     
    主站蜘蛛池模板: 麻豆国产VA免费精品高清在线| 亚洲日韩中文字幕日韩在线| 欧美激情综合亚洲一二区| 亚洲国产精品视频| 182tv免费视视频线路一二三| 亚洲日本在线电影| 亚洲熟女少妇一区二区| 国产免费久久精品99re丫y| j8又粗又长又硬又爽免费视频| 亚洲色偷偷av男人的天堂| 免费va人成视频网站全| APP在线免费观看视频| 亚洲Av无码国产一区二区| 亚洲∧v久久久无码精品| 国产一卡二卡≡卡四卡免费乱码| 国产一精品一av一免费爽爽 | 亚洲视频在线一区二区三区| 性做久久久久免费观看| 最近免费中文字幕大全免费版视频| 色欲aⅴ亚洲情无码AV| 久久亚洲AV成人无码软件| 免费在线不卡视频| 两性刺激生活片免费视频 | 麻豆国产VA免费精品高清在线| 四虎影视成人永久免费观看视频 | 亚洲色偷偷偷鲁综合| 精品久久久久久久免费人妻| 免费人妻无码不卡中文字幕系| 免费视频成人国产精品网站| 亚洲福利电影一区二区?| 亚洲人成影院在线无码按摩店| 热99re久久精品精品免费| 国产精品入口麻豆免费观看| a毛片免费播放全部完整| 色妞www精品视频免费看| 最新亚洲春色Av无码专区| 综合自拍亚洲综合图不卡区| 亚洲人JIZZ日本人| 亚洲综合色成在线播放| 免费真实播放国产乱子伦| 在线免费观看一级片|