2006年2月28日
#
Postfix 的好书,研读中
Announcing the Release Candidate for Ubuntu 6.06 LTS
https://lists.ubuntu.com/archives/ubuntu-announce/2006-May/000081.html2006-05-25, Matt Zimmerman writes:
The Ubuntu team is proud to announce the Releases Candidate of Ubuntu, Kubuntu and Edubuntu 6.06 LTS - codenamed "Dapper Drake". The Release Candidate includes installable live Desktop CDs, server images, alternate text-mode installation CDs and an upgrade wizard for users of the current stable release.
We consider this release candidate complete, stable and suitable for testing by any user. We would especially recommend that current Ubuntu 5.10 ("Breezy Badger") users and developers use the upgrade procedure described in the announcement. Ubuntu, Kubuntu and Edubuntu 6.06 LTS will be the first Ubuntu releases with long-term support: three years on the desktop, and five years on the server.
The purpose of the Release Candidate is to solicit one last round of testing before the final release. Please read the full announcement for download locations and upgrade information. Read more about the features available in this release here.
Dapper Release Schedule
https://wiki.ubuntu.com/DapperReleaseSchedule
期待中...
http://delynnberry.com/pages/rails-chm-documentation/
http://pragmatically.net/articles/2006/05/11/ruby-on-rails-gaining-on-j2ee
Ruby on Rails is rapidly gaining in popularity,
at least if you believe in lies, damn lies, statistics and Google's new service, Google Trends.
In the following image Ruby on Rails is the red line and J2EE the blue.
* Ruby on Rails * J2EE
It even seems like J2EE has been loosing in popularity, and I'm not surprised at all.
J2EE makes developers as happy as communism made... well communists. J2EE is central planning at it's best.
Programming Language Examples Alike Cookbook :http://pleac.sourceforge.net/
在google的搜索栏输入:
Agile Web Development with Rails
filetype:pdf
今天无意中在道喜技术日记上看到的,试验了一样,真的不错,不用浪费时间:)
这东西搜索了半天才搞到,我安装的是3.2的,下面的序列号一样可以使用,共享一下,省得大家再去找了 
install4j Enterprise Edition 3.1.3注册码、序列号、破解版、注册机
S/N: A-G42M#03948F-pzwgavu2ohmw#316
A-G42M#03948F-pzwgavu2ohmw#508
install4j Proffesional Edition 3.1.2注册码、序列号、破解版、注册机
S/N: A-G4iN#89756F-9qotdnr5rq9a#0015
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/fireevent.asp
Fires a specified event on the object.
Syntax
bFired
=
object.fireEvent(sEvent [,oEventObject])
Parameters
| sEvent | Required. String that specifies the name of the event to fire. |
| oEventObject | Optional. Object that specifies the event object from which to obtain event object properties. |
Return Value
Boolean. Returns one of the following values:
| true | Event fired successfully. |
| false | Event was cancelled. |
Remarks
If the event being fired cannot be cancelled, fireEvent always returns true.
Regardless of their values specified in the event object, the values of the four event properties—cancelBubble, returnValue, srcElement, and type—are automatically initialized to the values shown in the following table.
| Event object property | Value |
|---|
| cancelBubble | false |
| returnValue | true |
| srcElement | element on which the event is fired |
| type | name of the event that is fired |
Example
<html>
<head>
<script>
function fnfireevents()
{
odiv.innertext = " the cursor has moved over me! ";
obutton.fireevent(" onclick ");
}
</script>
</head>
<body>
<h1> using the fireevent method </h1>
by moving the cursor over the div below, the button is clicked.
<p>
<div id="odiv" onmouseover="fnfireevents();">
mouse over this!
</div>
<p>
<button id="obutton" onclick="this.innertext='i have been clicked!'">
button </button>
</body>
</html>
RoomType和RoomState的主键是Integer,在get的时候忘记转换为Integer了:
this
.getHibernateTemplate().execute(
new
HibernateCallback() {
public
Object doInHibernate(Session session)
throws
HibernateException {
room.setType((RoomType) session.get(RoomType.
class
, typeId));
room.setState((RoomState) session.get(RoomState.
class
, stateId));
session.update(room);
return
null
;
}
});
没想到hibernate居然大动干做,抛出一大堆的exception
java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 1
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1681)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3280)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
at com.phopesoft.hms.room.service.impl.RoomServiceImpl$3.doInHibernate(RoomServiceImpl.java:151)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:334)
这样的错误真是让我一点莫不着头脑,还好从后台打出的hql看到了错误的信息
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
could not execute query; uncategorized SQLException for SQL [
...
SQL state [null]; error code [17041]; 索引中丢失 IN 或 OUT 参数::1;
nested exception is java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 1
不就是没找到吗,干嘛要这样呢


将String类型转换为Integer就没事了
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
room.setType((RoomType) session.get(RoomType.class, new Integer(typeId)));
room.setState((RoomState) session.get(RoomState.class, new Integer(stateId)));
session.update(room);
return null;
}
});
在resin和weblogic上跑的很好的程序,今天早上移植到JBoss上 ,页面跑到<ww:if处没法正常运行,报错,换成<c:if 就没有问题了.
一大早的被郁闷了一下
感谢javaeye差沙和cac的回复.
OpenSessionInView默认的FlushMode为
FlushMode.NEVER
可以采用在写保存更新删除代码的时候手动更改FlushMode
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
session.setFlushMode(FlushMode.AUTO);
session.save(user);
session.flush();
return null;
}
});
但是这样做太繁琐了,第二种方式是采用spring的事务声明
<bean id="baseTransaction" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyTargetClass" value="true"/>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userService" parent="baseTransaction">
<property name="target">
<bean class="com.phopesoft.security.service.impl.UserServiceImpl"/>
</property>
</bean>
因为lazy的问题,还是采用了OpenSessionInView
一开始我的web.xml配置文件如下:
<filter>
<filter-name>opensession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
写了个保存的代码测试了一下,报如下的错误:
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations
are not allowed in read-only mode (FlushMode.NEVER) - turn your Session
into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1076)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:616)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:614)
at com.phopesoft.security.service.impl.UserServiceImpl.addUser(UserServiceImpl.java:40)
at com.phopesoft.security.web.UserAction.add(UserAction.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:365)




