2012年3月7日 星期三

Subclipse



本文章介紹基本的合併流程, 以Subclipse為例


在要合併的目錄, 可以由 Team --> 列出Subclipse所有功能


假設bdp是trunk project, bdp2是branch project

1.首先將新專案bdp2分支 Trunk > Branch


2.Branch開發到一半, 若要跟Trunk合併, 這時要選擇bdp2(也就是branch的project)按右鍵, 
選Team -> 合併 ->
選擇 Merge a range of revisions













3.開發完成後, 要回主線 Trunk < Branch, 這時要選擇bdp(也就是trunk的project)按右鍵, 

選Team -> 合併 ->

選擇 Reintegrate a branch



4.選擇要回去的branch的同階目錄(若從WebContent開始合併, 就指到branch的WebContent)

5.每次合併的結果, 可從 Merge Results Tab查看


Ignored File - A file ignored by version control. You can control what resources will be ignored by going to Window → Preferences → Team → Ignored Resources.
Unversioned File - A file not under version control. These are typically new files that you have not committed to the repository yet.
New File - A versioned file that needs to be added to the remote repository. These are typically files you have either renamed, or moved to a different directory.
Deleted File - A deleted folder. These are folders that you have deleted locally without yet committing the changes to the repository. Note that files are usually removed from the view when they're deleted locally, so they are normally not seen with this icon.
Synchronized File - A file with no local changes.
Local Changes - A file with local, uncommitted changes.
Locked File - A locked file.
Needs Lock - A file that needs a lock to be edited. These are typically files that cannot easily be merged (i.e. binary files), but may have many editors. A file needs a lock when its svn:needs-lock property is set, and Subversion will attempt to make these files read-only in the file system to enforce proper lock negotation.
Conflicted File - A conflicted file. These are typically files that had a commit/update conflict that you marked to resolve later.
Tree Conflicted File - A file that has a tree conflict. These are typically files that have local changes, but have since been moved, removed, or renamed in the repository since the last local copy update.
External File - A file that is external to the project. Linked external files cannot be committed to the repository.
Switched File - A file that has been switched. These are files which belongs to a different working copy than their local parent directory.
In a synchronization view (e.g. via Synchronize with Repository or Commit), as previously described, there are icons which indicate which direction a change is occurring in as well as additional information about that change. These are described below:
Outgoing
Commit Changes - A file whose contents have been modified and will be committed to the repository.
Commit Addition - A file that will be newly added to the repository. This may coincide with a file removal in cases where a file is moved or renamed..
Commit Removal - A file that will be removed from the repository. This may coincide with a file addition in cases where a file is moved or renamed.
Property Change - A file with property changes, in the Commit dialog. On the Synchronize tab, property changes are currently reflected as a normal file modification (Commit Changes).

在上次commit後, 部份屬性有變動
由合併的目錄, 會記錄合併後相關訊息(svn:mergeinfo)
以trunk合併branch情境來看
假設 trunk/WebContent merge branch/WebContent
原本上次合併是由 100 ~ 120, 目前最新版本是121, 合併後也會記錄一個版本, 所以會變成122, 那麼mergeinfo這檔案就是記錄100 ~ 122版本, 但重點是我們還沒有commit
所以此訊息會提示, 我們上次commit是100 ~ 120, 合併後版本變成 100 ~ 122, 它希望我們能commit這版本
為了要記錄這次合併的版本, 所做的提示(因為我們可能在下一階又commit其他變動)
Incoming
Remote Changes - A file that has content changes committed to the repository that will be applied to the local copy.
Pull Addition - A new file that will be added to the local copy from the repository. Like the outgoing file addition, this may be the result of a move or rename.
Pull Removal - A file that will be removed from the local copy because it has been removed from the repository. Like the outgoing file removal, this may be the result of a move or rename.
Conflict
Conflicting Versions - A file that has been changed in both the local copy and repository independently, causing a need for conflict resolution. Fixing this condition involves opening up the conflict view or forcibly overwriting changes locally or remotely.
Synchronization Tree Conflict - A file that has a tree conflict. This can occur when there are new changes to a file on one end (either local or remote), and the file is moved, removed, or renamed on the other.
Finally, the Synchronize with Repository option opens the Synchronize tab (Synchronize Tab) with the following buttons:
Synchronize Source - Synchronizes the local copy with the currently selected repository when clicked. Selecting from the drop-down allows switching between different remote code bases.
Show Incoming - Shows only incoming changes (remote → local).
Show Outgoing - Shows only outgoing changes (local → remote).
Show Incoming and Outgoing - Shows both incoming and outgoing changes (remote ↔ local).
Show Conflicts - Shows conflicting changes.
Update Incoming - Updates all local resources with incoming changes after prompt.
Commit Outgoing - Brings up the commit dialog to commit all outgoing changes.
Show Changesets - Breaks up the change lists by revisions.

