Ingo Maas created JCR-3851:
------------------------------
Summary: Check for database table existance fails due to wrong use
of connect-user name as current database schema
Key: JCR-3851
URL: https://issues.apache.org/jira/browse/JCR-3851
Project: Jackrabbit Content Repository
Issue Type: Bug
Components: jackrabbit-core
Environment: Oracle database
Reporter: Ingo Maas
It is very common in production environments to use two distinct database
users, one to connect to the database and one for table ownership. When setting
up the datasource, for example as JNDI resource in Tomcat's context.xml file,
an "initSql" setting is used to switch the current database schema. For Oracle
this can be done using the following SQL:
{code}
alter session set current_schema = TABLE_OWNER_SCHEMA
{code}
When using this setup, Jackrabbit's check for table existance in
{{org.apache.jackrabbit.core.util.db.ConnectionHelper.tableExists()}} fails
because it assumes that the connect-user, retrieved by
{{connection.getMetaData().getUserName()}}, is equal to the current database
schema.
The right way to retrieve the current database schema for Oracle is either to
execute the SQL statement
{{select sys_context('userenv', 'current_schema') from dual}}
or to get it from JDBC connection by calling
{{connection.getSchema()}}.
The latter has been introduced in JDBC 4.1 or JDK 7 and has the disadvantange
that many JDBC drivers still throw an AbstractMethodError to indicate 'Not
implemented yet'.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)