Sparkle’s Workshop

Archive for April, 2005

annotation for acegi

Posted on April 19, 2005 - Filed Under Java

UPDATE: The new version of acegi has itself’s annotation implement. So you don’t need this any more.
annotation is so good that i can’t wait to use it in acegi
code sample

import java.util.List;
import org.gotblog.common.acegi.SecurityConfig;
import org.springframework.transaction.annotation.Transactional;
public interface BookManager {
@Transactional
@SecurityConfig( { "ROLE_USER", "ROLE_ANONYMOUS" [...]

Read More..>>

acegi基本使用一

Posted on April 19, 2005 - Filed Under Uncategorized

acegi真的超级难用,花了大量时间才调试出来
我使用的版本是acegi-security-0.8.1
目标是使用acegi通过spring aop直接对service bean的每一个method做权限
在web.xml加入

Acegi Filter Chain Proxy
net.sf.acegisecurity.util.FilterToBeanProxy

targetClass

net.sf.acegisecurity.util.FilterChainProxy

Acegi Filter Chain Proxy
/*

FilterToBeanProxy是从servletfilter跳至spring bean的媒介
实际上,targetClass所接受的必须是spring bean定义了的类的类名
而且,这个类也是实现servletfilter接口的(以下称这个类为acegi filter)
FilterToBeanProxy是整个acegi的总入口,把servletfilter跟spring bean穿起来了
实现得非常好,建议参看源代码,代码也非常精练
targetClass只接受一个acegi filter,入口参数是类名
这个类名必须至少在spring定义一个bean
acegi里面有若干不同特性的预定acegi filter供选择使用
往往我们不仅仅需要一个acegi filter,所以这里我们借助FilterChainProxy
FilterChainProxy主要是通过正则表达式将特定的URI提交给若干acegi filter做处理
这样,acegi在web.xml的配置算完了
当然,acegi还有提供若干其他servletfilter
不过这次用不上

Read More..>>

hibernate

Posted on April 18, 2005 - Filed Under Uncategorized

session以request为边界,用spring opensessioninview filter+HibernateTemplate实现(其实就是ThreadLocal+ServletFilter)
transaction以service(不是DAO)为边界(如果一个service method里面需要有两段事务的话,就分成两个service method),用spring aop声明事务实现
另DAO可看实际情况考虑省去,代码迁移到service
你们肯定很少翻hibernate.org
http://www.hibernate.org/168.html
这里提到session和transaction的若干处理方法,介绍他们的优缺点,哪些不能用等等
我个人比较喜欢session-per-request-with-multiple-transactions
就是我上面所说的
另外还有两个application transaction做long Session的,大致就是之前断断续续讨论的detached objects、saveOrUpdate、hibernate version、httpsession保存po等等等等,用spring mvc可以实现,不过似乎这种做法目前接受度不高
http://up-u.com/?p=26
http://forum.javaeye.com/viewtopic.php?p=71858#71858

Read More..>>

Closures with CollectionUtils

Posted on April 14, 2005 - Filed Under Uncategorized

http://raibledesigns.com/page/rd?anchor=closures_with_collectionutils

List list = new ArrayList();

CollectionUtils.forAllDo(list, new Closure() {
public void execute(Object obj) {
// execute something for each item obj
}
});

看了这个代码片断,大家应该能写出forAllDo()和Closure的代码
不过这里跟groovy closure还有点差别,比groovy closure多了一层{}
其实groovy closure说白了就是函数指针,在c/c++里也有的东西
当然groovy把语法弄得更简单
java里是用只有一个method的interface的匿名子类来模拟函数指针
最明显的例子是thread里经常使用的Runnable接口
这么做没看出比函数指针好多少,只是java里没有“指针”,没有办法不这么处理
其实groovy没有办法脱离java没有“指针”这个问题
所以groovy closure也是用一个method的interface匿名子类来处理的
所以难免会表现出block的特性
就是之前大牛门讨论的return/break/continue在groovy closure里的事情

Read More..>>

spring transaction annotation

Posted on April 9, 2005 - Filed Under Uncategorized

public interface UserManager {
@Transactional
public void logUser(User user, Date logintime, String loginip);
}

关键点:
1、TransactionProxyFactoryBean的transactionAttributeSource注入AnnotationTransactionAttributeSource
2、删去transactionAttributes
3、可以与transactionAttributes共存
4、在interface加入annotation
5、可考虑使用autoproxying简化bean定义
6、参考AttributesTransactionAttributeSource

Read More..>>

Hibernate Annotations 3.0 Preview beta 1 for Hibernate 3.0 final released

Posted on April 9, 2005 - Filed Under Uncategorized

org.hibernate.cfg.AnnotationConfiguration

classpath:hibernate.cfg.xml

@Entity
@Table(name = “xyz_user”)
public class User {
@Id
public long getId() {
return id;
}
public String getName() {
return name;
}
@ManyToOne
@JoinColumn(name = “regionalCenter_fk”)
public RegionalCenter getRegionalCenter() {
return regionalCenter;
}
}
关键点:
1. 设置configurationClass为AnnotationConfiguration
2. 使用hibernate.cfg.xml做配置
3. 使用mapping [...]

Read More..>>

别偏信ria

Posted on April 4, 2005 - Filed Under Uncategorized

别偏信ria
ria没有5年成不了气候
你想做开拓者么
最后还不是落得替别人开路的下场
我还嫌目前的技术不够成熟
新技术?no way
下一代的web
再等10年吧
这10年不用吃饭吗

Read More..>>

Jetty Launcher patch for eclipse 3.1M6

Posted on April 4, 2005 - Filed Under Uncategorized

提示出错
Plug-in com.iw.plugins.jettylauncher was unable to load class
com.iw.plugins.jetty.launcher.JettyLaunchConfigurationDelegate.
从cvs下载jetty launcher的代码
导入到eclipse 3.1M6,若干编译错误
遂导入到eclipse 3.1M5a,没有编译错误
看来是3.1M6的API有所变化
对比发现三个问题

1、JavaLocalApplicationLaunchConfigurationDelegate的继承树改了,这个还不是关键,关键是还改名了
这是原来的继承树

AbstractJavaLaunchConfigurationDelegate
|–JavaAppletLaunchConfigurationDelegate
|–JavaLocalApplicationLaunchConfigurationDelegate
| \–JettyLaunchConfigurationDelegate
|–JavaRemoteApplicationLaunchConfigurationDelegate
\–SerialVersionLaunchConfigurationDelegate

这是新的继承树

AbstractJavaLaunchConfigurationDelegate
|–JavaLaunchDelegate
| \–JavaAppletLaunchConfigurationDelegate
|–JavaRemoteApplicationLaunchConfigurationDelegate
\–SerialVersionLaunchConfigurationDelegate

因此将

public final class JettyLaunchConfigurationDelegate extends JavaLocalApplicationLaunchConfigurationDelegate

改成

public final class JettyLaunchConfigurationDelegate extends JavaLaunchDelegate

2、方法

public static void relaunch(ILaunch launch) {
relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
}

没了
因此将

RelaunchActionDelegate.relaunch(launch);

改成

RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());

3、WorkbenchMessages.getString()取消了
改成static String的形式,似乎是认为这样性能比较高
因此将若干WorkbenchMessages.getString()改成static String
例如

WorkbenchMessages.getString(”SelectionDialog.selectLabel”)

改成

WorkbenchMessages.SelectionDialog_selectLabel

WorkbenchMessages.getString(”ContainerSelectionDialog.title”)

改成

“ContainerSelectionDialog.title”

因为并没有这个properties,getString()会返回原值
随便把for jetty 5.1.x的patch加上,然后用JDK 1.4模式编译一次
覆盖修改文件进jettylauncher.jar
成功

Read More..>>

各个版本的eclipse对jre版本的要求

Posted on April 3, 2005 - Filed Under Uncategorized

eclipse 2.1.3
You will need a 1.3 or 1.4 level Java runtime or Java development kit (JDK) installed on your machine in order to run Eclipse.
eclipse 3.0.2
You will need a 1.4.1 level or higher Java runtime or Java development kit (JDK) installed on your machine in order to run Eclipse.
eclipse 3.1M6
You will need a [...]

Read More..>>

WebWork 2.2 Release Notes

Posted on April 3, 2005 - Filed Under Uncategorized

http://wiki.opensymphony.com/display/WW/WebWork+2.2
webwork 2.2 release??
还是Mar 25, 2005??
跳上一层才发现是
WebWork 2.2 - Upcoming
原来是用wiki先写release notes
Ajax support 现在什么都扯上ajax了
IDE plugins for Eclipse 应该就是说eclipsework吧,eclipsework做得不错
Role/security? 希望能提供跟acegi整合
IoC container changes? Spring? 从来不用webwork的ioc
Spring WebFlow integration? 最近好像热门起来了
JSR-168 Integration? 门户,呵呵
众多特性还没决定,汗
看来webwork会从appfuse吸取很多东西,不错
webwork官方论坛有人说四月底会有rc
http://forums.opensymphony.com/thread.jspa?threadID=1087&tstart=30
不过看了webwork jira,进度不乐观

Read More..>> keep looking »