Add @JdbcMapper.SkipSQLCheck annotation, and another method to skip SQL checking in SimpleSQLChecker

This commit is contained in:
Travis Burtrum 2018-10-25 21:54:43 -04:00
parent 20c5cb6f8d
commit 243bf8c1ae
3 changed files with 16 additions and 4 deletions

View File

@ -42,7 +42,7 @@ public interface JdbcMapper extends Closeable {
OptionalBool allowReflection() default OptionalBool.DEFAULT;
/**
* This defaults to SimpleSQLParser, PrestoSQLParser is another option for Java 8, or implement your own
* This is the database type, used for in lists and SQL checking
* @return
*/
DatabaseType databaseType() default DatabaseType.DEFAULT;
@ -64,6 +64,13 @@ public interface JdbcMapper extends Closeable {
*/
public @interface RunInTransaction {}
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD})
/**
* This avoids calling sqlChecker on this method
*/
public @interface SkipSQLCheck {}
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD})
public @interface SQL {

View File

@ -611,7 +611,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
w.write("\t}\n");
if(sqlChecker != null)
if(sqlChecker != null && eeMethod.getAnnotation(JdbcMapper.SkipSQLCheck.class) == null)
sqlChecker.checkSql(processingEnv, genClass, mapper, databaseType, eeMethod, sqlStatement, bindParams, arrayInList);
}

View File

@ -36,8 +36,11 @@ public class SimpleSQLChecker implements SQLChecker {
return;
}
conn.setAutoCommit(false);
final String sql = getSqlToExecute(classElement, conn, databaseType, sqlStatement);
if(sql == null)
return; // skip this test
qm = new QueryMapper(conn);
qm.executeUpdate(getSqlToExecute(classElement, conn, databaseType, sqlStatement), getFakeBindParams(bindParams, conn, arrayInList));
qm.executeUpdate(sql, getFakeBindParams(bindParams, conn, arrayInList));
} catch (Exception e) {
handleException(getMessager(), e, classElement, method);
} finally {
@ -67,8 +70,10 @@ public class SimpleSQLChecker implements SQLChecker {
// oracle, being terrible, gives this error message for explain plans on MERGES
// so we will just execute those directly instead...
// ORA-00600: internal error code, arguments: [qctfrc : bfc], [22], [0], [5], [1], [1], [2], [371], [], [], [], []
// EXPLAIN PLAN FOR also does not work for BEGIN...
// we are assuming length is at least 5 after being trimmed, if anyone can come up with a valid SQL statement that is shorter let me know...
if (sqlStatement.trim().substring(0, 5).toUpperCase().equals("MERGE"))
final String firstWord = sqlStatement.trim().substring(0, 5).toUpperCase();
if (firstWord.equals("MERGE") || firstWord.equals("BEGIN"))
return sqlStatement;
return "EXPLAIN PLAN FOR " + sqlStatement;
case ANY: