Commits

Shantanu Kumar committed 00a3c1f

add Axion database support and API

Comments (0)

Files changed (3)

 - Improved support for MS-Excel workbooks via JDBC-ODBC bridge driver
 - [TODO] properties support in DataSource JDBC URL
 - [TODO] protocols for memory-connect, file-connect, net-connect
-- MonetDB support
-- [TODO] MckoiDDB support
+- Support for new database: MonetDB
+- Support for new database: Axion support
+- [TODO] Support for new database: MckoiDDB
 - Support for Java 7 (JDBC 4.1)
 - Use OSS-JDBC 0.6
 - Use Clojure 1.3.0 and modular contrib

src/main/clj/org/bituf/clj_dbcp.clj

       *show-jdbc-url* false)
 
 
+(defn print-jdbc-url
+  [db url]
+  (if *show-jdbc-url*
+    (println "\n**** " db " JDBC URL ****\n" url)))
+
+
 (defstruct datasource-args
   :classname :url :username :password)
 
   (let [url (str "jdbc:derby:" (if (empty? db-protocol) ""
                                  (str db-protocol ":"))
               db-path)]
-    (if *show-jdbc-url*
-      (println "\n**** Derby JDBC URL ****\n" url))
+    (print-jdbc-url "Derby" url)
     (make-datasource-args
       "org.apache.derby.jdbc.EmbeddedDriver" ; classname: must be in classpath
       url "sa" "sx"))) ; url, username and password
     http://www.h2database.com/html/features.html"
   [db-protocol db-path]
   (let [url (str "jdbc:h2:" db-protocol ":" db-path)]
-    (if *show-jdbc-url*
-      (println "\n**** H2 JDBC URL ****\n" url))
+    (print-jdbc-url "H2" url)
     (make-datasource-args
       "org.h2.Driver" ; classname: must be in classpath
       url "sa" ""))) ; url, username and password
     http://hsqldb.org/doc/guide/ch01.html"
   [db-protocol db-path]
   (let [url (str "jdbc:hsqldb:" db-protocol ":" db-path)]
-    (if *show-jdbc-url*
-      (println "\n**** HSQL JDBC URL ****\n" url))
+    (print-jdbc-url "HSQLDB" url)
     (make-datasource-args
       "org.hsqldb.jdbcDriver" ; classname: must be in classpath
       url "sa" ""))) ; url, username and password  
     (mysql-args \"localhost:3306\" \"emp\"   \"empuser\"   \"SeCrEt\")"
   [db-host:port db-name username password]
   (let [url (str "jdbc:mysql://" db-host:port "/" db-name)]
-    (if *show-jdbc-url*
-      (println "\n**** MySQL JDBC URL ****\n" url))
+    (print-jdbc-url "MySQL" url)
     (make-datasource-args
       "com.mysql.jdbc.Driver" ; classname: must be in classpath
       url username password)))
     (pgsql-args \"localhost:5432\" \"emp\"   \"empuser\"   \"SeCrEt\")"
   [db-host:port db-name username password]
   (let [url (str "jdbc:postgresql://" db-host:port "/" db-name)]
-    (if *show-jdbc-url*
-      (println "\n**** PostgreSQL JDBC URL ****\n" url))
+    (print-jdbc-url "PostgreSQL" url)
     (make-datasource-args
       "org.postgresql.Driver" ; classname: must be in classpath
       url username password)))
     (oracle-args \"localhost:1521\" \"emp\"   \"empuser\"   \"SeCrEt\")"
   [db-host:port system-id username password]
   (let [url (str "jdbc:oracle:thin:@//" db-host:port "/" system-id)]
-    (if *show-jdbc-url*
-      (println "\n**** Oracle JDBC URL ****\n" url))
+    (print-jdbc-url "Oracle" url)
     (make-datasource-args
       "oracle.jdbc.driver.OracleDriver" ; classname: must be in classpath
       url username password)))
     (db2-args \"localhost:50000\" \"emp\"   \"empuser\"   \"SeCrEt\")"
   [db-host:port db-name username password]
   (let [url (str "jdbc:db2://" db-host:port "/" db-name)]
-    (if *show-jdbc-url*
-      (println "\n**** DB2 JDBC URL ****\n" url))
+    (print-jdbc-url "DB2" url)
     (make-datasource-args
       "com.ibm.db2.jcc.DB2Driver" ; classname: must be in classpath
       url username password)))
               (and db-name (str "/" db-name)) ; database name (can be empty)
               (props-str properties)) ; properties (can be empty)
         ]
