Re: including sound or image files with Leiningen uberjar command

2011-09-16 Thread willyh
I use the following helper function:

(defn getResource
  "Load resource. This is guaranteed to work with JNLP'd jars."
  [resource-string]
  (.getResource (.getContextClassLoader (Thread/currentThread))
resource-string))

Note the comment. I had a lot of trouble loading resources when my
uberjars were deployed via JNLP.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: including sound or image files with Leiningen uberjar command

2011-09-16 Thread willyh
Great. I can eliminate another function from my general purpose
utilities file. Thanks. I need to comb the docs more.


On Sep 16, 9:21 am, Dave Ray  wrote:
> Note that this implementation is the same as (clojure.java.io/resource) [1].
>
> Dave
>
> [1]https://github.com/clojure/clojure/blob/3a3374f714e5a755b7de2a761f376...
>
>
>
>
>
>
>
> On Fri, Sep 16, 2011 at 8:58 AM, willyh  wrote:
> > I use the following helper function:
>
> > (defn getResource
> >  "Load resource. This is guaranteed to work with JNLP'd jars."
> >  [resource-string]
> >  (.getResource (.getContextClassLoader (Thread/currentThread))
> > resource-string))
>
> > Note the comment. I had a lot of trouble loading resources when my
> > uberjars were deployed via JNLP.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: using sqlite3

2011-11-09 Thread willyh
project.clj:
---
(defproject testsqlite "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :disable-deps-clean false
  :dependencies [[org.clojure/clojure "1.3.0"]
 [org.clojure/clojure-contrib "1.2.0"]
 [org.clojure/java.jdbc "0.1.0"]
 [org.xerial/sqlite-jdbc "3.7.2"]]
  :main testsqlite.core)

core.clj:
---
(ns testsqlite.core
  (:import [java.io File])
  (:require [clojure.java.jdbc :as sql])
  (:gen-class))

(def db-name "test.db")

(def db {
 :classname "org.sqlite.JDBC"
 :subprotocol "sqlite"; Protocol to use
 :subname db-name; Location of the db
 })

(def new-db-conn (merge db {:create true}))

(defn create-tables
 "Creates the tables needed."
 []
 (sql/create-table
  :members
  [:id :integer "PRIMARY KEY"]
  [:name "varchar(32)"]
  [:age :integer]
  [:programmer "tinyint"]))


(defn insert-record
  [name age programmer?]
  (sql/insert-values
   :members
   [:name
:age
:programmer]
   [name
age
programmer?]))


