kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 356657f61364859066a496cb268d4a437ee02662bcd6867322e922bdbd8c4977 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2016-06-01 16:23 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-07-22 09:47 -07:00 |
| Parents | dd37f80f3022 |
11 files changed
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +17 −18
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.ConsistencyLevel; |
| 19 | +import com.datastax.driver.core.Metadata; | |
| 19 | 20 | import com.datastax.driver.core.TableMetadata; |
| 20 | 21 | import com.datastax.driver.core.TypeCodec; |
| 21 | 22 | import com.datastax.driver.core.UserType; |
| @@ -34,8 +35,6 @@ | ||
| 34 | 35 | import java.util.*; |
| 35 | 36 | import java.util.concurrent.atomic.AtomicInteger; |
| 36 | 37 | |
| 37 | -import static com.datastax.driver.core.Metadata.quote; | |
| 38 | - | |
| 39 | 38 | /** |
| 40 | 39 | * Static methods that facilitates parsing: |
| 41 | 40 | * - {@link #parseEntity(Class, MappingManager)}: entity classes into {@link EntityMapper} instances |
| @@ -48,13 +47,13 @@ | ||
| 48 | 47 | @VisibleForTesting |
| 49 | 48 | static final Set<Class<? extends Annotation>> VALID_PROPERTY_ANNOTATIONS = ImmutableSet.of( |
| 50 | 49 | Column.class, |
| 50 | + Computed.class, | |
| 51 | 51 | ClusteringColumn.class, |
| 52 | 52 | Frozen.class, |
| 53 | 53 | FrozenKey.class, |
| 54 | 54 | FrozenValue.class, |
| 55 | 55 | PartitionKey.class, |
| 56 | - Transient.class, | |
| 57 | - Computed.class); | |
| 56 | + Transient.class); | |
| 58 | 57 | |
| 59 | 58 | @VisibleForTesting |
| 60 | 59 | static final Set<Class<? extends Annotation>> VALID_FIELD_ANNOTATIONS = ImmutableSet.of( |
| @@ -77,20 +76,20 @@ | ||
| 77 | 76 | static <T> EntityMapper<T> parseEntity(final Class<T> entityClass, MappingManager mappingManager) { |
| 78 | 77 | Table table = AnnotationChecks.getTypeAnnotation(Table.class, entityClass); |
| 79 | 78 | |
| 80 | - String ksName = table.caseSensitiveKeyspace() ? table.keyspace() : table.keyspace().toLowerCase(); | |
| 81 | - String tableName = table.caseSensitiveTable() ? table.name() : table.name().toLowerCase(); | |
| 79 | + String ksName = table.caseSensitiveKeyspace() ? Metadata.quote(table.keyspace()) : table.keyspace().toLowerCase(); | |
| 80 | + String tableName = table.caseSensitiveTable() ? Metadata.quote(table.name()) : table.name().toLowerCase(); | |
| 82 | 81 | |
| 83 | 82 | ConsistencyLevel writeConsistency = table.writeConsistency().isEmpty() ? null : ConsistencyLevel.valueOf(table.writeConsistency().toUpperCase()); |
| 84 | 83 | ConsistencyLevel readConsistency = table.readConsistency().isEmpty() ? null : ConsistencyLevel.valueOf(table.readConsistency().toUpperCase()); |
| 85 | 84 | |
| 86 | 85 | if (Strings.isNullOrEmpty(table.keyspace())) { |
| 87 | - ksName = mappingManager.getSession().getLoggedKeyspace(); | |
| 88 | - if (Strings.isNullOrEmpty(ksName)) | |
| 86 | + String loggedKeyspace = mappingManager.getSession().getLoggedKeyspace(); | |
| 87 | + if (Strings.isNullOrEmpty(loggedKeyspace)) | |
| 89 | 88 | throw new IllegalArgumentException(String.format( |
| 90 | - "Error creating mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 91 | - entityClass.getSimpleName(), | |
| 92 | - Table.class.getSimpleName() | |
| 89 | + "Error creating mapper for %s, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 90 | + entityClass | |
| 93 | 91 | )); |
| 92 | + ksName = Metadata.quote(loggedKeyspace); | |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | 95 | EntityMapper<T> mapper = new EntityMapper<T>(entityClass, ksName, tableName, writeConsistency, readConsistency); |
| @@ -154,17 +153,17 @@ | ||
| 154 | 153 | static <T> MappedUDTCodec<T> parseUDT(Class<T> udtClass, MappingManager mappingManager) { |
| 155 | 154 | UDT udt = AnnotationChecks.getTypeAnnotation(UDT.class, udtClass); |
| 156 | 155 | |
| 157 | - String ksName = udt.caseSensitiveKeyspace() ? udt.keyspace() : udt.keyspace().toLowerCase(); | |
| 158 | - String udtName = udt.caseSensitiveType() ? quote(udt.name()) : udt.name().toLowerCase(); | |
| 156 | + String ksName = udt.caseSensitiveKeyspace() ? Metadata.quote(udt.keyspace()) : udt.keyspace().toLowerCase(); | |
| 157 | + String udtName = udt.caseSensitiveType() ? Metadata.quote(udt.name()) : udt.name().toLowerCase(); | |
| 159 | 158 | |
| 160 | 159 | if (Strings.isNullOrEmpty(udt.keyspace())) { |
| 161 | - ksName = mappingManager.getSession().getLoggedKeyspace(); | |
| 162 | - if (Strings.isNullOrEmpty(ksName)) | |
| 160 | + String loggedKeyspace = mappingManager.getSession().getLoggedKeyspace(); | |
| 161 | + if (Strings.isNullOrEmpty(loggedKeyspace)) | |
| 163 | 162 | throw new IllegalArgumentException(String.format( |
| 164 | - "Error creating UDT codec for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 165 | - udtClass.getSimpleName(), | |
| 166 | - UDT.class.getSimpleName() | |
| 163 | + "Error creating UDT codec for %s, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 164 | + udtClass | |
| 167 | 165 | )); |
| 166 | + ksName = Metadata.quote(loggedKeyspace); | |
| 168 | 167 | } |
| 169 | 168 | |
| 170 | 169 | UserType userType = mappingManager.getSession().getCluster().getMetadata().getKeyspace(ksName).getUserType(udtName); |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/EntityMapper.java +2 −12
| @@ -20,13 +20,11 @@ | ||
| 20 | 20 | import java.util.ArrayList; |
| 21 | 21 | import java.util.List; |
| 22 | 22 | |
| 23 | -import static com.datastax.driver.core.querybuilder.QueryBuilder.quote; | |
| 24 | - | |
| 25 | 23 | class EntityMapper<T> { |
| 26 | 24 | |
| 27 | 25 | private final Class<T> entityClass; |
| 28 | - private final String keyspace; | |
| 29 | - private final String table; | |
| 26 | + final String keyspace; | |
| 27 | + final String table; | |
| 30 | 28 | |
| 31 | 29 | final ConsistencyLevel writeConsistency; |
| 32 | 30 | final ConsistencyLevel readConsistency; |
| @@ -44,14 +42,6 @@ | ||
| 44 | 42 | this.readConsistency = readConsistency; |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | - String getKeyspace() { | |
| 48 | - return quote(keyspace); | |
| 49 | - } | |
| 50 | - | |
| 51 | - String getTable() { | |
| 52 | - return quote(table); | |
| 53 | - } | |
| 54 | - | |
| 55 | 45 | int primaryKeySize() { |
| 56 | 46 | return partitionKeys.size() + clusteringColumns.size(); |
| 57 | 47 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/MappedUDTCodec.java +4 −8
| @@ -15,7 +15,10 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.mapping; |
| 17 | 17 | |
| 18 | -import com.datastax.driver.core.*; | |
| 18 | +import com.datastax.driver.core.CodecRegistry; | |
| 19 | +import com.datastax.driver.core.ProtocolVersion; | |
| 20 | +import com.datastax.driver.core.TypeCodec; | |
| 21 | +import com.datastax.driver.core.UserType; | |
| 19 | 22 | |
| 20 | 23 | import java.nio.ByteBuffer; |
| 21 | 24 | import java.util.Map; |
| @@ -48,10 +51,6 @@ | ||
| 48 | 51 | |
| 49 | 52 | @Override |
| 50 | 53 | protected ByteBuffer serializeField(T source, String fieldName, ProtocolVersion protocolVersion) { |
| 51 | - // The parent class passes lowercase names unquoted, but in our internal map of mappers they are always quoted | |
| 52 | - if (!fieldName.startsWith("\"")) | |
| 53 | - fieldName = Metadata.quote(fieldName); | |
| 54 | - | |
| 55 | 54 | PropertyMapper propertyMapper = columnMappers.get(fieldName); |
| 56 | 55 | |
| 57 | 56 | if (propertyMapper == null) |
| @@ -68,9 +67,6 @@ | ||
| 68 | 67 | |
| 69 | 68 | @Override |
| 70 | 69 | protected T deserializeAndSetField(ByteBuffer input, T target, String fieldName, ProtocolVersion protocolVersion) { |
| 71 | - if (!fieldName.startsWith("\"")) | |
| 72 | - fieldName = Metadata.quote(fieldName); | |
| 73 | - | |
| 74 | 70 | PropertyMapper propertyMapper = columnMappers.get(fieldName); |
| 75 | 71 | if (propertyMapper != null) { |
| 76 | 72 | TypeCodec<Object> codec = propertyMapper.customCodec; |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Mapper.java +2 −2
| @@ -72,8 +72,8 @@ | ||
| 72 | 72 | this.klass = klass; |
| 73 | 73 | this.mapper = mapper; |
| 74 | 74 | |
| 75 | - KeyspaceMetadata keyspace = session().getCluster().getMetadata().getKeyspace(mapper.getKeyspace()); | |
| 76 | - this.tableMetadata = keyspace == null ? null : keyspace.getTable(mapper.getTable()); | |
| 75 | + KeyspaceMetadata keyspace = session().getCluster().getMetadata().getKeyspace(mapper.keyspace); | |
| 76 | + this.tableMetadata = keyspace == null ? null : keyspace.getTable(mapper.table); | |
| 77 | 77 | |
| 78 | 78 | this.mapOneFunction = new Function<ResultSet, T>() { |
| 79 | 79 | @Override |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/PropertyMapper.java +14 −9
| @@ -130,18 +130,23 @@ | ||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | private String inferColumnName() { |
| 133 | - Column column = annotation(Column.class); | |
| 134 | - if (column != null && !column.name().isEmpty()) { | |
| 135 | - return Metadata.quote(column.caseSensitive() ? column.name() : column.name().toLowerCase()); | |
| 136 | - } | |
| 137 | - com.datastax.driver.mapping.annotations.Field udtField = annotation(com.datastax.driver.mapping.annotations.Field.class); | |
| 138 | - if (udtField != null && !udtField.name().isEmpty()) { | |
| 139 | - return Metadata.quote(udtField.caseSensitive() ? udtField.name() : udtField.name().toLowerCase()); | |
| 140 | - } | |
| 141 | 133 | if (isComputed()) { |
| 142 | 134 | return annotation(Computed.class).value(); |
| 143 | 135 | } |
| 144 | - return Metadata.quote(propertyName.toLowerCase()); | |
| 136 | + boolean caseSensitive = false; | |
| 137 | + String columnName = propertyName; | |
| 138 | + if (hasAnnotation(Column.class)) { | |
| 139 | + Column column = annotation(Column.class); | |
| 140 | + caseSensitive = column.caseSensitive(); | |
| 141 | + if (!column.name().isEmpty()) | |
| 142 | + columnName = column.name(); | |
| 143 | + } else if (hasAnnotation(com.datastax.driver.mapping.annotations.Field.class)) { | |
| 144 | + com.datastax.driver.mapping.annotations.Field udtField = annotation(com.datastax.driver.mapping.annotations.Field.class); | |
| 145 | + caseSensitive = udtField.caseSensitive(); | |
| 146 | + if (!udtField.name().isEmpty()) | |
| 147 | + columnName = udtField.name(); | |
| 148 | + } | |
| 149 | + return caseSensitive ? Metadata.quote(columnName) : columnName.toLowerCase(); | |
| 145 | 150 | } |
| 146 | 151 | |
| 147 | 152 | @SuppressWarnings("unchecked") |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/QueryType.java +3 −3
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | @Override |
| 32 | 32 | String makePreparedQueryString(TableMetadata table, EntityMapper<?> mapper, MappingManager manager, Set<PropertyMapper> columns, Collection<Mapper.Option> options) { |
| 33 | 33 | Insert insert = table == null |
| 34 | - ? insertInto(mapper.getKeyspace(), mapper.getTable()) | |
| 34 | + ? insertInto(mapper.keyspace, mapper.table) | |
| 35 | 35 | : insertInto(table); |
| 36 | 36 | for (PropertyMapper col : columns) |
| 37 | 37 | if (!col.isComputed()) |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | } |
| 66 | 66 | Select select; |
| 67 | 67 | if (table == null) { |
| 68 | - select = selection.from(mapper.getKeyspace(), mapper.getTable()); | |
| 68 | + select = selection.from(mapper.keyspace, mapper.table); | |
| 69 | 69 | } else { |
| 70 | 70 | select = selection.from(table); |
| 71 | 71 | } |
| @@ -83,7 +83,7 @@ | ||
| 83 | 83 | @Override |
| 84 | 84 | String makePreparedQueryString(TableMetadata table, EntityMapper<?> mapper, MappingManager manager, Set<PropertyMapper> columns, Collection<Mapper.Option> options) { |
| 85 | 85 | Delete delete = table == null |
| 86 | - ? delete().all().from(mapper.getKeyspace(), mapper.getTable()) | |
| 86 | + ? delete().all().from(mapper.keyspace, mapper.table) | |
| 87 | 87 | : delete().all().from(table); |
| 88 | 88 | Delete.Where where = delete.where(); |
| 89 | 89 | for (int i = 0; i < mapper.primaryKeySize(); i++) |
added driver-mapping/src/test/java/com/datastax/driver/mapping/MapperCaseSensitivenessTest.java +180 −0
| @@ -0,0 +1,180 @@ | ||
| 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 com.datastax.driver.core.CCMConfig; | |
| 19 | +import com.datastax.driver.core.CCMTestsSupport; | |
| 20 | +import com.datastax.driver.core.TestUtils; | |
| 21 | +import com.datastax.driver.mapping.annotations.*; | |
| 22 | +import com.google.common.base.Objects; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 25 | +import static com.datastax.driver.core.Metadata.quote; | |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * | |
| 30 | + */ | |
| 31 | +@CCMConfig(createKeyspace = false) | |
| 32 | +@SuppressWarnings({"unused", "WeakerAccess"}) | |
| 33 | +public class MapperCaseSensitivenessTest extends CCMTestsSupport { | |
| 34 | + | |
| 35 | + static final String KS = "ks_MapperCaseSensitivenessTest"; | |
| 36 | + static final String TABLE = "table_MapperCaseSensitivenessTest"; | |
| 37 | + static final String TYPE = "udt_MapperCaseSensitivenessTest"; | |
| 38 | + | |
| 39 | + UserNoKeyspace user = new UserNoKeyspace("id", new Address("street", "zip")); | |
| 40 | + | |
| 41 | + @Table(keyspace = KS, name = TABLE, caseSensitiveKeyspace = true, caseSensitiveTable = true) | |
| 42 | + static class User { | |
| 43 | + | |
| 44 | + @PartitionKey | |
| 45 | + @Column(caseSensitive = true) | |
| 46 | + private String userId; | |
| 47 | + | |
| 48 | + @Column(name = "Address", caseSensitive = true) | |
| 49 | + private Address address; | |
| 50 | + | |
| 51 | + public User() { | |
| 52 | + } | |
| 53 | + | |
| 54 | + public User(String userId, Address address) { | |
| 55 | + this.userId = userId; | |
| 56 | + this.address = address; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public String getUserId() { | |
| 60 | + return userId; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public void setUserId(String userId) { | |
| 64 | + this.userId = userId; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public Address getAddress() { | |
| 68 | + return address; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void setAddress(Address address) { | |
| 72 | + this.address = address; | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + public boolean equals(Object o) { | |
| 77 | + if (this == o) return true; | |
| 78 | + if (o == null || !(o instanceof User)) return false; | |
| 79 | + User user = (User) o; | |
| 80 | + return Objects.equal(userId, user.userId) && | |
| 81 | + Objects.equal(address, user.address); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + public int hashCode() { | |
| 86 | + return Objects.hashCode(userId, address); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + @UDT(keyspace = KS, name = TYPE, caseSensitiveKeyspace = true, caseSensitiveType = true) | |
| 91 | + static class Address { | |
| 92 | + | |
| 93 | + @Field(name = "Street", caseSensitive = true) | |
| 94 | + private String street; | |
| 95 | + | |
| 96 | + @Field(caseSensitive = true) | |
| 97 | + private String zipCode; | |
| 98 | + | |
| 99 | + public Address() { | |
| 100 | + } | |
| 101 | + | |
| 102 | + public Address(String street, String zipCode) { | |
| 103 | + this.street = street; | |
| 104 | + this.zipCode = zipCode; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public String getStreet() { | |
| 108 | + return street; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public void setStreet(String street) { | |
| 112 | + this.street = street; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public String getZipCode() { | |
| 116 | + return zipCode; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setZipCode(String zipCode) { | |
| 120 | + this.zipCode = zipCode; | |
| 121 | + } | |
| 122 | + | |
| 123 | + @Override | |
| 124 | + public boolean equals(Object o) { | |
| 125 | + if (this == o) return true; | |
| 126 | + if (o == null || !(o instanceof Address)) return false; | |
| 127 | + Address address = (Address) o; | |
| 128 | + return Objects.equal(street, address.street) && | |
| 129 | + Objects.equal(zipCode, address.zipCode); | |
| 130 | + } | |
| 131 | + | |
| 132 | + @Override | |
| 133 | + public int hashCode() { | |
| 134 | + return Objects.hashCode(getStreet(), getZipCode()); | |
| 135 | + } | |
| 136 | + } | |
| 137 | + | |
| 138 | + @Table(name = TABLE, caseSensitiveKeyspace = true, caseSensitiveTable = true) | |
| 139 | + static class UserNoKeyspace extends User { | |
| 140 | + | |
| 141 | + public UserNoKeyspace() { | |
| 142 | + } | |
| 143 | + | |
| 144 | + public UserNoKeyspace(String id, Address address) { | |
| 145 | + super(id, address); | |
| 146 | + } | |
| 147 | + | |
| 148 | + } | |
| 149 | + | |
| 150 | + @UDT(name = TYPE, caseSensitiveKeyspace = true, caseSensitiveType = true) | |
| 151 | + static class AddressNoKeyspace extends Address { | |
| 152 | + | |
| 153 | + } | |
| 154 | + | |
| 155 | + @Override | |
| 156 | + public void onTestContextInitialized() { | |
| 157 | + execute(String.format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, quote(KS), 1)); | |
| 158 | + useKeyspace(quote(KS)); | |
| 159 | + execute( | |
| 160 | + "CREATE TYPE " + quote(TYPE) + " (\"Street\" text, \"zipCode\" text)", | |
| 161 | + "CREATE TABLE " + quote(TABLE) + " (\"userId\" text PRIMARY KEY, \"Address\" frozen<" + quote(TYPE) + ">)"); | |
| 162 | + } | |
| 163 | + | |
| 164 | + @Test(groups = "short") | |
| 165 | + public void should_handle_case_sensitive_identifiers_when_keyspace_specified() throws Exception { | |
| 166 | + MappingManager mappingManager = new MappingManager(session()); | |
| 167 | + Mapper<User> mapper = mappingManager.mapper(User.class); | |
| 168 | + mapper.save(user); | |
| 169 | + assertThat(mapper.get(user.getUserId())).isEqualTo(user); | |
| 170 | + } | |
| 171 | + | |
| 172 | + @Test(groups = "short") | |
| 173 | + public void should_handle_case_sensitive_identifiers_whitout_keyspace_specified() throws Exception { | |
| 174 | + MappingManager mappingManager = new MappingManager(session()); | |
| 175 | + Mapper<UserNoKeyspace> mapper = mappingManager.mapper(UserNoKeyspace.class); | |
| 176 | + mapper.save(user); | |
| 177 | + assertThat(mapper.get(user.getUserId())).isEqualTo(user); | |
| 178 | + } | |
| 179 | + | |
| 180 | +} |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperComputedFieldsTest.java +1 −1
| @@ -91,7 +91,7 @@ | ||
| 91 | 91 | void should_add_aliases_for_fields_in_select_queries() { |
| 92 | 92 | BoundStatement bs = (BoundStatement) userMapper.getQuery("test"); |
| 93 | 93 | assertThat(bs.preparedStatement().getQueryString()) |
| 94 | - .contains("SELECT", "\"login\" AS col", "\"name\" AS col", "writetime(\"name\") AS col"); | |
| 94 | + .contains("SELECT", "login AS col", "name AS col", "writetime(\"name\") AS col"); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | @Test(groups = "short") |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperDefaultKeyspaceTest.java +2 −2
| @@ -92,7 +92,7 @@ | ||
| 92 | 92 | |
| 93 | 93 | @Test(groups = "short", |
| 94 | 94 | expectedExceptions = IllegalArgumentException.class, |
| 95 | - expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 95 | + expectedExceptionsMessageRegExp = "Error creating mapper for class com.datastax.driver.mapping.MapperDefaultKeyspaceTest\\$Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 96 | 96 | public void should_throw_a_meaningful_error_message_when_no_default_table_keyspace_and_session_not_logged() { |
| 97 | 97 | Session session2 = cluster().connect(); |
| 98 | 98 | MappingManager manager = new MappingManager(session2); |
| @@ -101,7 +101,7 @@ | ||
| 101 | 101 | |
| 102 | 102 | @Test(groups = "short", |
| 103 | 103 | expectedExceptions = IllegalArgumentException.class, |
| 104 | - expectedExceptionsMessageRegExp = "Error creating UDT codec for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 104 | + expectedExceptionsMessageRegExp = "Error creating UDT codec for class com.datastax.driver.mapping.MapperDefaultKeyspaceTest\\$GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 105 | 105 | public void should_throw_a_meaningful_error_message_when_no_default_udt_keyspace_and_session_not_logged() { |
| 106 | 106 | Session session2 = cluster().connect(); |
| 107 | 107 | MappingManager manager = new MappingManager(session2); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperSaveNullFieldsTest.java +4 −4
| @@ -83,14 +83,14 @@ | ||
| 83 | 83 | BoundStatement bs = (BoundStatement) mapper.saveQuery(newUser, options); |
| 84 | 84 | String queryString = bs.preparedStatement().getQueryString(); |
| 85 | 85 | if (nullName && !saveExpected) |
| 86 | - assertThat(queryString).as(description).doesNotContain("\"name\""); | |
| 86 | + assertThat(queryString).as(description).doesNotContain("name"); | |
| 87 | 87 | else |
| 88 | - assertThat(queryString).as(description).contains("\"name\""); | |
| 88 | + assertThat(queryString).as(description).contains("name"); | |
| 89 | 89 | |
| 90 | 90 | if (nullPhone && !saveExpected) |
| 91 | - assertThat(queryString).as(description).doesNotContain("\"phone\""); | |
| 91 | + assertThat(queryString).as(description).doesNotContain("phone"); | |
| 92 | 92 | else |
| 93 | - assertThat(queryString).as(description).contains("\"phone\""); | |
| 93 | + assertThat(queryString).as(description).contains("phone"); | |
| 94 | 94 | |
| 95 | 95 | // Save entity and check the data |
| 96 | 96 | mapper.save(newUser, options); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +10 −10
| @@ -380,7 +380,7 @@ | ||
| 380 | 380 | /** |
| 381 | 381 | * Ensures that if a table is altered after a {@link Mapper} is created that it continues to work as long as |
| 382 | 382 | * the change is compatible. A new column is added to the table in this case, which is a compatible change. |
| 383 | - * <p> | |
| 383 | + * <p/> | |
| 384 | 384 | * It also ensures that after the change is made that requesting a new {@link Mapper} returns a different instance |
| 385 | 385 | * instead of the existing one. |
| 386 | 386 | * |
| @@ -407,7 +407,7 @@ | ||
| 407 | 407 | /** |
| 408 | 408 | * Ensures that if a UDT is altered after a {@link Mapper} is created that has a UDT that it continues to work as |
| 409 | 409 | * long as the change is compatible. A new field is added to the table in this case, which is a compatible change. |
| 410 | - * <p> | |
| 410 | + * <p/> | |
| 411 | 411 | * It also ensures that after the change is made that requesting a new {@link TypeCodec} for that UDT and a new |
| 412 | 412 | * {@link Mapper} for a table using that UDT returns different instances instead of the existing ones. |
| 413 | 413 | * |
| @@ -440,7 +440,7 @@ | ||
| 440 | 440 | * Ensures that if a table is dropped after a {@link Mapper} is created that the {@link Mapper} can no longer |
| 441 | 441 | * successfully make queries and that attempting to create a new {@link Mapper} throws an |
| 442 | 442 | * {@link IllegalArgumentException}. |
| 443 | - * <p> | |
| 443 | + * <p/> | |
| 444 | 444 | * It also ensures that requesting a {@link Mapper} fails as the previous {@link Mapper} was evicted and a new |
| 445 | 445 | * one cannot be created as the table has been dropped. |
| 446 | 446 | * |
| @@ -471,14 +471,14 @@ | ||
| 471 | 471 | manager.mapper(User.class); |
| 472 | 472 | fail("Expected IllegalArgumentException"); |
| 473 | 473 | } catch (IllegalArgumentException e) { |
| 474 | - assertThat(e.getMessage()).isEqualTo("Table users does not exist in keyspace " + keyspace); | |
| 474 | + assertThat(e.getMessage()).isEqualTo("Table users does not exist in keyspace \"" + keyspace + "\""); | |
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
| 479 | 479 | * Ensures that if a table is altered after a {@link Mapper} is created that it no longer continues to work if |
| 480 | 480 | * the change is not compatible. A column is dropped from the table in this case, which is an incompatible change. |
| 481 | - * <p> | |
| 481 | + * <p/> | |
| 482 | 482 | * It also ensures that requesting a {@link Mapper} fails as the previous {@link Mapper} was evicted and a new |
| 483 | 483 | * one cannot be created as a declared column is missing from the schema but is present in the class definition. |
| 484 | 484 | * |
| @@ -509,7 +509,7 @@ | ||
| 509 | 509 | manager.mapper(User.class); |
| 510 | 510 | fail("Expected IllegalArgumentException"); |
| 511 | 511 | } catch (IllegalArgumentException e) { |
| 512 | - assertThat(e.getMessage()).isEqualTo(String.format("Column \"mainaddress\" does not exist in table %s.users", keyspace)); | |
| 512 | + assertThat(e.getMessage()).isEqualTo(String.format("Column mainaddress does not exist in table \"%s\".users", keyspace)); | |
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | |
| @@ -517,10 +517,10 @@ | ||
| 517 | 517 | * Ensures that if a UDT is altered after a {@link Mapper} is created that it no longer continues to work if |
| 518 | 518 | * the change made to the UDT is not compatible. A field is renamed in the UDT in this case, which is not a |
| 519 | 519 | * compatible change. |
| 520 | - * <p> | |
| 520 | + * <p/> | |
| 521 | 521 | * It also ensures that requesting a {@link Mapper} fails as the previous {@link Mapper} was evicted and a new |
| 522 | 522 | * one cannot be created as a declared field is missing from the schema but is present in the class definition. |
| 523 | - * <p> | |
| 523 | + * <p/> | |
| 524 | 524 | * Also verifies that a {@link TypeCodec} cannot be requested for the UDT as well. |
| 525 | 525 | * |
| 526 | 526 | * @jira_ticket JAVA-1126 |
| @@ -552,13 +552,13 @@ | ||
| 552 | 552 | manager.mapper(User.class); |
| 553 | 553 | fail("Expected IllegalArgumentException"); |
| 554 | 554 | } catch (IllegalArgumentException e) { |
| 555 | - assertThat(e.getMessage()).isEqualTo(String.format("Field \"ZIP_code\" does not exist in type %s.address", keyspace)); | |
| 555 | + assertThat(e.getMessage()).isEqualTo(String.format("Field \"ZIP_code\" does not exist in type \"%s\".address", keyspace)); | |
| 556 | 556 | } |
| 557 | 557 | try { |
| 558 | 558 | manager.udtCodec(Address.class); |
| 559 | 559 | fail("Expected IllegalArgumentException"); |
| 560 | 560 | } catch (IllegalArgumentException e) { |
| 561 | - assertThat(e.getMessage()).isEqualTo(String.format("Field \"ZIP_code\" does not exist in type %s.address", keyspace)); | |
| 561 | + assertThat(e.getMessage()).isEqualTo(String.format("Field \"ZIP_code\" does not exist in type \"%s\".address", keyspace)); | |
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | 564 |