Duran's technical life
踏踏实实学技术,认认真真做研究。

2006年7月14日

从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 阅读(9140) | 评论 (4)编辑 收藏

2006年7月13日

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

2005年9月9日

@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 阅读(694) | 评论 (1)编辑 收藏

2005年9月7日

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

2005年9月6日

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

2005年8月12日

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

2005年8月9日

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

2005年7月14日

抵达深圳

在中国改革开放的贞操牌坊,更加强烈感受了GCD领导下的中国特色的社会主义和谐社会。罗湖区1w的小套间,随处可见benz和BMW。晚上去吃海鲜,一盘盘的叫不上名来,味道倒是鲜美:-)

实习第一天

XX信息公司研发部实习员工登记,领工卡,认识组员,了解项目情况,做了一天需求分析,easy。在公司里写程序的感觉和学校不大一样,一边写一边就能听到boss在隔壁办公室训斥某人。小小的不满:液晶显示器不多,自然轮不到我。小小小的不满:QQ不能用就算了,msn好像都不能用。

posted @ 2005-07-14 18:07 Duran's technical life 阅读(603) | 评论 (0)编辑 收藏

2005年6月17日

性能比较: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 阅读(707) | 评论 (1)编辑 收藏
仅列出标题  下一页