Search in sources :

Example 1 with SqlScriptParser

use of org.jdbi.v3.core.internal.SqlScriptParser in project jdbi by jdbi.

the class Script method splitToStatements.

private List<String> splitToStatements(String script) {
    final List<String> statements = new ArrayList<>();
    String lastStatement = new SqlScriptParser((t, sb) -> {
        addStatement(sb.toString(), statements);
        sb.setLength(0);
    }).parse(new ANTLRStringStream(script));
    addStatement(lastStatement, statements);
    return statements;
}
Also used : List(java.util.List) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Handle(org.jdbi.v3.core.Handle) SqlScriptParser(org.jdbi.v3.core.internal.SqlScriptParser) ArrayList(java.util.ArrayList) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ArrayList(java.util.ArrayList) SqlScriptParser(org.jdbi.v3.core.internal.SqlScriptParser)

Example 2 with SqlScriptParser

use of org.jdbi.v3.core.internal.SqlScriptParser in project irontest by zheng-wang.

the class IronTestUtils method getStatements.

/**
 * Parse the sqlRequest to get SQL statements, trimmed and without comments.
 * @param sqlRequest
 * @return
 */
public static List<String> getStatements(String sqlRequest) {
    final List<String> statements = new ArrayList<>();
    String lastStatement = new SqlScriptParser((t, sb) -> {
        statements.add(sb.toString().trim());
        sb.setLength(0);
    }).parse(new ANTLRStringStream(sqlRequest));
    statements.add(lastStatement.trim());
    // remove all empty statements
    statements.removeAll(Collections.singleton(""));
    return statements;
}
Also used : SSLContext(javax.net.ssl.SSLContext) Metadata.metadata(com.github.tomakehurst.wiremock.common.Metadata.metadata) XPathExpressionException(javax.xml.xpath.XPathExpressionException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) io.irontest.models.mixin(io.irontest.models.mixin) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.http.Header) Base64(org.apache.commons.codec.binary.Base64) EntityUtils(org.apache.http.util.EntityUtils) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) io.irontest.models(io.irontest.models) java.net(java.net) Document(org.w3c.dom.Document) ResultSet(java.sql.ResultSet) org.apache.http.client.methods(org.apache.http.client.methods) HTTPAPIResponse(io.irontest.core.teststep.HTTPAPIResponse) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID(io.irontest.IronTestConstants.WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID) PlainTextStubNotMatchedRenderer(com.github.tomakehurst.wiremock.verification.notmatched.PlainTextStubNotMatchedRenderer) HttpHeaders(org.apache.http.HttpHeaders) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) UrlEscapers(com.google.common.net.UrlEscapers) HttpEntity(org.apache.http.HttpEntity) StringEntity(org.apache.http.entity.StringEntity) WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER(io.irontest.IronTestConstants.WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER) UrlValidator(org.apache.commons.validator.routines.UrlValidator) HTTPHeader(io.irontest.models.teststep.HTTPHeader) LoggedResponse(com.github.tomakehurst.wiremock.http.LoggedResponse) MQRFH2Folder(io.irontest.models.teststep.MQRFH2Folder) HttpClients(org.apache.http.impl.client.HttpClients) ResultSetMetaData(java.sql.ResultSetMetaData) ClientProtocolException(org.apache.http.client.ClientProtocolException) java.util(java.util) SQLStatementType(io.irontest.db.SQLStatementType) TransformerException(javax.xml.transform.TransformerException) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) Encoding(com.github.tomakehurst.wiremock.common.Encoding) SQLException(java.sql.SQLException) HttpClient(org.apache.http.client.HttpClient) ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Jdbi(org.jdbi.v3.core.Jdbi) JsonParser(com.fasterxml.jackson.core.JsonParser) TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SqlScriptParser(org.jdbi.v3.core.internal.SqlScriptParser) IOException(java.io.IOException) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) com.github.tomakehurst.wiremock.matching(com.github.tomakehurst.wiremock.matching) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) ResponseHandler(org.apache.http.client.ResponseHandler) HttpHost(org.apache.http.HttpHost) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) SqlScriptParser(org.jdbi.v3.core.internal.SqlScriptParser)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 Encoding (com.github.tomakehurst.wiremock.common.Encoding)1 Metadata.metadata (com.github.tomakehurst.wiremock.common.Metadata.metadata)1 LoggedResponse (com.github.tomakehurst.wiremock.http.LoggedResponse)1 ResponseDefinition (com.github.tomakehurst.wiremock.http.ResponseDefinition)1 com.github.tomakehurst.wiremock.matching (com.github.tomakehurst.wiremock.matching)1 ServeEvent (com.github.tomakehurst.wiremock.stubbing.ServeEvent)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)1 PlainTextStubNotMatchedRenderer (com.github.tomakehurst.wiremock.verification.notmatched.PlainTextStubNotMatchedRenderer)1 UrlEscapers (com.google.common.net.UrlEscapers)1 WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID (io.irontest.IronTestConstants.WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID)1 WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER (io.irontest.IronTestConstants.WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER)1 HTTPAPIResponse (io.irontest.core.teststep.HTTPAPIResponse)1 SQLStatementType (io.irontest.db.SQLStatementType)1 io.irontest.models (io.irontest.models)1 io.irontest.models.mixin (io.irontest.models.mixin)1