|
38 | 38 | import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata; |
39 | 39 | import com.google.spanner.v1.CommitRequest; |
40 | 40 | import com.google.spanner.v1.ExecuteBatchDmlRequest; |
| 41 | +import com.google.spanner.v1.ExecuteSqlRequest; |
41 | 42 | import com.google.spanner.v1.ResultSetMetadata; |
42 | 43 | import com.google.spanner.v1.ResultSetStats; |
43 | 44 | import com.google.spanner.v1.StructType; |
@@ -870,4 +871,104 @@ public void testExecuteAutoBatchDml() throws SQLException { |
870 | 871 | assertEquals(3, request.getStatementsCount()); |
871 | 872 | assertEquals(1, mockSpanner.countRequestsOfType(CommitRequest.class)); |
872 | 873 | } |
| 874 | + |
| 875 | + @Test |
| 876 | + public void testLastStatement_AutoCommit_Query() throws SQLException { |
| 877 | + try (Connection connection = createJdbcConnection(); |
| 878 | + Statement statement = connection.createStatement()) { |
| 879 | + //noinspection EmptyTryBlock |
| 880 | + try (ResultSet ignore = statement.executeQuery(query)) { |
| 881 | + } |
| 882 | + } |
| 883 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 884 | + assertFalse(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 885 | + } |
| 886 | + |
| 887 | + @Test |
| 888 | + public void testLastStatement_AutoCommit_Dml() throws SQLException { |
| 889 | + try (Connection connection = createJdbcConnection(); |
| 890 | + Statement statement = connection.createStatement()) { |
| 891 | + statement.executeUpdate(dml); |
| 892 | + } |
| 893 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 894 | + assertTrue(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 895 | + } |
| 896 | + |
| 897 | + @Test |
| 898 | + public void testLastStatement_AutoCommit_DmlReturning() throws SQLException { |
| 899 | + try (Connection connection = createJdbcConnection(); |
| 900 | + Statement statement = connection.createStatement()) { |
| 901 | + //noinspection EmptyTryBlock |
| 902 | + try (ResultSet ignore = statement.executeQuery(dmlReturning)) { |
| 903 | + } |
| 904 | + } |
| 905 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 906 | + assertTrue(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 907 | + } |
| 908 | + |
| 909 | + @Test |
| 910 | + public void testLastStatement_AutoCommit_BatchDml() throws SQLException { |
| 911 | + try (Connection connection = createJdbcConnection(); |
| 912 | + Statement statement = connection.createStatement()) { |
| 913 | + statement.addBatch(dml); |
| 914 | + statement.addBatch(dml); |
| 915 | + statement.executeBatch(); |
| 916 | + } |
| 917 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteBatchDmlRequest.class)); |
| 918 | + assertTrue(mockSpanner.getRequestsOfType(ExecuteBatchDmlRequest.class).get(0).getLastStatements()); |
| 919 | + } |
| 920 | + |
| 921 | + @Test |
| 922 | + public void testLastStatement_Transaction_Query() throws SQLException { |
| 923 | + try (Connection connection = createJdbcConnection(); |
| 924 | + Statement statement = connection.createStatement()) { |
| 925 | + connection.setAutoCommit(false); |
| 926 | + //noinspection EmptyTryBlock |
| 927 | + try (ResultSet ignore = statement.executeQuery(query)) { |
| 928 | + } |
| 929 | + connection.commit(); |
| 930 | + } |
| 931 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 932 | + assertFalse(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 933 | + } |
| 934 | + |
| 935 | + @Test |
| 936 | + public void testLastStatement_Transaction_Dml() throws SQLException { |
| 937 | + try (Connection connection = createJdbcConnection(); |
| 938 | + Statement statement = connection.createStatement()) { |
| 939 | + connection.setAutoCommit(false); |
| 940 | + statement.executeUpdate(dml); |
| 941 | + connection.commit(); |
| 942 | + } |
| 943 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 944 | + assertFalse(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 945 | + } |
| 946 | + |
| 947 | + @Test |
| 948 | + public void testLastStatement_Transaction_DmlReturning() throws SQLException { |
| 949 | + try (Connection connection = createJdbcConnection(); |
| 950 | + Statement statement = connection.createStatement()) { |
| 951 | + connection.setAutoCommit(false); |
| 952 | + //noinspection EmptyTryBlock |
| 953 | + try (ResultSet ignore = statement.executeQuery(dmlReturning)) { |
| 954 | + } |
| 955 | + connection.commit(); |
| 956 | + } |
| 957 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class)); |
| 958 | + assertFalse(mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0).getLastStatement()); |
| 959 | + } |
| 960 | + |
| 961 | + @Test |
| 962 | + public void testLastStatement_Transaction_BatchDml() throws SQLException { |
| 963 | + try (Connection connection = createJdbcConnection(); |
| 964 | + Statement statement = connection.createStatement()) { |
| 965 | + connection.setAutoCommit(false); |
| 966 | + statement.addBatch(dml); |
| 967 | + statement.addBatch(dml); |
| 968 | + statement.executeBatch(); |
| 969 | + connection.commit(); |
| 970 | + } |
| 971 | + assertEquals(1, mockSpanner.countRequestsOfType(ExecuteBatchDmlRequest.class)); |
| 972 | + assertFalse(mockSpanner.getRequestsOfType(ExecuteBatchDmlRequest.class).get(0).getLastStatements()); |
| 973 | + } |
873 | 974 | } |
0 commit comments