All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sql2o.quirks.parameterparsing.impl.DefaultSqlParameterParsingStrategy Maven / Gradle / Ivy

There is a newer version: 1.9.0-RC1
Show newest version
package org.sql2o.quirks.parameterparsing.impl;

import org.sql2o.quirks.parameterparsing.SqlParameterParsingStrategy;
import org.sql2o.tools.AbstractCache;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by lars on 11.04.14.
 */
public class DefaultSqlParameterParsingStrategy implements SqlParameterParsingStrategy {

    public CharParser[] getCharParsers(Map> paramMap) {
        return new CharParser[]{
                new QuoteParser(),
                new DoubleHyphensCommentParser(),
                new ForwardSlashCommentParser(),
                new ParameterParser(paramMap),
                new DefaultParser()
        };
    }

    @SuppressWarnings("ConstantConditions")
    public String parseSql(String statement, Map> paramMap) {
        final int length = statement.length();
        final StringBuilder parsedQuery = new StringBuilder(length);

        final CharParser[] charParsers = getCharParsers(paramMap);

        for (int idx = 0; idx < length; idx++) {
            for (CharParser parser : charParsers) {
                char c = statement.charAt(idx);
                if (parser.canParse(c, statement, idx)){
                    idx = parser.parse(c, idx, parsedQuery, statement, length);
                    break;
                }
            }
        }

        return parsedQuery.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy