@@ -2452,6 +2452,8 @@ public String execute(@RequestBody String request, HttpSession session) {
24522452 char c = sqlRest .charAt (i );
24532453 if (c == '?' || c == '+' || c == '-' || (c >= '0' && c <= '9' ) || (c >= 'A' && c <= 'Z' ) || (c >= 'a' && c <= 'z' )) {
24542454 endInd ++;
2455+ } else {
2456+ break ;
24552457 }
24562458 }
24572459 } else {
@@ -2568,103 +2570,134 @@ public String execute(@RequestBody String request, HttpSession session) {
25682570 long rsDuration = 0 ;
25692571 long executeStartTime = System .currentTimeMillis ();
25702572
2571- if (DemoSQLConfig .DATABASE_INFLUXDB .equals (database ) || DemoSQLConfig .DATABASE_CASSANDRA .equals (database )) {
2572- JSONObject result = executor .execute (config , false );
2573- executeDuration = System .currentTimeMillis () - executeStartTime ;
2573+ try {
2574+ if (DemoSQLConfig .DATABASE_INFLUXDB .equals (database ) || DemoSQLConfig .DATABASE_CASSANDRA .equals (database )) {
2575+ JSONObject result = executor .execute (config , false );
2576+ executeDuration = System .currentTimeMillis () - executeStartTime ;
25742577
2575- if (isWrite ) {
2576- updateCount = result == null ? 0 : result .getIntValue (JSONResponse .KEY_COUNT );
2577- } else {
2578- arr = result == null ? null : result .getJSONArray (DemoSQLExecutor .KEY_RAW_LIST );
2579- if (arr == null ) {
2580- arr = new JSONArray ();
2581- if (result != null ) {
2582- arr .add (result );
2578+ if (isWrite ) {
2579+ updateCount = result == null ? 0 : result .getIntValue (JSONResponse .KEY_COUNT );
2580+ } else {
2581+ arr = result == null ? null : result .getJSONArray (DemoSQLExecutor .KEY_RAW_LIST );
2582+ if (arr == null ) {
2583+ arr = new JSONArray ();
2584+ if (result != null ) {
2585+ arr .add (result );
2586+ }
25832587 }
25842588 }
2585- }
2586- } else {
2587- Connection connection = executor .getConnection (config );
2588- Statement statement = executor .getStatement (config , trimmedSQL );
2589- if (statement instanceof PreparedStatement ) {
2590- if (EXECUTE_STRICTLY ) {
2591- if (isWrite ) {
2592- try {
2593- connection .setAutoCommit (false );
2594- // connection.beginRequest();
2595- int rows = ((PreparedStatement ) statement ).executeUpdate ();
2596- if (rows > maxCount ) {
2597- throw new UnsupportedOperationException ("实际影响数量 " + rows + " 超过上限 " + maxCount + " ! 已回滚变更" );
2589+ } else {
2590+ Connection connection = executor .getConnection (config );
2591+ Statement statement = executor .getStatement (config , trimmedSQL );
2592+ if (statement instanceof PreparedStatement ) {
2593+ if (EXECUTE_STRICTLY ) {
2594+ if (isWrite ) {
2595+ try {
2596+ connection .setAutoCommit (false );
2597+ // connection.beginRequest();
2598+ int rows = ((PreparedStatement ) statement ).executeUpdate ();
2599+ if (rows > maxCount ) {
2600+ throw new UnsupportedOperationException ("实际影响数量 " + rows + " 超过上限 " + maxCount + " ! 已回滚变更" );
2601+ }
2602+ } catch (Throwable e ) {
2603+ connection .rollback ();
2604+ throw e ;
25982605 }
2599- } catch (Throwable e ) {
2600- connection .rollback ();
2601- throw e ;
2606+ } else {
2607+ ((PreparedStatement ) statement ).executeQuery ();
26022608 }
26032609 } else {
2604- ((PreparedStatement ) statement ).executeQuery ();
2610+ ((PreparedStatement ) statement ).execute ();
26052611 }
26062612 } else {
2607- ((PreparedStatement ) statement ).execute ();
2608- }
2609- } else {
2610- if (arg != null && ! arg .isEmpty ()) {
2611- throw new UnsupportedOperationException ("非预编译模式不允许传参 args !" );
2612- }
2613+ if (arg != null && ! arg .isEmpty ()) {
2614+ throw new UnsupportedOperationException ("非预编译模式不允许传参 args !" );
2615+ }
26132616
2614- if (EXECUTE_STRICTLY ) {
2615- if (isWrite ) {
2616- try {
2617- connection .setAutoCommit (false );
2618- // connection.beginRequest();
2619- int rows = statement .executeUpdate (sql );
2620- if (rows > maxCount ) {
2621- throw new UnsupportedOperationException ("实际影响数量 " + rows + " 超过上限 " + maxCount + " ! 已回滚变更" );
2617+ if (EXECUTE_STRICTLY ) {
2618+ if (isWrite ) {
2619+ try {
2620+ connection .setAutoCommit (false );
2621+ // connection.beginRequest();
2622+ int rows = statement .executeUpdate (sql );
2623+ if (rows > maxCount ) {
2624+ throw new UnsupportedOperationException ("实际影响数量 " + rows + " 超过上限 " + maxCount + " ! 已回滚变更" );
2625+ }
2626+ } catch (Throwable e ) {
2627+ connection .rollback ();
2628+ throw e ;
26222629 }
2623- } catch (Throwable e ) {
2624- connection .rollback ();
2625- throw e ;
2630+ } else {
2631+ statement .executeQuery (sql );
26262632 }
26272633 } else {
2628- statement .executeQuery (sql );
2634+ statement .execute (sql );
26292635 }
2630- } else {
2631- statement .execute (sql );
26322636 }
2633- }
26342637
2635- executeDuration = System .currentTimeMillis () - executeStartTime ;
2638+ executeDuration = System .currentTimeMillis () - executeStartTime ;
2639+
2640+ arr = new JSONArray ();
2641+ ResultSet rs = statement .getResultSet ();
2642+ ResultSetMetaData rsmd = rs == null ? null : rs .getMetaData ();
2643+ int length = rsmd == null ? 0 : rsmd .getColumnCount ();
2644+
26362645
2637- arr = new JSONArray ();
2638- ResultSet rs = statement .getResultSet ();
2639- ResultSetMetaData rsmd = rs == null ? null : rs .getMetaData ();
2640- int length = rsmd == null ? 0 : rsmd .getColumnCount ();
2646+ long cursorStartTime = System .currentTimeMillis ();
2647+ while (rs != null && rs .next ()) {
2648+ cursorDuration += System .currentTimeMillis () - cursorStartTime ;
26412649
2650+ JSONObject obj = JSON .newJSONObject ();
2651+ for (int i = 1 ; i <= length ; i ++) {
2652+ long sqlStartTime = System .currentTimeMillis ();
2653+ String name = rsmd .getColumnName (i ); // rsmd.getColumnLable(i);
2654+ Object value = rs .getObject (i );
2655+ rsDuration += System .currentTimeMillis () - sqlStartTime ;
26422656
2643- long cursorStartTime = System .currentTimeMillis ();
2644- while (rs != null && rs .next ()) {
2645- cursorDuration += System .currentTimeMillis () - cursorStartTime ;
2657+ obj .put (name , value );
2658+ }
2659+
2660+ arr .add (obj );
2661+ }
26462662
2647- JSONObject obj = JSON .newJSONObject ();
2648- for (int i = 1 ; i <= length ; i ++) {
2649- long sqlStartTime = System .currentTimeMillis ();
2650- String name = rsmd .getColumnName (i ); // rsmd.getColumnLable(i);
2651- Object value = rs .getObject (i );
2652- rsDuration += System .currentTimeMillis () - sqlStartTime ;
2663+ // try {
2664+ updateCount = statement .getUpdateCount ();
2665+ if (WRITE_STRICTLY && isWrite && updateCount > maxCount ) {
2666+ try {
2667+ connection .rollback ();
2668+ } catch (Throwable e ) {
2669+ e .printStackTrace ();
2670+ }
26532671
2654- obj . put ( name , value );
2672+ throw new IllegalArgumentException ( "实际影响数量 " + updateCount + " 超过上限 " + maxCount + " ! 已回滚变更" );
26552673 }
26562674
2657- arr .add (obj );
2658- }
2675+ try {
2676+ connection .commit ();
2677+ } finally {
2678+ try {
2679+ statement .close ();
2680+ } catch (Throwable e ) {
2681+ e .printStackTrace ();
2682+ }
26592683
2660- // try {
2661- updateCount = statement .getUpdateCount ();
2662- if (WRITE_STRICTLY && isWrite && updateCount > maxCount ) {
2663- throw new IllegalArgumentException ("实际影响数量 " + updateCount + " 超过上限 " + maxCount + " ! 已回滚变更" );
2684+ try {
2685+ connection .close ();
2686+ } catch (Throwable e ) {
2687+ e .printStackTrace ();
2688+ }
2689+ }
2690+
2691+ // } catch (Throwable e) {
2692+ // e.printStackTrace();
2693+ // }
2694+ }
2695+ } finally {
2696+ try {
2697+ executor .close ();
2698+ } catch (Throwable e ) {
2699+ e .printStackTrace ();
26642700 }
2665- // } catch (Throwable e) {
2666- // e.printStackTrace();
2667- // }
26682701 }
26692702
26702703 JSONObject result = newSuccessResult ();
0 commit comments