kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | db6abd0a7648194566a6269dedf474b950c651895aab56b3a60f9c88710d60e1 |
|---|---|
| Author | Alexandre Dutra <alexdut@gmail.com> · 2015-06-11 14:46 +02:00 |
| Committer | Alexandre Dutra <alexdut@gmail.com> · 2015-06-11 14:46 +02:00 |
| Parents | 69d85ad116db, e2d9ac348058 |
2 files changed
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 |