kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 349110a54a94d3c04bbde6a06a8cf2aadd0b8c7dbc15244d43d24e9ff27b6312 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-11-07 18:18 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-07 18:18 +01:00 |
| Parents | 31b3bab3142a |
2 files changed
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +12 −0
| @@ -61,6 +61,12 @@ | ||
| 61 | 61 | |
| 62 | 62 | if (Strings.isNullOrEmpty(table.keyspace())) { |
| 63 | 63 | ksName = mappingManager.getSession().getLoggedKeyspace(); |
| 64 | + if (Strings.isNullOrEmpty(ksName)) | |
| 65 | + throw new IllegalArgumentException(String.format( | |
| 66 | + "Error creating mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 67 | + entityClass.getSimpleName(), | |
| 68 | + Table.class.getSimpleName() | |
| 69 | + )); | |
| 64 | 70 | } |
| 65 | 71 | |
| 66 | 72 | EntityMapper<T> mapper = factory.create(entityClass, ksName, tableName, writeConsistency, readConsistency); |
| @@ -113,6 +119,12 @@ | ||
| 113 | 119 | |
| 114 | 120 | if (Strings.isNullOrEmpty(udt.keyspace())) { |
| 115 | 121 | ksName = mappingManager.getSession().getLoggedKeyspace(); |
| 122 | + if (Strings.isNullOrEmpty(ksName)) | |
| 123 | + throw new IllegalArgumentException(String.format( | |
| 124 | + "Error creating UDT mapper for class %s, the @%s annotation declares no default keyspace, and the session is not currently logged to any keyspace", | |
| 125 | + udtClass.getSimpleName(), | |
| 126 | + UDT.class.getSimpleName() | |
| 127 | + )); | |
| 116 | 128 | } |
| 117 | 129 | |
| 118 | 130 | EntityMapper<T> mapper = factory.create(udtClass, ksName, udtName, null, null); |
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperDefaultKeyspaceTest.java +19 −0
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.util.*; |
| 19 | 19 | |
| 20 | +import com.datastax.driver.core.Session; | |
| 20 | 21 | import com.datastax.driver.mapping.annotations.*; |
| 21 | 22 | import com.google.common.base.Objects; |
| 22 | 23 | import org.testng.annotations.Test; |
| @@ -219,4 +220,22 @@ | ||
| 219 | 220 | m.delete(group); |
| 220 | 221 | assertNull(m.get(groupId)); |
| 221 | 222 | } |
| 223 | + | |
| 224 | + @Test(groups = "short", | |
| 225 | + expectedExceptions = IllegalArgumentException.class, | |
| 226 | + expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 227 | + public void should_throw_a_meaningful_error_message_when_no_default_table_keyspace_and_session_not_logged() { | |
| 228 | + Session session2 = cluster.connect(); | |
| 229 | + MappingManager manager = new MappingManager(session2); | |
| 230 | + manager.mapper(Group.class); | |
| 231 | + } | |
| 232 | + | |
| 233 | + @Test(groups = "short", | |
| 234 | + expectedExceptions = IllegalArgumentException.class, | |
| 235 | + expectedExceptionsMessageRegExp = "Error creating UDT mapper for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace") | |
| 236 | + public void should_throw_a_meaningful_error_message_when_no_default_udt_keyspace_and_session_not_logged() { | |
| 237 | + Session session2 = cluster.connect(); | |
| 238 | + MappingManager manager = new MappingManager(session2); | |
| 239 | + manager.udtMapper(GroupName.class); | |
| 240 | + } | |
| 222 | 241 | } |