DefaultNameGenerator implements NameGenerator { @Override public synchronized TableName generateIdentitySequenceName(AkibanInformationSchema ais, TableName table, String column) { String proposed = String.format(IDENTITY_SEQUENCE_FORMAT, table.getTableName(), column); return findUnique(ais.getSequences().keySet(), new TableName(table.getSchemaName(), proposed)); } DefaultNameGenerator();  DefaultNameGenerator(AkibanInformationSchema ais); @Override synchronized int generateTableID(TableName name); @Override synchronized int generateIndexID(int rootTableID); @Override synchronized TableName generateIdentitySequenceName(AkibanInformationSchema ais, TableName table, String column); @Override synchronized String generateJoinName(TableName parentTable, TableName childTable, String[] pkColNames, String [] fkColNames); @Override synchronized String generateJoinName(TableName parentTable, TableName childTable, List<JoinColumn> columns); @Override synchronized String generateJoinName(TableName parentTable, TableName childTable, List<String> pkColNames, List<String> fkColNames); @Override synchronized String generateFullTextIndexPath(FullTextIndex index); @Override synchronized TableName generateFKConstraintName(String schemaName, String tableName); @Override synchronized TableName generatePKConstraintName( String schemaName, String tableName); @Override synchronized TableName generateUniqueConstraintName( String schemaName, String tableName); @Override synchronized void mergeAIS(AkibanInformationSchema ais); @Override synchronized void removeTableID(int tableID); @Override synchronized Set<String> getStorageNames(); static Map<Integer,Integer> collectMaxIndexIDs(AkibanInformationSchema ais); static String findUnique(Collection<String> set, String original, int maxLength); static String makeUnique(Collection<String> treeNames, String proposed, int maxLength); static String schemaNameForIndex(Index index); static final int MAX_IDENT; }
@Test public void identitySequenceName() { AkibanInformationSchema ais = new AkibanInformationSchema(); TableName table = new TableName("test", "t"); assertEquals(new TableName("test", "t_s1_seq"), generator.generateIdentitySequenceName(ais, table, "s1")); }
@Test public void identitySequenceNameConflict() { AkibanInformationSchema ais = new AkibanInformationSchema(); Sequence.create(ais, "test", "t_s_seq", 1, 1, 1, 10, false); assertEquals(new TableName("test", "t_s_seq$1"), generator.generateIdentitySequenceName(ais, new TableName("test", "t"), "s")); }
@Test public void identitySequenceTruncate() { AkibanInformationSchema ais = new AkibanInformationSchema(); char[] chars = new char[DefaultNameGenerator.MAX_IDENT]; Arrays.fill(chars, 'a'); String maxIdent = new String(chars); assertEquals(new TableName("test", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$1"), generator.generateIdentitySequenceName(ais, new TableName("test", maxIdent), "s")); assertEquals(new TableName("test", "t_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$1"), generator.generateIdentitySequenceName(ais, new TableName("test", "t"), maxIdent)); assertEquals(new TableName("test", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$1"), generator.generateIdentitySequenceName(ais, new TableName("test", maxIdent), maxIdent)); Sequence.create(ais, "test", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$1", 1, 1, 1, 10, false); assertEquals(new TableName("test", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa$2"), generator.generateIdentitySequenceName(ais, new TableName("test", maxIdent), "s")); }