mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
71613: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 71277: Merged V4.1-BUG-FIX (4.1.9) to V4.2-BUG-FIX (4.2.3) 70543: Merged DEV to V4.1-BUG-FIX (4.1.9) 70393 : MNT-11231 : SchemaBootstrap SQL Script execution cannot handle complex SQL statements - Custom sql statements delimeter directive was implemtned for SchemaBootstrap and ScriptExecutorImpl. - Unit tests added. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74702 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -28,4 +28,6 @@ schema.update.err.script_not_found=The schema script could not be found at locat
|
||||
schema.update.err.statement_include_before_sql=Script include ''--INCLUDE:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_before_sql=Variable assignment with ''--ASSIGN:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.statement_var_assignment_format=Variable assignment uses format ''--ASSIGN:x=col'' where ''x'' is the variable to assign to and ''col'' is the column value to extract (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with '';'' (line {0} of {1}).
|
||||
schema.update.err.statement_terminator=Scripts must terminate all statements with ''{0}'' (line {1} of {2}).
|
||||
schema.update.err.delimiter_set_before_sql=Custom delimiter ''--SET-DELIMITER:'' must occur before starting the SQL statement (line {0} of {1}).
|
||||
schema.update.err.delimiter_invalid=Custom delimiter ''--SET-DELIMITER:'' must set non-empty delimiter (line {0} of {1}).
|
@@ -160,6 +160,8 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
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";
|
||||
private static final String ERR_DELIMITER_SET_BEFORE_SQL = "schema.update.err.delimiter_set_before_sql";
|
||||
private static final String ERR_DELIMITER_INVALID = "schema.update.err.delimiter_invalid";
|
||||
private static final String DEBUG_SCHEMA_COMP_NO_REF_FILE = "system.schema_comp.debug.no_ref_file";
|
||||
private static final String INFO_SCHEMA_COMP_ALL_OK = "system.schema_comp.info.all_ok";
|
||||
private static final String WARN_SCHEMA_COMP_PROBLEMS_FOUND = "system.schema_comp.warn.problems_found";
|
||||
@@ -1257,6 +1259,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
int batchUpperLimit = 0;
|
||||
int batchSize = 1;
|
||||
Map<String, Object> varAssignments = new HashMap<String, Object>(13);
|
||||
String delimiter = ";";
|
||||
// Special variable assignments:
|
||||
if (dialect instanceof PostgreSQLDialect)
|
||||
{
|
||||
@@ -1360,6 +1363,22 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
connection.setAutoCommit(true);
|
||||
continue;
|
||||
}
|
||||
else if (sql.startsWith("--SET-DELIMITER:"))
|
||||
{
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
// This can only be set before a new SQL statement
|
||||
throw AlfrescoRuntimeException.create(ERR_DELIMITER_SET_BEFORE_SQL, (line - 1), scriptUrl);
|
||||
}
|
||||
|
||||
// We're good...so set the new delimiter
|
||||
String newDelim = sql.substring(16).trim();
|
||||
if (newDelim.length() == 0)
|
||||
{
|
||||
throw AlfrescoRuntimeException.create(ERR_DELIMITER_INVALID, (line - 1), scriptUrl);
|
||||
}
|
||||
delimiter = newDelim;
|
||||
}
|
||||
|
||||
// Check for comments
|
||||
if (sql.length() == 0 ||
|
||||
@@ -1370,7 +1389,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
// we have an unterminated statement
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_TERMINATOR, (line - 1), scriptUrl);
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_TERMINATOR, delimiter, (line - 1), scriptUrl);
|
||||
}
|
||||
// there has not been anything to execute - it's just a comment line
|
||||
continue;
|
||||
@@ -1378,7 +1397,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
// have we reached the end of a statement?
|
||||
boolean execute = false;
|
||||
boolean optional = false;
|
||||
if (sql.endsWith(";"))
|
||||
if (sql.endsWith(delimiter))
|
||||
{
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
execute = true;
|
||||
@@ -1387,7 +1406,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
|
||||
else if (sql.endsWith("(optional)") || sql.endsWith("(OPTIONAL)"))
|
||||
{
|
||||
// Get the end of statement
|
||||
int endIndex = sql.lastIndexOf(';');
|
||||
int endIndex = sql.lastIndexOf(delimiter);
|
||||
if (endIndex > -1)
|
||||
{
|
||||
sql = sql.substring(0, endIndex);
|
||||
|
@@ -66,6 +66,8 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
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";
|
||||
private static final String ERR_DELIMITER_SET_BEFORE_SQL = "schema.update.err.delimiter_set_before_sql";
|
||||
private static final String ERR_DELIMITER_INVALID = "schema.update.err.delimiter_invalid";
|
||||
private static final int DEFAULT_MAX_STRING_LENGTH = 1024;
|
||||
private static volatile int maxStringLength = DEFAULT_MAX_STRING_LENGTH;
|
||||
private Dialect dialect;
|
||||
@@ -313,6 +315,7 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
int batchUpperLimit = 0;
|
||||
int batchSize = 1;
|
||||
Map<String, Object> varAssignments = new HashMap<String, Object>(13);
|
||||
String delimiter = ";";
|
||||
// Special variable assignments:
|
||||
if (dialect instanceof PostgreSQLDialect)
|
||||
{
|
||||
@@ -417,6 +420,22 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
connection.setAutoCommit(true);
|
||||
continue;
|
||||
}
|
||||
else if (sql.startsWith("--SET-DELIMITER:"))
|
||||
{
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
// This can only be set before a new SQL statement
|
||||
throw AlfrescoRuntimeException.create(ERR_DELIMITER_SET_BEFORE_SQL, (line - 1), scriptUrl);
|
||||
}
|
||||
|
||||
// We're good...so set the new delimiter
|
||||
String newDelim = sql.substring(16).trim();
|
||||
if (newDelim.length() == 0)
|
||||
{
|
||||
throw AlfrescoRuntimeException.create(ERR_DELIMITER_INVALID, (line - 1), scriptUrl);
|
||||
}
|
||||
delimiter = newDelim;
|
||||
}
|
||||
|
||||
// Check for comments
|
||||
if (sql.length() == 0 ||
|
||||
@@ -427,7 +446,7 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
if (sb.length() > 0)
|
||||
{
|
||||
// we have an unterminated statement
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_TERMINATOR, (line - 1), scriptUrl);
|
||||
throw AlfrescoRuntimeException.create(ERR_STATEMENT_TERMINATOR, delimiter, (line - 1), scriptUrl);
|
||||
}
|
||||
// there has not been anything to execute - it's just a comment line
|
||||
continue;
|
||||
@@ -435,7 +454,7 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
// have we reached the end of a statement?
|
||||
boolean execute = false;
|
||||
boolean optional = false;
|
||||
if (sql.endsWith(";"))
|
||||
if (sql.endsWith(delimiter))
|
||||
{
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
execute = true;
|
||||
@@ -444,7 +463,7 @@ public class ScriptExecutorImpl implements ScriptExecutor
|
||||
else if (sql.endsWith("(optional)") || sql.endsWith("(OPTIONAL)"))
|
||||
{
|
||||
// Get the end of statement
|
||||
int endIndex = sql.lastIndexOf(';');
|
||||
int endIndex = sql.lastIndexOf(delimiter);
|
||||
if (endIndex > -1)
|
||||
{
|
||||
sql = sql.substring(0, endIndex);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package org.alfresco.repo.domain.schema.script;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -155,4 +156,58 @@ public class ScriptExecutorImplIntegrationTest
|
||||
assertEquals("schema.update.err.script_not_found", e.getMsgId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void emptyCustomDelimiter() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/empty-delimiter.sql");
|
||||
fail("Script execution should fail.");
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
assertEquals("schema.update.err.delimiter_invalid", e.getMsgId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void wrongUsageCustomDelimiter() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/wrong-usage-delimiter.sql");
|
||||
fail("Script execution should fail.");
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
assertEquals("schema.update.err.delimiter_set_before_sql", e.getMsgId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void unterminatedCustomDelimiter() throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/unterminated-custom-delimiter.sql");
|
||||
fail("Script execution should fail.");
|
||||
}
|
||||
catch (AlfrescoRuntimeException e)
|
||||
{
|
||||
assertEquals("schema.update.err.statement_terminator", e.getMsgId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void customDelimiter() throws Exception
|
||||
{
|
||||
scriptExecutor.executeScriptUrl("scriptexec/${db.script.dialect}/custom-delimiter.sql");
|
||||
String select = "select message from alf_test_custom_delimiter";
|
||||
List<String> res = jdbcTmpl.queryForList(select, String.class);
|
||||
assertEquals(2, res.size());
|
||||
assertEquals("custom delimter success", res.get(0));
|
||||
assertEquals("custom delimter success again", res.get(1));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
--SET-DELIMITER: /
|
||||
drop table alf_test_custom_delimiter/ --(optional)
|
||||
|
||||
create table alf_test_custom_delimiter
|
||||
(
|
||||
message VARCHAR(255)
|
||||
)/
|
||||
|
||||
insert into alf_test_custom_delimiter (message) values ('custom delimter success')/
|
||||
|
||||
--SET-DELIMITER: ;
|
||||
insert into alf_test_custom_delimiter (message) values ('custom delimter success again');
|
@@ -0,0 +1 @@
|
||||
--SET-DELIMITER:
|
@@ -0,0 +1,3 @@
|
||||
--SET-DELIMITER: /
|
||||
select 1;
|
||||
|
@@ -0,0 +1,3 @@
|
||||
select 1
|
||||
--SET-DELIMITER: /
|
||||
;
|
Reference in New Issue
Block a user