The Artima Developer Community
Sponsored Link

Java Buzz Forum
The Same Code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
The Same Code Posted: Nov 24, 2004 4:45 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: The Same Code
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

Same thing in three languages (one language twice, doing two styles). All technically as very realistic pseudo-code =)

Handle h;
try {
    h = dbi.open();
    h.begin()
    final Collection results = h.query(CHANGED_DESCRIPTIONS);
    for (Iterator i = results.iterator(); i.hasNext();) {
        final Map row = (Map) i.next();
        System.out.println(row.get("name"));
    }
} catch (Exception e) {
    if (h != null && h.isOpen()) {
        if (h.isInTransaction()) {
            h.rollback();
        }
    }
    throw new DBIException("...", e);
} catch (Error e) {
    if (h != null && h.isOpen()) {
        if (h.isInTransaction()) {
            h.rollback();
        }
    }
    throw new DBIError("...", e);
} finally {
    if (h != null) {
        h.close();
    }
}

or

dbi.open(new HandleCallback() {
    public void withHandle(final Handle handle) throws Exception {
        handle.inTransaction(new TransactionCallback() {
            public void inTransaction(final Handle handle) throws Exception {
                handle.query(CHANGED_DESCRIPTIONS, new RowCallback() {
                    public void eachRow(final Handle handle, final Map row) throws Exception {
                        System.out.println(row.get("name"));
                    }
                });
            }
        });
    }
});

or (this one is even more pseudocode'ish)

(invoke dbi 'with-handle (lambda (handle) 
    (invoke handle 'in-transaction (lambda(handle)
        (invoke handle 'each-row (CHANGED_DESCRIPTIONS lambda(row) 
            (print (map-get row 'name))))))))

or

dbi.open do |handle|
    handle.inTransaction do 
        handle.query(CHANGED_DESCRIPTIONS) { |row| puts row['name'] }
    end
end

?

Read: The Same Code

Topic: UDDI: Hype & reality & Role of Standards body Previous Topic   Next Topic Topic: Tiger's Spotlight - Simplicity with Room for Improvement

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use