Search in sources :

Example 21 with Select

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;
}
Also used : Select(db.Select) Rows(db.Rows)

Example 22 with Select

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);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) AdminTask(web.AdminTask)

Example 23 with Select

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("\"", "&quot;")).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>");
}
Also used : HTMLWriter(web.HTMLWriter) Select(db.Select)

Example 24 with Select

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;
}
Also used : SQLException(java.sql.SQLException) Select(db.Select) ResultSet(java.sql.ResultSet)

Example 25 with Select

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();
}
Also used : SQLException(java.sql.SQLException) Select(db.Select) ResultSet(java.sql.ResultSet)

Aggregations

Select (db.Select)67 SQLException (java.sql.SQLException)24 ResultSet (java.sql.ResultSet)21 HTMLWriter (web.HTMLWriter)18 ArrayList (java.util.ArrayList)9 JDBCColumn (db.JDBCColumn)7 File (java.io.File)7 IOException (java.io.IOException)6 MessagingException (javax.mail.MessagingException)6 MimeMessage (javax.mail.internet.MimeMessage)6 AdminTask (web.AdminTask)6 FilePathStringBuilder (web.FilePathStringBuilder)6 Person (app.Person)5 JDBCTable (db.JDBCTable)5 NameValuePairs (db.NameValuePairs)5 View (db.View)5 DBObject (db.DBObject)4 ViewDef (db.ViewDef)4 InternetAddress (javax.mail.internet.InternetAddress)4 Page (app.Page)3