MappingSqlQuery
is a reusable query in which concrete subclasses must implement the abstractmapRow(..)
method to convert each row of the supplied ResultSet
into an object of the type specified. The following example shows a custom query that maps the data from the t_actor
relation to an instance of the Actor
class.
public class ActorMappingQuery extends MappingSqlQuery<Actor> {
public ActorMappingQuery(DataSource ds) {
super(ds, "select id,first_name, last_name from t_actor where id = ?");
super.declareParameter(new SqlParameter("id", Types.INTEGER));
compile();
}
@Override protected Actor mapRow(ResultSet rs, int rowNumber) throws SQLException {
Actor actor = new Actor();
actor.setId(rs.getLong("id"));
actor.setFirstName(rs.getString("first_name"));
actor.setLastName(rs.getString("last_name"));
return actor;
}
}
The class extends MappingSqlQuery
parameterized with the Actor
type. The constructor for this customer query takes the DataSource
as the only parameter. In this constructor you call the constructor on the superclass with the DataSource
and the SQL that should be executed to retrieve the rows for this query. This SQL will be used to create aPreparedStatement
so it may contain place holders for any parameters to be passed in during execution.You must declare each parameter using the declareParameter
method passing in an SqlParameter
. The SqlParameter
takes a name and the JDBC type as defined in java.sql.Types
. After you define all parameters, you call thecompile()
method so the statement can be prepared and later executed. This class is thread-safe after it is compiled, so as long as these instances are created when the DAO is initialized they can be kept as instance variables and be reused.
private ActorMappingQuery actorMappingQuery;
@Autowired public void setDataSource(DataSource dataSource) {
this.actorMappingQuery = new ActorMappingQuery(dataSource);
}
public Customer getCustomer(Long id) {
return actorMappingQuery.findObject(id);
}
The method in this example retrieves the customer with the id that is passed in as the only parameter. Since we only want one object returned we simply call the convenience method findObject
with the id as parameter. If we had instead a query that returned a list of objects and took additional parameters then we would use one of the execute methods that takes an array of parameter values passed in as varargs.
public List<Actor> searchForActors(int age, String namePattern) {
List<Actor> actors = actorSearchMappingQuery.execute(age, namePattern);
return actors;
}
分享到:
相关推荐
包含acegi-security-1.0.7.jar,acegi-security-1.0.7-sources.jar,acegi-security-cas-1.0.7.jar,acegi-security-cas-1.0.7-sources.jar,acegi-security-catalina-1.0.7.jar,acegi-security-catalina-1.0.7-...
acegi,acegi,acegi
Acegi中文参考手册,提供JAVA统一接口登陆
spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+acegi+中文手册spring+...
权限控制技术的解释,acegi中文参考手册
Acegi安全系统,是一个用于Spring Framework的安全框架,能够和目前流行的Web... 在Acegi安全系统中,需要被认证的用户,系统或代理称为"Principal"。Acegi安全系统和其他的安全系统不同,它并没有角色和用户组的概念。
Acegi文档 spring acegi 详细文档
不错的ACEGI 教程
Acegi(version1.0.4)中文参考手册.doc
acegi 框架 介绍 spring 安全
acegi-security 1.0.2.jar
Acegi能做什么 Acegi的体系结构 Acegi核心组件 典型的web认证过程 Acegi的登陆认证 Acegi对安全对象的访问控制 Filter 组件 Acegi的不足之处
<bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"> <value>select username,password,enabled from users where username=?</value> </property> ...
Acegi (version1.0.4)中文参考手册.Acegi Security为基于J2EE的企业应用软件提供全面的安全解决方案。正如你在本手册中看到的那样,我们尝试为您提供有用的,高可配置的安全系统。
1、一个Acegi的例子,可以运行 2、一个很好的学Acegi的网址,0基础学习Acegi,强烈推荐 3、有什么问题可以发邮件heroshen@126.com讨论
关于Acegi的安全框架,里面有Acegi的实例,讲述得挺清楚的,
讲述acegi的使用方法,和对acegi的一些基本类讲解。
这是基于acegi框架实现的basic认证的具体demo,详细的教程可以参考博客地址:http://blog.csdn.net/llhhyy1989/article/details/19708655
acegi,spring的安全验证框架