.
在javaeye中搜索了一下,发现了Readonly的帖子,将web.xml修改为如下:
<filter>
<filter-name>opensession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
</filter>
保存的代码顺利通过测试,但是删除的代码却不能通过了.出现如下的错误:
org.hibernate.HibernateException: Illegal attempt to associate a collection
with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:790)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:768)
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:772)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:766)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:762)
同样在论坛里面搜索到遇到这个问题的朋友,回帖说去掉singleSession!
迷惑了
正好这段时间有空,开始研读rails。本身我没有ruby基础,也一直没有太大的兴趣,这本书正好是对没有ruby基础人写的rails教程。
Thanks manning:)
|
Mergere, Inc. is excited to announce the release of Better Builds with
Maven, the ultimate resource to help you unleash the power of the Apache
Software Foundation's Maven project. Better Builds with Maven is
written by Vincent Massol, Jason van Zyl and other key contributors of the Maven
community and combines detailed explanations and code examples to walk you
through improving your software development process with Maven
2.0.
|
Better Builds with Maven covers:
- An introduction to Maven 2.0
- Advanced tools for "power" users
- Creating J2EE builds and using J2EE models
- Extending builds through plugins
- Monitoring source code, testing, dependencies and releases
- Leveraging repositories, continuous integration and transitive dependency
- Converting existing Ant builds
Whether you are a current Maven user or are interested in changing software
development tools, Better Builds with Maven will help you leverage the
technologies and best practices found in Apache Maven.
下载:http://www.mergere.com/m2book_download.jsp
今天在python-chinese邮件列表中看到一则好消息,下面的来自maillist
Liang Osmond :已经和原作者联系好了,Dive into Python 的官方中文版地址为
http://www.woodpecker.org.cn/diveintopython/现在如果您访问
http://diveintopython.org/ 的
已经是新的地址了。或者
http://cn.diveintopython.org/ 直接访问
另外,Dive into Python 的官方中文版将纳入 Ubuntu 6.06 (Dapper),Ubuntu社区的 zhengpeng.hou (zhengpeng.hou AT gmail DOT com)正在制作并测试 deb 包,特表示感谢。
个人比较偏好IDEA,虽然eclipse有freemarker的plugin,但是还是舍不得为了一个plugin而选用Eclipse,google了一下发现有人把自己的Live template共享了,呵呵,正好拿来用用
http://weblog.flop.ca/2005/03/27/1111947748000.html
好久没有去书店了,一直没空,喜欢看去逛书店,已经养成这个习惯了,每个月都回去看看。
无意中看到一本:《领域驱动设计:软件核心复杂性应对之道》觉得挺不错的,买下来研读中o_o

