kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 03c6ab42daf56b2c91b4d31ec317981017fce88acc8fad1c3ccb46fd16348c25 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:29 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:29 +02:00 |
| Parents | 39b978b2db6d, 4c6dd1e29c05 |
5 files changed
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/QueryBuilder.java +1 −5
| @@ -227,11 +227,7 @@ | ||
| 227 | 227 | * @return the quoted column name. |
| 228 | 228 | */ |
| 229 | 229 | public static String quote(String columnName) { |
| 230 | - StringBuilder sb = new StringBuilder(); | |
| 231 | - sb.append('"'); | |
| 232 | - Utils.appendName(columnName, sb); | |
| 233 | - sb.append('"'); | |
| 234 | - return sb.toString(); | |
| 230 | + return '"' + columnName + '"'; | |
| 235 | 231 | } |
| 236 | 232 | |
| 237 | 233 | /** |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java +4 −1
| @@ -59,11 +59,14 @@ | ||
| 59 | 59 | return sb; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - // Returns null if it's not really serializable (function call, bind markers, ...) | |
| 62 | + // Returns false if it's not really serializable (function call, bind markers, ...) | |
| 63 | 63 | static boolean isSerializable(Object value) { |
| 64 | 64 | if (value instanceof BindMarker || value instanceof FCall || value instanceof CName) |
| 65 | 65 | return false; |
| 66 | 66 | |
| 67 | + if (value instanceof RawString) | |
| 68 | + return false; | |
| 69 | + | |
| 67 | 70 | // We also don't serialize fixed size number types. The reason is that if we do it, we will |
| 68 | 71 | // force a particular size (4 bytes for ints, ...) and for the query builder, we don't want |
| 69 | 72 | // users to have to bother with that. |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +94 −46
| @@ -55,10 +55,10 @@ | ||
| 55 | 55 | |
| 56 | 56 | query = "SELECT a,b,\"C\" FROM foo WHERE a IN ('127.0.0.1','127.0.0.3') AND \"C\"='foo' ORDER BY a ASC,b DESC LIMIT 42;"; |
| 57 | 57 | select = select("a", "b", quote("C")).from("foo") |
| 58 | - .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 59 | - .and(eq(quote("C"), "foo")) | |
| 60 | - .orderBy(asc("a"), desc("b")) | |
| 61 | - .limit(42); | |
| 58 | + .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) | |
| 59 | + .and(eq(quote("C"), "foo")) | |
| 60 | + .orderBy(asc("a"), desc("b")) | |
| 61 | + .limit(42); | |
| 62 | 62 | assertEquals(select.toString(), query); |
| 63 | 63 | |
| 64 | 64 | query = "SELECT writetime(a),ttl(a) FROM foo ALLOW FILTERING;"; |
| @@ -124,35 +124,35 @@ | ||
| 124 | 124 | assertEquals(select.toString(), query); |
| 125 | 125 | |
| 126 | 126 | try { |
| 127 | - select = select().countAll().from("foo").orderBy(asc("a"), desc("b")).orderBy(asc("a"), desc("b")); | |
| 127 | + select().countAll().from("foo").orderBy(asc("a"), desc("b")).orderBy(asc("a"), desc("b")); | |
| 128 | 128 | fail(); |
| 129 | 129 | } catch (IllegalStateException e) { |
| 130 | 130 | assertEquals(e.getMessage(), "An ORDER BY clause has already been provided"); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | try { |
| 134 | - select = select().column("a").all().from("foo"); | |
| 134 | + select().column("a").all().from("foo"); | |
| 135 | 135 | fail(); |
| 136 | 136 | } catch (IllegalStateException e) { |
| 137 | 137 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | try { |
| 141 | - select = select().column("a").countAll().from("foo"); | |
| 141 | + select().column("a").countAll().from("foo"); | |
| 142 | 142 | fail(); |
| 143 | 143 | } catch (IllegalStateException e) { |
| 144 | 144 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | try { |
| 148 | - select = select().all().from("foo").limit(-42); | |
| 148 | + select().all().from("foo").limit(-42); | |
| 149 | 149 | fail(); |
| 150 | 150 | } catch (IllegalArgumentException e) { |
| 151 | 151 | assertEquals(e.getMessage(), "Invalid LIMIT value, must be strictly positive"); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | try { |
| 155 | - select = select().all().from("foo").limit(42).limit(42); | |
| 155 | + select().all().from("foo").limit(42).limit(42); | |
| 156 | 156 | fail(); |
| 157 | 157 | } catch (IllegalStateException e) { |
| 158 | 158 | assertEquals(e.getMessage(), "A LIMIT value has already been provided"); |
| @@ -168,48 +168,67 @@ | ||
| 168 | 168 | |
| 169 | 169 | query = "INSERT INTO foo(a,b,\"C\",d) VALUES (123,'127.0.0.1','foo''bar',{'x':3,'y':2}) USING TIMESTAMP 42 AND TTL 24;"; |
| 170 | 170 | insert = insertInto("foo") |
| 171 | - .value("a", 123) | |
| 172 | - .value("b", InetAddress.getByName("127.0.0.1")) | |
| 173 | - .value(quote("C"), "foo'bar") | |
| 174 | - .value("d", new TreeMap<String, Integer>(){{ put("x", 3); put("y", 2); }}) | |
| 175 | - .using(timestamp(42)).and(ttl(24)); | |
| 171 | + .value("a", 123) | |
| 172 | + .value("b", InetAddress.getByName("127.0.0.1")) | |
| 173 | + .value(quote("C"), "foo'bar") | |
| 174 | + .value("d", new TreeMap<String, Integer>() {{ | |
| 175 | + put("x", 3); | |
| 176 | + put("y", 2); | |
| 177 | + }}) | |
| 178 | + .using(timestamp(42)).and(ttl(24)); | |
| 176 | 179 | assertEquals(insert.toString(), query); |
| 177 | 180 | |
| 178 | 181 | query = "INSERT INTO foo(a,b) VALUES (2,null);"; |
| 179 | 182 | insert = insertInto("foo") |
| 180 | - .value("a", 2) | |
| 181 | - .value("b", null); | |
| 183 | + .value("a", 2) | |
| 184 | + .value("b", null); | |
| 182 | 185 | assertEquals(insert.toString(), query); |
| 183 | 186 | |
| 184 | 187 | query = "INSERT INTO foo(a,b) VALUES ({2,3,4},3.4) USING TTL 24 AND TIMESTAMP 42;"; |
| 185 | - insert = insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 188 | + insert = insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 189 | + add(2); | |
| 190 | + add(3); | |
| 191 | + add(4); | |
| 192 | + }}, 3.4 }).using(ttl(24)).and(timestamp(42)); | |
| 186 | 193 | assertEquals(insert.toString(), query); |
| 187 | 194 | |
| 188 | 195 | query = "INSERT INTO foo.bar(a,b) VALUES ({2,3,4},3.4) USING TTL ? AND TIMESTAMP ?;"; |
| 189 | 196 | insert = insertInto("foo", "bar") |
| 190 | - .values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 }) | |
| 191 | - .using(ttl(bindMarker())) | |
| 192 | - .and(timestamp(bindMarker())); | |
| 197 | + .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 198 | + add(2); | |
| 199 | + add(3); | |
| 200 | + add(4); | |
| 201 | + }}, 3.4 }) | |
| 202 | + .using(ttl(bindMarker())) | |
| 203 | + .and(timestamp(bindMarker())); | |
| 193 | 204 | assertEquals(insert.toString(), query); |
| 194 | 205 | |
| 195 | 206 | // commutative result of TIMESTAMP |
| 196 | 207 | query = "INSERT INTO foo.bar(a,b,c) VALUES ({2,3,4},3.4,123) USING TIMESTAMP 42;"; |
| 197 | 208 | insert = insertInto("foo", "bar") |
| 198 | - .using(timestamp(42)) | |
| 199 | - .values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 }) | |
| 200 | - .value("c", 123); | |
| 209 | + .using(timestamp(42)) | |
| 210 | + .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 211 | + add(2); | |
| 212 | + add(3); | |
| 213 | + add(4); | |
| 214 | + }}, 3.4 }) | |
| 215 | + .value("c", 123); | |
| 201 | 216 | assertEquals(insert.toString(), query); |
| 202 | 217 | |
| 203 | 218 | // commutative result of value() and values() |
| 204 | 219 | query = "INSERT INTO foo(c,a,b) VALUES (123,{2,3,4},3.4) USING TIMESTAMP 42;"; |
| 205 | 220 | insert = insertInto("foo") |
| 206 | - .using(timestamp(42)) | |
| 207 | - .value("c", 123) | |
| 208 | - .values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 }); | |
| 221 | + .using(timestamp(42)) | |
| 222 | + .value("c", 123) | |
| 223 | + .values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 224 | + add(2); | |
| 225 | + add(3); | |
| 226 | + add(4); | |
| 227 | + }}, 3.4 }); | |
| 209 | 228 | assertEquals(insert.toString(), query); |
| 210 | 229 | |
| 211 | 230 | try { |
| 212 | - insert = insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ 1, 2, 3 }); | |
| 231 | + insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ 1, 2, 3 }); | |
| 213 | 232 | fail(); |
| 214 | 233 | } catch (IllegalArgumentException e) { |
| 215 | 234 | assertEquals(e.getMessage(), "Got 2 names but 3 values"); |
| @@ -251,20 +270,31 @@ | ||
| 251 | 270 | assertEquals(update.toString(), query); |
| 252 | 271 | |
| 253 | 272 | query = "UPDATE foo SET b=b-[1,2,3],c=c+{1},d=d+{2,3,4};"; |
| 254 | - update = update("foo").with(discardAll("b", Arrays.asList(1, 2, 3))).and(add("c", 1)).and(addAll("d", new TreeSet<Integer>(){{ add(2); add(3); add(4); }})); | |
| 273 | + update = update("foo").with(discardAll("b", Arrays.asList(1, 2, 3))).and(add("c", 1)).and(addAll("d", new TreeSet<Integer>() {{ | |
| 274 | + add(2); | |
| 275 | + add(3); | |
| 276 | + add(4); | |
| 277 | + }})); | |
| 255 | 278 | assertEquals(update.toString(), query); |
| 256 | 279 | |
| 257 | 280 | query = "UPDATE foo SET b=b-{2,3,4},c['k']='v',d=d+{'x':3,'y':2};"; |
| 258 | - update = update("foo").with(removeAll("b", new TreeSet<Integer>(){{ add(2); add(3); add(4); }})) | |
| 259 | - .and(put("c", "k", "v")) | |
| 260 | - .and(putAll("d", new TreeMap<String, Integer>(){{ put("x", 3); put("y", 2); }})); | |
| 281 | + update = update("foo").with(removeAll("b", new TreeSet<Integer>() {{ | |
| 282 | + add(2); | |
| 283 | + add(3); | |
| 284 | + add(4); | |
| 285 | + }})) | |
| 286 | + .and(put("c", "k", "v")) | |
| 287 | + .and(putAll("d", new TreeMap<String, Integer>() {{ | |
| 288 | + put("x", 3); | |
| 289 | + put("y", 2); | |
| 290 | + }})); | |
| 261 | 291 | assertEquals(update.toString(), query); |
| 262 | 292 | |
| 263 | 293 | query = "UPDATE foo USING TTL 400;"; |
| 264 | 294 | update = update("foo").using(ttl(400)); |
| 265 | 295 | assertEquals(update.toString(), query); |
| 266 | 296 | |
| 267 | - query = "UPDATE foo SET a="+new BigDecimal(3.2)+",b=42 WHERE k=2;"; | |
| 297 | + query = "UPDATE foo SET a=" + new BigDecimal(3.2) + ",b=42 WHERE k=2;"; | |
| 268 | 298 | update = update("foo").with(set("a", new BigDecimal(3.2))).and(set("b", new BigInteger("42"))).where(eq("k", 2)); |
| 269 | 299 | assertEquals(update.toString(), query); |
| 270 | 300 | |
| @@ -281,7 +311,7 @@ | ||
| 281 | 311 | assertEquals(update.toString(), query); |
| 282 | 312 | |
| 283 | 313 | try { |
| 284 | - update = update("foo").using(ttl(-400)); | |
| 314 | + update("foo").using(ttl(-400)); | |
| 285 | 315 | fail(); |
| 286 | 316 | } catch (IllegalArgumentException e) { |
| 287 | 317 | assertEquals(e.getMessage(), "Invalid ttl, must be positive"); |
| @@ -327,14 +357,14 @@ | ||
| 327 | 357 | assertEquals(delete.toString(), query); |
| 328 | 358 | |
| 329 | 359 | try { |
| 330 | - delete = delete().column("a").all().from("foo"); | |
| 360 | + delete().column("a").all().from("foo"); | |
| 331 | 361 | fail(); |
| 332 | 362 | } catch (IllegalStateException e) { |
| 333 | 363 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 334 | 364 | } |
| 335 | 365 | |
| 336 | 366 | try { |
| 337 | - delete = delete().from("foo").using(timestamp(-1240003134L)); | |
| 367 | + delete().from("foo").using(timestamp(-1240003134L)); | |
| 338 | 368 | fail(); |
| 339 | 369 | } catch (IllegalArgumentException e) { |
| 340 | 370 | assertEquals(e.getMessage(), "Invalid timestamp, must be positive"); |
| @@ -365,7 +395,11 @@ | ||
| 365 | 395 | query += "DELETE a[3],b['foo'],c FROM foo WHERE k=1;"; |
| 366 | 396 | query += "APPLY BATCH;"; |
| 367 | 397 | batch = batch() |
| 368 | - .add(insertInto("foo").values(new String[]{ "a", "b"}, new Object[]{ new TreeSet<Integer>(){{ add(2); add(3); add(4); }}, 3.4 })) | |
| 398 | + .add(insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ new TreeSet<Integer>() {{ | |
| 399 | + add(2); | |
| 400 | + add(3); | |
| 401 | + add(4); | |
| 402 | + }}, 3.4 })) | |
| 369 | 403 | .add(update("foo").with(setIdx("a", 2, "foo")).and(prependAll("b", Arrays.asList(3, 2, 1))).and(remove("c", "a")).where(eq("k", 2))) |
| 370 | 404 | .add(delete().listElt("a", 3).mapElt("b", "foo").column("c").from("foo").where(eq("k", 1))) |
| 371 | 405 | .using(timestamp(42)); |
| @@ -452,12 +486,9 @@ | ||
| 452 | 486 | assertEquals(batch.toString(), query); |
| 453 | 487 | } |
| 454 | 488 | |
| 455 | - @Test(groups = "unit", expectedExceptions={IllegalArgumentException.class}) | |
| 489 | + @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) | |
| 456 | 490 | public void batchMixedCounterTest() throws Exception { |
| 457 | - String query; | |
| 458 | - Statement batch; | |
| 459 | - | |
| 460 | - batch = batch() | |
| 491 | + batch() | |
| 461 | 492 | .add(update("foo").with(incr("a", 1))) |
| 462 | 493 | .add(update("foo").with(set("b", 2))) |
| 463 | 494 | .add(update("foo").with(incr("c", 3))) |
| @@ -471,8 +502,8 @@ | ||
| 471 | 502 | |
| 472 | 503 | query = "INSERT INTO test(k,c) VALUES (0,?);"; |
| 473 | 504 | insert = insertInto("test") |
| 474 | - .value("k", 0) | |
| 475 | - .value("c", bindMarker()); | |
| 505 | + .value("k", 0) | |
| 506 | + .value("c", bindMarker()); | |
| 476 | 507 | assertEquals(insert.toString(), query); |
| 477 | 508 | } |
| 478 | 509 | |
| @@ -499,7 +530,6 @@ | ||
| 499 | 530 | assertEquals(select.toString(), query); |
| 500 | 531 | } |
| 501 | 532 | |
| 502 | - | |
| 503 | 533 | @Test(groups = "unit") |
| 504 | 534 | public void selectInjectionTests() throws Exception { |
| 505 | 535 | |
| @@ -631,7 +661,7 @@ | ||
| 631 | 661 | |
| 632 | 662 | query = "DELETE a,b FROM foo WHERE a IN ('b','c''); --comment');"; |
| 633 | 663 | delete = delete("a", "b").from("foo") |
| 634 | - .where(in("a", "b", "c'); --comment")); | |
| 664 | + .where(in("a", "b", "c'); --comment")); | |
| 635 | 665 | assertEquals(delete.toString(), query); |
| 636 | 666 | |
| 637 | 667 | query = "DELETE FROM foo WHERE \"k=1 OR k\">42;"; |
| @@ -660,6 +690,7 @@ | ||
| 660 | 690 | public void rejectUnknownValueTest() throws Exception { |
| 661 | 691 | |
| 662 | 692 | try { |
| 693 | + //noinspection ResultOfMethodCallIgnored | |
| 663 | 694 | update("foo").with(set("a", new byte[13])).where(eq("k", 2)).toString(); |
| 664 | 695 | fail("Byte arrays should not be valid, ByteBuffer should be used instead"); |
| 665 | 696 | } catch (IllegalArgumentException e) { |
| @@ -705,7 +736,7 @@ | ||
| 705 | 736 | |
| 706 | 737 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)>=('a',2) AND (c1,c2)<('b',0);"; |
| 707 | 738 | select = select().all().from("foo").where(eq("k", 4)).and(gte(Arrays.asList("c1", "c2"), Arrays.<Object>asList("a", 2))) |
| 708 | - .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 739 | + .and(lt(Arrays.asList("c1", "c2"), Arrays.<Object>asList("b", 0))); | |
| 709 | 740 | assertEquals(select.toString(), query); |
| 710 | 741 | |
| 711 | 742 | query = "SELECT * FROM foo WHERE k=4 AND (c1,c2)<=('a',2);"; |
| @@ -790,5 +821,22 @@ | ||
| 790 | 821 | update("foo").with(append("l", bindMarker())).where(eq("k", 1)); |
| 791 | 822 | fail("Expected an exception"); |
| 792 | 823 | } catch (InvalidQueryException e) { /*expected*/ } |
| 824 | + | |
| 825 | + } | |
| 826 | + | |
| 827 | + @Test(groups = "unit") | |
| 828 | + public void should_quote_complex_column_names() { | |
| 829 | + // A column name can be anything as long as it's quoted, so "foo.bar" is a valid name | |
| 830 | + String query = "SELECT * FROM foo WHERE \"foo.bar\"=1;"; | |
| 831 | + Statement statement = select().from("foo").where(eq(quote("foo.bar"), 1)); | |
| 832 | + | |
| 833 | + assertThat(statement.toString()).isEqualTo(query); | |
| 834 | + } | |
| 835 | + | |
| 836 | + @Test(groups = "unit") | |
| 837 | + public void should_not_serialize_raw_query_values() { | |
| 838 | + RegularStatement select = select().from("test").where(gt("i", raw("1"))); | |
| 839 | + assertThat(select.getQueryString()).doesNotContain("?"); | |
| 840 | + assertThat(select.getValues(ProtocolVersion.V3)).isNull(); | |
| 793 | 841 | } |
| 794 | 842 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Enumerated.java +1 −1
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | * The optional {@link EnumType} value defined how the enumeration must be |
| 30 | 30 | * persisted. |
| 31 | 31 | */ |
| 32 | -@Target(ElementType.FIELD) | |
| 32 | +@Target(value = {ElementType.FIELD, ElementType.PARAMETER}) | |
| 33 | 33 | @Retention(RetentionPolicy.RUNTIME) |
| 34 | 34 | public @interface Enumerated { |
| 35 | 35 | /** |
added driver-mapping/src/test/java/com/datastax/driver/mapping/MapperAccessorParamsTest.java +90 −0
| @@ -0,0 +1,90 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.mapping; | |
| 17 | + | |
| 18 | +import java.util.Collection; | |
| 19 | + | |
| 20 | +import com.google.common.collect.Lists; | |
| 21 | +import org.testng.annotations.Test; | |
| 22 | + | |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 24 | + | |
| 25 | +import com.datastax.driver.core.CCMBridge; | |
| 26 | +import com.datastax.driver.mapping.annotations.*; | |
| 27 | + | |
| 28 | +public class MapperAccessorParamsTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 29 | + @Override | |
| 30 | + protected Collection<String> getTableDefinitions() { | |
| 31 | + return Lists.newArrayList("CREATE TABLE user ( key int primary key, gender int)", | |
| 32 | + "CREATE INDEX on user(gender)"); | |
| 33 | + | |
| 34 | + } | |
| 35 | + | |
| 36 | + @Test(groups = "short") | |
| 37 | + void should_include_enumtype_in_accessor() { | |
| 38 | + Mapper<User> userMapper = new MappingManager(session).mapper(User.class); | |
| 39 | + userMapper.save(new User(1, 0)); | |
| 40 | + userMapper.save(new User(2, 1)); | |
| 41 | + | |
| 42 | + UserAccessor accessor = new MappingManager(session) | |
| 43 | + .createAccessor(UserAccessor.class); | |
| 44 | + assertThat(accessor.getUser(Enum.MALE).one().getGender()).isEqualTo(0); | |
| 45 | + assertThat(accessor.getUser(Enum.MALE).one().getKey()).isEqualTo(1); | |
| 46 | + | |
| 47 | + } | |
| 48 | + | |
| 49 | + enum Enum { | |
| 50 | + MALE, FEMALE | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Accessor | |
| 54 | + public interface UserAccessor { | |
| 55 | + @Query("select * from user where gender=:val") | |
| 56 | + Result<User> getUser(@Param("val") @Enumerated(EnumType.ORDINAL) Enum value); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Table(name = "user") | |
| 60 | + public static class User { | |
| 61 | + @PartitionKey | |
| 62 | + private int key; | |
| 63 | + | |
| 64 | + private int gender; | |
| 65 | + | |
| 66 | + public User() { | |
| 67 | + } | |
| 68 | + | |
| 69 | + public User(int k, int val) { | |
| 70 | + this.key = k; | |
| 71 | + this.gender = val; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public int getKey() { | |
| 75 | + return this.key; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void setKey(int pk) { | |
| 79 | + this.key = pk; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public int getGender() { | |
| 83 | + return this.gender; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setGender(int val) { | |
| 87 | + this.gender = val; | |
| 88 | + } | |
| 89 | + } | |
| 90 | +} | |
| No newline at the end of the file |