从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还专门在首页开了一大块来炫耀。
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.
去年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上。
@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.
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之间可以做到完全解构。但在实际开发时没有必要死扣,代码结构清晰有活力就好。
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语句,看到了吗?
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.
在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__;