public static void checkValidTableName(String identifier) throws ADQLIdentifierException { String[] parts = identifier.split("[.]"); String schemaName = null; String tableName = identifier; if (parts.length == 2) { schemaName = parts[0]; tableName = parts[1]; } else if (parts.length > 2) { throw new ADQLIdentifierException("invalid table name: " + identifier + " (too many parts)"); } if (schemaName != null) { checkValidIdentifier(schemaName); } checkValidIdentifier(tableName); }
/** * Get a List that describes each VOTable column. * * @throws java.io.IOException * @throws VOTableParserException if unable to parse the VOTable. * @return List of ColumnDesc describing the VOTable columns. */ @Override public TableDesc getTableDesc() throws IOException, VOTableParserException { init(); TableDesc tableDesc = TapSchemaUtil.createTableDesc(UploadManager.SCHEMA, tableName, votable); log.debug("table: " + tableDesc); return tableDesc; }
private Map<String, Format> createColumnFormats() { columnFormats = new HashMap<String, Format>(columnNames.size()); for (String col : columnNames) { ColumnDesc colDesc = tableDesc.getColumn(col); VOTableField voTableField = TapSchemaUtil.convert(colDesc); Format format = formatFactory.getFormat(voTableField); columnFormats.put(col, format); } return columnFormats; }
checkValidIdentifier(schemaName); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid ADQL identifier (schema name): " + schemaName, ex); checkValidTableName(tableName); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid ADQL identifier (table name): " + tableName, ex); checkValidIdentifier(f.getName()); ColumnDesc columnDesc = TapSchemaUtil.convert(tableName, f); log.debug("column: " + f + " -> " + columnDesc); ret.getColumnDescs().add(columnDesc);
public void createIndex(ColumnDesc cd, boolean unique) { try { TapSchemaUtil.checkValidTableName(cd.getTableName()); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid table name: " + cd.getTableName(), ex); TapSchemaUtil.checkValidIdentifier(cd.getColumnName()); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid column name: " + cd.getColumnName(), ex);
/** * Validates that the given String is a valid ADQL identifier. * * @param identifier String to be tested. * @throws ADQLIdentifierException */ public static void checkValidIdentifier(String identifier) throws ADQLIdentifierException { // identifier shouldn't be null and cannot be an empty string. if (identifier == null || identifier.trim().isEmpty()) { throw new ADQLIdentifierException("Identifier is null or empty"); } // identifier cannot start with, contain, or end, with a space. if (identifier.startsWith(" ") || identifier.contains(" ") || identifier.endsWith(" ")) { throw new ADQLIdentifierException("Identifier contains spaces"); } // identifier must start with a letter {aA-zZ}. if (!isAsciiLetter(identifier.charAt(0))) { throw new ADQLIdentifierException("Identifier must start with a letter"); } // subsequent characters must be letters, underscores, or digits. for (int i = 1; i < identifier.length(); i++) { if (!isValidIdentifierCharacter(identifier.charAt(i))) { throw new ADQLIdentifierException("Identifier contains an invalid character " + identifier.charAt(i)); } } }
/** * Checks if the char is either a US ASCII char, an underscore, * of a digit. * * @param c char to test. * @return true if the char is a valid ADQL identifier char, false otherwise. */ public static boolean isValidIdentifierCharacter(char c) { if (c == '_' || isAsciiLetter(c) || Character.isDigit(c)) { return true; } return false; } }
public void dropTable(String tableName) { try { TapSchemaUtil.checkValidTableName(tableName); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid table name: " + tableName, ex);
public void createTable(TableDesc table) { try { TapSchemaUtil.checkValidTableName(table.getTableName()); } catch (ADQLIdentifierException ex) { throw new IllegalArgumentException("invalid table name: " + table.getTableName(), ex); TapSchemaUtil.checkValidIdentifier(cd.getColumnName());
private TableDesc toTableDesc(VOTableDocument doc) { // TODO: reject if the table has any rows? try to insert them if it is small enough? for (VOTableResource vr : doc.getResources()) { VOTableTable vtab = vr.getTable(); if (vtab != null) { TableDesc ret = TapSchemaUtil.createTableDesc("default", "default", vtab); log.debug("create from VOtable: " + ret); return ret; } } throw new IllegalArgumentException("no table description found in VOTable document"); } }
TapSchemaUtil.checkValidIdentifier(tableName);