* @param identifier
* @return
* @throws org.dbwiki.exception.WikiException
*/
public synchronized DatabaseWikiPage get(ResourceIdentifier identifier) throws org.dbwiki.exception.WikiException {
DatabaseWikiPage page = null;
PageIdentifier p = (PageIdentifier)identifier;
if (p.isRootIdentifier()) {
return null;
}
String name = p.toQueryString();
long timestamp = p.getTimestamp();
try {
Connection con = _connector.getConnection();
PreparedStatement pStmtSelectPage = null;
if(timestamp == -1) {
pStmtSelectPage = con.prepareStatement(
"SELECT " +
DatabaseConstants.RelPagesColID + ", " +
DatabaseConstants.RelPagesColContent + ", " +
DatabaseConstants.RelPagesColTimestamp + ", " +
DatabaseConstants.RelPagesColUser + " " +
"FROM " + _relName + DatabaseConstants.RelationPages + " " +
"WHERE " + DatabaseConstants.RelPagesColName + " = ? " +
"ORDER BY " + DatabaseConstants.RelPagesColTimestamp + " DESC");
} else {
pStmtSelectPage = con.prepareStatement(
"SELECT " +
DatabaseConstants.RelPagesColID + ", " +
DatabaseConstants.RelPagesColContent + ", " +
DatabaseConstants.RelPagesColTimestamp + ", " +
DatabaseConstants.RelPagesColUser + " " +
"FROM " + _relName + DatabaseConstants.RelationPages + " " +
"WHERE " + DatabaseConstants.RelPagesColName + " = ?" +
"AND " + DatabaseConstants.RelPagesColTimestamp + " = ?");
pStmtSelectPage.setLong(2, timestamp);
}
pStmtSelectPage.setString(1, name);
ResultSet rs = pStmtSelectPage.executeQuery();
if (rs.next()) {
page =
new DatabaseWikiPage(
rs.getInt(DatabaseConstants.RelPagesColID),
name,
rs.getString(DatabaseConstants.RelPagesColContent),
rs.getLong(DatabaseConstants.RelPagesColTimestamp),
_users.get(rs.getInt(DatabaseConstants.RelPagesColUser)));