use of db.Select in project common by zenlunatics.
the class News method writeItems.
// --------------------------------------------------------------------------
/**
* @param num_items max items to write, 0 means write only ones sent
* @param rs
* @param request
* @throws IOException
*/
private void writeItems(int num_items, ResultSet rs, Request request) throws IOException {
Calendar now = Calendar.getInstance();
State state = (State) request.getSessionAttribute("news state");
int items_written = 0;
NewsItem item = null;
while (true) {
try {
while (rs.next()) {
Timestamp last_update = rs.getTimestamp("last_update");
if (state.earliest == null || state.earliest.after(last_update))
state.earliest = last_update;
if (state.latest == null || state.latest.before(last_update))
state.latest = last_update;
String provider_name = rs.getString("provider");
NewsProvider provider = getProvider(provider_name);
if (provider == null)
System.out.println("no provider named " + provider_name);
else if (item == null)
item = provider.newItem(rs, request);
else if (!item.merge(provider, rs)) {
++items_written;
if (items_written == num_items)
break;
item.write(now);
item = provider.newItem(rs, request);
}
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
}
if (items_written < num_items - 1 && 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);
rs = request.db.select(query);
try {
if (!rs.isBeforeFirst())
break;
} catch (SQLException e) {
request.abort(e);
}
} else
break;
}
if (item != null)
item.write(now);
}
use of db.Select in project common by zenlunatics.
the class News method editItem.
// --------------------------------------------------------------------------
private void editItem(int id, Request request) throws IOException {
String[] item = request.db.readRow(new Select("provider,item_id").from("news").whereIdEquals(id));
NewsProvider provider = m_providers.get(item[0]);
if (provider != null)
provider.writeEditForm(Integer.parseInt(item[1]), id, request);
}
use of db.Select in project common by zenlunatics.
the class News method rebuild.
// --------------------------------------------------------------------------
@AdminTask
public void rebuild(String provider_name, Request request) throws IOException {
NewsProvider provider = getProvider(provider_name);
if (provider == null) {
request.writer.write("provider " + provider_name + " not found");
return;
}
request.db.delete("news", "provider='" + provider_name + "'");
try {
ResultSet rs = request.db.select(new Select("*").from(provider.getTable()));
NameValuePairs name_value_pairs = new NameValuePairs();
while (rs.next()) {
name_value_pairs.clear();
name_value_pairs.set("provider", provider_name);
name_value_pairs.set("item_id", rs.getInt("id"));
name_value_pairs.set("_owner_", rs.getInt("_owner_"));
String timestamp = rs.getString("_timestamp_");
name_value_pairs.set("_timestamp_", timestamp);
name_value_pairs.set("last_update", timestamp);
for (JDBCColumn column : provider.m_duplicate_columns) name_value_pairs.set(column.name, rs.getString(column.name));
request.db.insert("news", name_value_pairs);
}
rs.getStatement().close();
} catch (SQLException e) {
request.abort(e);
}
}
use of db.Select in project common by zenlunatics.
the class NewsFeed method writeEditForm.
// --------------------------------------------------------------------------
@Override
public void writeEditForm(int item_id, int news_id, Request request) throws IOException {
HTMLWriter writer = request.writer;
writer.write("<div class=\"status\">");
writer.setAttribute("rows", "2");
writer.textAreaExpanding("post", "width:100%", request.db.lookupString(new Select("text").from(m_table).whereIdEquals(item_id)), false);
writer.js("Dialog.top().add_ok('Save',function(){XHR_post(context+'/NewsFeed/" + item_id + "/update','text='+encodeURIComponent($('post').value),function(){replace_news_item(" + news_id + ")})});");
}
use of db.Select in project common by zenlunatics.
the class Surveys method write.
// ----------------------------------------------------------------------
public static void write(Request request) throws IOException {
int take_survey_id = request.getInt("take", 0);
int view_survey_id = request.getInt("view", 0);
if (take_survey_id != 0)
new Survey(take_survey_id, request.db).setPageNum(0, request).writeForm(request);
else if (view_survey_id != 0 && request.db.lookupBoolean(new Select("show_answers").from("surveys").whereIdEquals(view_survey_id)))
new Survey(view_survey_id, request.db).writeAnswers(request);
else
request.site.newView("surveys", request).setColumn(new Column("view").setDisplayName("").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "view" }, new String[] { "id" }).setText("view answers"), false)).writeComponent();
}
Aggregations