kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 4978bf2a395d5e2254025a0a847b41317cf155492d3ac53036655e8a44975601 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-06-30 17:11 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-06-30 17:11 +02:00 |
| Parents | ea7f986172f9 |
4 files changed
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +6 −2
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | import com.google.common.base.Strings; |
| 28 | 28 | |
| 29 | 29 | import com.datastax.driver.core.ConsistencyLevel; |
| 30 | +import com.datastax.driver.core.ProtocolVersion; | |
| 30 | 31 | import com.datastax.driver.mapping.MethodMapper.EnumParamMapper; |
| 31 | 32 | import com.datastax.driver.mapping.MethodMapper.NestedUDTParamMapper; |
| 32 | 33 | import com.datastax.driver.mapping.MethodMapper.ParamMapper; |
| @@ -74,7 +75,10 @@ | ||
| 74 | 75 | for (Field field : entityClass.getDeclaredFields()) { |
| 75 | 76 | if(field.isSynthetic() || (field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) |
| 76 | 77 | continue; |
| 77 | - | |
| 78 | + | |
| 79 | + if (!mappingManager.supportsAliases && field.getAnnotation(Computed.class) != null) | |
| 80 | + throw new UnsupportedOperationException("Computed fields are not supported with native protocol v1"); | |
| 81 | + | |
| 78 | 82 | AnnotationChecks.validateAnnotations(field, "entity", |
| 79 | 83 | Column.class, ClusteringColumn.class, Enumerated.class, Frozen.class, FrozenKey.class, |
| 80 | 84 | FrozenValue.class, PartitionKey.class, Transient.class, Computed.class); |
| @@ -95,7 +99,7 @@ | ||
| 95 | 99 | } |
| 96 | 100 | } |
| 97 | 101 | |
| 98 | - AtomicInteger columnCounter = new AtomicInteger(0); | |
| 102 | + AtomicInteger columnCounter = mappingManager.supportsAliases ? new AtomicInteger(0) : null; | |
| 99 | 103 | |
| 100 | 104 | Collections.sort(pks, fieldComparator); |
| 101 | 105 | Collections.sort(ccs, fieldComparator); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Mapper.java +4 −2
| @@ -27,8 +27,8 @@ | ||
| 27 | 27 | import org.slf4j.LoggerFactory; |
| 28 | 28 | |
| 29 | 29 | import com.datastax.driver.core.*; |
| 30 | -import com.datastax.driver.mapping.annotations.Computed; | |
| 31 | 30 | import com.datastax.driver.mapping.annotations.Accessor; |
| 31 | +import com.datastax.driver.mapping.annotations.Computed; | |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * An object handling the mapping of a particular class. |
| @@ -327,7 +327,9 @@ | ||
| 327 | 327 | * @see #map(ResultSet) |
| 328 | 328 | */ |
| 329 | 329 | public Result<T> mapAliased(ResultSet resultSet) { |
| 330 | - return new Result<T>(resultSet, mapper, protocolVersion, true); | |
| 330 | + return (manager.supportsAliases) | |
| 331 | + ? new Result<T>(resultSet, mapper, protocolVersion, true) | |
| 332 | + : map(resultSet); | |
| 331 | 333 | } |
| 332 | 334 | |
| 333 | 335 | /** |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/MappingManager.java +7 −0
| @@ -32,6 +32,7 @@ | ||
| 32 | 32 | public class MappingManager { |
| 33 | 33 | |
| 34 | 34 | private final Session session; |
| 35 | + final boolean supportsAliases; | |
| 35 | 36 | |
| 36 | 37 | private volatile Map<Class<?>, Mapper<?>> mappers = Collections.<Class<?>, Mapper<?>>emptyMap(); |
| 37 | 38 | private volatile Map<Class<?>, UDTMapper<?>> udtMappers = Collections.<Class<?>, UDTMapper<?>>emptyMap(); |
| @@ -44,6 +45,12 @@ | ||
| 44 | 45 | */ |
| 45 | 46 | public MappingManager(Session session) { |
| 46 | 47 | this.session = session; |
| 48 | + | |
| 49 | + ProtocolVersion protocolVersion = session.getCluster().getConfiguration().getProtocolOptions().getProtocolVersionEnum(); | |
| 50 | + // The real condition should be Cassandra version >= 2.0, but mappers need this so that generated queries are compatible, | |
| 51 | + // and we don't know in advance the version of all future peers. | |
| 52 | + // At least if protocol >=2 we know there won't be any 1.2 nodes. | |
| 53 | + this.supportsAliases = (protocolVersion != ProtocolVersion.V1); | |
| 47 | 54 | } |
| 48 | 55 | |
| 49 | 56 | /** |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperComputedFieldsTest.java +2 −0
| @@ -25,6 +25,7 @@ | ||
| 25 | 25 | |
| 26 | 26 | import com.datastax.driver.core.*; |
| 27 | 27 | import com.datastax.driver.core.exceptions.InvalidQueryException; |
| 28 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 28 | 29 | import com.datastax.driver.mapping.annotations.*; |
| 29 | 30 | |
| 30 | 31 | import static com.datastax.driver.core.Assertions.assertThat; |
| @@ -34,6 +35,7 @@ | ||
| 34 | 35 | * annotation to map computed fields. |
| 35 | 36 | */ |
| 36 | 37 | @SuppressWarnings("unused") |
| 38 | +@CassandraVersion(major = 2.0) | |
| 37 | 39 | public class MapperComputedFieldsTest extends CCMBridge.PerClassSingleNodeCluster { |
| 38 | 40 | |
| 39 | 41 | @Override |