Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.1' into java712

Conflicts:
	driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java
Changeset3cc9d8815f070ad35860d870cde0427fa7315b2a629ffceab4430b5bb78c940b
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:13 +02:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-11 15:13 +02:00
Parents9e939f5989a5, 0fc7265fe63e

Browse the files at this changeset

4 files changed

modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java +4 −1
@@ -59,11 +59,14 @@
5959 return sb;
6060 }
6161
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, ...)
6363 static boolean isSerializable(Object value) {
6464 if (value instanceof BindMarker || value instanceof FCall || value instanceof CName)
6565 return false;
6666
67+ if (value instanceof RawString)
68+ return false;
69+
6770 // We also don't serialize fixed size number types. The reason is that if we do it, we will
6871 // force a particular size (4 bytes for ints, ...) and for the query builder, we don't want
6972 // 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 @@
123123 assertEquals(select.toString(), query);
124124
125125 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"));
127127 fail();
128128 } catch (IllegalStateException e) {
129129 assertEquals(e.getMessage(), "An ORDER BY clause has already been provided");
130130 }
131131
132132 try {
133- select = select().column("a").all().from("foo");
133+ select().column("a").all().from("foo");
134134 fail();
135135 } catch (IllegalStateException e) {
136136 assertEquals(e.getMessage(), "Some columns ([a]) have already been selected.");
137137 }
138138
139139 try {
140- select = select().column("a").countAll().from("foo");
140+ select().column("a").countAll().from("foo");
141141 fail();
142142 } catch (IllegalStateException e) {
143143 assertEquals(e.getMessage(), "Some columns ([a]) have already been selected.");
144144 }
145145
146146 try {
147- select = select().all().from("foo").limit(-42);
147+ select().all().from("foo").limit(-42);
148148 fail();
149149 } catch (IllegalArgumentException e) {
150150 assertEquals(e.getMessage(), "Invalid LIMIT value, must be strictly positive");
151151 }
152152
153153 try {
154- select = select().all().from("foo").limit(42).limit(42);
154+ select().all().from("foo").limit(42).limit(42);
155155 fail();
156156 } catch (IllegalStateException e) {
157157 assertEquals(e.getMessage(), "A LIMIT value has already been provided");
@@ -227,7 +227,7 @@
227227 assertEquals(insert.toString(), query);
228228
229229 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 });
231231 fail();
232232 } catch (IllegalArgumentException e) {
233233 assertEquals(e.getMessage(), "Got 2 names but 3 values");
@@ -310,7 +310,7 @@
310310 assertEquals(update.toString(), query);
311311
312312 try {
313- update = update("foo").using(ttl(-400));
313+ update("foo").using(ttl(-400));
314314 fail();
315315 } catch (IllegalArgumentException e) {
316316 assertEquals(e.getMessage(), "Invalid ttl, must be positive");
@@ -356,14 +356,14 @@
356356 assertEquals(delete.toString(), query);
357357
358358 try {
359- delete = delete().column("a").all().from("foo");
359+ delete().column("a").all().from("foo");
360360 fail();
361361 } catch (IllegalStateException e) {
362362 assertEquals(e.getMessage(), "Some columns ([a]) have already been selected.");
363363 }
364364
365365 try {
366- delete = delete().from("foo").using(timestamp(-1240003134L));
366+ delete().from("foo").using(timestamp(-1240003134L));
367367 fail();
368368 } catch (IllegalArgumentException e) {
369369 assertEquals(e.getMessage(), "Invalid timestamp, must be positive");
@@ -487,10 +487,7 @@
487487
488488 @Test(groups = "unit", expectedExceptions = { IllegalArgumentException.class })
489489 public void batchMixedCounterTest() throws Exception {
490- String query;
491- Statement batch;
492-
493- batch = batch()
490+ batch()
494491 .add(update("foo").with(incr("a", 1)))
495492 .add(update("foo").with(set("b", 2)))
496493 .add(update("foo").with(incr("c", 3)))
@@ -692,6 +689,7 @@
692689 public void rejectUnknownValueTest() throws Exception {
693690
694691 try {
692+ //noinspection ResultOfMethodCallIgnored
695693 update("foo").with(set("a", new byte[13])).where(eq("k", 2)).toString();
696694 fail("Byte arrays should not be valid, ByteBuffer should be used instead");
697695 } catch (IllegalArgumentException e) {
@@ -812,4 +810,11 @@
812810
813811 assertThat(statement.toString()).isEqualTo(query);
814812 }
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+ }
815820 }
modified driver-mapping/src/main/java/com/datastax/driver/mapping/annotations/Enumerated.java +1 −1
@@ -29,7 +29,7 @@
2929 * The optional {@link EnumType} value defined how the enumeration must be
3030 * persisted.
3131 */
32-@Target(ElementType.FIELD)
32+@Target(value = {ElementType.FIELD, ElementType.PARAMETER})
3333 @Retention(RetentionPolicy.RUNTIME)
3434 public @interface Enumerated {
3535 /**
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