@@ -245,7 +245,63 @@ void testInvalidTableName() {
245245 .isInstanceOf (SpannerDataException .class )
246246 .hasMessage ("Error getting table name for EntityBadName" )
247247 .hasStackTraceContaining (
248- "Only letters, numbers, and underscores are allowed in table names: ;DROP TABLE your_table;" );
248+ "Only letters, numbers, and underscores are allowed in table names, and at most one dot: ;DROP TABLE your_table;" );
249+ }
250+
251+ @ Test
252+ void testValidTableNameWithDot () {
253+ SpannerPersistentEntityImpl <EntityWithValidDotName > entity =
254+ new SpannerPersistentEntityImpl <>(
255+ TypeInformation .of (EntityWithValidDotName .class ),
256+ this .spannerMappingContext ,
257+ this .spannerEntityProcessor );
258+
259+ assertThat (entity .tableName ()).isEqualTo ("schema.table" );
260+ }
261+
262+ @ Test
263+ void testInvalidTableNameWithDotAtStart () {
264+ SpannerPersistentEntityImpl <EntityWithDotAtStart > entity =
265+ new SpannerPersistentEntityImpl <>(
266+ TypeInformation .of (EntityWithDotAtStart .class ),
267+ this .spannerMappingContext ,
268+ this .spannerEntityProcessor );
269+
270+ assertThatThrownBy (entity ::tableName )
271+ .isInstanceOf (SpannerDataException .class )
272+ .hasMessage ("Error getting table name for EntityWithDotAtStart" )
273+ .hasStackTraceContaining (
274+ "Only letters, numbers, and underscores are allowed in table names, and at most one dot: .table" );
275+ }
276+
277+ @ Test
278+ void testInvalidTableNameWithDotAtEnd () {
279+ SpannerPersistentEntityImpl <EntityWithDotAtEnd > entity =
280+ new SpannerPersistentEntityImpl <>(
281+ TypeInformation .of (EntityWithDotAtEnd .class ),
282+ this .spannerMappingContext ,
283+ this .spannerEntityProcessor );
284+
285+ assertThatThrownBy (entity ::tableName )
286+ .isInstanceOf (SpannerDataException .class )
287+ .hasMessage ("Error getting table name for EntityWithDotAtEnd" )
288+ .hasStackTraceContaining (
289+ "Only letters, numbers, and underscores are allowed in table names, and at most one dot: table." );
290+ }
291+
292+ @ Test
293+ void testInvalidTableNameWithMultipleDots () {
294+ SpannerPersistentEntityImpl <EntityWithMultipleDots > entity =
295+ new SpannerPersistentEntityImpl <>(
296+ TypeInformation .of (EntityWithMultipleDots .class ),
297+ this .spannerMappingContext ,
298+ this .spannerEntityProcessor );
299+
300+ assertThatThrownBy (entity ::tableName )
301+ .isInstanceOf (SpannerDataException .class )
302+ .hasMessage ("Error getting table name for EntityWithMultipleDots" )
303+ .hasStackTraceContaining (
304+ "Only letters, numbers, and underscores are allowed in table names, and at most one dot: schema.table.subtable" );
249305 }
250306
251307 @ Test
@@ -267,7 +323,7 @@ void testSpelInvalidName() {
267323 .isInstanceOf (SpannerDataException .class )
268324 .hasMessage ("Error getting table name for EntityWithExpression" )
269325 .hasStackTraceContaining (
270- "Only letters, numbers, and underscores are allowed in table names: "
326+ "Only letters, numbers, and underscores are allowed in table names, and at most one dot : "
271327 + "table_; DROP TABLE your_table;" );
272328 }
273329
@@ -475,6 +531,30 @@ private static class EntityBadName {
475531 String something ;
476532 }
477533
534+ @ Table (name = "schema.table" )
535+ private static class EntityWithValidDotName {
536+ @ PrimaryKey (keyOrder = 1 )
537+ String id ;
538+ }
539+
540+ @ Table (name = ".table" )
541+ private static class EntityWithDotAtStart {
542+ @ PrimaryKey (keyOrder = 1 )
543+ String id ;
544+ }
545+
546+ @ Table (name = "table." )
547+ private static class EntityWithDotAtEnd {
548+ @ PrimaryKey (keyOrder = 1 )
549+ String id ;
550+ }
551+
552+ @ Table (name = "schema.table.subtable" )
553+ private static class EntityWithMultipleDots {
554+ @ PrimaryKey (keyOrder = 1 )
555+ String id ;
556+ }
557+
478558 @ Table (name = "custom_test_table" )
479559 private static class TestEntity {
480560 @ PrimaryKey (keyOrder = 1 )
0 commit comments