SqlTypeChecker { public static boolean isSelectSql(String sourceSql) { return StringHelper.removeXMLCdataTag(SqlParseHelper.removeSqlComments(sourceSql)).trim().toLowerCase().matches("(?is)\\s*select\\s.*\\sfrom\\s+.*"); }  static boolean isSelectSql(String sourceSql); static boolean isUpdateSql(String sourceSql); static boolean isDeleteSql(String sourceSql); static boolean isInsertSql(String sourceSql);  }
@Test public void test_isSelectSql() throws Throwable{ boolean result = sqlTypeChecker.isSelectSql(" select * from hibernate" ); assertTrue(result); result = sqlTypeChecker.isSelectSql("a select * from hibernate" ); assertFalse(result); result = sqlTypeChecker.isSelectSql(" select * from hibernate" ); assertTrue(result); result = sqlTypeChecker.isSelectSql(" select * from hibernate " ); assertTrue(result); result = sqlTypeChecker.isSelectSql("select * from hibernate --hibernate" ); assertTrue(result); result = sqlTypeChecker.isSelectSql("--select * from hibernate --hibernate" ); assertFalse(result); result = sqlTypeChecker.isSelectSql("" ); assertFalse(result); assertTrue(sqlTypeChecker.isSelectSql("<![CDATA[ select * from user ]]>" )); }