<< Back to previous view

[JDBC-149] quoted could accept a keyword for a database type and "do the right thing" Created: 17/Nov/16  Updated: 22/Nov/16  Resolved: 22/Nov/16

Status: Resolved
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Sean Corfield Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None


 Description   
(quoted :mysql) ;; (quoted \`)
(quoted :mssql) ;; (quoted \[ \])
...

Look at HoneySQL to see what it does. https://github.com/jkk/honeysql/blob/160e2821b8eac50c77c1c175cf821b559d532339/src/honeysql/format.cljc#L224 Answer: :ansi, :mysql, :sqlserver, :oracle – note that it double up any embedded (closing) quote character which java.jdbc has never supported.



 Comments   
Comment by Sean Corfield [ 22/Nov/16 1:08 AM ]

Will be in 0.7.0-alpha2 (or whatever the next release is).





[JDBC-148] get-connection should prioritize its choices better Created: 16/Nov/16  Updated: 22/Nov/16  Resolved: 22/Nov/16

Status: Resolved
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Sean Corfield Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None


 Description   

If you have a :datasource element, the rest should be ignored. This would allow (assoc db-spec :datasource (make-pool db-spec)) to work. Right now the presence of other things in the db-spec would override the :datasource key.

Need to review the order of clauses in get-connection to make sure that they are in a more sensible ordering. At first glance (string? db-spec) and (instance? URI db-spec) should come first, then connection, then datasource, factory, connection-uri, then others?






[JDBC-145] Deadlock when using JDBC from two separate threads with two separate drivers Created: 06/Oct/16  Updated: 24/Nov/16  Resolved: 22/Nov/16

Status: Resolved
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Rogan Morrow Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None
Environment:

Ubuntu 16.04, Leiningen


Attachments: File core.clj     File project.clj     Zip Archive staticinitializer.zip    

 Description   

In `clojure.java.jdbc`, it is possible for the function `get-connection` to call `clojure.lang.RT/loadClassForName` on the driver's classname. JDBC drivers have a static initializer to register themselves with `java.sql.DriverManager` upon load. However, `DriverManager`, as part of its static initializer, loads every implementation of `Driver` on the classpath. This causes an insidious bug when trying to use JDBC from two separate threads where each thread is using a different driver.

For example, if thread A tries to call `get-connection` with a db-spec using driver X, and thread B tries to call `get-connection` with a db-spec using driver Y, then thread A will load driver X which in turn loads `DriverManager`, which again in turn tries to load all drivers on the classpath, including driver Y. If driver Y is simultaneously being loaded by thread B, then driver Y will be trying to load `DriverManager` which is trying to load driver Y, thus creating deadlock. This behaviour can be reliably reproduced using the Clojure files attached.

I am not sure if this is even the responsibility of JDBC to fix. If you want to patch it on the JDBC side, it is easily possible to do so by making sure `DriverManager` is loaded before trying to load the driver.



 Comments   
Comment by Sean Corfield [ 17/Oct/16 11:56 PM ]

Definitely an interesting edge case and, like you, I am not sure if this is the responsibility of java.jdbc to fix. I would note that java.jdbc imports DriverManager so I would expect its static initializer to be run as part of loading the clojure.java.jdbc namespace and thus DriverManager should be loaded before get-connection is called...?

Comment by Rogan Morrow [ 18/Oct/16 12:31 AM ]

It would appear that import does not actually load the class and that classes are only loaded by Clojure at the point that they are first referenced, at least that is my observation based on the output of lein run on the attached project in staticinitializer.zip.

Comment by Sean Corfield [ 18/Oct/16 12:38 AM ]

Cool, will take a look at that. Not what I expected the behavior to be, if you're right.

Comment by Sean Corfield [ 22/Nov/16 1:28 AM ]

Can you try the latest master version (which force-loads DriverManager prior to calling classForName on the driver) to see if it solves this issue?

Comment by Sean Corfield [ 22/Nov/16 1:28 AM ]

Should be fixed in 0.7.0-alpha2

Comment by Rogan Morrow [ 24/Nov/16 7:21 PM ]

I tested master and it no longer deadlocks. Thanks for the fix.

Comment by Sean Corfield [ 24/Nov/16 10:17 PM ]

Thank you for verifying that Roger!





Generated at Sun Dec 11 02:30:35 CST 2016 using JIRA 4.4#649-r158309.