http://www.douban.com/subject/1629512/
新开发的产品需要考虑多语言的问题,i18n一直只是看过,并没有正在的用到项目中,觉得应该是个很容易的事情,谁知今天却折腾了我一把:(
首先修改webwork.properties:
webwork.locale=zh_CN
webwork.i18n.encoding=GBK
修改native2ascii的编码
<target name="i18n">
<native2ascii
encoding="GBK"
src="${src.java.dir}"
dest="${classes.dir}"
includes="**/*_zh_CN.properties"/>
<copy
todir="${classes.dir}">
<fileset dir="${src.java.dir}">
<exclude name="**/*.java"/>
<exclude name="**/*_zh_CN.properties"/>
</fileset>
</copy>
</target>
修改页面:
<%@ page contentType="text/html; charset=GBK" %>
搞定了!这个问题居然折腾我好大一会儿,一开始我以为用utf-8就行了,谁知道就是不灵:(
webwork i18n:http://www.opensymphony.com/webwork/wikidocs/Internationalization.html
SVN Service Wrapper for Windows
This is my Win32 Service wrapper for SVN. Source is included, and its in the public domain. No need to copyright this stuff.
Usage instructions:
SVNService -? to display this list
SVNService -install <svnserve parameters> to install the service
SVNService -setup <svnserve parameters> to change command line parameters for svnserve
SVNService -remove to remove the service
SVNService -debug to run as a console app for debugging
Example:
SVNService -install -d -r c:\svnrepo
SVNService -setup -d -r c:\otherplace\svnrepo
IMPORTANT:
Make sure you place SVNService.exe in the same directory as svnserve.exe
Special thanks go to Craig Link at Microsoft for creating the initial service.c.
-Magnus Norddahl
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="spring" javascript="UserDAO">
<param name="beanName" value="userDao"/>
<include method="addUser"/>
<include method="removeUser"/>
<include method="findUserByName"/>
</create>
<convert converter="bean" match="martin.dwr.demo.model.User">
<param name="include" value="id,name,password,age"/>
</convert>
</allow>
</dwr>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>config-admin</param-name>
<param-value>WEB-INF/classes/dwr.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml
<bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
浏览:
http://localhost:8080/demo/dwr/index.html 查看调试信息
AnnotationSessionFactoryBean 继承LocalSessionFactoryBean
今天用到,查了一下refrence,顺便把它贴出来:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>${db.driverClass}</value>
</property>
<property name="jdbcUrl">
<value>${db.url}</value>
</property>
<property name="properties">
<props>
<prop key="c3p0.acquire_increment">5</prop>
<prop key="c3p0.idle_test_period">100</prop>
<prop key="c3p0.max_size">100</prop>
<prop key="c3p0.max_statements">0</prop>
<prop key="c3p0.min_size">10</prop>
<prop key="user">${db.user}</prop>
<prop key="password">${db.pass}</prop>
</props>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
<property name="dataSource" ref="c3p0DataSource"/>
<property name="annotatedClasses" value="martin.dwr.demo.model.User"/>
</bean>
<bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
Smack is a library for communicating with XMPP servers to perform instant messaging and chat.
package cn.martin.xmpp;
import org.jivesoftware.smack.GroupChat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.packet.Message;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.AfterClass;
/**
* @author martin
*/
public class SmackTest {
private static XMPPConnection con;
@BeforeClass
public static void getConnection() throws XMPPException {
con = new XMPPConnection("rabbit");
con.login("martinx", "1234");
}
@Test
public void chatWithSingle() throws XMPPException {
con.createChat("martin@rabbit").sendMessage("Simple Message");
}
@Test
public void chatWithGroup() throws XMPPException {
String room = "dd@conference.rabbit";
GroupChat groupChat = con.createGroupChat(room);
groupChat.join("martinx");
Message message = groupChat.createMessage();
message.setBody("Group Chat Test");
groupChat.sendMessage(message);
}
@Test
public void chatWithReturnedMessage() throws XMPPException {
Chat chat = con.createChat("martin@rabbit");
Message message = chat.createMessage();
message.setBody("Hello Martin");
message.setProperty("favoriteColor", "red");
chat.sendMessage(message);
//获取回复
while (true) {
Message _message = chat.nextMessage();
chat.sendMessage(_message.getBody());
}
}
@AfterClass
public static void closeConnection() {
con.close();
}
}
看了
http://forum.javaeye.com/viewtopic.php?t=19089很是感兴趣,想做一个,明天继续

http://www.instrumentalservices.com/index.php?option=com_content&task=view&id=45&Itemid=52
Gunjan Doshi
Instrumental Services Inc.
Abstract: JUnit needs no introduction. Originally written by Kent Beck and Erich Gamma, the software is the preferred tool of choice for developer testing. Now, the team of Kent Beck and Erich Gamma is back again with a new version of JUnit – 4.0. This quick reference guide is for programmers and testers looking to migrate to JUnit 4.0. If you have a flight to catch or do not want to spend 10 minutes going through the guide, just jump to the summary section and you will learn enough.
For the purpose of this article, I will call JUnit 3.8.1 and its predecessors as the old JUnit and JUnit 4.0 as the new JUnit.
Table of contents:
This guide contains the following sections:
· Old JUnit revisited
· Cut the chase to JUnit 4.0
· Run the tests
· Set up and tear down
· One-time set up and tear down
· Expecting exceptions
· Other Annotations
o Ignoring a test
o Timing out a test
· Summary
Old JUnit revisited
Using the old JUnit, let us write a test, which verifies the availability of a book in the library.
To summarize the steps:
· We extend from junit.framework.TestCase.
· We name the test methods with a prefix of ‘test’.
· We validate conditions using one of the several assert methods.
Cut the chase to JUnit 4.0
Let us write the same test using JUnit 4.0.
When I upgrade to a new version I look for tasks, I do not have to do anymore. Here is the same code with notes telling us what not to do anymore.
To summarize:
· We do not extend from junit.framework.TestCase.
· We do not prefix the test method with ‘test’.
Next, I look for new tasks I must always do. The diagram below summarizes what we must do according to the new JUnit standards:
To summarize:
· Use a normal class and not extend from junit.framework.TestCase.
· Use the Test annotation to mark a method as a test method. To use the Test annotation, we need to import org.junit.Test
· Use one of the assert methods. There is no difference between the old assert methods and the new assert methods. An easy way to use the assert method is to do a static import as shown by point 2 in the code above.
· Run the test using JUnit4TestAdapter. If you want to learn more about JUnit4TestAdapter, keep reading ahead.
Run the tests
Unfortunately, our favorite development environments are still unaware of JUnit 4. JUnit4Adapter enables compatibility with the old runners so that the new JUnit 4 tests can be run with the old runners. The suite method in the diagram above illustrates the use of JUnit4Adapter.
Alternatively, you can use the JUnitCore class in the org.junit.runner package. JUnit 4 runner can also run tests written using the old JUnit. To run the tests using the JUnitCore class via the command line, type:
java org.junit.runner.JUnitCore LibraryTest
Set up and tear down
The new JUnit provides two new annotations for set up and tear down:
· @Before: Method annotated with @Before executes before every test.
· @After: Method annotated with @After executes after every test.
Here is the code that demonstrates the use of @Before and @After:
Two features of @Before and @After annotations that are helpful to learn:
· You can have any number of @Before and @After as you need.
· It is possible to inherit the @Before and @After methods. New JUnit executes @Before methods in superclass before the inherited @Before methods. @After methods in subclasses are executed before the inherited @After methods.
One-time set up and tear down
The new JUnit4 provides @BeforeClass and @AfterClass annotations for one-time set up and tear down. This is similar to the TestSetup class in the old junit.extensions package, which ran setup code once before all the tests and cleanup code once after all the tests.
Here is the code that demonstrates @BeforeClass and @AfterClass:
Unlike @Before and @After annotations, only one set of @BeforeClass and @AfterClass annotations are allowed.
Expecting exceptions
The new JUnit makes checking for exceptions very easy. The @Test annotation takes a parameter, which declares the type of Exception that should be thrown. The code below demonstrates this:
In the code above, bookNotAvailableInLibrary is a test, which passes only if BookNotAvailableException is thrown. The test fails if no exception is thrown. Test also fails if a different exception is thrown.
Other Annotations
Ignoring a test
The @Ignore annotation tells the runner to ignore the test and report that it was not run. You can pass in a string as a parameter to @Ignore annotation that explains why the test was ignored. E.g. The new JUnit will not run a test method annotated with @Ignore(“Database is down”) but will only report it. The version of JUnit4Adapter, I used, did not work with @Ignore annotation. Kent Beck has informed me that the next version of JUnitAdapter will fix this problem.
Timing out a test
You can pass in a timeout parameter to the test annotation to specify the timeout period in milliseconds. If the test takes more, it fails. E.g. A method annotated with @Test (timeout=10) fails if it takes more than 10 milliseconds.
Finally, I would like to thank Kent Beck for taking the time to demonstrate and teach the new JUnit to me.
Summary
To summarize the new JUnit style:
- It Requires JDK 5 to run.
- Test classes do not have to extend from junit.framework.TestCase.
- Test methods do not have to be prefixed with ‘test’.
- There is no difference between the old assert methods and the new assert methods.
- Use @Test annotations to mark a method as a test case.
- @Before and @After annotations take care of set up and tear down.
- @BeforeClass and @AfterClass annotations take care of one time set up and one time tear down.
- @Test annotations can take a parameter for timeout. Test fails if the test takes more time to execute.
- @Test annotations can take a parameter that declares the type of exception to be thrown.
- JUnit4Adapter enables running the new JUnit4 tests using the old JUnit runners.
- Old JUnit tests can be run in the new JUnit4 runner.
|
摘要: 今天有时间大体看了一下Hibernate Annotations,决定放弃xdoclet生成hbm的想法,开始学习annotation.首先大体的来看一下:一:Class Level:1:通过@Entity声明当前pojo为实体Bean2:通过@Table定义对应数据库表的属性 name:表名,默认实体类名 uniqueConstraints:定义表...
阅读全文
无非就是两种方法
1:Servlet
2: Listener
Servlet:
package 
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServlet;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
/**
* @author martin
*/
public class LuceneTimerServlet extends HttpServlet {
private static Logger logger = Logger.getLogger(LuceneTimerServlet.class);
private static Timer timer;
static {
timer = new Timer(true);
timer.schedule(new TimerTask() {
public void run() {
System.out.println("开始创建索引@" + getTime(Calendar.getInstance()));
TaxDocIndexer indexer = new TaxDocIndexer();
indexer.setFirstRun(Boolean.TRUE);
indexer.fetch();
System.out.println("索引创建成功@" + getTime(Calendar.getInstance()));
}
},
getFirstTime(),
getPeriod()
);
}
public void destroy() {
logger.debug("LuceneTimerServlet.destroy() begin");
timer.cancel();
}
/**
* 从服务启动起算,第二天零时开始执行
*
* @return Timer第一次执行时间
*/
private static Date getFirstTime() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
logger.debug("开始执行时间:" + getTime(calendar));
return calendar.getTime();
}
/**
* @param calendar
* @return formated time string
*/
private static String getTime(Calendar calendar) {
return new StringBuffer()
.append(calendar.get(Calendar.YEAR)).append("年")
.append(calendar.get(Calendar.MONTH) + 1).append("月")
.append(calendar.get(Calendar.DAY_OF_MONTH)).append("日 ")
.append(calendar.get(Calendar.HOUR_OF_DAY)).append("时")
.append(calendar.get(Calendar.MINUTE)).append("分")
.append(calendar.get(Calendar.SECOND)).append("秒")
.toString();
}
/**
* 计算一天的时间间隔
* 一天24小时×每小时60分×每分60秒×1000
*
* @return 一天时间
*/
private static long getPeriod() {
return 86400000;
}
} 配置web.xml
<servlet>
<servlet-name>luceneTimerServlet</servlet-name>
<servlet-class>sompackage.servlet.LuceneTimerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
如果采用Listener,则是:
<listener>
<listener-class>sompackage.servlet.LuceneTimerServlet</listener-class>
</listener>
以前总在珠江路上看到名人专卖店,以为名人还不错,谁知道买了个电子词典,到家就花屏!
NND,骗子!以后肯定不会看名人的产品!
走了,正在准备办理离职手续,心里总觉的有点点失落,也许我还真的对这个公司有点期盼,也许对自己的选择不是太满意,也许我没有做到我自己想做的事太多,也许什么都不是只是我的心情不好,走了,终究决定走了...
该去寻找我自己的天空去了,我不可这样堕落的活下去了,自己对自己得有个交代。
我看中了一家小公司,是我朋友的,我可以按我想法的去给公司开发成品,我可以用我最喜欢的技术,我可以做我任何想做的事,我自由了!
祝自己好运!
From: Doug Cutting <
cutting@apache.org>
To:
java-user@lucene.apache.org------------------------
Release 1.9-final of Lucene is now available from:
http://www.apache.org/dyn/closer.cgi/lucene/java/This release has many improvements since release 1.4.3, including new
features, performance improvements, bug fixes, etc. For details, see:
http://svn.apache.org/viewcvs.cgi/*checkout*/lucene/java/tags/lucene_1_9_final/CHANGES.txt1.9 will be the last 1.x release. It is both back-compatible with 1.4.3
and forward-compatible with the upcoming 2.0 release. Many methods and
classes in 1.4.3 have been deprecated in 1.9 and will be removed in 2.0.
Applications must compile against 1.9 without deprecation warnings
before they are compatible with 2.0.
Doug
Encarta® Instant Answers says:
Hi again, martin.xus! How can I help you?
Did you know? With only a few exceptions, true cacti are found exclusively in the Western Hemisphere.
今早它突然冒出来这么一句

好玩:)
上一周一直在做全文检索,做个小结:
一:关于Lucene
这个没什么可说的了,有什么问题看Lucene in Action,要是还没能解答问题,请教mail-list
二:万恶的LOB
我的情况:JDK1.3.1,本地测试是oracle的驱动,测试机上是weblogic的驱动,必须在提交的时候手工改为
OutputStream out =(( weblogic.jdbc.common.OracleBlob)blob).getBinaryOutputStream();三:另存为word
在写文件前添加如下代码:

<%
@ page contentType="application/vnd.ms-word;charset=gbk" language="java" %>
<html>

<%
String docName =new String(request.getParameter("docName") .getBytes("GB2312"),"8859_1");
response.setHeader("Content-disposition", "attachment;filename=" + docName + ".doc");
%>四:XML解析
XStream
五:AJAX
prototype