--

Conflict
Delete:只要是目錄有變動, 都算是
Add:
Edit:
Local:本機修改
Incoming:是别人修改, 你要Update或Merge進来

Tree Conflict
update情況
Local delete, incoming edit upon update
Local edit, incoming delete upon update
Local delete, incoming delete upon update (二邊都刪掉, 直接標記解決就行)

merge情況
Local missing, incoming edit upon merge
Local edit, incoming delete upon merge (當trunk合併branch, 若trunk修改此檔案, 但trunk刪除時)
Local add, incoming add upon merge (當branch回trunk, 若truck已有此檔案, 但trunk也新增)


測試:
Local delete, incoming edit upon update









最好是每次合併後, 都檢查一下是否有 Tree Conflict, 因為不是每次都有提示


2012年2月22日 星期三

Criteria



分頁
@SuppressWarnings("unchecked")
public List listByUserIdAndState(int userId, int state, int first, int size) {

    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.eq("state", state));
    criteria.setFirstResult(first);
    criteria.setMaxResults(size);
 
    return criteria.list();
}

排序

@SuppressWarnings("unchecked")
public List listByUserIdAndState(int userId, int state, int first, int size) {

    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.eq("state", state));
    criteria.addOrder(Order.desc("updateTime"));
    criteria.setFirstResult(first);
    criteria.setMaxResults(size);
 
    return criteria.list();
}

使用add()方法加入條件時, 預設是使用and來組合條件, 若要用or

    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.or(
          Restrictions.eq("state",  new Integer(1) ),
          Restrictions.isNull("state")
    ));
    return criteria.list();

Like

    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.like("phone", "%" + phone + "%"));
    return criteria.list();

Restrictions
Restrictions.eq
Restrictions.allEq (參數為map)
Restrictions.gt
Restrictions.ge
Restrictions.lt
Restrictions.le
Restrictions.between
Restrictions.like
Restrictions.in
Restrictions.and
Restrictions.or
Restrictions.isNull
Restrictions.isNotNull
Restrictions.sqlRestriction
Order.asc
Order.descMatchMode.EXACT  = "like 'value'"
MatchMode.ANYWHERE = "like '%value%'"
MatchMode.START = like 'value%'"
MatchMode.END = "like '%value'"


Disjunction 

      Criteria criteria = ss.createCriteria(User.class);
      criteria.add(Restrictions.eq("userId", userId));
      Criterion phoneCriterion = Restrictions.like("phone", phone, MatchMode.ANYWHERE);
      Criterion mobileCriterion = Restrictions.like("mobile", mobile, MatchMode.ANYWHERE);
      Disjunction disjunction = Restrictions.disjunction();
      disjunction.add(phoneCriterion);
      disjunction.add(mobileCriterion);
      criteria.add(disjunction);

      return criteria.list();



Count
public int countByUserIdAndState(int userId, int state) {

    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.add(Restrictions.eq("state", state));
    criteria.setProjection(Projections.rowCount());
 
    return (Integer) criteria.uniqueResult();
}

group by
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("area"), "area");
    projectionList.add(Projections.rowCount(), "userId");  
     
    Criteria criteria = ss.createCriteria(User.class);
    criteria.add(Restrictions.eq("userId", userId));
    criteria.setProjection(projectionList);
     
    return criteria.list();

回傳結果
public List<HashMap<String, Integer>> listUser(int userId) {
      ProjectionList projectionList = Projections.projectionList();
      projectionList.add(Projections.groupProperty("area"), "area");  
      projectionList.add(Projections.rowCount(), "userId");  
      Criteria criteria = ss.createCriteria(User.class);
      criteria.add(Restrictions.eq("userId", userId));
      criteria.setProjection(projectionList);
      criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
      return criteria.list();
}



Example 用目前的物件查詢


User user = new User(); 
user.setAge(new Integer(30)); 
Criteria criteria = session.createCriteria(User.class); 
criteria.add(Example.create(user)); 
List users = criteria.list();

Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ from T_USER this_ where (this_.age=?)

sqlRestriction  - 直接下SQL

Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.sqlRestriction(
"{alias}.name LIKE (?)", "todd%", Hibernate.STRING));
List users = criteria.list();

HQL

String hql = "select * from user"; 
Query query = session.createQuery(hql); 
list = query.list();


2011年10月13日 星期四

jquery 1.3 mouseleave event, trigger select option

jquery 1.3 mouseleave event, trigger select option

這是bug嗎? 若綁定mouseleave, 底下若有select tag時, 也會多trigger leave


< div class="move_wrp">
    < select>
       < option>
    < /select>
< /div>

解決方式

$j(".move_wrp").mouseleave(function(e){
    if ((typeof e.fromElement != 'undefined' && !e.fromElement.length) ||
        (typeof e.fromElement == 'undefined' && e.target.tagName != 'SELECT')) {
      $j(this).hide();
    }
  });

2010年12月14日 星期二

安裝apache, subverion

安裝Subverion筆記
   
    目標:
        visualsvn 移機
        再加上修改密碼功能
           
    環境:
        ubuntu10
        apache2.2
        php5
        Subversion
       
    1.使用samba mount到 VisualSvn
        mount.cifs //xx.xx.xx.xx/SvnRepository /usr/local/SvnRoot -o user=xxx,pass=xxx
       
    2.安裝apache2
        sudo apt-get install apache2 apache2-common apache2-utils apache2-doc
        預設裝在
            /etc/apache2/
            /etc/apache2/apache2.conf
        root
            /var/www
       
    3.安裝subversion
        sudo apt-get install subversion libapache2-svn
   
    4.設定環境, 使用apache2去管理Subversion
   
        4.1 文件有提到要使用liunx的group去管理權限 (重要, 才能commit)
            sudo addgroup subversion
            sudo usermod -G subversion -a www-data
           
            sudo chown -R root:subversion myproject
            sudo chown -R www-data:www-data /var/local/svnroot
            --> 授予 Apache(www-data) 使用者存取的權限
           
            /etc/group
           
        4.2 初始化一個repository
            sudo svnadmin create /usr/local/SvnRoot
   
        4.3 修改dav_svn.conf
            sudo vi /etc/apache2/mods-available/dav_svn.conf
            --> 此路徑底下的文件生效
                DAV svn
                #SVNParentPath /mnt/SvnRepository
                SVNParentPath /usr/local/SvnRoot

                   --> SVNPath指Subversion的檔案庫路徑,SVNParentPath指此路徑底下所有目錄
                   都會是Subversion檔案庫
                AuthType Basic
                AuthName "Agenda eSolution Java Dept Subversion repository"
                AuthUserFile /etc/subversion/passwd               
                AuthzSVNAccessFile /etc/subversion/authz
                Require valid-user
                #SVNAutoversioning on
           

        4.4 Subversion 設定文件路徑 /etc/subversion/
            新增Subversion使用者
                sudo htpasswd /etc/subversion/passwd todd (-c 會砍掉檔案重建)
           
            新增Subversion權限
                [aliases]
                # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=
                Research Institute/CN=Joe Average

                [groups]
                testgroup=todd

                [svn:/]
                *=

                [test:/]
                @agenda= rw
                todd2= rw
    5.SSL
        5.1 安裝
            sudo apt-get install ssl-cert
           
        5.2 Enable the SSL Apache module
            sudo a2enmod ssl
       
            /etc/apache2/ports.conf
            應該要有
               
                Listen 443
               

       
        5.3 生成一個 SSL證書
            mkdir /etc/apache2/ssl
            sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
           
        5.4 修改/etc/apache2/sites-available/default-ssl
           
            改成產生的路徑
            #SSLCertificateFile    /etc/apache/ssl/apache.pem
            #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key ?

        5.5 修改/etc/apache2/mods-available/dav_svn.conf
           
                ...
                SSLRequireSSL --> 加入
           

   
        5.6 這一步很重要
            sudo a2ensite default-ssl
            sudo /etc/init.d/apache2 restart
   
        5.7 根憑證 (Root CA) 作法:
            建立根憑證的 Private Key:
                openssl genrsa -des3 -out RootCA.key 2048
                    密碼請來問我
           
            產生根憑證的申請書:
                openssl req -new -key RootCA.key -out RootCA.req
                chmod og-rwx RootCA.key
               
            使用根憑證本身簽髮根憑證:
                openssl x509 -req -days 3650 -sha1 -extensions v3_ca -signkey RootCA.key
                -in RootCA.req -out RootCA.crt

                rm -f RootCA.req
        5.8 伺服器憑證作法:
            建立伺服器憑證的 Private Key:
                openssl genrsa -out HostCA.key 2048
           
            產生伺服器憑證的申請書
                openssl req -new -key HostCA.key -out HostCA.req
                chmod og-rwx HostCA.key
               
                tip: 在填申請伺服器憑證申請書時 (Common Name) 要填上主機的全名,
                    不然用client去連subversion時會出現
                    server certificate was missing commonName attribute in subject name的錯誤
               
            使用根憑證簽發伺服器憑證
                openssl x509 -req -days 365 -sha1 -extensions v3_req -CA RootCA.crt
                -CAkey RootCA.key -CAserial RootCA.srl -CAcreateserial -in HostCA.req
                -out HostCA.crt

                rm -f HostCA.req
               
        5.9 修改 vi /etc/apache2/sites-available/default-ssl
            SSLCertificateFile    /etc/apache2/ssl/RootCA.crt
            SSLCertificateKeyFile /etc/apache2/ssl/RootCA.key
   
            tip: 這裡認證的檔案是使用 RootCA的,
                    我之前打了HostCA, 會出現
                    svn: OPTIONS of 'https://xxxx.xxxx.xxxx.xxxx/svn/xxxx':
                    SSL handshake failed: \ SSL error code 01 的錯誤
   
    6.新增修改帳密的 passwd.php
       
        5.1.安裝php5
            sudo apt-get install php5
            sudo apt-get install libapache2-mod-php5
       
        5.2.新增 /var/www/passwd.php
       
        5.3.修改 /etc/apache2/mods-available/dav_svn.conf, 目的是使用apache來做驗證
            在apache增加一個Alias, 設定該路徑需要認證, 指定認證的文件為 Subversion
       
            Alias /svntools "/var/www/"
           
                    Require valid-user
                    # how to authenticate a user
                    AuthType Basic
                    AuthName "Subversion Tools"
                    AuthUserFile /etc/subversion/passwd
           


        5.4.修改權限
            chmod 777 /etc/subversion/passwd
       
    最後 restart server時, 會要打上CA憑證的密碼 --> 這裡可以再改成起動時就設, 這部份未處理
    修改 httpd.conf 加入 ServerName xxxx.xxxx.xxxx.xxxx   
       
    7.改成對外
        將原本 VisualSVN Server導到 xx.xx.xx.xx:443
       
        所以修改 VisualSVN Server\conf\httpd.conf
        7.1 要打開 #LoadModule ssl_module bin/mod_ssl.so
       
            SSLProxyEngine on
            proxyPass xxx
            ProxyPassReverse xxx
       

安裝tomcat

    java
        sudo apt-get install openjdk-6-jdk
        cd /usr/lib/jvm/java-1.6.0-openjdk/
   
    tomcat
        tar xvzf apache-tomcat-6.0.14.tar.gz
        sudo mv apache-tomcat-6.0.14 /usr/local/tomcat
        vi /etc/init.d/tomcat
       
        export CATALINA_HOME=/usr/local/tomcat
        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
        export PATH=$JAVA_HOME/bin:$PATH

        /usr/local/tomcat/lib/
            jtds-1.2.jar
            proxool-0.9.0RC3.jar
            proxool-0.9.1.jar
            proxool-cglib.jar

        /usr/local/tomcat/conf/content.xml
               
                factory="org.logicalcobwebs.proxool.ProxoolDataSource"
                name="jdbc/xxx"
                password="xxx"
                proxool.alias="xxx"
                proxool.driver-class="net.sourceforge.jtds.jdbc.Driver"
                proxool.driver-url="jdbc:jtds:sqlserver://xx.xx.xx.xx:1433;databaseName=xxx"
                proxool.prototype-count="4"
                type="javax.sql.DataSource"
                 user="xxx"/>

        目前先copy 到 /usr/local/tomcat/webapps/rbs
       
        sudo /etc/init.d/tomcat start
        sudo /etc/init.d/tomcat restart
       
        demo:
            http://xx.xx.xx.xx:8080/xxx/