Chapter 10: JPA Integration"
From Documentation
Line 1: | Line 1: | ||
− | = Overview = | + | = Overview = |
+ | ''Java Persistence API'' (JPA) is a POJO-based persistence specification. It offers ''object-relational mapping'' solution to enterprise Java applications. In this chapter, we don't create new applications, but re-write data persistence part of previous examples with JPA. | ||
+ | |||
+ | In previous chapters, we mimic a database with a static list as follows: | ||
+ | |||
+ | <source lang='java' high='4, 12'> | ||
+ | public class UserInfoServiceImpl implements UserInfoService,Serializable{ | ||
+ | |||
+ | |||
+ | static protected List<User> userList = new ArrayList<User>(); | ||
+ | static{ | ||
+ | userList.add(new User("anonymous","1234","Anonymous","[email protected]")); | ||
+ | userList.add(new User("admin","1234","Admin","[email protected]")); | ||
+ | userList.add(new User("zkoss","1234","ZKOSS","[email protected]")); | ||
+ | } | ||
+ | |||
+ | /** synchronized is just because we use static userList in this demo to prevent concurrent access **/ | ||
+ | public synchronized User findUser(String account){ | ||
+ | int s = userList.size(); | ||
+ | for(int i=0;i<s;i++){ | ||
+ | User u = userList.get(i); | ||
+ | if(account.equals(u.getAccount())){ | ||
+ | return User.clone(u); | ||
+ | } | ||
+ | } | ||
+ | return null; | ||
+ | } | ||
+ | |||
+ | ... | ||
+ | } | ||
+ | </source> | ||
= Configuration= | = Configuration= |
Revision as of 04:34, 5 February 2013
Overview
Java Persistence API (JPA) is a POJO-based persistence specification. It offers object-relational mapping solution to enterprise Java applications. In this chapter, we don't create new applications, but re-write data persistence part of previous examples with JPA.
In previous chapters, we mimic a database with a static list as follows:
public class UserInfoServiceImpl implements UserInfoService,Serializable{
static protected List<User> userList = new ArrayList<User>();
static{
userList.add(new User("anonymous","1234","Anonymous","[email protected]"));
userList.add(new User("admin","1234","Admin","[email protected]"));
userList.add(new User("zkoss","1234","ZKOSS","[email protected]"));
}
/** synchronized is just because we use static userList in this demo to prevent concurrent access **/
public synchronized User findUser(String account){
int s = userList.size();
for(int i=0;i<s;i++){
User u = userList.get(i);
if(account.equals(u.getAccount())){
return User.clone(u);
}
}
return null;
}
...
}