Search in sources :

Example 6 with ColumnNamer

use of org.h2.util.ColumnNamer in project h2database by h2database.

the class TestColumnNamer method test.

@Override
public void test() {
    ColumnNamer columnNamer = new ColumnNamer(null);
    columnNamer.getConfiguration().configure("MAX_IDENTIFIER_LENGTH = 30");
    columnNamer.getConfiguration().configure("REGULAR_EXPRESSION_MATCH_ALLOWED = '[A-Za-z0-9_]+'");
    columnNamer.getConfiguration().configure("REGULAR_EXPRESSION_MATCH_DISALLOWED = '[^A-Za-z0-9_]+'");
    columnNamer.getConfiguration().configure("DEFAULT_COLUMN_NAME_PATTERN = 'colName$$'");
    columnNamer.getConfiguration().configure("GENERATE_UNIQUE_COLUMN_NAMES = 1");
    int index = 0;
    for (String id : ids) {
        Expression columnExp = ValueExpression.getDefault();
        String newColumnName = columnNamer.getColumnName(columnExp, index + 1, id);
        assertNotNull(newColumnName);
        assertTrue(newColumnName.length() <= 30);
        assertTrue(newColumnName.length() >= 1);
        assertEquals(newColumnName, expectedColumnName[index]);
        index++;
    }
}
Also used : ColumnNamer(org.h2.util.ColumnNamer) ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression)

Aggregations

Expression (org.h2.expression.Expression)5 ColumnNamer (org.h2.util.ColumnNamer)5 ExpressionColumn (org.h2.expression.ExpressionColumn)4 ValueExpression (org.h2.expression.ValueExpression)2 Column (org.h2.table.Column)2 ArrayList (java.util.ArrayList)1 Query (org.h2.command.dml.Query)1 Alias (org.h2.expression.Alias)1 Index (org.h2.index.Index)1 IndexType (org.h2.index.IndexType)1 DbException (org.h2.message.DbException)1 DataType (org.h2.value.DataType)1