Kawai Wiki

Compare Revisions

Ignore whitespace Rev 79 → Rev 80

/trunk/src/main/java/org/kawai/dao/jdbc/JdbcPageDAO.java
2,6 → 2,7
 
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
344,10 → 345,47
@Override
public List<Revision> loadRevisions(String name, Language lang) {
Revision r = new Revision();
r.setName(name);
r.setLanguageId(lang.getId());
PreparedStatement stmt = null;
ResultSet rset = null;
return session.loadList(r, "revision desc");
try {
StringBuilder query = new StringBuilder(256);
query.append("select ").append(session.buildSelect(Revision.class, "r"));
query.append(", ").append(session.buildSelect(User.class, "u"));
query.append(" from Revisions r join Users u on r.user_id = u.id");
query.append(" where r.name = ? and r.language_id = ?");
query.append(" order by revision desc");
query.append(" limit 50");
stmt = conn.prepareStatement(query.toString());
stmt.setString(1, name);
stmt.setInt(2, lang.getId());
rset = stmt.executeQuery();
List<Revision> revisions = new ArrayList<Revision>(50);
while(rset.next()) {
Revision r = new Revision();
session.populateBean(rset, r, "r");
User u = new User();
session.populateBean(rset, u, "u");
r.setUser(u);
revisions.add(r);
}
return revisions;
} catch(Exception e) {
throw new RuntimeException(e);
} finally {
close(stmt, rset);
}
}
}