Connection conn = JDBCDatabaseTransaction.getConnection();
PreparedStatement ps = null;
ResultSet result = null;
RatingDO ratingDO = new RatingDO();
try {
if (resourceImpl instanceof CollectionImpl) {
String sql = "SELECT R.REG_ID, R.REG_RATING, R.REG_RATED_TIME " +
"FROM REG_RATING R, REG_RESOURCE_RATING RR " +
"WHERE RR.REG_PATH_ID=? AND RR.REG_RESOURCE_NAME IS NULL AND " +
"RR.REG_RATING_ID=R.REG_ID AND R.REG_USER_ID=? AND " +
"R.REG_TENANT_ID=? AND RR.REG_TENANT_ID=?";
ps = conn.prepareStatement(sql);
ps.setInt(1, resourceImpl.getPathID());
ps.setString(2, userID);
ps.setInt(3, CurrentSession.getTenantId());
ps.setInt(4, CurrentSession.getTenantId());
} else {
String sql = "SELECT R.REG_ID, R.REG_RATING, R.REG_RATED_TIME " +
"FROM REG_RATING R, REG_RESOURCE_RATING RR " +
"WHERE RR.REG_PATH_ID=? AND RR.REG_RESOURCE_NAME = ? AND " +
"RR.REG_RATING_ID=R.REG_ID AND R.REG_USER_ID=? AND " +
"R.REG_TENANT_ID=? AND RR.REG_TENANT_ID=?";
ps = conn.prepareStatement(sql);
ps.setInt(1, resourceImpl.getPathID());
ps.setString(2, resourceImpl.getName());
ps.setString(3, userID);
ps.setInt(4, CurrentSession.getTenantId());
ps.setInt(5, CurrentSession.getTenantId());
}
result = ps.executeQuery();
if (result.next()) {
ratingDO.setRating(result.getInt(DatabaseConstants.RATING_FIELD));
ratingDO.setRatedTime(new java.util.Date(
result.getTimestamp(DatabaseConstants.RATED_TIME_FIELD).getTime()));
ratingDO.setRatedUserName(userID);
ratingDO.setRatingID(result.getInt(DatabaseConstants.ID_FIELD));
}
} catch (SQLException e) {
String msg = "Failed to get rating on resource " + resourceImpl.getPath() +
" done by user " + userID + ". " + e.getMessage();