Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)

71584: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud)
      70325: Merged V4.1-BUG-FIX (4.1.9) to V4.2-BUG-FIX (4.2.3)
         70145: MNT-8629: Merged DEV to V4.1-BUG-FIX (4.1.9)
            70077: MNT-8629: Support requested for DB2 when schema name does not match DB user name.
               - Take into account schema name during update


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74685 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-06-25 15:09:31 +00:00
parent 18736883bf
commit 8a2b11108a
4 changed files with 86 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -24,6 +24,8 @@ import java.sql.ResultSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
/**
* Helper class to collect all of our DatabaseMetaData interpretations in one place.
@@ -35,12 +37,19 @@ public class DatabaseMetaDataHelper {
private static Log logger = LogFactory.getLog(DatabaseMetaDataHelper.class);
private Configuration cfg;
public void setLocalSessionFactory(LocalSessionFactoryBean localSessionFactory)
{
this.cfg = localSessionFactory.getConfiguration();
}
/**
* Trys to determine the schema name from the DatabaseMetaData obtained from the Connection.
* @param connection A database connection
* @return
*/
public static String getSchema(Connection connection)
private String getSchemaFromConnection(Connection connection)
{
if (connection == null) {
@@ -89,4 +98,33 @@ public class DatabaseMetaDataHelper {
}
return null;
}
public String getSchema(Connection connection)
{
String schema = null;
if (this.cfg != null)
{
String tmpSchema = this.cfg.getProperty("hibernate.default_schema");
if (tmpSchema != null && tmpSchema.trim().length() > 0)
{
schema = tmpSchema;
}
}
// if hibernate.default_schema was specified as a system property, then override previous value
String tmpSchema = System.getProperty("hibernate.default_schema");
if (tmpSchema != null && tmpSchema.length() > 0)
{
schema = tmpSchema;
}
if (schema == null)
{
schema = getSchemaFromConnection(connection);
}
return schema;
}
}