org.broadleafcommerce.common.util.sql.importsql.DemoOracleSingleLineSqlCommandExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of broadleaf-common Show documentation
Show all versions of broadleaf-common Show documentation
A collection of classes shared by broadleaf profile, cms, admin, and core.
/*
* #%L
* BroadleafCommerce Common Libraries
* %%
* Copyright (C) 2009 - 2013 Broadleaf Commerce
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.broadleafcommerce.common.util.sql.importsql;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.broadleafcommerce.common.logging.SupportLogManager;
import org.broadleafcommerce.common.logging.SupportLogger;
import org.hibernate.tool.hbm2ddl.SingleLineSqlCommandExtractor;
/**
* This is a utility class that is only meant to be used for testing the BLC demo on Oracle. In our current
* 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.
*
* @author Jeff Fischer
*/
public class DemoOracleSingleLineSqlCommandExtractor extends SingleLineSqlCommandExtractor {
private static final SupportLogger LOGGER = SupportLogManager.getLogger("UserOverride", DemoOracleSingleLineSqlCommandExtractor.class);
private static final String BOOLEANTRUEMATCH = "(?i)(true)";
private static final String BOOLEANFALSEMATCH = "(?i)(false)";
private static final String TIMESTAMPMATCH = "(? stringList = new ArrayList(Arrays.asList(statements)); //Arrays.asList is immutable
int j=0;
for (String statement : statements) {
if (statement.matches(".*[)]\\s*[,].*")) {
int pos = statement.toUpperCase().indexOf("VALUES ") + "VALUES ".length();
String prefix = statement.substring(0, pos);
stringList.remove(j);
String values = statement.substring(pos, statement.length());
String[] tokens = values.split("[)]\\s*[,]\\s*[(]");
String[] newStatements = new String[tokens.length];
for (int i=0; i