I greatly appreciate the excellent recent spate of “getting started”
discussions/docs, and I’ve had no trouble at all in bootstrapping new
Clojure projects. But I wonder if there is (yet? anymore?) a canonical
way of embedding Clojure into my existing codebase without refactoring
my existing deployment model. Everything I’ve seen on the web on the
subject is at least a year old.
A repl is a great debugging and diagnostic tool (and it gives me an
excuse to use Clojure at work), but the embedding feels shadier than
I’m comfortable with. Here’s a cartoon:
public class ExampleMain {
private static ApplicationContext staticCtx;
public static void main(String[] args) {
// About 30 man-years of effort is embodied in the following line,
including
// lots of o-r mappings, database credentials, and many scattered
properties.
staticCtx = loadSpringContext(“enormous-spring-file.xml”);
if (args[0].equals(“shell-mode”)) {
clojure.main.main(new String[]{}); // starts up more or less
instantly
} else {
doNormalWork(); // runs for many minutes before hitting
breakpoint
}
System.exit(0);
}
}
so then, thanks to having a static Spring context bean, I can then do
things like:
(def get-bean [beanname] (.getBean com.example.ExampleMain/staticCtx
beanname))
(def dao (get-bean “readOnlyJpaDao”))
;; now I can interrogate my big Oracle database...
(def customer-to-debug (.getCustomer dao “customerID4200000213”))
;; picked out a single Customer object; probably initialized a bunch
of JPA stuff, too
(map #(.getVisitTime %) (.getVisits customer-to-debug))
(count (filter #(> .getVisitTime % *last-week*) #(.getVisits customer-
to-debug)))
;; etc.
It's a vanilla repl (though running it in a shell in emacs helps).
What I’d *really* like to do is start up swank-clojure, pass locals
(like the Spring context, some timing information, etc.) into the
clojure environment, and so forth.
Apologies if I’m missing something obvious (although I suppose that’s
what “getting started” docs are for:).
Thanks.
--josh
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
To unsubscribe, reply using "remove me" as the subject.