use of db.Select in project common by zenlunatics.
the class RecordOwnerAccessPolicy method userOwnsRecord.
// --------------------------------------------------------------------------
private boolean userOwnsRecord(String from, int id, Request request) {
Rows data = new Rows(request.db).select(new Select(m_many_many_table == null ? OWNER_COLUMN : "id").from(from).whereIdEquals(id));
data.next();
boolean user_owns_record = userOwnsRecord(data, request);
data.close();
return user_owns_record;
}
use of db.Select in project common by zenlunatics.
the class Pictures method recordAllSizes.
// --------------------------------------------------------------------------
@AdminTask
public void recordAllSizes(Request request) {
ResultSet rs = request.db.select(new Select("id,file").from(m_table));
try {
while (rs.next()) {
BufferedImage image = ImageIO.read(new File(request.site.getBaseFilePath().append(m_table).append(rs.getString("file")).toString()));
request.db.update(m_table, "width=" + image.getWidth() + ",height=" + image.getHeight(), rs.getInt("id"));
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
} catch (IOException e) {
request.abort(e);
}
}
use of db.Select in project common by zenlunatics.
the class PicturesNewsItem method write.
// --------------------------------------------------------------------------
@Override
public void write(Calendar now) throws IOException {
HTMLWriter writer = m_request.writer;
writer.write("<div id=\"ni").write(m_news_id).write("\" class=\"news_item\"><div>");
writeHeader(now, writer);
int num_pictures = m_item_ids.size();
if (num_pictures > 1)
masonry(2);
else {
int item_id = m_item_ids.get(0);
String[] image = m_request.db.readRow(new Select("file,caption,_owner_").from("pictures").whereIdEquals(item_id));
writer.write("\n<img src=\"").write(m_request.getContext()).write("/pictures/thumbs/").write(image[0]).write("\" onclick=\"Gallery.setFiles(['").write(image[0]).write("'],[").write(item_id).write("],[").jsString(Pictures.buildTitle(Integer.toString(item_id), image[1], m_request.site.lookupName(Integer.parseInt(image[2]), m_request.db), null).replace("\"", """)).write("]);Gallery.open(0);\" style=\"cursor:pointer;\"/>");
}
writer.write("</div>");
Likes.write(m_provider, m_item_id, m_request);
Comments.writeComments(m_provider.getTable(), m_item_id, m_request);
writer.write("</div>");
}
use of db.Select in project common by zenlunatics.
the class News method doGet.
// --------------------------------------------------------------------------
@Override
public boolean doGet(Request request) throws IOException {
String action = request.getPathSegment(-1);
if ("News".equals(action)) {
writeFeed(request);
return true;
}
if ("edit".equals(action)) {
editItem(request.getPathSegmentInt(-2), request);
return true;
}
if ("likes".equals(action)) {
int item_id = request.getPathSegmentInt(-2);
NewsProvider provider = getProvider(request.getPathSegment(-3));
Likes.write(provider, item_id, request);
return true;
}
if ("new".equals(action)) {
State state = (State) request.getSessionAttribute("news state");
if (state != null && state.latest != null) {
Select query = new Select("*").from("news").where("last_update>'" + state.latest + "'").orderBy("last_update DESC");
String where = (String) request.getSessionAttribute("news where");
if (where != null)
query.andWhere(where);
ResultSet rs = request.db.select(query);
writeItems(0, rs, request);
}
return true;
}
if ("next".equals(action)) {
State state = (State) request.getSessionAttribute("news state");
if (state != null && state.earliest != null) {
Select query = new Select("*").from("news").where("last_update<'" + state.earliest + "'").orderBy("last_update DESC").limit(20);
String where = (String) request.getSessionAttribute("news where");
if (where != null)
query.andWhere(where);
ResultSet rs = request.db.select(query);
writeItems(0, rs, request);
}
return true;
}
// write single item
ResultSet rs = request.db.select(new Select("*").from("news").whereIdEquals(action));
try {
if (rs.next()) {
NewsProvider news_provider = m_providers.get(rs.getString("provider"));
news_provider.newItem(rs, request).write(Calendar.getInstance());
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
}
return true;
}
use of db.Select in project common by zenlunatics.
the class News method writeFeed.
// --------------------------------------------------------------------------
private void writeFeed(Request request) throws IOException {
String display_name = request.site.getDisplayName();
Feed feed = new Feed(display_name, request.getURL().ensureProtocol(request.request).toString(), display_name + " News", request.db.lookupDate(new Select("MAX(_timestamp_)").from("news")), request);
ResultSet rs = request.db.select("SELECT id,item_id,provider,_timestamp_ FROM news ORDER BY id");
try {
while (rs.next()) request.writer.write("\n");
// int item_id = rs.getInt(2);
// NewsProvider provider = getProvider(rs.getString(3));
// if (provider != null)
// feed.writeEntry(provider.getItemTitle(item_id, request), provider.getItemURL(item_id, request), rs.getString(1), rs.getDate(4), provider.getItemSummary(item_id, request));
rs.getStatement().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
feed.close();
}
Aggregations