Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private String generateName(String candidateName, int reserved)
ret = legalName + i;
}

if (_dialect.isIdentifierTooLong(ret))
if (isIdentifierTooLong(ret))
throw new IllegalStateException("generateName() produced a name that was too long for " + _dialect.getProductName() + ": \"" + ret + "\" was generated from \"" + candidateName + "\"");

if (ret.length() > 255)
Expand All @@ -86,6 +86,11 @@ private String generateName(String candidateName, int reserved)
return claimName(ret);
}

private boolean isIdentifierTooLong(String candidate)
{
return _dialect.isIdentifierTooLong(candidate);
}

public static class TestCase extends Assert
{
@Test
Expand All @@ -101,11 +106,11 @@ public void testGenerateName()
testCandidates(255, dialect, StringUtilsLabKey::generateSpecialCharacterString);

// Test that the same string over and over again generates a unique name
testCandidates(255, dialect, i -> "kumquat");
testCandidates(255, dialect, _ -> "kumquat");
// Same, but test case sensitivity
testCandidates(255, dialect, i -> i % 2 == 0 ? "kumquat" : "KUMQUAT");
String randomString = StringUtilsLabKey.generateSpecialCharacterString(255);
testCandidates(255, dialect, i -> randomString);
testCandidates(255, dialect, _ -> randomString);
}

private void testCandidates(int count, SqlDialect dialect, Function<Integer, String> candidateSupplier)
Expand All @@ -119,7 +124,7 @@ private void testCandidates(int count, SqlDialect dialect, Function<Integer, Str
String generated = generator.generateColumnName(candidate);
boolean exists = uniqueNames.contains(candidate);

if (exists || dialect.isIdentifierTooLong(candidate + StringUtils.repeat("x", COLUMN_RESERVED_LENGTH)))
if (exists || generator.isIdentifierTooLong(candidate + StringUtils.repeat("x", COLUMN_RESERVED_LENGTH)))
assertNotEquals(candidate, generated);
else
assertEquals(candidate, generated);
Expand Down