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

          日歷

          <2012年6月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          搜索

          •  

          最新評論

          2012年6月28日

          2012.09.19 office for mac 2011更新到14.2.4版本,最大的變化就是解決了office在pro retina中的顯示問題。

           

          檢查并安裝更新到14.2.4之后,我的retina中office的顯示完全OK了.

          這是office for mac team的官方聲明鏈接link

          這是網(wǎng)上關(guān)于升級到14.2.4之后仍然無效的解決方法的鏈接link2.

           

          posted @ 2012-10-13 09:53 timelyxyz 閱讀(234) | 評論 (0)編輯 收藏

          并集:Set1 union Set2

          交集:Set1 intersect Set2

          posted @ 2012-10-11 21:15 timelyxyz 閱讀(241) | 評論 (0)編輯 收藏

          正確語句
          1 update jytuser set userid=(select member.userid from member where member.id=jytuser.owner_id)

           

          有2個易錯點: 

          1)表自關(guān)聯(lián)好像行不通。我猜想會不會和查詢時建立的索引更改有關(guān)。

          2)這種寫法postgres不支持

          1 update jytuser,member set jytuser.userid=member.userid where jytuser.owner_id=jmember.id and jytuser.userid=0;

          報錯如下:

           

          posted @ 2012-10-10 11:36 timelyxyz 閱讀(204) | 評論 (0)編輯 收藏

          最近在做數(shù)據(jù)同步的項目,過程中接觸了spring+jdbc的開發(fā)模式(IDE: sts),然后開始使用maven管理項目。目前碰到的一個問題是在本地添加一個repository,加的是用于連接sqlserver的驅(qū)動包sqljdbc4.jar。我在很多maven倉庫里都沒找到這個jar,只能手動的下載來,然后添加到本地倉庫里。發(fā)現(xiàn)這個包好像很多人沒有添加成功,我在這里找到了解決方法http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/

          主要步驟如下:

          1. 本地下載sqljdbc4.jar

          2. 解壓到本地文件夾中,并找到sqljdbc4.jar路徑

          3. 打開命令窗口,執(zhí)行以下語句(前提:先配置好maven環(huán)境變量)

          1 C:\Users\nbxyz>mvn install:install-file -Dfile=e:\sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

          4."BUILD SUCCESS"即添加成功



          生成的pom文件如下

          1 <?xml version="1.0" encoding="UTF-8"?>
          2 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
          3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          4   <modelVersion>4.0.0</modelVersion>
          5   <groupId>com.microsoft.sqlserver</groupId>
          6   <artifactId>sqljdbc4</artifactId>
          7   <version>4.0</version>
          8   <description>POM was created from install:install-file</description>
          9 </project>

           

          posted @ 2012-10-09 14:40 timelyxyz 閱讀(314) | 評論 (0)編輯 收藏

           1     private static Map<String, Long> getPictureHeightAndWidthMap(String picUrl) {
           2         Map<String, Long> map = new HashMap();
           3         try {
           4             URL url = new URL(picUrl);
           5             HttpURLConnection connection = (HttpURLConnection) url
           6                     .openConnection();
           7             DataInputStream in = new DataInputStream(
           8                     connection.getInputStream());
           9             BufferedImage image = ImageIO.read(in);
          10             map.put("w", image.getWidth() * 1L);
          11             map.put("h", image.getHeight() * 1L);
          12             connection.disconnect();
          13             in.close();
          14         } catch (IOException e) {
          15             e.printStackTrace();
          16         }
          17         return map;
          18     }
          19 
          20     public static Long getHeight(String picUrl) {
          21         Map<String, Long> map = getPictureHeightAndWidthMap(picUrl);
          22         return null == map.get("h") ? 0 : map.get("h");
          23     }
          24 
          25     public static Long getWidth(String picUrl) {
          26         Map<String, Long> map = getPictureHeightAndWidthMap(picUrl);
          27         return null == map.get("w") ? 0 : map.get("w");
          28     }

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

          Do "Show package contents" on the Eclipse.app.  
          Edit Contents/Info.plist.  
          Just above   

          </dict>
          </plist>

          Place this:  

          <key>NSHighResolutionCapable</key> 
          <true/>

          Then, log out or make a copy of the app so that OSX will notice the change.  Now, the info window will not show "Open in Low Resolution" as checked.  Launch Eclipse and enjoy your new retina awesomeness.

          solution from https://bugs.eclipse.org/bugs/show_bug.cgi?id=382972

          同樣的方法也可以解決的軟件有:Spring tool suites.

          posted @ 2012-09-22 18:27 timelyxyz 閱讀(329) | 評論 (0)編輯 收藏

          1 首先查看PATH
          命令:$PATH  
           
          2 如何設(shè)置PATH
          命令:echo "export PATH=xxxxxx:$PATH" >> ~/.bash_profile
          解釋:把"export PATH=xxxxxx:$PATH"輸出打印到~/.bash_profile中去。
           
          3 Unix知識補充:~/.bash_profile介紹
          mac和linux終端一般用bash來進行解析。當(dāng)bash在讀完了整體環(huán)境變量的/etc/profile并借此調(diào)用其他配置文件后,接下來則是會讀取用戶自定義的個人配置文件。bash讀取的文件總共有三種:
          ~/.bash_profile   ~/.bash_login    ~/.profile
          其實bash再啟動是只讀上面文件的一個,而讀取的順序則是依照上面的順序。也就是說讀到bash_profile就不讀后面的了,如果bash_profile不存在,后面的才能有機會。
          讓我們來看看bash_profile里面有什么內(nèi)容:
          命令:cat ~/.bash_profile 
          最后重啟你的終端就會有剛才設(shè)置的全局變量了。 
           【2012.02.28更新】
          最直觀的方法是:
          cd ~
          open .bash_profile
          這時候就會直接用記事本程序打開這個配置文件,比在終端里那么設(shè)置要簡單直觀多了。
          要注意一點那就是配置文件里的變量是會覆蓋的,比如
          export PATH=1
          export PATH=2
          那么后面的2會把前面的1覆蓋的。

          posted @ 2012-09-22 17:14 timelyxyz 閱讀(488) | 評論 (0)編輯 收藏

          hibernate默認(rèn)的,以及網(wǎng)絡(luò)上的主流支持left join的表關(guān)系是one-to-many的,可以使用left join fetch(需要配置lazy="true" fetch="select"),也可以使用Criteria或者CriteriaQuery(link1 link2)來進行查詢。

           

          對于many-to-one,首先我們先建兩個model:

           

          @Entity
          public class ClassOne {
          public String id;
          public boolean isDeleted;  
          }

          @Entity

          public class ClassTwo {
          public String id; 
          @ManyToOne
          public ClassOne classOne; // 父表
          public boolean isDeleted;  
          }

           目前有兩個需求:

           

          (1)select a.id,b.id from ClassTwo as b left join b.classOne as a;【正確,獲取到了所有ClassOne表的數(shù)據(jù)項】

          (2)select a.id,count(b.id) from ClassTwo as b left join b.classOne as a where a.isDeleted=false and b.isDeleted=false group by a.id;【count結(jié)果中把0的濾去了,沒達(dá)到我的需求】 

          對于第二種,目前我還沒找到具體的解決方法,仍需研究。 

           

          posted @ 2012-09-18 13:47 timelyxyz 閱讀(223) | 評論 (0)編輯 收藏

          hi

          outer-join     fetch     lazy         主鍵表class     檢索策略         檢索方式
          true/false/auto     select     false         true/false     立即檢索(n+1次查詢)     所有
          -         -     no-proxy/proxy     true         延遲檢索         所有
          -         -     -         false         立即檢索(n+1次查詢)     所有
          -         join     false         true/false     inner join         QBC,get()/load()
          -         -     -         -         立即檢索(n+1次查詢)     HQL,NativeSQL
          -         join     no-proxy/proxy     false         inner join         QBC,get()/load()
          -         -     -         -         立即檢索(n+1次查詢)     HQL,NativeSQL
          -         -     -         true         inner join         QBC,get()/load()
          -         -     -         -         延遲檢索




          String hql = "select t,count(tp) from ContentTag_Post as tp     left join fetch tp.tag as t"
              + " where tp.tag=t and t.owner.id=? "
              + " and tp.isDeleted=false and t.isDeleted=false "
              + " group by t order by t.createTime desc ";


                  String hql = "select t,count(tp) from ContentTag as t left join ContentTag_Post as tp "
                          + " where t.owner.id=? and t=tp.tag "
                          + " and t.isDeleted=false and tp.isDeleted=false "
                          + " group by t order by t.createTime desc ";

           Path expected for join!
          2012-08-22 12:47:37 [ERROR]  Invalid path: 'tp.tag'
          right-hand operand of a binary operator was null
          <AST>:0:0: unexpected end of subtree
          left-hand operand of a binary operator was null


          select查詢 join查詢

          @LazyToOne用法
          http://docs.jboss.org/hibernate/annotations/3.4/reference/zh_cn/html/entity.html
          Java中的transient,volatile和strictfp關(guān)鍵字
          http://www.iteye.com/topic/52957
          transient
            Java語言的關(guān)鍵字,用來表示一個域不是該對象串行化的一部分。當(dāng)一個對象被串行化的時候,transient型變量的值不包括在串行化的表示中,然而非transient型的變量是被包括進去的


          class A implements Serializable {
           private String name;
           transient private String address;
          }

          那么你在串行化(IO流等)A類時 給它的name和address屬性賦值,那么你在提取A時,拿到了name屬性,但是卻拿不到address屬性。




          lazy是延時的意思,如果lazy=true,那么就是說數(shù)據(jù)庫中關(guān)聯(lián)子表的信息在hibernate容器啟動的時候不會加載,而是在你真正的訪問到字表非標(biāo)識字段的時候,才會去加載。
          反之,如果lazy=false的話,就是說,子表的信息會同主表信息同時加載。
          一般用只有完全用到子表信息的時候,才會lazy=false

          join 查詢的時候,是用以條語句查處所有記錄,包括關(guān)聯(lián)表記錄,select查出的是N+1條記錄,兩個都是差不多的,但是如果用了lazy=true,延遲加載的話,select在查詢時只會查出主表記錄,也就是1,如果其他地方也用到了數(shù)據(jù),此時就會自動在執(zhí)行查詢,查出N,可以降低內(nèi)存消耗 .還有,hibernate是的session是輕量級的,創(chuàng)建和銷毀都不花很多資源,查詢數(shù)據(jù)也很快,這里fetch主要起這個作用    

          Path expected for join! unexpected end of subtree

          posted @ 2012-09-04 10:55 timelyxyz 閱讀(156) | 評論 (0)編輯 收藏

          使用條件如下:

          a left join  b

          a must be b's parent

          posted @ 2012-07-24 11:37 timelyxyz 閱讀(392) | 評論 (0)編輯 收藏

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

          會在next,或者remove的時候檢查當(dāng)前集合是否會在修改狀態(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的同時,修改了這個集合,導(dǎo)致了這個錯誤的出現(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)有關(guān)的默認(rèn)名稱分隔符,為了方便,它被表示為一個字符串。此字符串只包含一個字符,即 separatorChar
          public static final char separatorChar
          與系統(tǒng)有關(guān)的默認(rèn)名稱分隔符。此字段被初始化為包含系統(tǒng)屬性 file.separator 值的第一個字符。在 UNIX 系統(tǒng)上,此字段的值為 '/';在 Microsoft Windows 系統(tǒng)上,它為 '\\'

          注意:

          路徑名字符串與抽象路徑名之間的轉(zhuǎn)換與系統(tǒng)有關(guān)。將抽象路徑名轉(zhuǎn)換為路徑名字符串時,每個名稱與下一個名稱之間用一個默認(rèn)分隔符 隔開。默認(rèn)名稱分隔符由系統(tǒng)屬性 file.separator 定義,可通過此類的公共靜態(tài)字段 separatorseparatorChar 使其可用。將路徑名字符串轉(zhuǎn)換為抽象路徑名時,可以使用默認(rè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")報錯,應(yīng)修改為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關(guān)鍵字: Hibernate

          在Hibernate中, 計算某列非重復(fù)記錄的總數(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)編輯 收藏

          主站蜘蛛池模板: 乡宁县| 大英县| 高雄县| 庐江县| 松溪县| 平凉市| 富锦市| 尉氏县| 瑞丽市| 马尔康县| 南昌市| 凌云县| 那坡县| 六盘水市| 班戈县| 长寿区| 招远市| 来安县| 澳门| 闸北区| 汉寿县| 尤溪县| 扎赉特旗| 岱山县| 恭城| 雷州市| 山西省| 渝北区| 昌平区| 万载县| 定结县| 阜城县| 福建省| 花垣县| 定日县| 江孜县| 大城县| 扎鲁特旗| 南靖县| 高密市| 百色市|