Merged V2.2 to HEAD

7560: Better handling of exceptions in WCM File Picker when folder or search restriction values invalid
   7567: Minor fix-up of incorrectly encoded text
         Fixed line endings on repository.properties
   7568: Fixed AR-1812: Use hibernate.default_schema to control visibility of metadata queries


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8415 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-03-03 14:10:10 +00:00
parent bfbd50e2fa
commit 428e92479a
3 changed files with 234 additions and 198 deletions

View File

@@ -10,6 +10,7 @@ schema.update.msg.executing_statement= Executing statement: {0}
schema.update.msg.optional_statement_failed=Optional statement execution failed:\n SQL: {0}\n Error: {1}\n File: {2}\n Line: {3}
schema.update.warn.dialect_unsupported=Alfresco should not be used with database dialect {0}.
schema.update.warn.dialect_hsql=Alfresco is using the HSQL default database. Please only use this while evaluating Alfresco, it is NOT recommended for production or deployment!
schema.update.err.found_multiple=\nMore than one Alfresco schema was found when querying the database metadata.\n Limit the database user's permissions or set the 'hibernate.default_schema' property in 'custom-hibernate-dialect.properties'.
schema.update.err.previous_failed=A previous schema upgrade failed. Revert to the original database before attempting the upgrade again.
schema.update.err.statement_failed=Statement execution failed:\n SQL: {0}\n Error: {1}\n File: {2}\n Line: {3}
schema.update.err.update_failed=Schema auto-update failed

View File

@@ -52,7 +52,7 @@ system.bootstrap.config_check.strict=true
# Server Max Users - limit number of users with non-expired tickets
# note:
# -1 allows any number of users,<EFBFBD>assuming not in single-user mode
# -1 allows any number of users, assuming not in single-user mode
# 0 prevents further logins, including the ability to enter single-user mode
server.maxusers=-1

View File

@@ -42,7 +42,6 @@ import java.util.List;
import java.util.Properties;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch;
import org.alfresco.repo.content.filestore.FileContentWriter;
import org.alfresco.service.ServiceRegistry;
@@ -95,6 +94,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
private static final String MSG_OPTIONAL_STATEMENT_FAILED = "schema.update.msg.optional_statement_failed";
private static final String WARN_DIALECT_UNSUPPORTED = "schema.update.warn.dialect_unsupported";
private static final String WARN_DIALECT_HSQL = "schema.update.warn.dialect_hsql";
private static final String ERR_MULTIPLE_SCHEMAS = "schema.update.err.found_multiple";
private static final String ERR_PREVIOUS_FAILED_BOOTSTRAP = "schema.update.err.previous_failed";
private static final String ERR_STATEMENT_FAILED = "schema.update.err.statement_failed";
private static final String ERR_UPDATE_FAILED = "schema.update.err.update_failed";
@@ -230,31 +230,61 @@ public class SchemaBootstrap extends AbstractLifecycleBean
}
/**
* Count applied patches. This fails if multiple applied patch tables are found,
* which normally indicates that the schema view needs to be limited.
*
* @param cfg The Hibernate config
* @param connection a valid database connection
* @return Returns the number of applied patches
* @throws NoSchemaException if the table of applied patches can't be found
*/
private int countAppliedPatches(Connection connection) throws Exception
private int countAppliedPatches(Configuration cfg, Connection connection) throws Exception
{
String defaultSchema = cfg.getProperty("hibernate.default_schema");
if (defaultSchema != null && defaultSchema.length() == 0)
{
defaultSchema = null;
}
String defaultCatalog = cfg.getProperty("hibernate.default_catalog");
if (defaultCatalog != null && defaultCatalog.length() == 0)
{
defaultCatalog = null;
}
DatabaseMetaData dbMetadata = connection.getMetaData();
ResultSet tableRs = dbMetadata.getTables(null, null, "%", null);
ResultSet tableRs = dbMetadata.getTables(defaultCatalog, defaultSchema, "%", null);
boolean newPatchTable = false;
boolean oldPatchTable = false;
try
{
boolean multipleSchemas = false;
while (tableRs.next())
{
String tableName = tableRs.getString("TABLE_NAME");
if (tableName.equalsIgnoreCase("applied_patch"))
{
if (oldPatchTable || newPatchTable)
{
// Found earlier
multipleSchemas = true;
}
oldPatchTable = true;
break;
}
else if (tableName.equalsIgnoreCase("alf_applied_patch"))
{
if (oldPatchTable || newPatchTable)
{
// Found earlier
multipleSchemas = true;
}
newPatchTable = true;
break;
}
}
// We go through all the tables so that multiple visible schemas are detected
if (multipleSchemas)
{
throw new AlfrescoRuntimeException(ERR_MULTIPLE_SCHEMAS);
}
}
finally
{
@@ -271,6 +301,11 @@ public class SchemaBootstrap extends AbstractLifecycleBean
int count = rs.getInt(1);
return count;
}
catch (SQLException e)
{
// This should work at least and is probably an indication of the user viewing multiple schemas
throw new AlfrescoRuntimeException(ERR_MULTIPLE_SCHEMAS);
}
finally
{
try { stmt.close(); } catch (Throwable e) {}
@@ -424,7 +459,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
boolean create = false;
try
{
countAppliedPatches(connection);
countAppliedPatches(cfg, connection);
}
catch (NoSchemaException e)
{
@@ -501,7 +536,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
boolean apply) throws Exception
{
// first check if there have been any applied patches
int appliedPatchCount = countAppliedPatches(connection);
int appliedPatchCount = countAppliedPatches(cfg, connection);
if (appliedPatchCount == 0)
{
// This is a new schema, so upgrade scripts are irrelevant
@@ -747,7 +782,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
}
if (dialectClazz.equals(HSQLDialect.class))
{
logger.info(I18NUtil.getMessage(WARN_DIALECT_HSQL));
LogUtil.info(logger, WARN_DIALECT_HSQL);
}
// Ensure that our static connection provider is used