-    (if *show-jdbc-url*
-      (println "\n**** jTDS JDBC URL ****\n" url))
+    (print-jdbc-url "jTDS" url)
     (make-datasource-args
       "net.sourceforge.jtds.jdbc.Driver" ; classname: must be in classpath
       ;; JDBC URL
     http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC"
   [db-path]
   (let [url (str "jdbc:sqlite:" db-path)]
-    (if *show-jdbc-url*
-      (println "\n**** SQLite JDBC URL ****\n" url))
+    (print-jdbc-url "SQLite" url)
     (make-datasource-args
       "org.sqlite.JDBC" ; classname: must be in classpath
       url ; url
     (sqlite-datasource)))
 
 
+; === Axion-DB config ===
+;
+(defn axion-args
+  "Create datasource args for the Axion database. Axion database can be
+  hosted off the memory, or a file. Example JDBC URLs it should create are:
+    jdbc:axion:employee:C:/work/mydatabase.db        -- file
+    jdbc:axion:employee:/home/leo/work/mydatabase.db -- file
+    jdbc:axion:employee                              -- memory
+  Arguments:
+    db-path (String) for file   -- <filepath>
+                     for memory -- :memory:
+  Example:
+    (sqlite-args \"C:/work/mydatabase.db\")
+    (sqlite-args \":memory:\")
+  Maven/Lein/Cake Dependencies:
+    org.xerial/sqlite-jdbc/3.7.2 (or a later version)
+  See also:
+    http://axion.tigris.org/quickstart.html"
+  [db-name db-path]
+  (let [url (str "jdbc:axiondb:" db-name (if db-path (str ":" db-path)))]
+    (print-jdbc-url "Axion" url)
+    (make-datasource-args
+      "org.axiondb.jdbc.AxionDriver" ; classname: must be in classpath
+      url ; url
+      "sa" ; username
+      ""   ; password
+      )))
+
+
+(defn axion-datasource
+  "Create an Axion data source.
+  See also: axion-args"
+  ([db-name db-path]
+    (make-datasource (axion-args db-name db-path)))
+  ([db-name]
+    (sqlite-datasource db-name)))
+
+
+(defn axion-filesystem-datasource
+  "Create a filesystem (file) based Axion datasource.
+  See also: axion-datasource, axion-args"
+  ([db-name db-path]
+    (axion-datasource db-name db-path))
+  ([db-name]
+    (axion-datasource db-name "."))
+  ([]
+    (axion-datasource (str "axion" default-db-name) ".")))
+
+
+(defn axion-memory-datasource
+  "Create an in-memory Axion datasource.
+  See also: axion-datasource, axion-args"
+  ([db-name]
+    (axion-datasource db-name nil))
+  ([]
+    (axion-datasource (str "axion" default-db-name) nil)))
+
+
 ; === CUBRID config ===
 ;
 (defn cubrid-args
             http://j.mp/fS5Evv (short URL of the above)"
   [db-host:port db-name username password]
   (let [url (format "jdbc:cubrid:%s:%s:::" db-host:port db-name)]
-    (if *show-jdbc-url*
-      (println "\n**** CUBRID JDBC URL ****\n" url))
+    (print-jdbc-url "CUBRID" url)
     (make-datasource-args
       "cubrid.jdbc.driver.CUBRIDDriver" ; classname: must be in classpath
       url
             http://j.mp/trXYGP (short URL of the above)"
   [db-host:port db-name username password]
   (let [url (format "jdbc:monetdb://%s/%s" db-host:port db-name)]
-    (if *show-jdbc-url*
-      (println "\n**** MonetDB JDBC URL ****\n" url))
+    (print-jdbc-url "MonetDB" url)
     (make-datasource-args
       "nl.cwi.monetdb.jdbc.MonetDriver" ; classname: must be in classpath
       url
             http://j.mp/hf5Vtj (short URL of the above)"
   [db-host:port db-path username password]
   (let [url (format "jdbc:firebirdsql://%s/%s" db-host:port db-path)]
-    (if *show-jdbc-url*
-      (println "\n**** Firebird JDBC URL ****\n" url))
+    (print-jdbc-url "Firebird" url)
     (make-datasource-args
       "org.firebirdsql.jdbc.FBDriver" ; classname: must be in classpath
       url username password)))
             http://j.mp/hNatr1 (short URL of the above)"
   [odbc-dsn username password properties]
   (let [url (format "jdbc:odbc:%s%s" odbc-dsn (props-str properties))]
-    (if *show-jdbc-url*
-      (println "\n**** JDBC-ODBC Bridge URL ****\n" url))
+    (print-jdbc-url "JDBC-ODBC Bridge" url)
     (make-datasource-args
       "sun.jdbc.odbc.JdbcOdbcDriver" ; classname: provided by JDK
       url username password)))
   through ODBC. May not be supported in Clojure 1.3."
   ([^String dsn properties]
     (let [url (format "jdbc:odbc:%s%s" dsn (props-str properties))]
-      (if *show-jdbc-url*
-        (println "\n**** JDBC-ODBC Bridge URL for lite DataSource ****\n" url))
+    (print-jdbc-url "JDBC-ODBC Bridge for Lite DataSource" url)
       (lite-datasource
         "sun.jdbc.odbc.JdbcOdbcDriver" ; driver classname
         url)))

src/test/clj/org/bituf/test_clj_dbcp.clj

     (sqlite-filesystem-datasource "sqlitefile")))
 
 
+(deftest test-axion
+  ;; in-memory (no dbname)
+  (test-datasource
+    (axion-memory-datasource))
+  ;; file system (default dbname)
+  (test-datasource
+    (axion-filesystem-datasource))
+  ;; file system
+  (test-datasource
+    (axion-filesystem-datasource "sqlitefile")))
+
+
 (defn test-network-datasource
   "Test a network JDBC datasource - CUBRID, MySQL, PostgreSQL, Oracle, DB2, jTDS etc.
   dbtoken must be same as first token (before period) in dbcred.properties file.
   (test-h2)
   (test-hsql)
   (test-sqlite)
+  (test-axion)
   (test-firebird)
   (test-mysql)
   (test-cubrid)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.