1. Shantanu Kumar
  2. Clj-DBCP

Commits

Shantanu Kumar  committed 89d469e

add CUBRID datasource creation function and unit tests

  • Participants
  • Parent commits c1a29e4
  • Branches default

Comments (0)

Files changed (3)

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

View file
     (sqlite-datasource)))
 
 
+; === CUBRID config ===
+;
+(defn cubrid-args
+  "Create datasource args for the CUBRID database. The default database port is
+  8001 but the JDBC connection typically happens through a broker at port 33000
+  or 30000. Example JDBC URL:
+    jdbc:cubrid:localhost:33000:demodb:::
+  Arguments:
+    db-host:port  (String) database hostname and :port-no (colon, then port-no)
+    db-name       (String) database name to connect to
+    username      (String) database username
+    password      (String) password for the database user
+  Examples:
+    (cubrid-args \"localhost:33000\" \"sales\" \"salesuser\" \"secret\")
+    (cubrid-args \"localhost:30000\" \"emp\"   \"empuser\"   \"SeCrEt\")
+  See also: http://wiki.cubrid.org/index.php/CUBRID_Manuals/cubrid_2008_R3.0_manual/Getting_Started_with_CUBRID/JDBC_Sample
+            http://j.mp/fS5Evv (short URL of the above)"
+  [db-host:port db-name username password]
+  (make-datasource-args
+    "cubrid.jdbc.driver.CUBRIDDriver" ; classname: must be in classpath
+    (format "jdbc:cubrid:%s:%s:::" db-host:port db-name) ; url
+    username ; username
+    password ; password
+    ))
+
+
+(defn cubrid-datasource
+  "Create CUBRID data source
+  See also: cubrid-args"
+  [db-host:port db-name username password]
+  (let [args (cubrid-args
+               db-host:port db-name username password)
+        ds   (create-datasource args)]
+    (set-validation-query! ds
+      "SELECT 1;")))

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

View file
     (fail "MySQL not tested")))
 
 
+(deftest test-cubrid
+  (if (is-true? (:cubrid.testconn dbcred))
+    (test-network-datasource "cubrid" cubrid-datasource)
+    (fail "CUBRID not tested")))
+
+
 (deftest test-pgsql
   (if (is-true? (:pgsql.testconn dbcred))
     (test-network-datasource "pgsql" pgsql-datasource)
   (test-hsql)
   (test-sqlite)
   (test-mysql)
+  (test-cubrid)
   (test-pgsql)
   (smoketest-untested-datasources)
   (test-jndi)

File src/test/dbcred.properties

View file
 # hostport can also be in the form "localhost:3306"
 mysql.testconn=true
 mysql.hostport=localhost
-mysql.database=cljdbcp
+mysql.database=bituf
 mysql.username=root
 mysql.password=
 
+# CUBRID credentials
+# hostport can also be in the form "localhost:33000"
+cubrid.testconn=true
+cubrid.hostport=localhost:33000
+cubrid.database=bituf
+cubrid.username=dba
+cubrid.password=root
+
 # PostgreSQL credentials
 # hostport can also be in the form "localhost:5432"
 pgsql.testconn=true
 pgsql.hostport=localhost
-pgsql.database=cljdbcp
+pgsql.database=bituf
 pgsql.username=root
 pgsql.password=root
 
 # database is SID
 oracle.testconn=false
 oracle.hostport=localhost
-oracle.database=cljdbcp
+oracle.database=bituf
 oracle.username=root
 oracle.password=root
 
 # hostport can also be in the form "localhost:50000"
 db2.testconn=false
 db2.hostport=localhost
-db2.database=cljdbcp
+db2.database=bituf
 db2.username=root
 db2.password=root
 
 # hostport can also be in the form "localhost:1433"
 sqlserver.testconn=false
 sqlserver.hostport=localhost
-sqlserver.database=cljdbcp
+sqlserver.database=bituf
 sqlserver.username=root
 sqlserver.password=root
 
 # hostport can also be in the form "localhost:7100"
 sybase.testconn=false
 sybase.hostport=localhost
-sybase.database=cljdbcp
+sybase.database=bituf
 sybase.username=root
 sybase.password=root