Monday, 11 August 2008

Usage of NetBean 6.x Editor

Hot keys:
  1. Ctrl + space : Code completion.
  2. Alt + Insert : Generate "getter and setter; constructor; delegate; add property; etc"
  3. Alt + Enter : ???
  4. Ctrl + R : factoring name.
  5. Shift + Esc : enlarge current window.

Tutorial on using NetBean IDE

Persist LOB using JPA in J2EE/J2SE

-----------------------------------------------------------------------------------------------
JPA (Sun persistence standard)==> Persistence Provider (Toplink) ==> JDBC (version 11.)

1) JPA provides a simple solution for persisting LOB in Database. Developer only need to annotate the Entity variable that is a LOB. Looks like that, at least from the document, that I have read.
2) However, persistence manager seems cannot persist a string bigger than 4000 byte. Why?
//------------------------------------------------------------------------------------------------
The reason is that the JDBC driver, I am using, ojdbc14.jar, which is only compatible for jdk1.4 not for jdk1.5. It doesn't support write BLOB into database just like writing in a String. So I download the latest version JDBC driver, ojdbc5.jar, and problem solved at once.
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
JDBC driver: ojdbc14.
  • Specification-Title: "Oracle JDBC driver classes for use with JDK1.4"
  • Specification-Version: "Oracle JDBC Driver version - 9.0.2.0.0"
JDBC driver 10.2 above, it can treat Clob as if they were strings, with code like:

ps = conn.createPreparedStatement( "update tab set lob =?");
ps.setString(1,"Bob")

The actual way this is done internally depends on the size of String set on the bind-parameter.

Better performance can be squeezed out of this for String between 4000 bytes and 32Kb, using a bit of PL/SQL:

ps = conn.prepareStatement("begin \n
update tab set lob= ? where id = ?;\n
End;")
Ps.setString(1, StringUpTo32K);



Log4j notes


log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n

Log4j提供的appender有以下几种:
  1. org.apache.log4j.ConsoleAppender(控制台)
  2. org.apache.log4j.FileAppender(文件)
  3. org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)
  4. org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生新文件)
  5. org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
Log4j提供的layout有以下几种:
  1. org.apache.log4j.HTMLLayout(以HTML表格形式布局),
  2. org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
  3. org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
  4. org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)
Log4j 自定义格式
  1. %p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
  2. %r 输出自应用启动到输出该log信息耗费的毫秒数
  3. %c 输出所属的类目,通常就是所在类的全名
  4. %t 输出产生该日志事件的线程名
  5. %n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
  6. %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy MMM dd HH:mm:ss,SSS},输出类似: 2002年10月18日 22:10:28,921
  7. %l 输出日志事件的发生位置,包括类目名、发生的线程,以及在代码中的行数。举例:Testlog4.main(TestLog4.java:10)

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...