kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 3cc9d8815f070ad35860d870cde0427fa7315b2a629ffceab4430b5bb78c940b |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:13 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:13 +02:00 |
| Parents | 9e939f5989a5, 0fc7265fe63e |
4 files changed
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 +18 −13
| @@ -123,35 +123,35 @@ | ||
| 123 | 123 | assertEquals(select.toString(), query); |
| 124 | 124 | |
| 125 | 125 | try { |
| 126 | - select = select().countAll().from("foo").orderBy(asc("a"), desc("b")).orderBy(asc("a"), desc("b")); | |
| 126 | + select().countAll().from("foo").orderBy(asc("a"), desc("b")).orderBy(asc("a"), desc("b")); | |
| 127 | 127 | fail(); |
| 128 | 128 | } catch (IllegalStateException e) { |
| 129 | 129 | assertEquals(e.getMessage(), "An ORDER BY clause has already been provided"); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | try { |
| 133 | - select = select().column("a").all().from("foo"); | |
| 133 | + select().column("a").all().from("foo"); | |
| 134 | 134 | fail(); |
| 135 | 135 | } catch (IllegalStateException e) { |
| 136 | 136 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | try { |
| 140 | - select = select().column("a").countAll().from("foo"); | |
| 140 | + select().column("a").countAll().from("foo"); | |
| 141 | 141 | fail(); |
| 142 | 142 | } catch (IllegalStateException e) { |
| 143 | 143 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | try { |
| 147 | - select = select().all().from("foo").limit(-42); | |
| 147 | + select().all().from("foo").limit(-42); | |
| 148 | 148 | fail(); |
| 149 | 149 | } catch (IllegalArgumentException e) { |
| 150 | 150 | assertEquals(e.getMessage(), "Invalid LIMIT value, must be strictly positive"); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | try { |
| 154 | - select = select().all().from("foo").limit(42).limit(42); | |
| 154 | + select().all().from("foo").limit(42).limit(42); | |
| 155 | 155 | fail(); |
| 156 | 156 | } catch (IllegalStateException e) { |
| 157 | 157 | assertEquals(e.getMessage(), "A LIMIT value has already been provided"); |
| @@ -227,7 +227,7 @@ | ||
| 227 | 227 | assertEquals(insert.toString(), query); |
| 228 | 228 | |
| 229 | 229 | try { |
| 230 | - insert = insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ 1, 2, 3 }); | |
| 230 | + insertInto("foo").values(new String[]{ "a", "b" }, new Object[]{ 1, 2, 3 }); | |
| 231 | 231 | fail(); |
| 232 | 232 | } catch (IllegalArgumentException e) { |
| 233 | 233 | assertEquals(e.getMessage(), "Got 2 names but 3 values"); |
| @@ -310,7 +310,7 @@ | ||
| 310 | 310 | assertEquals(update.toString(), query); |
| 311 | 311 | |
| 312 | 312 | try { |
| 313 | - update = update("foo").using(ttl(-400)); | |
| 313 | + update("foo").using(ttl(-400)); | |
| 314 | 314 | fail(); |
| 315 | 315 | } catch (IllegalArgumentException e) { |
| 316 | 316 | assertEquals(e.getMessage(), "Invalid ttl, must be positive"); |
| @@ -356,14 +356,14 @@ | ||
| 356 | 356 | assertEquals(delete.toString(), query); |
| 357 | 357 | |
| 358 | 358 | try { |
| 359 | - delete = delete().column("a").all().from("foo"); | |
| 359 | + delete().column("a").all().from("foo"); | |
| 360 | 360 | fail(); |
| 361 | 361 | } catch (IllegalStateException e) { |
| 362 | 362 | assertEquals(e.getMessage(), "Some columns ([a]) have already been selected."); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | try { |
| 366 | - delete = delete().from("foo").using(timestamp(-1240003134L)); | |
| 366 | + delete().from("foo").using(timestamp(-1240003134L)); | |
| 367 | 367 | fail(); |
| 368 | 368 | } catch (IllegalArgumentException e) { |
| 369 | 369 | assertEquals(e.getMessage(), "Invalid timestamp, must be positive"); |
| @@ -487,10 +487,7 @@ | ||
| 487 | 487 | |
| 488 | 488 | @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class }) |
| 489 | 489 | public void batchMixedCounterTest() throws Exception { |
| 490 | - String query; | |
| 491 | - Statement batch; | |
| 492 | - | |
| 493 | - batch = batch() | |
| 490 | + batch() | |
| 494 | 491 | .add(update("foo").with(incr("a", 1))) |
| 495 | 492 | .add(update("foo").with(set("b", 2))) |
| 496 | 493 | .add(update("foo").with(incr("c", 3))) |
| @@ -692,6 +689,7 @@ | ||
| 692 | 689 | public void rejectUnknownValueTest() throws Exception { |
| 693 | 690 | |
| 694 | 691 | try { |
| 692 | + //noinspection ResultOfMethodCallIgnored | |
| 695 | 693 | update("foo").with(set("a", new byte[13])).where(eq("k", 2)).toString(); |
| 696 | 694 | fail("Byte arrays should not be valid, ByteBuffer should be used instead"); |
| 697 | 695 | } catch (IllegalArgumentException e) { |
| @@ -812,4 +810,11 @@ | ||
| 812 | 810 | |
| 813 | 811 | assertThat(statement.toString()).isEqualTo(query); |
| 814 | 812 | } |
| 813 | + | |
| 814 | + @Test(groups = "unit") | |
| 815 | + public void should_not_serialize_raw_query_values() { | |
| 816 | + RegularStatement select = select().from("test").where(gt("i", raw("1"))); | |
| 817 | + assertThat(select.getQueryString()).doesNotContain("?"); | |
| 818 | + assertThat(select.getValues(ProtocolVersion.V3)).isNull(); | |
| 819 | + } | |
| 815 | 820 | } |
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 |