com.undefinedlabs.scope.rules.sql.provider.internal.PreparedStatementQueryUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scope-rule-java-sql Show documentation
Show all versions of scope-rule-java-sql Show documentation
Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly identify, troubleshoot and fix failed builds.
This artifact contains the classes to instrument the Java SQL package.
package com.undefinedlabs.scope.rules.sql.provider.internal;
import com.undefinedlabs.scope.rules.sql.model.PreparedStatementQueryParameter;
import com.undefinedlabs.scope.sender.internal.serializers.ObjectMapperFactory;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.Map;
public enum PreparedStatementQueryUtils {
INSTANCE;
public String generateParamKey(final int sqlParamIndex) {
return "?".concat(String.valueOf(sqlParamIndex));
}
public String extractSqlMethod(final String sqlStatement) {
if(StringUtils.isEmpty(sqlStatement)){
return null;
}
final String[] chuncks = sqlStatement.split(" ", 2);
return chuncks.length > 0 ? chuncks[0] : null;
}
public String generateSqlParamsAsString(final Map map) {
if(map == null || map.isEmpty()){
return null;
}
try {
return ObjectMapperFactory.newConfiguredObjectMapper().writeValueAsString(map);
} catch(IOException e){
throw new RuntimeException(e);
}
}
public String buildSql(String sqlStatement, Map parametersMap) {
if(StringUtils.isEmpty(sqlStatement)){
return null;
}
if(parametersMap == null || parametersMap.isEmpty()){
return sqlStatement;
}
String sql = sqlStatement;
for(PreparedStatementQueryParameter sqlParam : parametersMap.values()){
sql = sql.replaceFirst("\\?", sqlParam.getValue());
}
return sql;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy