commands = new ArrayList<>();
+ try (BufferedReader bufferedReader = new BufferedReader(reader)) {
+ StringBuilder currentCommand = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty() || line.startsWith("--") || line.startsWith("//")) {
+ continue;
+ }
+ currentCommand.append(line);
+ if (line.endsWith(";")) {
+ String command = currentCommand.toString();
+ command = command.substring(0, command.length() - 1); // Remove semicolon
+
+ // Any MySQL-specific newlines replace with special character newlines
+ command = command.replaceAll(
+ DemoPostgresSingleLineSqlCommandExtractor.NEWLINE_REPLACEMENT_REGEX,
+ "' || CHAR(13) || CHAR(10) || '"
+ );
+
+ //remove the double backslashes - hsql does not honor backslash as an escape character
+ command = command.replaceAll(DemoSqlServerSingleLineSqlCommandExtractor.DOUBLEBACKSLASHMATCH, "\\\\");
+
+ //replace escaped double quotes (\") with encoded double quote
+ command = command.replaceAll("\\\\\"", "' || CHAR(34) || '");
+
+ commands.add(command);
+ currentCommand = new StringBuilder();
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading SQL commands", e);
}
- return newCommands;
+ return commands.toArray(new String[0]);
}
}
diff --git a/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoOracleSingleLineSqlCommandExtractor.java b/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoOracleSingleLineSqlCommandExtractor.java
index 14a45b3b71..015a9b64ed 100644
--- a/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoOracleSingleLineSqlCommandExtractor.java
+++ b/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoOracleSingleLineSqlCommandExtractor.java
@@ -10,7 +10,7 @@
* the Broadleaf End User License Agreement (EULA), Version 1.1
* (the "Commercial License" located at http://license.broadleafcommerce.org/commercial_license-1.1.txt)
* shall apply.
- *
+ *
* Alternatively, the Commercial License may be replaced with a mutually agreed upon license (the "Custom License")
* between you and Broadleaf Commerce. You may not use this file except in compliance with the applicable license.
* #L%
@@ -19,8 +19,9 @@
import org.broadleafcommerce.common.logging.SupportLogManager;
import org.broadleafcommerce.common.logging.SupportLogger;
-import org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor;
+import java.io.BufferedReader;
+import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,9 +34,12 @@
* import sql files, there are a number of value declarations that are incompatible with Oracle. This
* custom extractor takes care of transforming those values into something Oracle understands.
*
+ * Updated for Hibernate 6.x: Hibernate's SingleLineSqlCommandExtractor no longer exists, so this class now
+ * implements its own SQL command extraction logic.
+ *
* @author Jeff Fischer
*/
-public class DemoOracleSingleLineSqlCommandExtractor extends SingleLineSqlCommandExtractor {
+public class DemoOracleSingleLineSqlCommandExtractor {
public static final String TRUE = "1";
public static final String FALSE = "0";
@@ -47,14 +51,13 @@ public class DemoOracleSingleLineSqlCommandExtractor extends SingleLineSqlComman
private static final String TIMESTAMPMATCH = "(? commands = new ArrayList<>();
+ try (BufferedReader bufferedReader = new BufferedReader(reader)) {
+ StringBuilder currentCommand = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty() || line.startsWith("--") || line.startsWith("//")) {
+ continue;
+ }
+ currentCommand.append(line);
+ if (line.endsWith(";")) {
+ String command = currentCommand.toString();
+ command = command.substring(0, command.length() - 1); // Remove semicolon
+ commands.add(command);
+ currentCommand = new StringBuilder();
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading SQL commands", e);
+ }
+ return commands.toArray(new String[0]);
+ }
+
protected void handleBooleans(String[] statements) {
for (int j=0; j
*
- * Add:
- * {@code blPU.hibernate.hbm2ddl.import_files_sql_extractor=org.broadleafcommerce.common.util.sql.importsql.DemoPostgresSingleLineSqlCommandExtractor
- * blEventPU.hibernate.hbm2ddl.import_files_sql_extractor=org.broadleafcommerce.common.util.sql.importsql.DemoPostgresSingleLineSqlCommandExtractor}
- *
- * in properties file to run load scripts through this extractor
+ * Updated for Hibernate 6.x: Hibernate's SingleLineSqlCommandExtractor no longer exists, so this class now
+ * implements its own SQL command extraction logic.
*
* @author Jay Aisenbrey (cja769)
*/
-public class DemoPostgresSingleLineSqlCommandExtractor extends SingleLineSqlCommandExtractor {
+public class DemoPostgresSingleLineSqlCommandExtractor {
public static final String NEWLINE_REPLACEMENT_REGEX = "\\\\r\\\\n";
@Serial
private static final long serialVersionUID = 1L;
- @Override
public String[] extractCommands(Reader reader) {
- String[] commands = super.extractCommands(reader);
- String[] newCommands = new String[commands.length];
- int i = 0;
- for (String command : commands) {
- String newCommand = command;
+ List commands = new ArrayList<>();
+ try (BufferedReader bufferedReader = new BufferedReader(reader)) {
+ StringBuilder currentCommand = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty() || line.startsWith("--") || line.startsWith("//")) {
+ continue;
+ }
+ currentCommand.append(line);
+ if (line.endsWith(";")) {
+ String command = currentCommand.toString();
+ command = command.substring(0, command.length() - 1); // Remove semicolon
- // Replacing all double single quotes with double double quotes to simplify regex. Original regex caused
- // StackOverFlow exception by exploiting a known issue in java. See - http://bugs.java.com/view_bug.do?bug_id=5050507
- newCommand = newCommand.replaceAll("''", "\"\"");
+ // Replacing all double single quotes with double double quotes to simplify regex. Original regex caused
+ // StackOverFlow exception by exploiting a known issue in java. See - http://bugs.java.com/view_bug.do?bug_id=5050507
+ command = command.replaceAll("''", "\"\"");
- // Find all string values being set and put an 'E' outside. This has to be done in Postgres so that escapes
- // are evaluated correctly
- newCommand = newCommand.replaceAll("('.*?')", "E$1");
- newCommand = newCommand.replaceAll("\"\"", "''");
+ // Find all string values being set and put an 'E' outside. This has to be done in Postgres so that escapes
+ // are evaluated correctly
+ command = command.replaceAll("('.*?')", "E$1");
+ command = command.replaceAll("\"\"", "''");
- // Any MySQL-specific newlines replace with special character newlines
- newCommand = newCommand.replaceAll(NEWLINE_REPLACEMENT_REGEX, "' || CHR(13) || CHR(10) || '");
- // Any MySQL CHAR functions with CHR
- Pattern charPattern = Pattern.compile("CHAR\\((\\d+)\\)");
- Matcher charMatcher = charPattern.matcher(newCommand);
- if (charMatcher.find()) {
- String charCode = charMatcher.group(1);
- newCommand = charMatcher.replaceAll("CHR(" + charCode + ")");
- }
+ // Any MySQL-specific newlines replace with special character newlines
+ command = command.replaceAll(NEWLINE_REPLACEMENT_REGEX, "' || CHR(13) || CHR(10) || '");
+ // Any MySQL CHAR functions with CHR
+ Pattern charPattern = Pattern.compile("CHAR\\((\\d+)\\)");
+ Matcher charMatcher = charPattern.matcher(command);
+ if (charMatcher.find()) {
+ String charCode = charMatcher.group(1);
+ command = charMatcher.replaceAll("CHR(" + charCode + ")");
+ }
- // Replace CURRENT_TIMESTAMP with date_trunc('second', CURRENT_TIMESTAMP) otherwise the time will be in fractions of a second
- // This is an issue because when adding a collection item to a sandboxable item the time will be rounded and
- // an attempt to save straight to production will occur resulting in an error
- newCommand = newCommand.replaceAll(
- "CURRENT_TIMESTAMP", "date_trunc('second', CURRENT_TIMESTAMP)"
- );
+ // Replace CURRENT_TIMESTAMP with date_trunc('second', CURRENT_TIMESTAMP) otherwise the time will be in fractions of a second
+ // This is an issue because when adding a collection item to a sandboxable item the time will be rounded and
+ // an attempt to save straight to production will occur resulting in an error
+ command = command.replaceAll(
+ "CURRENT_TIMESTAMP", "date_trunc('second', CURRENT_TIMESTAMP)"
+ );
- newCommands[i] = newCommand;
- i++;
+ commands.add(command);
+ currentCommand = new StringBuilder();
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading SQL commands", e);
}
- return newCommands;
+ return commands.toArray(new String[0]);
}
}
diff --git a/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoSqlServerSingleLineSqlCommandExtractor.java b/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoSqlServerSingleLineSqlCommandExtractor.java
index 90d404b305..1ea041538e 100644
--- a/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoSqlServerSingleLineSqlCommandExtractor.java
+++ b/common/src/main/java/org/broadleafcommerce/common/util/sql/importsql/DemoSqlServerSingleLineSqlCommandExtractor.java
@@ -10,7 +10,7 @@
* the Broadleaf End User License Agreement (EULA), Version 1.1
* (the "Commercial License" located at http://license.broadleafcommerce.org/commercial_license-1.1.txt)
* shall apply.
- *
+ *
* Alternatively, the Commercial License may be replaced with a mutually agreed upon license (the "Custom License")
* between you and Broadleaf Commerce. You may not use this file except in compliance with the applicable license.
* #L%
@@ -19,9 +19,9 @@
import org.broadleafcommerce.common.logging.SupportLogManager;
import org.broadleafcommerce.common.logging.SupportLogger;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor;
+import java.io.BufferedReader;
+import java.io.IOException;
import java.io.Reader;
import java.io.Serial;
import java.util.ArrayList;
@@ -32,9 +32,12 @@
* import sql files, there are a number of value declarations that are incompatible with Sql Server. This
* custom extractor takes care of transforming those values into something SQL Server understands.
*
+ * Updated for Hibernate 6.x: Hibernate's SingleLineSqlCommandExtractor no longer exists, so this class now
+ * implements its own SQL command extraction logic.
+ *
* @author Jeff Fischer
*/
-public class DemoSqlServerSingleLineSqlCommandExtractor extends SingleLineSqlCommandExtractor {
+public class DemoSqlServerSingleLineSqlCommandExtractor {
public static final String DOUBLEBACKSLASHMATCH = "(\\\\\\\\)";
public static final String TRUE = "'TRUE'";
@@ -50,19 +53,42 @@ public class DemoSqlServerSingleLineSqlCommandExtractor extends SingleLineSqlCom
private static final String TIMESTAMPMATCH = "(?i)(current_date)";
protected boolean alreadyRun = false;
- @Override
public String[] extractCommands(Reader reader) {
if (!alreadyRun) {
alreadyRun = true;
LOGGER.support("Converting hibernate.hbm2ddl.import_files sql statements for compatibility with SQL Server");
}
- String[] statements = super.extractCommands(reader);
+ String[] statements = extractCommandsFromReader(reader);
handleReplacements(statements);
return statements;
}
+ private String[] extractCommandsFromReader(Reader reader) {
+ List commands = new ArrayList<>();
+ try (BufferedReader bufferedReader = new BufferedReader(reader)) {
+ StringBuilder currentCommand = new StringBuilder();
+ String line;
+ while ((line = bufferedReader.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty() || line.startsWith("--") || line.startsWith("//")) {
+ continue;
+ }
+ currentCommand.append(line);
+ if (line.endsWith(";")) {
+ String command = currentCommand.toString();
+ command = command.substring(0, command.length() - 1); // Remove semicolon
+ commands.add(command);
+ currentCommand = new StringBuilder();
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error reading SQL commands", e);
+ }
+ return commands.toArray(new String[0]);
+ }
+
protected void handleReplacements(String[] statements) {
for (int j=0; j annotationType() {
return RequestMapping.class;
diff --git a/common/src/main/resources/META-INF/persistence-common.xml b/common/src/main/resources/META-INF/persistence-common.xml
index 8f71b5b373..83ffb06a76 100644
--- a/common/src/main/resources/META-INF/persistence-common.xml
+++ b/common/src/main/resources/META-INF/persistence-common.xml
@@ -62,7 +62,6 @@
-
diff --git a/common/src/main/resources/bl-common-applicationContext-persistence.xml b/common/src/main/resources/bl-common-applicationContext-persistence.xml
index 533d8d0d66..bdb329d215 100644
--- a/common/src/main/resources/bl-common-applicationContext-persistence.xml
+++ b/common/src/main/resources/bl-common-applicationContext-persistence.xml
@@ -31,6 +31,8 @@
+
+