posts - 35, comments - 0, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

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

这是网上关于升级到14.2.4之后仍然无效的解决方法的链接link2.

 

posted @ 2012-10-13 09:53 timelyxyz 阅读(220) | 评论 (0)编辑 收藏

并集:Set1 union Set2

交集:Set1 intersect Set2

posted @ 2012-10-11 21:15 timelyxyz 阅读(230) | 评论 (0)编辑 收藏

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

 

有2个易错点: 

1)表自关联好像行不通。我猜想会不会和查询时建立的索引更改有关。

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 阅读(194) | 评论 (0)编辑 收藏

最近在做数据同步的项目,过程中接触了spring+jdbc的开发模式(IDE: sts),然后开始使用maven管理项目。目前碰到的一个问题是在本地添加一个repository,加的是用于连接sqlserver的驱动包sqljdbc4.jar。我在很多maven仓库里都没找到这个jar,只能手动的下载来,然后添加到本地仓库里。发现这个包好像很多人没有添加成功,我在这里找到了解决方法http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/

主要步骤如下:

1. 本地下载sqljdbc4.jar

2. 解压到本地文件夹中,并找到sqljdbc4.jar路径

3. 打开命令窗口,执行以下语句(前提:先配置好maven环境变量)

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 阅读(302) | 评论 (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 阅读(407) | 评论 (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 阅读(317) | 评论 (0)编辑 收藏

1 首先查看PATH
命令:$PATH  
 
2 如何设置PATH
命令:echo "export PATH=xxxxxx:$PATH" >> ~/.bash_profile
解释:把"export PATH=xxxxxx:$PATH"输出打印到~/.bash_profile中去。
 
3 Unix知识补充:~/.bash_profile介绍
mac和linux终端一般用bash来进行解析。当bash在读完了整体环境变量的/etc/profile并借此调用其他配置文件后,接下来则是会读取用户自定义的个人配置文件。bash读取的文件总共有三种:
~/.bash_profile   ~/.bash_login    ~/.profile
其实bash再启动是只读上面文件的一个,而读取的顺序则是依照上面的顺序。也就是说读到bash_profile就不读后面的了,如果bash_profile不存在,后面的才能有机会。
让我们来看看bash_profile里面有什么内容:
命令:cat ~/.bash_profile 
最后重启你的终端就会有刚才设置的全局变量了。 
 【2012.02.28更新】
最直观的方法是:
cd ~
open .bash_profile
这时候就会直接用记事本程序打开这个配置文件,比在终端里那么设置要简单直观多了。
要注意一点那就是配置文件里的变量是会覆盖的,比如
export PATH=1
export PATH=2
那么后面的2会把前面的1覆盖的。

posted @ 2012-09-22 17:14 timelyxyz 阅读(467) | 评论 (0)编辑 收藏

hibernate默认的,以及网络上的主流支持left join的表关系是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表的数据项】

(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结果中把0的滤去了,没达到我的需求】 

对于第二种,目前我还没找到具体的解决方法,仍需研究。 

 

posted @ 2012-09-18 13:47 timelyxyz 阅读(184) | 评论 (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关键字
http://www.iteye.com/topic/52957
transient
  Java语言的关键字,用来表示一个域不是该对象串行化的一部分。当一个对象被串行化的时候,transient型变量的值不包括在串行化的表示中,然而非transient型的变量是被包括进去的


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

那么你在串行化(IO流等)A类时 给它的name和address属性赋值,那么你在提取A时,拿到了name属性,但是却拿不到address属性。




lazy是延时的意思,如果lazy=true,那么就是说数据库中关联子表的信息在hibernate容器启动的时候不会加载,而是在你真正的访问到字表非标识字段的时候,才会去加载。
反之,如果lazy=false的话,就是说,子表的信息会同主表信息同时加载。
一般用只有完全用到子表信息的时候,才会lazy=false

join 查询的时候,是用以条语句查处所有记录,包括关联表记录,select查出的是N+1条记录,两个都是差不多的,但是如果用了lazy=true,延迟加载的话,select在查询时只会查出主表记录,也就是1,如果其他地方也用到了数据,此时就会自动在执行查询,查出N,可以降低内存消耗 .还有,hibernate是的session是轻量级的,创建和销毁都不花很多资源,查询数据也很快,这里fetch主要起这个作用    

Path expected for join! unexpected end of subtree

posted @ 2012-09-04 10:55 timelyxyz 阅读(139) | 评论 (0)编辑 收藏

使用条件如下:

a left join  b

a must be b's parent

posted @ 2012-07-24 11:37 timelyxyz 阅读(380) | 评论 (0)编辑 收藏

突然抛了一个concurrentModificationException错误,Iterator的一个基本概念没有掌握导致的这个错误,就是在Iterator的实现类。比如Hashtable里面的内部类
 private class Enumerator<T> implements Enumeration<T>, Iterator<T>

会在next,或者remove的时候检查当前集合是否会在修改状态,如果是的话,就会抛出 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的同时,修改了这个集合,导致了这个错误的出现

 

在Map或者Collection的时候,不要用它们的API直接修改集合的内容,如果要修改可以用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 阅读(106) | 评论 (0)编辑 收藏

API语法:

File(String pathname)
通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。
public static final String separator
与系统有关的默认名称分隔符,为了方便,它被表示为一个字符串。此字符串只包含一个字符,即 separatorChar
public static final char separatorChar
与系统有关的默认名称分隔符。此字段被初始化为包含系统属性 file.separator 值的第一个字符。在 UNIX 系统上,此字段的值为 '/';在 Microsoft Windows 系统上,它为 '\\'

注意:

路径名字符串与抽象路径名之间的转换与系统有关。将抽象路径名转换为路径名字符串时,每个名称与下一个名称之间用一个默认分隔符 隔开。默认名称分隔符由系统属性 file.separator 定义,可通过此类的公共静态字段 separatorseparatorChar 使其可用。将路径名字符串转换为抽象路径名时,可以使用默认名称分隔符或者底层系统支持的任何其他名称分隔符来分隔其中的名称。

 

例如,我希望的文件绝对路径是E:\dev\workspace\iclass_web/conf/filterconfig.xml(计作myPath),有两种创建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"

 我的系统是windows32位,io.File的一个字段FileSystem是一个抽象类,FileSystem被一个Win32FileSystem类继承,从而实现里面的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 阅读(148) | 评论 (0)编辑 收藏

Hibernate中使用COUNT DISTINCT关键字: Hibernate

在Hibernate中, 计算某列非重复记录的总数, 使用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 阅读(109) | 评论 (0)编辑 收藏