Browse Source

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

dependabot/maven/junit-junit-4.13.1
Travis Burtrum 4 years ago
parent
commit
243bf8c1ae
  1. 9
      common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java
  2. 2
      jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java
  3. 9
      jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/SimpleSQLChecker.java

9
common/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapper.java

@ -42,7 +42,7 @@ public interface JdbcMapper extends Closeable { @@ -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 { @@ -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 {

2
jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java

@ -611,7 +611,7 @@ public class JdbcMapperProcessor extends AbstractProcessor { @@ -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);
}

9
jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/SimpleSQLChecker.java

@ -36,8 +36,11 @@ public class SimpleSQLChecker implements SQLChecker { @@ -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 { @@ -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:

Loading…
Cancel
Save