mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V3.1 to HEAD
14192: Support for variable assignment and replacement in upgrade scripts 14263 (RECORD ONLY) 14286: Merged V2.2 to V3.1 14124: Fixed ETWOTWO-961: FileFolderService.listFolders throws UnsupportedOperationException for AVM nodes 14277: Fixed ETWOTWO-1228: CLONE -NodeService properties don't support collections of collections for d:any 14302: Merged DEV/V3.1_UPGRADE_SCRIPTS_2 to V3.1: DB2 scripts and other minor changes 14126 (RECORD ONLY) 14193 (RECORD ONLY) 14205: Next version of DB upgrade scripts for SQLServer and DB2 14208: Enterprise DB scripts review: Move scripts to correct locations as a first pass 14211: Carried V2.1-A script change into branch; use STR() function for numeric to string comparison 14212: Moved script from old SQLServer dialect directory 14213: Minor script formatting 14303: Merged DEV/V3.1_UPGRADE_SCRIPTS_2 to V3.1: DB2 scripts and other formatting 14214: Removed redundant scripts; these are all covered by generic scripts 14236: Format SQL 14248: Formatting of SQL to produce meaningful diffs 14266: Next version of upgrade scripts 14281: Clean up formatting of SQL scripts using Convert utility ___________________________________________________________________ Modified: svn:mergeinfo Merged /alfresco/BRANCHES/DEV/V3.1_UPGRADE_SCRIPTS_2:r14126,14193,14205,14208,14211-14213 Merged /alfresco/BRANCHES/V2.2:r14124,14130,14277 Merged /alfresco/BRANCHES/V3.1:r14192,14263,14286,14302-14303 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14652 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,7 +39,9 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -125,6 +127,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
private static final String ERR_VALIDATION_FAILED = "schema.update.err.validation_failed";
|
||||
private static final String ERR_SCRIPT_NOT_RUN = "schema.update.err.update_script_not_run";
|
||||
private static final String ERR_SCRIPT_NOT_FOUND = "schema.update.err.script_not_found";
|
||||
private static final String ERR_STATEMENT_VAR_ASSIGNMENT_BEFORE_SQL = "schema.update.err.statement_var_assignment_before_sql";
|
||||
private static final String ERR_STATEMENT_VAR_ASSIGNMENT_FORMAT = "schema.update.err.statement_var_assignment_format";
|
||||
private static final String ERR_STATEMENT_TERMINATOR = "schema.update.err.statement_terminator";
|
||||
|
||||
public static final int DEFAULT_LOCK_RETRY_COUNT = 24;
|
||||
@@ -910,6 +914,9 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
int line = 0;
|
||||
// loop through all statements
|
||||
StringBuilder sb = new StringBuilder(1024);
|
||||
String fetchVarName = null;
|
||||
String fetchColumnName = null;
|
||||
Map<String, Object> varAssignments = new HashMap<String, Object>(13);
|
||||
while(true)
|
||||
{
|
||||
String sqlOriginal = reader.readLine();
|
||||
@@ -923,6 +930,25 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
|
||||
// trim it
|
||||
String sql = sqlOriginal.trim();
|
||||
// Check for variable assignment
|
||||
if (sql.startsWith("--ASSIGN:"))
|
||||
{
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
// This can only be set before a new SQL statement
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_VAR_ASSIGNMENT_BEFORE_SQL, (line - 1), scriptUrl);
|
||||
}
|
||||
String assignStr = sql.substring(9, sql.length());
|
||||
String[] assigns = assignStr.split("=");
|
||||
if (assigns.length != 2 || assigns[0].length() == 0 || assigns[1].length() == 0)
|
||||
{
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_VAR_ASSIGNMENT_FORMAT, (line - 1), scriptUrl);
|
||||
}
|
||||
fetchVarName = assigns[0];
|
||||
fetchColumnName = assigns[1];
|
||||
continue;
|
||||
}
|
||||
// Check for comments
|
||||
if (sql.length() == 0 ||
|
||||
sql.startsWith( "--" ) ||
|
||||
sql.startsWith( "//" ) ||
|
||||
@@ -978,8 +1004,23 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
if (execute)
|
||||
{
|
||||
sql = sb.toString();
|
||||
executeStatement(connection, sql, optional, line, scriptFile);
|
||||
|
||||
// Perform variable replacement using the ${var} format
|
||||
for (Map.Entry<String, Object> entry : varAssignments.entrySet())
|
||||
{
|
||||
String var = entry.getKey();
|
||||
Object val = entry.getValue();
|
||||
sql = sql.replaceAll("\\$\\{" + var + "\\}", val.toString());
|
||||
}
|
||||
|
||||
Object fetchedVal = executeStatement(connection, sql, fetchColumnName, optional, line, scriptFile);
|
||||
if (fetchVarName != null && fetchColumnName != null)
|
||||
{
|
||||
varAssignments.put(fetchVarName, fetchedVal);
|
||||
}
|
||||
sb = new StringBuilder(1024);
|
||||
fetchVarName = null;
|
||||
fetchColumnName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -993,8 +1034,16 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
/**
|
||||
* Execute the given SQL statement, absorbing exceptions that we expect during
|
||||
* schema creation or upgrade.
|
||||
*
|
||||
* @param fetchColumnName the name of the column value to return
|
||||
*/
|
||||
private void executeStatement(Connection connection, String sql, boolean optional, int line, File file) throws Exception
|
||||
private Object executeStatement(
|
||||
Connection connection,
|
||||
String sql,
|
||||
String fetchColumnName,
|
||||
boolean optional,
|
||||
int line,
|
||||
File file) throws Exception
|
||||
{
|
||||
StringBuilder executedStatements = executedStatementsThreadLocal.get();
|
||||
if (executedStatements == null)
|
||||
@@ -1003,15 +1052,25 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
}
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
Object ret = null;
|
||||
try
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
LogUtil.debug(logger, MSG_EXECUTING_STATEMENT, sql);
|
||||
}
|
||||
stmt.execute(sql);
|
||||
boolean haveResults = stmt.execute(sql);
|
||||
// Record the statement
|
||||
executedStatements.append(sql).append(";\n\n");
|
||||
if (haveResults && fetchColumnName != null)
|
||||
{
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
if (rs.next())
|
||||
{
|
||||
// Get the result value
|
||||
ret = rs.getObject(fetchColumnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
@@ -1030,6 +1089,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
{
|
||||
try { stmt.close(); } catch (Throwable e) {}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user