Why Derby does not use property 'currentShema' from my WAS datasource?

人走茶凉 提交于 2019-12-02 17:03:55

问题


I'd like to know why derby does not take into account property 'currentSchema' defined on a given datasource (WAS for current example) ?

My problem is quite the same that Nastya have in this post: Omit schema in the DERBY Query But there is no answer to his/her last comment.

So, i have an application working on different datasources (same database but one schema per datasource). I thought that Derby would use the property 'currentSchema' defined on a datasource if i tell him to use this datasource, but all my named queries are executed on schema 'DEV' (database user name)instead of the schema defined in my datasource property 'currentSchema'. I know that's derby default behaviour when no schema is provided with the query and if no SET CURRENT SCHEMA statement executed before, but...

Is there any existing solution or coming improvement into Derby to solve this use case ? (i do not consider this as an issue as Derby has been designed to use a schema per user i think)

Thanks in advance for any suggestion.

PS: To understand why i need this: i have written scripts to automatically configure derby datasources into developer's workstation (local websphere) so that they can deploy / run their applications onto a local database instead of a common DB2 developement one. But i would avoid doing a SET CURRENT SCHEMA statement before every request in the application code just to solve this issue... (performance impact on the other real environments) And of course i cannot change local database to use something else than Derby :)


回答1:


I have found a solution, specific to my use case as the fix is done with WebSphere configuration.

Solution: Configure the datasource to automatically execute an SQL query to validate a new connection pooled from this datasource. The SQL query is

SET CURRENT SCHEMA MY_SCHEMA

where 'MY_SCHEMA' is specific to each datasource.

This is of course configurable with wsadmin scripting by updating:

  • J2EEResourceProperty 'preTestSQLString' on the datasource, with value = SQL query
  • 'testConnections' property of datasource pool with value 'true'

Without specific server environment like WebSphere to auto execute SQL query on a fresh connection pooled, i fear this is not possible, unless doing it in the code with an EntityManager producer. But that mean you have to write code specific to your environments, and this is not... nice.



来源:https://stackoverflow.com/questions/19032112/why-derby-does-not-use-property-currentshema-from-my-was-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!