mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
58756: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 58733: Merged DEV to V4.2-BUG-FIX (4.2.1) 58696: MNT-9111 : MS SQL Server 2008 R2 where user's default schema is not 'dbo', schema validator fails on subsequent restarts and application fails startup Fixed SchemaBootstrap to use the required schema from db.schema.name property if set. 58712: MNT-9111 : MS SQL Server 2008 R2 where user's default schema is not 'dbo', schema validator fails on subsequent restarts and application fails startup Corrected the fix from r58696. Added the db.schema.name to repository.properties. Corrected property handling. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62030 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -72,6 +72,9 @@
|
|||||||
<property name="hibernateMaxExecutions">
|
<property name="hibernateMaxExecutions">
|
||||||
<value>${system.hibernateMaxExecutions}</value>
|
<value>${system.hibernateMaxExecutions}</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="dbSchemaName">
|
||||||
|
<value>${db.schema.name}</value>
|
||||||
|
</property>
|
||||||
<property name="updateSchema">
|
<property name="updateSchema">
|
||||||
<value>${db.schema.update}</value>
|
<value>${db.schema.update}</value>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -349,6 +349,7 @@ lucene.defaultAnalyserResourceBundleName=alfresco/model/dataTypeAnalyzers
|
|||||||
transformer.Archive.includeContents=false
|
transformer.Archive.includeContents=false
|
||||||
|
|
||||||
# Database configuration
|
# Database configuration
|
||||||
|
db.schema.name=
|
||||||
db.schema.stopAfterSchemaBootstrap=false
|
db.schema.stopAfterSchemaBootstrap=false
|
||||||
db.schema.update=true
|
db.schema.update=true
|
||||||
db.schema.update.lockRetryCount=24
|
db.schema.update.lockRetryCount=24
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -75,10 +75,10 @@ import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSQLServerDialect;
|
|||||||
import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSybaseAnywhereDialect;
|
import org.alfresco.repo.domain.hibernate.dialect.AlfrescoSybaseAnywhereDialect;
|
||||||
import org.alfresco.repo.domain.patch.AppliedPatchDAO;
|
import org.alfresco.repo.domain.patch.AppliedPatchDAO;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.descriptor.Descriptor;
|
|
||||||
import org.alfresco.service.descriptor.DescriptorService;
|
import org.alfresco.service.descriptor.DescriptorService;
|
||||||
import org.alfresco.util.DatabaseMetaDataHelper;
|
import org.alfresco.util.DatabaseMetaDataHelper;
|
||||||
import org.alfresco.util.LogUtil;
|
import org.alfresco.util.LogUtil;
|
||||||
|
import org.alfresco.util.PropertyCheck;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
import org.alfresco.util.schemacomp.MultiFileDumper;
|
import org.alfresco.util.schemacomp.MultiFileDumper;
|
||||||
@@ -259,7 +259,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
private int schemaUpdateLockRetryWaitSeconds = DEFAULT_LOCK_RETRY_WAIT_SECONDS;
|
private int schemaUpdateLockRetryWaitSeconds = DEFAULT_LOCK_RETRY_WAIT_SECONDS;
|
||||||
private int maximumStringLength;
|
private int maximumStringLength;
|
||||||
private Properties globalProperties;
|
private Properties globalProperties;
|
||||||
|
private String dbSchemaName;
|
||||||
|
|
||||||
private ThreadLocal<StringBuilder> executedStatementsThreadLocal = new ThreadLocal<StringBuilder>();
|
private ThreadLocal<StringBuilder> executedStatementsThreadLocal = new ThreadLocal<StringBuilder>();
|
||||||
|
|
||||||
public SchemaBootstrap()
|
public SchemaBootstrap()
|
||||||
@@ -406,8 +407,18 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
{
|
{
|
||||||
ActionQueue.setMAX_EXECUTIONS_SIZE(hibernateMaxExecutions);
|
ActionQueue.setMAX_EXECUTIONS_SIZE(hibernateMaxExecutions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set db.schema.name to be used
|
||||||
|
*/
|
||||||
|
public void setDbSchemaName(String dbSchemaName)
|
||||||
|
{
|
||||||
|
if (PropertyCheck.isValidPropertyString(dbSchemaName))
|
||||||
|
{
|
||||||
|
this.dbSchemaName = dbSchemaName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the properties map from which we look up some configuration settings.
|
* Sets the properties map from which we look up some configuration settings.
|
||||||
*
|
*
|
||||||
@@ -552,7 +563,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
*/
|
*/
|
||||||
private int countAppliedPatches(Configuration cfg, Connection connection) throws Exception
|
private int countAppliedPatches(Configuration cfg, Connection connection) throws Exception
|
||||||
{
|
{
|
||||||
String defaultSchema = DatabaseMetaDataHelper.getSchema(connection);
|
String defaultSchema = dbSchemaName != null ? dbSchemaName : DatabaseMetaDataHelper.getSchema(connection);
|
||||||
|
|
||||||
if (defaultSchema != null && defaultSchema.length() == 0)
|
if (defaultSchema != null && defaultSchema.length() == 0)
|
||||||
{
|
{
|
||||||
defaultSchema = null;
|
defaultSchema = null;
|
||||||
@@ -1008,9 +1020,10 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
setHistory("full").
|
setHistory("full").
|
||||||
setJobExecutorActivate(false).
|
setJobExecutorActivate(false).
|
||||||
buildProcessEngine();
|
buildProcessEngine();
|
||||||
|
|
||||||
|
String schemaName = dbSchemaName != null ? dbSchemaName : DatabaseMetaDataHelper.getSchema(connection);
|
||||||
// create or upgrade the DB schema
|
// create or upgrade the DB schema
|
||||||
engine.getManagementService().databaseSchemaUpgrade(connection, null, DatabaseMetaDataHelper.getSchema(connection));
|
engine.getManagementService().databaseSchemaUpgrade(connection, null, schemaName);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -1853,8 +1866,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
XMLToSchema xmlToSchema = new XMLToSchema(is);
|
XMLToSchema xmlToSchema = new XMLToSchema(is);
|
||||||
xmlToSchema.parse();
|
xmlToSchema.parse();
|
||||||
Schema reference = xmlToSchema.getSchema();
|
Schema reference = xmlToSchema.getSchema();
|
||||||
|
|
||||||
ExportDb exporter = new ExportDb(dataSource, dialect, descriptorService);
|
ExportDb exporter = new ExportDb(dataSource, dialect, descriptorService);
|
||||||
|
exporter.setDbSchemaName(dbSchemaName);
|
||||||
// Ensure that the database objects we're validating are filtered
|
// Ensure that the database objects we're validating are filtered
|
||||||
// by the same prefix as the reference file.
|
// by the same prefix as the reference file.
|
||||||
exporter.setNamePrefix(reference.getDbPrefix());
|
exporter.setNamePrefix(reference.getDbPrefix());
|
||||||
@@ -2030,11 +2043,11 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
|||||||
|
|
||||||
if (dbPrefixes == null)
|
if (dbPrefixes == null)
|
||||||
{
|
{
|
||||||
dumper = new MultiFileDumper(outputDir, fileNameTemplate, dbToXMLFactory);
|
dumper = new MultiFileDumper(outputDir, fileNameTemplate, dbToXMLFactory, dbSchemaName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dumper = new MultiFileDumper(dbPrefixes, outputDir, fileNameTemplate, dbToXMLFactory);
|
dumper = new MultiFileDumper(dbPrefixes, outputDir, fileNameTemplate, dbToXMLFactory, dbSchemaName);
|
||||||
}
|
}
|
||||||
List<File> files = dumper.dumpFiles();
|
List<File> files = dumper.dumpFiles();
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -41,7 +41,8 @@ public class DbToXML
|
|||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
private File outputFile;
|
private File outputFile;
|
||||||
private String namePrefix = "alf_";
|
private String namePrefix = "alf_";
|
||||||
|
private String dbSchemaName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Uses a default name prefix of 'alf_' during the export.
|
* Constructor. Uses a default name prefix of 'alf_' during the export.
|
||||||
*/
|
*/
|
||||||
@@ -61,12 +62,22 @@ public class DbToXML
|
|||||||
this(context, outputFile);
|
this(context, outputFile);
|
||||||
this.namePrefix = namePrefix;
|
this.namePrefix = namePrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an optional default schema name
|
||||||
|
*
|
||||||
|
* @param dbSchemaName
|
||||||
|
*/
|
||||||
|
public void setDbSchemaName(String dbSchemaName)
|
||||||
|
{
|
||||||
|
this.dbSchemaName = dbSchemaName;
|
||||||
|
}
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
ExportDb exporter = new ExportDb(context);
|
ExportDb exporter = new ExportDb(context);
|
||||||
exporter.setNamePrefix(namePrefix);
|
exporter.setNamePrefix(namePrefix);
|
||||||
|
exporter.setDbSchemaName(dbSchemaName);
|
||||||
exporter.execute();
|
exporter.execute();
|
||||||
Schema schema = exporter.getSchema();
|
Schema schema = exporter.getSchema();
|
||||||
// Write to a string buffer and then write the results to a file
|
// Write to a string buffer and then write the results to a file
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -70,6 +70,9 @@ public class ExportDb
|
|||||||
/** Only top-level tables starting with namePrefix will be exported, set to empty string for all objects */
|
/** Only top-level tables starting with namePrefix will be exported, set to empty string for all objects */
|
||||||
private String namePrefix = "alf_";
|
private String namePrefix = "alf_";
|
||||||
|
|
||||||
|
/** Default schema name to use */
|
||||||
|
private String dbSchemaName;
|
||||||
|
|
||||||
private final static Log log = LogFactory.getLog(ExportDb.class);
|
private final static Log log = LogFactory.getLog(ExportDb.class);
|
||||||
|
|
||||||
|
|
||||||
@@ -390,6 +393,11 @@ public class ExportDb
|
|||||||
*/
|
*/
|
||||||
private String getSchemaName(final DatabaseMetaData dbmd) throws SQLException
|
private String getSchemaName(final DatabaseMetaData dbmd) throws SQLException
|
||||||
{
|
{
|
||||||
|
if (this.dbSchemaName != null)
|
||||||
|
{
|
||||||
|
return this.dbSchemaName;
|
||||||
|
}
|
||||||
|
|
||||||
String schemaName = null;
|
String schemaName = null;
|
||||||
final ResultSet schemas = dbmd.getSchemas();
|
final ResultSet schemas = dbmd.getSchemas();
|
||||||
while (schemas.next())
|
while (schemas.next())
|
||||||
@@ -512,4 +520,14 @@ public class ExportDb
|
|||||||
{
|
{
|
||||||
this.namePrefix = namePrefix;
|
this.namePrefix = namePrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default schema name
|
||||||
|
*
|
||||||
|
* @param dbSchemaName the default schema name
|
||||||
|
*/
|
||||||
|
public void setDbSchemaName(String dbSchemaName)
|
||||||
|
{
|
||||||
|
this.dbSchemaName = dbSchemaName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -47,6 +47,7 @@ public class MultiFileDumper
|
|||||||
private final DbToXMLFactory dbToXMLFactory;
|
private final DbToXMLFactory dbToXMLFactory;
|
||||||
private final static String fileNameSuffix = ".xml";
|
private final static String fileNameSuffix = ".xml";
|
||||||
public final static String[] DEFAULT_PREFIXES = new String[] { "alf_", "avm_", "jbpm_", "act_" };
|
public final static String[] DEFAULT_PREFIXES = new String[] { "alf_", "avm_", "jbpm_", "act_" };
|
||||||
|
private String defaultSchemaName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,8 +57,9 @@ public class MultiFileDumper
|
|||||||
* @param directory
|
* @param directory
|
||||||
* @param fileNameTemplate
|
* @param fileNameTemplate
|
||||||
* @param dbToXMLFactory
|
* @param dbToXMLFactory
|
||||||
|
* @param defaultSchemaName
|
||||||
*/
|
*/
|
||||||
public MultiFileDumper(String[] dbPrefixes, File directory, String fileNameTemplate, DbToXMLFactory dbToXMLFactory)
|
public MultiFileDumper(String[] dbPrefixes, File directory, String fileNameTemplate, DbToXMLFactory dbToXMLFactory, String defaultSchemaName)
|
||||||
{
|
{
|
||||||
ParameterCheck.mandatory("dbPrefixes", dbPrefixes);
|
ParameterCheck.mandatory("dbPrefixes", dbPrefixes);
|
||||||
ParameterCheck.mandatory("directory", directory);
|
ParameterCheck.mandatory("directory", directory);
|
||||||
@@ -72,6 +74,7 @@ public class MultiFileDumper
|
|||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
this.fileNameTemplate = fileNameTemplate;
|
this.fileNameTemplate = fileNameTemplate;
|
||||||
this.dbToXMLFactory = dbToXMLFactory;
|
this.dbToXMLFactory = dbToXMLFactory;
|
||||||
|
this.defaultSchemaName = defaultSchemaName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,10 +85,11 @@ public class MultiFileDumper
|
|||||||
* @param directory
|
* @param directory
|
||||||
* @param fileNameTemplate
|
* @param fileNameTemplate
|
||||||
* @param dbToXMLFactory
|
* @param dbToXMLFactory
|
||||||
|
* @param defaultSchemaName can be null
|
||||||
*/
|
*/
|
||||||
public MultiFileDumper(File directory, String fileNameTemplate, DbToXMLFactory dbToXMLFactory)
|
public MultiFileDumper(File directory, String fileNameTemplate, DbToXMLFactory dbToXMLFactory, String defaultSchemaName)
|
||||||
{
|
{
|
||||||
this(DEFAULT_PREFIXES, directory, fileNameTemplate, dbToXMLFactory);
|
this(DEFAULT_PREFIXES, directory, fileNameTemplate, dbToXMLFactory, defaultSchemaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +103,7 @@ public class MultiFileDumper
|
|||||||
File outputFile = TempFileProvider.createTempFile(fileNamePrefix, fileNameSuffix, directory);
|
File outputFile = TempFileProvider.createTempFile(fileNamePrefix, fileNameSuffix, directory);
|
||||||
files.add(outputFile);
|
files.add(outputFile);
|
||||||
DbToXML dbToXML = dbToXMLFactory.create(outputFile, dbPrefix);
|
DbToXML dbToXML = dbToXMLFactory.create(outputFile, dbPrefix);
|
||||||
|
dbToXML.setDbSchemaName(defaultSchemaName);
|
||||||
dbToXML.execute();
|
dbToXML.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -61,14 +61,14 @@ public class MultiFileDumperTest
|
|||||||
public void exceptionThrownWhenZeroPrefixesUsed()
|
public void exceptionThrownWhenZeroPrefixesUsed()
|
||||||
{
|
{
|
||||||
// Shouldn't be able to construct a dumper with no prefixes to dump.
|
// Shouldn't be able to construct a dumper with no prefixes to dump.
|
||||||
new MultiFileDumper(new String[] {}, TempFileProvider.getTempDir(), "", dbToXMLFactory);
|
new MultiFileDumper(new String[] {}, TempFileProvider.getTempDir(), "", dbToXMLFactory, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void exceptionThrownWhenNullPrefixListUsed()
|
public void exceptionThrownWhenNullPrefixListUsed()
|
||||||
{
|
{
|
||||||
// Shouldn't be able to construct a dumper with no prefixes to dump.
|
// Shouldn't be able to construct a dumper with no prefixes to dump.
|
||||||
new MultiFileDumper(null, TempFileProvider.getTempDir(), "", dbToXMLFactory);
|
new MultiFileDumper(null, TempFileProvider.getTempDir(), "", dbToXMLFactory, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class MultiFileDumperTest
|
|||||||
File directory = TempFileProvider.getTempDir();
|
File directory = TempFileProvider.getTempDir();
|
||||||
String fileNamePattern = "SchemaDump-MySQL-{0}-";
|
String fileNamePattern = "SchemaDump-MySQL-{0}-";
|
||||||
|
|
||||||
MultiFileDumper dumper = new MultiFileDumper(prefixes, directory, fileNamePattern, dbToXMLFactory);
|
MultiFileDumper dumper = new MultiFileDumper(prefixes, directory, fileNamePattern, dbToXMLFactory, null);
|
||||||
|
|
||||||
when(dbToXMLFactory.create(argThat(isFileNameStartingWith("SchemaDump-MySQL-a_-")), eq("a_"))).
|
when(dbToXMLFactory.create(argThat(isFileNameStartingWith("SchemaDump-MySQL-a_-")), eq("a_"))).
|
||||||
thenReturn(dbToXMLForA);
|
thenReturn(dbToXMLForA);
|
||||||
@@ -106,7 +106,7 @@ public class MultiFileDumperTest
|
|||||||
File directory = TempFileProvider.getTempDir();
|
File directory = TempFileProvider.getTempDir();
|
||||||
String fileNamePattern = "SchemaDump-MySQL-{0}-";
|
String fileNamePattern = "SchemaDump-MySQL-{0}-";
|
||||||
|
|
||||||
MultiFileDumper dumper = new MultiFileDumper(directory, fileNamePattern, dbToXMLFactory);
|
MultiFileDumper dumper = new MultiFileDumper(directory, fileNamePattern, dbToXMLFactory, null);
|
||||||
|
|
||||||
Map<String, DbToXML> xmlExporters = new HashMap<String, DbToXML>(MultiFileDumper.DEFAULT_PREFIXES.length);
|
Map<String, DbToXML> xmlExporters = new HashMap<String, DbToXML>(MultiFileDumper.DEFAULT_PREFIXES.length);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user