kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 174fb0a64d43861db099b5feb4a46d53a4812327781e2fe3494b975fe81af665 |
|---|---|
| Author | Smirnov Danil <d.smirnov@hh.ru> · 2016-05-04 20:33 +03:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-05-11 11:24 -07:00 |
| Parents | 2529393d3013 |
5 files changed
modified changelog/README.md +1 −0
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | - [bug] JAVA-1179: Request objects should be copied when executed. |
| 6 | 6 | - [improvement] JAVA-1182: Throw error when synchronous call made on I/O thread. |
| 7 | +- [bug] JAVA-1184: Unwrap StatementWrappers when extracting column definitions. | |
| 7 | 8 | |
| 8 | 9 | |
| 9 | 10 | ### 2.0.12.1 |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +3 −0
| @@ -59,6 +59,9 @@ | ||
| 59 | 59 | |
| 60 | 60 | ColumnDefinitions columnDefs; |
| 61 | 61 | if (r.metadata.columns == null) { |
| 62 | + if (statement instanceof StatementWrapper) { | |
| 63 | + statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 64 | + } | |
| 62 | 65 | assert statement instanceof BoundStatement; |
| 63 | 66 | columnDefs = ((BoundStatement) statement).statement.getPreparedId().resultSetMetadata; |
| 64 | 67 | assert columnDefs != null; |
modified driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java +3 −0
| @@ -118,6 +118,9 @@ | ||
| 118 | 118 | * of statements for a BatchStatement allowed by the underlying protocol). |
| 119 | 119 | */ |
| 120 | 120 | public BatchStatement add(Statement statement) { |
| 121 | + if (statement instanceof StatementWrapper) { | |
| 122 | + statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 123 | + } | |
| 121 | 124 | |
| 122 | 125 | // We handle BatchStatement here (rather than in getIdAndValues) as it make it slightly |
| 123 | 126 | // easier to avoid endless loop if the use mistakenly pass a batch that depends on this |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +1 −1
| @@ -143,7 +143,7 @@ | ||
| 143 | 143 | setException(new DriverInternalError(String.format("Got unexpected %s response from %s", response.type, connection.address))); |
| 144 | 144 | break; |
| 145 | 145 | } |
| 146 | - } catch (RuntimeException e) { | |
| 146 | + } catch (Throwable e) { | |
| 147 | 147 | // If we get a bug here, the client will not get it, so better forwarding the error |
| 148 | 148 | setException(new DriverInternalError("Unexpected error while processing response from " + connection.address, e)); |
| 149 | 149 | } |
modified driver-core/src/test/java/com/datastax/driver/core/StatementWrapperTest.java +58 −1
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.policies.*; |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 19 | 20 | import com.google.common.collect.Lists; |
| 20 | 21 | import org.testng.annotations.Test; |
| 21 | 22 | |
| @@ -26,9 +27,15 @@ | ||
| 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
| 27 | 28 | |
| 28 | 29 | public class StatementWrapperTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | + | |
| 31 | + private static final String INSERT_QUERY = "insert into test (k, v) values (?, ?)"; | |
| 32 | + private static final String SELECT_QUERY = "select * from test where k = ?"; | |
| 33 | + | |
| 29 | 34 | @Override |
| 30 | 35 | protected Collection<String> getTableDefinitions() { |
| 31 | - return Lists.newArrayList(); | |
| 36 | + return Lists.newArrayList( | |
| 37 | + "create table test (k text primary key, v int)" | |
| 38 | + ); | |
| 32 | 39 | } |
| 33 | 40 | |
| 34 | 41 | CustomLoadBalancingPolicy loadBalancingPolicy = new CustomLoadBalancingPolicy(); |
| @@ -83,6 +90,56 @@ | ||
| 83 | 90 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); |
| 84 | 91 | } |
| 85 | 92 | |
| 93 | + @CassandraVersion(major=2.0) | |
| 94 | + @Test(groups = "short") | |
| 95 | + public void should_execute_wrapped_simple_statement() { | |
| 96 | + session.execute(new CustomStatement(new SimpleStatement(INSERT_QUERY, "key_simple", 1))); | |
| 97 | + | |
| 98 | + ResultSet rs = session.execute(new CustomStatement(new SimpleStatement(SELECT_QUERY, "key_simple"))); | |
| 99 | + assertThat(rs.one().getInt("v")).isEqualTo(1); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Test(groups = "short") | |
| 103 | + public void should_execute_wrapped_bound_statement() { | |
| 104 | + PreparedStatement preparedStatement = session.prepare(new SimpleStatement(INSERT_QUERY)); | |
| 105 | + session.execute(new CustomStatement(preparedStatement.bind("key_bound", 1))); | |
| 106 | + | |
| 107 | + preparedStatement = session.prepare(new SimpleStatement(SELECT_QUERY)); | |
| 108 | + ResultSet rs = session.execute(new CustomStatement(preparedStatement.bind("key_bound"))); | |
| 109 | + assertThat(rs.one().getInt("v")).isEqualTo(1); | |
| 110 | + } | |
| 111 | + | |
| 112 | + @CassandraVersion(major=2.0) | |
| 113 | + @Test(groups = "short") | |
| 114 | + public void should_execute_wrapped_batch_statement() { | |
| 115 | + BatchStatement batchStatement = new BatchStatement(); | |
| 116 | + batchStatement.add(new SimpleStatement(INSERT_QUERY, "key_batch", 1)); | |
| 117 | + | |
| 118 | + session.execute(new CustomStatement(batchStatement)); | |
| 119 | + | |
| 120 | + ResultSet rs = session.execute(SELECT_QUERY, "key_batch"); | |
| 121 | + assertThat(rs.one().getInt("v")).isEqualTo(1); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @CassandraVersion(major=2.0) | |
| 125 | + @Test(groups = "short") | |
| 126 | + public void should_add_wrapped_batch_statement_to_batch_statement() { | |
| 127 | + BatchStatement batchStatementForWrapping = new BatchStatement(); | |
| 128 | + batchStatementForWrapping.add(new SimpleStatement(INSERT_QUERY, "key1", 1)); | |
| 129 | + | |
| 130 | + BatchStatement batchStatement = new BatchStatement(); | |
| 131 | + batchStatement.add(new CustomStatement(new SimpleStatement(INSERT_QUERY, "key2", 2))); | |
| 132 | + batchStatement.add(new CustomStatement(batchStatementForWrapping)); | |
| 133 | + | |
| 134 | + session.execute(batchStatement); | |
| 135 | + | |
| 136 | + ResultSet rs = session.execute(SELECT_QUERY, "key1"); | |
| 137 | + assertThat(rs.one().getInt("v")).isEqualTo(1); | |
| 138 | + | |
| 139 | + rs = session.execute(SELECT_QUERY, "key2"); | |
| 140 | + assertThat(rs.one().getInt("v")).isEqualTo(2); | |
| 141 | + } | |
| 142 | + | |
| 86 | 143 | /** |
| 87 | 144 | * A custom wrapper that's just used to mark statements. |
| 88 | 145 | */ |