(defn get-records
  [record-fn]
  (sql/with-query-results
rs
["select * from members"]
(doseq [r rs]
  (record-fn r

(defn delete-record
  [id]
  (sql/delete-rows :members ["id = ?" id]))

(defn -main
  [& args]
  (when (not (.exists (File. db-name)))
(sql/with-connection new-db-conn
  (create-tables)))
  (cond (= (nth args 0) "insert")
(sql/with-connection db
  (insert-record (nth args 1)
 (Integer/parseInt (nth args 2))
 (Integer/parseInt (nth args 3
(= (nth args 0) "dump")
(sql/with-connection db
  (get-records println))
(= (nth args 0) "delete")
(sql/with-connection db
  (delete-record (Integer/parseInt (nth args 1
)
  )


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: using sqlite3

2011-11-09 Thread willyh
Use this project.clj instead (eliminating the reference to clojure-contrib):
(defproject testsqlite "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :disable-deps-clean false
  :dependencies [[org.clojure/clojure "1.3.0"]
 [org.clojure/java.jdbc "0.1.0"]
 [org.xerial/sqlite-jdbc "3.7.2"]]
  :main testsqlite.core)


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: sqlitejdbc jar on clojars

2011-11-09 Thread willyh
I'm using the sqlite-jdbc jar from a maven repository. I use this in
my leiningen project to fetch it:

[org.xerial/sqlite-jdbc "3.7.2"]

I haven't had any issues with it, but that doesn't mean you won't.


On Nov 9, 12:50 pm, labwor...@gmail.com wrote:
> sqlite3 had some problems but a later version (3.7.9) seems to work. Now
> the sqlitejdbc jar on clojars version 0.5.6 has the same problems as the
> old sqlite3 command line. Basically, I get this error below when reading
> certain .sqlite files. Is there a latest version of the sqlitejdcb driver
> for clojure?
> cljstudent.sqlite=> (get-data)
> java.sql.SQLException: file is encrypted or is not a database
> (NO_SOURCE_FILE:0

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure Stored Procedure

2011-11-19 Thread willyh
Here's how I do it with clojure.java.jdbc:


(defn do-stored
  "Executes an (optionally parameterized) SQL callable statement on
  the open database connection. Each param-group is a seq of values
  for all of the parameters."
  [sql & param-groups]
  (with-open [stmt (.prepareCall (sql/connection) sql)]
(doseq [param-group param-groups]
  (doseq [[index value] (map vector (iterate inc 1) param-group)]
(.setObject stmt index value))
  (.addBatch stmt))
(sql/transaction
 (seq (.executeBatch stmt)


(defn insert-sample-log
  [process-code
   csid
   sample-id
   container-id
   container-well
   tube-barcode
   username
   comment]
  (do-stored "{call
bsms_owner.Add_Sample_Log(?, ?, ?, ?, ?, ?, ?, ?)}"
 [process-code
  csid
  sample-id
  container-id
  container-well
  tube-barcode
  username
  comment]))

Hope that helps.

Cheers,

Willy


On Nov 19, 3:14 pm, Ghadi Shayban  wrote:
> I'm trying to load and execute an Oracle Java Stored Procedure...
> written in Clojure.
>
> Has anyone successfully managed to do this?  Are you done throwing
> up?  I would appreciate any direction
>
> I have a little clj that is AOT compiled, and I load the whole jar
> into the DB successfully.
>
> What I'm running into is half of the classfiles inside clojure.jar
> including RT get marked as invalid by the database class "resolver".
> They have a 30-char max on pkg/class names, and anything longer gets
> entered into a lookup table.
>
> This seems to be a good 
> referencehttp://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.ht...
>
> I'm not too familiar with custom class loaders, and I'm not sure
> that's what I'd need.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure Stored Procedure

2011-11-19 Thread willyh
Sorry. I read your message too fast.

Cheers,

Willy


On Nov 19, 3:52 pm, Ghadi Shayban  wrote:
> Your code calls an existing stored procedure on the database.  I'm
> wondering about *creating* a native Java stored procedure *inside* the
> database.  Oracle supports Java 1.5 inside the DB, might as well use
> clojure.
>
> On Nov 19, 3:34 pm, willyh  wrote:
>
>
>
>
>
>
>
> > Here's how I do it with clojure.java.jdbc:
>
> > (defn do-stored
> >   "Executes an (optionally parameterized) SQL callable statement on
> >   the open database connection. Each param-group is a seq of values
> >   for all of the parameters."
> >   [sql & param-groups]
> >   (with-open [stmt (.prepareCall (sql/connection) sql)]
> >     (doseq [param-group param-groups]
> >       (doseq [[index value] (map vector (iterate inc 1) param-group)]
> >         (.setObject stmt index value))
> >       (.addBatch stmt))
> >     (sql/transaction
> >      (seq (.executeBatch stmt)
>
> > (defn insert-sample-log
> >   [process-code
> >    csid
> >    sample-id
> >    container-id
> >    container-well
> >    tube-barcode
> >    username
> >    comment]
> >   (do-stored "{call
> > bsms_owner.Add_Sample_Log(?, ?, ?, ?, ?, ?, ?, ?)}"
> >              [process-code
> >               csid
> >               sample-id
> >               container-id
> >               container-well
> >               tube-barcode
> >               username
> >               comment]))
>
> > Hope that helps.
>
> > Cheers,
>
> > Willy
>
> > On Nov 19, 3:14 pm, Ghadi Shayban  wrote:
>
> > > I'm trying to load and execute an Oracle Java Stored Procedure...
> > > written in Clojure.
>
> > > Has anyone successfully managed to do this?  Are you done throwing
> > > up?  I would appreciate any direction
>
> > > I have a little clj that is AOT compiled, and I load the whole jar
> > > into the DB successfully.
>
> > > What I'm running into is half of the classfiles inside clojure.jar
> > > including RT get marked as invalid by the database class "resolver".
> > > They have a 30-char max on pkg/class names, and anything longer gets
> > > entered into a lookup table.
>
> > > This seems to be a good 
> > > referencehttp://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.ht...
>
> > > I'm not too familiar with custom class loaders, and I'm not sure
> > > that's what I'd need.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en