Add @JdbcMapper.SkipSQLCheck annotation, and another method to skip SQL checking in SimpleSQLChecker
This commit is contained in:
parent
20c5cb6f8d
commit
243bf8c1ae
|
@ -42,7 +42,7 @@ public interface JdbcMapper extends Closeable {
|
||||||
OptionalBool allowReflection() default OptionalBool.DEFAULT;
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
DatabaseType databaseType() default DatabaseType.DEFAULT;
|
DatabaseType databaseType() default DatabaseType.DEFAULT;
|
||||||
|
@ -64,6 +64,13 @@ public interface JdbcMapper extends Closeable {
|
||||||
*/
|
*/
|
||||||
public @interface RunInTransaction {}
|
public @interface RunInTransaction {}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
/**
|
||||||
|
* This avoids calling sqlChecker on this method
|
||||||
|
*/
|
||||||
|
public @interface SkipSQLCheck {}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
public @interface SQL {
|
public @interface SQL {
|
||||||
|
|
|
@ -611,7 +611,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
w.write("\t}\n");
|
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);
|
sqlChecker.checkSql(processingEnv, genClass, mapper, databaseType, eeMethod, sqlStatement, bindParams, arrayInList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,11 @@ public class SimpleSQLChecker implements SQLChecker {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
|
final String sql = getSqlToExecute(classElement, conn, databaseType, sqlStatement);
|
||||||
|
if(sql == null)
|
||||||
|
return; // skip this test
|
||||||
qm = new QueryMapper(conn);
|
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) {
|
} catch (Exception e) {
|
||||||
handleException(getMessager(), e, classElement, method);
|
handleException(getMessager(), e, classElement, method);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -67,8 +70,10 @@ public class SimpleSQLChecker implements SQLChecker {
|
||||||
// oracle, being terrible, gives this error message for explain plans on MERGES
|
// oracle, being terrible, gives this error message for explain plans on MERGES
|
||||||
// so we will just execute those directly instead...
|
// so we will just execute those directly instead...
|
||||||
// ORA-00600: internal error code, arguments: [qctfrc : bfc], [22], [0], [5], [1], [1], [2], [371], [], [], [], []
|
// 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...
|
// 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 sqlStatement;
|
||||||
return "EXPLAIN PLAN FOR " + sqlStatement;
|
return "EXPLAIN PLAN FOR " + sqlStatement;
|
||||||
case ANY:
|
case ANY:
|
||||||
|
|
Loading…
Reference in New Issue