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

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

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

    posts - 35, comments - 0, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    突然拋了一個concurrentModificationException錯誤,Iterator的一個基本概念沒有掌握導致的這個錯誤,就是在Iterator的實現(xiàn)類。比如Hashtable里面的內(nèi)部類
     private class Enumerator<T> implements Enumeration<T>, Iterator<T>

    會在next,或者remove的時候檢查當前集合是否會在修改狀態(tài),如果是的話,就會拋出 ConcurrentModificationException,而他自己remove則是使用了同步的方法,而且同步了modCount;expectedModCount;

     1 public T next() {
     2      if (modCount != expectedModCount)
     3          throw new ConcurrentModificationException();
     4      return nextElement();
     5  }
     6 
     7 
     8 public void remove() {
     9      if (!iterator)
    10         throw new UnsupportedOperationException();
    11      if (lastReturned == null)
    12         throw new IllegalStateException("Hashtable Enumerator");
    13      if (modCount != expectedModCount)
    14         throw new ConcurrentModificationException();
    15 
    16      synchronized(Hashtable.this) {
    17         Entry[] tab = Hashtable.this.table;
    18         int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length;
    19 
    20      for (Entry<K,V> e = tab[index], prev = null; e != null; prev = e, e = e.next) {
    22       if (e == lastReturned) {
    23          modCount++;
    24          expectedModCount++;
    25          if (prev == null)
    26             tab[index] = e.next;
    27          else
    28             prev.next = e.next;
    29          count--;
    30          lastReturned = null;
    31          return;
    32       }
    33      }
    34      throw new ConcurrentModificationException();
    35      }
    36     }
    37     }
    而自己在next的同時,修改了這個集合,導致了這個錯誤的出現(xiàn)

     

    在Map或者Collection的時候,不要用它們的API直接修改集合的內(nèi)容,如果要修改可以用Iterator的remove()方法,例如:
    1 public void setReparation( Reparation reparation ) {
    2         for (Iterator it = this.reparations.iterator();it.hasNext();){    //reparations為Collection
    3             Reparation repa = (Reparation)it.next();
    4             if (repa.getId() == reparation.getId()){
    5                 this.reparations.remove(repa);
    6                 this.reparations.add(reparation);
    7             }
    8         }
    9    }

     

    如上寫會在運行期報ConcurrentModificationException,可以如下修改:

     

     1  public void setReparation( Reparation reparation ) {
     2         boolean flag = false;
     3         for (Iterator it = this.reparations.iterator();it.hasNext();){    //reparations為Collection
     4             Reparation repa = (Reparation)it.next();
     5             if (repa.getId() == reparation.getId()){
     6                 it.remove();
     7                 flag = true;
     8                 break;
     9             }
    10         }
    11         if(flag){
    12           this.reparations.add(reparation);
    13         }
    14     }

     

     

    原文摘自 alreal 

     

    posted @ 2012-07-17 17:01 timelyxyz 閱讀(111) | 評論 (0)編輯 收藏

    API語法:

    File(String pathname)
    通過將給定路徑名字符串轉(zhuǎn)換為抽象路徑名來創(chuàng)建一個新 File 實例。
    public static final String separator
    與系統(tǒng)有關的默認名稱分隔符,為了方便,它被表示為一個字符串。此字符串只包含一個字符,即 separatorChar
    public static final char separatorChar
    與系統(tǒng)有關的默認名稱分隔符。此字段被初始化為包含系統(tǒng)屬性 file.separator 值的第一個字符。在 UNIX 系統(tǒng)上,此字段的值為 '/';在 Microsoft Windows 系統(tǒng)上,它為 '\\'

    注意:

    路徑名字符串與抽象路徑名之間的轉(zhuǎn)換與系統(tǒng)有關。將抽象路徑名轉(zhuǎn)換為路徑名字符串時,每個名稱與下一個名稱之間用一個默認分隔符 隔開。默認名稱分隔符由系統(tǒng)屬性 file.separator 定義,可通過此類的公共靜態(tài)字段 separatorseparatorChar 使其可用。將路徑名字符串轉(zhuǎn)換為抽象路徑名時,可以使用默認名稱分隔符或者底層系統(tǒng)支持的任何其他名稱分隔符來分隔其中的名稱。

     

    例如,我希望的文件絕對路徑是E:\dev\workspace\iclass_web/conf/filterconfig.xml(計作myPath),有兩種創(chuàng)建File的形式:

    1)new File(myPath)不會報錯;

    2)new File("E:\dev\workspace\iclass_web/conf/filterconfig.xm")報錯,應修改為new File("E:\\dev\\workspace\\iclass_web/conf/filterconfig.xml"

     我的系統(tǒng)是windows32位,io.File的一個字段FileSystem是一個抽象類,F(xiàn)ileSystem被一個Win32FileSystem類繼承,從而實現(xiàn)里面的public abstract String normalize(String path);方法。

     Win32FileSystem部分源碼如下:

     1 private final char slash;  2     private final char altSlash;  3     private final char semicolon;  4
     5     public Win32FileSystem() {  6     slash = ((String) AccessController.doPrivileged(  7               new GetPropertyAction("file.separator"))).charAt(0);  8     semicolon = ((String) AccessController.doPrivileged(  9               new GetPropertyAction("path.separator"))).charAt(0); 10     altSlash = (this.slash == '\\') ? '/' : '\\'; 11     } 12 13     private boolean isSlash(char c) { 14     return (c == '\\') || (c == '/'); 15     } 16 17     private boolean isLetter(char c) { 18     return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); 19     } 20 21     private String slashify(String p) { 22     if ((p.length() > 0) && (p.charAt(0) != slash)) return slash + p; 23     else return p; 24     } 25    26     /* Check that the given pathname is normal.  If not, invoke the real 27        normalizer on the part of the pathname that requires normalization. 28        This way we iterate through the whole pathname string only once. */ 29     public String normalize(String path) { 30     int n = path.length(); 31     char slash = this.slash; 32     char altSlash = this.altSlash; 33     char prev = 0; 34     for (int i = 0; i < n; i++) { 35         char c = path.charAt(i); 36         if (c == altSlash) 37         return normalize(path, n, (prev == slash) ? i - 1 : i); 38         if ((c == slash) && (prev == slash) && (i > 1)) 39         return normalize(path, n, i - 1); 40         if ((c == ':') && (i > 1)) 41         return normalize(path, n, 0); 42         prev = c; 43     } 44     if (prev == slash) return normalize(path, n, n - 1); 45     return path; 46     }

     

    posted @ 2012-07-10 17:12 timelyxyz 閱讀(154) | 評論 (0)編輯 收藏

    Hibernate中使用COUNT DISTINCT關鍵字: Hibernate

    在Hibernate中, 計算某列非重復記錄的總數(shù), 使用COUNT + DISTINCT

    在MySQL中,可以使用

    sql 代碼
    1. select COUNT(DISTINCT(name)) from products  

    但在Hibernate中卻不能用如下格式

    1. select COUNT(DISTINCT(name)) from ProductDTO  

    需要把里面的括號去掉, 改成

    1. select COUNT(DISTINCT name ) from ProductDTO  

    在MySQL中也可以使用這種樣式.

    posted @ 2012-06-28 13:24 timelyxyz 閱讀(121) | 評論 (0)編輯 收藏

    報錯現(xiàn)象

    Oops: JPAQueryException
    An unexpected error occured caused by exception JPAQueryException: Error while executing query select t from TurnedIn t, Notification n  where n.itemId=t.id and n.type=? and n.receiver.id=? and n.isDeleted=false group by t order by t.createTime desc: org.hibernate.type.SerializationException: could not deserialize
    ...
    Caused by: java.io.InvalidClassException: models.member.Member; local class incompatible: stream classdesc serialVersionUID = 8996579512119659486, local class serialVersionUID = -7513555048418418149

    異常原因

    本地和遠程的member序列化后的serialVersionUID不

    解決方法

    將本地的序列化的類中的版本號(serialVersionUID )改成和遠程中一樣,在本地的序列化類里的private static final long serialVersionUID =  改成遠程的就行了,如果沒有的話就加上這句。

     

    關于“org.hibernate.type.SerializationException: could not deserialize”,我查了很多的資料,大概有以下幾個原因:

    1.該類的序列版本號與從流中讀取的類描述符的版本號不匹配(jdk版本更換會造成這個問題)

    2.該類包含未知數(shù)據(jù)類型(hibernate配置文件中未指定數(shù)據(jù)類型)

    3.該類沒有可訪問的無參數(shù)構造方法


     

     

     

    posted @ 2012-06-26 09:51 timelyxyz 閱讀(1088) | 評論 (0)編輯 收藏

    pgSql

    語法 to_number(text, text)

    例子 select to_number(trim(both 'ibs' from classname), '999999') as cn from bbs order by cn   /*trim(both 'ibs' from classname)去除classname字段中的'ibs'字符*/

    mySql

    語法 str*1 / str+1 / -str  /*str為varchar的數(shù)字,此處不一定是1,只要是數(shù)字即可*/

    hql

    語法 to_number(text, text)

     

    例子 select b from BBS b where b.isDeleted=false order by to_number(trim(both 'ibs' from b.className), '999999')


     

     

    pgSql數(shù)據(jù)類型格式化函數(shù) 

    posted @ 2012-06-14 15:43 timelyxyz 閱讀(583) | 評論 (0)編輯 收藏

    order by isTop desc


     

    默認false在前;按desc,true在前

    posted @ 2012-06-13 15:00 timelyxyz 閱讀(731) | 評論 (0)編輯 收藏

          在push之前有時候會不放心是不是忘記加某些文件,或者是不是多刪了個什么東西,這時候希望能夠看看上次commit都做了些什么。

    一開始想到的是用git diff,但是git diff用于當前修改尚未commit的時候較為方便,一旦commit后,需要指定上次節(jié)點的名稱(一個hash值),不方便。這種時候用git log更合適,因為commit的內(nèi)容會以log來記錄。

    下面記錄幾個常用的情境以及對應的命令。

    僅僅想看最近誰有提交,以及提交的描述

    對應命令 git log

    顯示Sample

     

    commit 6305aa81a265f9316b606d3564521c43f0d6c9a3
    Author: XXX
    Date:   Thu Nov 3 11:38:15 2011 +0800

        fill author information in the head of files and format some code

    commit 8e8a4a96e134dab8f045937efee35bd710006946
    Author: XXX
    Date:   Thu Nov 3 04:05:34 2011 +0800

        user management is mostly complete

        details:
        add support for account disable/enable
        rewrite most related views to suit the above need
        provide two decorators for access control (see README)
        fixed many errors in Milestone 1

    commit 2870cd564371d8ad043d0da426a5770d36412421
    Author: XXX
    Date:   Mon Oct 17 20:19:04 2011 -0400

        fix the bug of get_ori_url_from_shorturl().

    commit b6cdd881a19ecaff838d5825c3a6b7058fdd498a
    Author: XXX
    Date:   Mon Oct 17 20:17:37 2011 -0400

        fix the bug of get_article_from_short_url.

    僅僅想看最后一次的提交

    對應命令參數(shù) -n 1

    顯示Sample

    commit 6305aa81a265f9316b606d3564521c43f0d6c9a3
    Author: XXX
    Date: Thu Nov 3 11:38:15 2011 +0800

    fill author information in the head of files and format some code

    想看到最近一次提交所有更改過的文件

    對應命令 git log -n 1 --stat

    顯示Sample

    commit 6305aa81a265f9316b606d3564521c43f0d6c9a3
    Author: XXX
    Date:   Thu Nov 3 11:38:15 2011 +0800

        fill author information in the head of files and format some code

    Site/accounts/decorators.py                        |    2 +-
    Site/accounts/forms.py                             |    1 +
    Site/accounts/models.py                            |    1 +
    Site/accounts/readme                               |    3 ++-
    Site/accounts/templates/account_activate.html      |    1 +
    Site/accounts/templates/account_disabled.html      |    1 +

    28 files changed, 37 insertions(+), 8 deletions(-)

    想看到最近一次提交所有更改的細節(jié)

    對應命令 git log -n 1 -p

    顯示Sample

    commit 6305aa81a265f9316b606d3564521c43f0d6c9a3
    Author: XXX
    Date:   Thu Nov 3 11:38:15 2011 +0800

        fill author information in the head of files and format some code

    diff --git a/Site/accounts/decorators.py b/Site/accounts/decorators.py
    index 22522bc..a6bb440 100755
    --- a/Site/accounts/decorators.py
    +++ b/Site/accounts/decorators.py
    @@ -1,9 +1,9 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    +# author: Rex Nov. 3, 2011
    from functools import wraps
    from django.core.urlresolvers import reverse
    from django.http import HttpResponseRedirect
    -from django.utils.decorators import available_attrs
    from Site.accounts.models import UserProfile

    def login_required(view_func):
    diff --git a/Site/accounts/forms.py b/Site/accounts/forms.py
    index 016710b..778d92a 100755
    --- a/Site/accounts/forms.py
    +++ b/Site/accounts/forms.py
    @@ -1,5 +1,6 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    +# author: Rex Nov. 3, 201

    有了這幾條命令,基本上對于想看最近更改的情境就可以應付過去了。最后一條并不很常用,如果有visual的工具可能更直觀些。

     

    原文轉(zhuǎn)自git使用點滴

     

    posted @ 2012-06-13 12:24 timelyxyz 閱讀(216) | 評論 (0)編輯 收藏

          Onunload,onbeforeunload都是在刷新或關閉時調(diào)用,可以在<script>腳本中通過window.onunload 來指定或者在<body>里指定。區(qū)別在于onbeforeunload在onunload之前執(zhí)行,它還可以阻止onunload的執(zhí)行。

        Onbeforeunload也是在頁面刷新或關閉時調(diào)用,Onbeforeunload是正要去服務器讀取新的頁面時調(diào)用,此時還沒開始讀取;而 onunload則已經(jīng)從服務器上讀到了需要加載的新的頁面,在即將替換掉當前頁面時調(diào)用。Onunload是無法阻止頁面的更新和關閉的。而 Onbeforeunload 可以做到。曾經(jīng)做一個考試系統(tǒng),涉及到防止用戶半途退出考試(有意或者無意),代碼如下:

     

    <body onbeforeunload=" checkLeave()">

     

    <script>
    function checkLeave(){
        event.returnValue="確定放棄考試?(考試作廢,不記錄成績)";
    }
    </script>

     

     

    這樣可以讓用戶確認是否要退出考場,其實BLOGJAVA在用戶編寫B(tài)LOG時,如果不保存而跳轉(zhuǎn)到其他頁面,也會有一個確認的提示(防止誤操作),也是用到Onbeforeunload。

       另外還可以用來在頁面關閉的時候關閉session,代碼如下(注:用window.screenLeft > 10000 來區(qū)分關閉和刷新操作):

    <body onbeforeunload=" closeSession()">

     

    <script>
    function closeSession (){
        //關閉(刷新的時候不關閉Session)
        if(window.screenLeft>10000){
           //關閉Session的操作(可以運用AJAX)
        }
    }
    </script>

     

     

     

    文章摘自 blogJava

     

    posted @ 2012-06-11 16:11 timelyxyz 閱讀(138) | 評論 (0)編輯 收藏

    問題描述:firefox下js中動態(tài)組裝select時指定option的selected屬性的失效

     

    有問題的代碼如下:

     1                         // 加載select列表
     2                         var teaOption ='', ownerSel = $("ownerSel");
     3                         for(var i = 0; i < teaList.length; i ++){
     4                             var teacher = teaList[i];
     5                             if(teacher.isDeleted === false){
     6                                 var tid = teacher.id, tName = teacher.fullName, newOption;
     7                                 var flag = ((tid === formerOwnerId) ? 'selected="selected"' : '');
     9                                 teaOption += '<option value="'+tid+'" '+ flag +'>'+ tName +'</option>';
    10                             }
    11                         }
    12                         ownerSel.html(teaOption);

     此時selected屬性無效,ff中的select顯示的是option列表的最后一個。

    原因貌似是這樣子:
    selected這個屬性本身是沒有錯的,你在頁面開始加載的前寫好,然后瀏覽器加載的時候就會讀取這個dom,然后有selected這個效果。
    但是通過js動態(tài)組裝的select的html代碼,在ie下我剛剛試了下可行(我剛剛失敗的原因是三目運算符處少加了一個括號);firefox下,在請求加載的同時加載dom元素,但是ff內(nèi)核可能是為了追求速度,而省略了一些dom的屬性的加載,導致了selected這個屬性的失效。

    解決方法(我用的是mootools):在加載的時候?qū)ption元素通過如下解決

     1                         // 加載select列表
     2                         var ownerSel = $("ownerSel");
     3                         for(var i = 0; i < teaList.length; i ++){
     4                             var teacher = teaList[i];
     5                             if(teacher.isDeleted === false){
     6                                 var tid = teacher.id, tName = teacher.fullName, newOption;
     7                                 if(tid === formerOwnerId)
     8                                     newOption = new Element('option', {"value" : tid, "selected" : "selected"}).html(tName);
     9                                 else
    10                                     newOption = new Element('option', {"value" : tid}).html(tName);
    11                                 ownerSel.grab(newOption); // 將新的element插入到select中
    12                             }
    13                         }

     

    posted @ 2012-06-07 08:34 timelyxyz 閱讀(1561) | 評論 (0)編輯 收藏

    錯誤 org.hibernate.HibernateException: ordinal parameter mismatch 。

    我的錯誤是未將hql語句設置參數(shù)時的占位符去掉(粗糙流了下- -///)

    1 hql += " and bbs.id=? " + bbs.id;

     

     

    在這之前網(wǎng)上發(fā)現(xiàn)的另一種錯誤也很值得注意:在數(shù)據(jù)表中用了關鍵字“call” 作為數(shù)據(jù)字段,所以產(chǎn)生了這個問題。Hibernate報錯如下:

     

     org.hibernate.HibernateException: ordinal parameter mismatch
     at org.hibernate.engine.query.HQLQueryPlan.buildParameterMetadata(HQLQueryPlan.java:225)
     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:95)
     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
     at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
     at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
     at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
     at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
      ......
     

     

     出錯的原因是在org.hibernate.engine.query.ParameterParser類中有下列一段代碼

     

    1 public static void parse(String sqlString, Recognizer recognizer) throws QueryException{
    2     boolean hasMainOutputParameter = sqlString.indexOf( "call" ) > 0 &&
    3                                    sqlString.indexOf( "?" ) < sqlString.indexOf( "call" ) &&
    4                                    sqlString.indexOf( "=" ) < sqlString.indexOf( "call" );
    5     ......
    6 }

     


    我們都知道hibernate3可以調(diào)用存儲過程或函數(shù),但是有一定的限制(具體可以查看hibernate官方手冊)。
    據(jù)我分析這段代碼應該是用來分析字符串是否是調(diào)用存儲過程或函數(shù)的語句。
    解決方法:
    1.不要在表或列中,出現(xiàn)"call"字樣
    2.用Criteria來代替hql語句

     

    posted @ 2012-06-06 13:20 timelyxyz 閱讀(332) | 評論 (0)編輯 收藏

    僅列出標題
    共4頁: 上一頁 1 2 3 4 下一頁 
    主站蜘蛛池模板: 国产中文字幕在线免费观看 | 免费人成在线观看视频高潮| 亚洲免费观看视频| 99久久国产免费-99久久国产免费| 亚洲人成人77777在线播放| 日本xxwwxxww在线视频免费 | 91情侣在线精品国产免费| 老妇激情毛片免费| 亚洲AV无码成人精品区天堂| 成人毛片免费视频| 国产va免费精品| 99久久国产亚洲综合精品| 在线亚洲精品自拍| 国产成人无码免费看视频软件 | 亚洲人成图片网站| 青青草原亚洲视频| 成年男女男精品免费视频网站| www免费黄色网| 亚洲欧美国产日韩av野草社区| 亚洲国产第一站精品蜜芽| 午夜a级成人免费毛片| 国产精品白浆在线观看免费| 亚洲国产精品ⅴa在线观看| 亚洲av不卡一区二区三区| 免费人成视频在线观看不卡| www视频在线观看免费| 91免费国产视频| 国产精品亚洲专区在线播放 | 亚洲精品国产高清在线观看| 亚洲av日韩av无码黑人| 免费观看亚洲人成网站| 免费观看AV片在线播放| 久久国产精品免费观看| 337P日本欧洲亚洲大胆精品| 亚洲婷婷综合色高清在线| 亚洲精品无码Av人在线观看国产| 国产一级高清免费观看| 毛片免费全部播放一级| 亚洲w码欧洲s码免费| 男人j进入女人j内部免费网站| 无码毛片一区二区三区视频免费播放 |