[#7127] NPE while fetching certain indexes during code generation
This commit is contained in:
parent
404eadf2d6
commit
37e1db50ba
@ -143,38 +143,41 @@ public class H2Database extends AbstractDatabase {
|
||||
final Result<Record> columns = entry.getValue();
|
||||
|
||||
final SchemaDefinition tableSchema = getSchema(index.get(Indexes.TABLE_SCHEMA));
|
||||
if (tableSchema == null)
|
||||
continue indexLoop;
|
||||
|
||||
final String indexName = index.get(Indexes.INDEX_NAME);
|
||||
final String tableName = index.get(Indexes.TABLE_NAME);
|
||||
final TableDefinition table = getTable(tableSchema, tableName);
|
||||
if (table == null)
|
||||
continue indexLoop;
|
||||
|
||||
final boolean unique = !index.get(Indexes.NON_UNIQUE, boolean.class);
|
||||
|
||||
if (table != null) {
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(Indexes.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(Indexes.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(Indexes.COLUMN_NAME)),
|
||||
SortOrder.ASC,
|
||||
column.get(Indexes.ORDINAL_POSITION, int.class)
|
||||
));
|
||||
}
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(Indexes.COLUMN_NAME)),
|
||||
SortOrder.ASC,
|
||||
column.get(Indexes.ORDINAL_POSITION, int.class)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -143,38 +143,41 @@ public class HSQLDBDatabase extends AbstractDatabase {
|
||||
final Result<Record> cols = entry.getValue();
|
||||
|
||||
final SchemaDefinition tableSchema = getSchema(index.get(SYSTEM_INDEXINFO.TABLE_SCHEM));
|
||||
if (tableSchema == null)
|
||||
continue indexLoop;
|
||||
|
||||
final String indexName = index.get(SYSTEM_INDEXINFO.INDEX_NAME);
|
||||
final String tableName = index.get(SYSTEM_INDEXINFO.TABLE_NAME);
|
||||
final TableDefinition table = getTable(tableSchema, tableName);
|
||||
if (table == null)
|
||||
continue indexLoop;
|
||||
|
||||
final boolean unique = !index.get(SYSTEM_INDEXINFO.NON_UNIQUE, boolean.class);
|
||||
|
||||
if (table != null) {
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : cols)
|
||||
if (table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : cols)
|
||||
if (table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
{
|
||||
for (Record column : cols) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)),
|
||||
"D".equals(column.get(SYSTEM_INDEXINFO.ASC_OR_DESC)) ? SortOrder.DESC : SortOrder.ASC,
|
||||
column.get(SYSTEM_INDEXINFO.ORDINAL_POSITION, int.class)
|
||||
));
|
||||
}
|
||||
{
|
||||
for (Record column : cols) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(SYSTEM_INDEXINFO.COLUMN_NAME)),
|
||||
"D".equals(column.get(SYSTEM_INDEXINFO.ASC_OR_DESC)) ? SortOrder.DESC : SortOrder.ASC,
|
||||
column.get(SYSTEM_INDEXINFO.ORDINAL_POSITION, int.class)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -147,38 +147,41 @@ public class MySQLDatabase extends AbstractDatabase {
|
||||
final Result<Record> columns = entry.getValue();
|
||||
|
||||
final SchemaDefinition tableSchema = getSchema(index.get(Statistics.TABLE_SCHEMA));
|
||||
if (tableSchema == null)
|
||||
continue indexLoop;
|
||||
|
||||
final String indexName = index.get(Statistics.INDEX_NAME);
|
||||
final String tableName = index.get(Statistics.TABLE_NAME);
|
||||
final TableDefinition table = getTable(tableSchema, tableName);
|
||||
if (table == null)
|
||||
continue indexLoop;
|
||||
|
||||
final boolean unique = !index.get(Statistics.NON_UNIQUE, boolean.class);
|
||||
|
||||
if (table != null) {
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(Statistics.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(Statistics.COLUMN_NAME)) == null)
|
||||
continue indexLoop;
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(Statistics.COLUMN_NAME)),
|
||||
SortOrder.ASC,
|
||||
column.get(Statistics.SEQ_IN_INDEX, int.class)
|
||||
));
|
||||
}
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(Statistics.COLUMN_NAME)),
|
||||
SortOrder.ASC,
|
||||
column.get(Statistics.SEQ_IN_INDEX, int.class)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -176,46 +176,49 @@ public class PostgresDatabase extends AbstractDatabase {
|
||||
.orderBy(1, 2, 3)) {
|
||||
|
||||
final SchemaDefinition tableSchema = getSchema(record.get(tnsp.NSPNAME));
|
||||
if (tableSchema == null)
|
||||
continue indexLoop;
|
||||
|
||||
final String indexName = record.get(irel.RELNAME);
|
||||
final String tableName = record.get(trel.RELNAME);
|
||||
final String[] columns = record.value5();
|
||||
final Integer[] options = record.value6();
|
||||
final TableDefinition table = getTable(tableSchema, tableName);
|
||||
if (table == null)
|
||||
continue indexLoop;
|
||||
|
||||
final boolean unique = record.get(i.INDISUNIQUE);
|
||||
|
||||
if (table != null) {
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (String column : columns)
|
||||
if (table.getColumn(column) == null)
|
||||
continue indexLoop;
|
||||
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (String column : columns)
|
||||
if (table.getColumn(column) == null)
|
||||
continue indexLoop;
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
{
|
||||
for (int ordinal = 0; ordinal < columns.length; ordinal++) {
|
||||
ColumnDefinition column = table.getColumn(columns[ordinal]);
|
||||
|
||||
{
|
||||
for (int ordinal = 0; ordinal < columns.length; ordinal++) {
|
||||
ColumnDefinition column = table.getColumn(columns[ordinal]);
|
||||
// [#6307] Some background info on this bitwise operation here:
|
||||
// https://stackoverflow.com/a/18128104/521799
|
||||
SortOrder order = (options[ordinal] & 1) == 1 ? SortOrder.DESC : SortOrder.ASC;
|
||||
|
||||
// [#6307] Some background info on this bitwise operation here:
|
||||
// https://stackoverflow.com/a/18128104/521799
|
||||
SortOrder order = (options[ordinal] & 1) == 1 ? SortOrder.DESC : SortOrder.ASC;
|
||||
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
column,
|
||||
order,
|
||||
ordinal + 1
|
||||
));
|
||||
}
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
column,
|
||||
order,
|
||||
ordinal + 1
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -141,38 +141,41 @@ public class SQLiteDatabase extends AbstractDatabase {
|
||||
final Result<Record> columns = entry.getValue();
|
||||
|
||||
final SchemaDefinition tableSchema = getSchemata().get(0);
|
||||
if (tableSchema == null)
|
||||
continue indexLoop;
|
||||
|
||||
final String indexName = index.get(fIndexName);
|
||||
final String tableName = index.get(SQLiteMaster.NAME);
|
||||
final TableDefinition table = getTable(tableSchema, tableName);
|
||||
if (table == null)
|
||||
continue indexLoop;
|
||||
|
||||
final boolean unique = index.get(fUnique);
|
||||
|
||||
if (table != null) {
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(fColumnName)) == null)
|
||||
continue indexLoop;
|
||||
|
||||
// [#6310] [#6620] Function-based indexes are not yet supported
|
||||
for (Record column : columns)
|
||||
if (table.getColumn(column.get(fColumnName)) == null)
|
||||
continue indexLoop;
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
result.add(new AbstractIndexDefinition(tableSchema, indexName, table, unique) {
|
||||
List<IndexColumnDefinition> indexColumns = new ArrayList<IndexColumnDefinition>();
|
||||
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(fColumnName)),
|
||||
SortOrder.ASC,
|
||||
column.get(fSeqno, int.class)
|
||||
));
|
||||
}
|
||||
{
|
||||
for (Record column : columns) {
|
||||
indexColumns.add(new DefaultIndexColumnDefinition(
|
||||
this,
|
||||
table.getColumn(column.get(fColumnName)),
|
||||
SortOrder.ASC,
|
||||
column.get(fSeqno, int.class)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected List<IndexColumnDefinition> getIndexColumns0() {
|
||||
return indexColumns;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -705,14 +705,7 @@ final class ParserImpl implements Parser {
|
||||
private static final SelectQueryImpl<Record> parseSelect(ParserContext ctx, Integer degree) {
|
||||
return parseSelect(ctx, degree, null);
|
||||
}
|
||||
/*
|
||||
* QueryPart condition = parseNot(ctx);
|
||||
|
||||
while (parseKeywordIf(ctx, "AND"))
|
||||
condition = toCondition(ctx, condition).and(toCondition(ctx, parseNot(ctx)));
|
||||
|
||||
return condition;
|
||||
*/
|
||||
private static final SelectQueryImpl<Record> parseSelect(ParserContext ctx, Integer degree, WithImpl with) {
|
||||
SelectQueryImpl<Record> result = parseQueryExpressionBody(ctx, degree, with);
|
||||
|
||||
@ -3254,9 +3247,9 @@ final class ParserImpl implements Parser {
|
||||
Name alias = null;
|
||||
|
||||
if (parseKeywordIf(ctx, "AS"))
|
||||
alias = parseIdentifier(ctx);
|
||||
alias = parseIdentifier(ctx, true);
|
||||
else if (!peekKeyword(ctx, SELECT_KEYWORDS))
|
||||
alias = parseIdentifierIf(ctx);
|
||||
alias = parseIdentifierIf(ctx, true);
|
||||
|
||||
result.add(alias == null ? field : field.as(alias));
|
||||
}
|
||||
@ -5798,7 +5791,11 @@ final class ParserImpl implements Parser {
|
||||
}
|
||||
|
||||
private static final Name parseIdentifier(ParserContext ctx) {
|
||||
Name result = parseIdentifierIf(ctx);
|
||||
return parseIdentifier(ctx, false);
|
||||
}
|
||||
|
||||
private static final Name parseIdentifier(ParserContext ctx, boolean allowAposQuotes) {
|
||||
Name result = parseIdentifierIf(ctx, allowAposQuotes);
|
||||
|
||||
if (result == null)
|
||||
throw ctx.expected("Identifier");
|
||||
@ -5807,12 +5804,17 @@ final class ParserImpl implements Parser {
|
||||
}
|
||||
|
||||
private static final Name parseIdentifierIf(ParserContext ctx) {
|
||||
return parseIdentifierIf(ctx, false);
|
||||
}
|
||||
|
||||
private static final Name parseIdentifierIf(ParserContext ctx, boolean allowAposQuotes) {
|
||||
parseWhitespaceIf(ctx);
|
||||
|
||||
char quoteEnd =
|
||||
parseIf(ctx, '"') ? '"'
|
||||
: parseIf(ctx, '`') ? '`'
|
||||
: parseIf(ctx, '[') ? ']'
|
||||
: allowAposQuotes && parseIf(ctx, '\'') ? '\''
|
||||
: 0;
|
||||
|
||||
int start = ctx.position;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user