Example usage for com.google.common.base VerifyException VerifyException

List of usage examples for com.google.common.base VerifyException VerifyException

Introduction

In this page you can find the example usage for com.google.common.base VerifyException VerifyException.

Prototype

public VerifyException(@Nullable Throwable cause) 

Source Link

Document

Constructs a VerifyException with the cause cause and a message that is null if cause is null, and cause.toString() otherwise.

Usage

From source file:org.opendaylight.yangtools.triemap.LNodeEntries.java

final LNodeEntries<K, V> remove(final LNodeEntry<K, V> entry) {
    if (entry == this) {
        return next();
    }//from  w ww . j av a 2  s . co  m

    // This will result in a list with a long tail, i.e last entry storing explicit null. Overhead is amortized
    // against the number of entries. We do not retain chains shorter than two, so the worst-case overhead is
    // half-a-reference for an entry.
    final Multiple<K, V> ret = new Multiple<>(this);

    Multiple<K, V> last = ret;
    LNodeEntries<K, V> cur = next();
    while (cur != null) {
        // We cannot use equals() here, as it is wired to key equality and we must never compare entries based on
        // that property. This method is intended to remove a known reference, so identity is what we want.
        if (entry == cur) {
            last.next = cur.next();
            return ret;
        }

        final Multiple<K, V> tmp = new Multiple<>(cur);
        last.next = tmp;
        last = tmp;
        cur = cur.next();
    }

    throw new VerifyException(String.format("Failed to find entry %s", entry));
}

From source file:io.prestosql.plugin.cassandra.CassandraClusteringPredicatesExtractor.java

private static ClusteringPushDownResult getClusteringKeysSet(List<CassandraColumnHandle> clusteringColumns,
        TupleDomain<ColumnHandle> predicates, VersionNumber cassandraVersion) {
    ImmutableMap.Builder<ColumnHandle, Domain> domainsBuilder = ImmutableMap.builder();
    ImmutableList.Builder<String> clusteringColumnSql = ImmutableList.builder();
    int currentClusteringColumn = 0;
    for (CassandraColumnHandle columnHandle : clusteringColumns) {
        Domain domain = predicates.getDomains().get().get(columnHandle);
        if (domain == null) {
            break;
        }/* w  w w . j  a va  2s  . com*/
        if (domain.isNullAllowed()) {
            break;
        }
        String predicateString = null;
        predicateString = domain.getValues().getValuesProcessor().transform(ranges -> {
            List<Object> singleValues = new ArrayList<>();
            List<String> rangeConjuncts = new ArrayList<>();
            String predicate = null;

            for (Range range : ranges.getOrderedRanges()) {
                if (range.isAll()) {
                    return null;
                }
                if (range.isSingleValue()) {
                    singleValues.add(CassandraCqlUtils.cqlValue(toCQLCompatibleString(range.getSingleValue()),
                            columnHandle.getCassandraType()));
                } else {
                    if (!range.getLow().isLowerUnbounded()) {
                        switch (range.getLow().getBound()) {
                        case ABOVE:
                            rangeConjuncts.add(CassandraCqlUtils.validColumnName(columnHandle.getName()) + " > "
                                    + CassandraCqlUtils.cqlValue(
                                            toCQLCompatibleString(range.getLow().getValue()),
                                            columnHandle.getCassandraType()));
                            break;
                        case EXACTLY:
                            rangeConjuncts
                                    .add(CassandraCqlUtils.validColumnName(columnHandle.getName()) + " >= "
                                            + CassandraCqlUtils.cqlValue(
                                                    toCQLCompatibleString(range.getLow().getValue()),
                                                    columnHandle.getCassandraType()));
                            break;
                        case BELOW:
                            throw new VerifyException("Low Marker should never use BELOW bound");
                        default:
                            throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
                        }
                    }
                    if (!range.getHigh().isUpperUnbounded()) {
                        switch (range.getHigh().getBound()) {
                        case ABOVE:
                            throw new VerifyException("High Marker should never use ABOVE bound");
                        case EXACTLY:
                            rangeConjuncts
                                    .add(CassandraCqlUtils.validColumnName(columnHandle.getName()) + " <= "
                                            + CassandraCqlUtils.cqlValue(
                                                    toCQLCompatibleString(range.getHigh().getValue()),
                                                    columnHandle.getCassandraType()));
                            break;
                        case BELOW:
                            rangeConjuncts.add(CassandraCqlUtils.validColumnName(columnHandle.getName()) + " < "
                                    + CassandraCqlUtils.cqlValue(
                                            toCQLCompatibleString(range.getHigh().getValue()),
                                            columnHandle.getCassandraType()));
                            break;
                        default:
                            throw new AssertionError("Unhandled bound: " + range.getHigh().getBound());
                        }
                    }
                }
            }

            if (!singleValues.isEmpty() && !rangeConjuncts.isEmpty()) {
                return null;
            }
            if (!singleValues.isEmpty()) {
                if (singleValues.size() == 1) {
                    predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " = "
                            + singleValues.get(0);
                } else {
                    predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " IN ("
                            + Joiner.on(",").join(singleValues) + ")";
                }
            } else if (!rangeConjuncts.isEmpty()) {
                predicate = Joiner.on(" AND ").join(rangeConjuncts);
            }
            return predicate;
        }, discreteValues -> {
            if (discreteValues.isWhiteList()) {
                ImmutableList.Builder<Object> discreteValuesList = ImmutableList.builder();
                for (Object discreteValue : discreteValues.getValues()) {
                    discreteValuesList.add(CassandraCqlUtils.cqlValue(toCQLCompatibleString(discreteValue),
                            columnHandle.getCassandraType()));
                }
                String predicate = CassandraCqlUtils.validColumnName(columnHandle.getName()) + " IN ("
                        + Joiner.on(",").join(discreteValuesList.build()) + ")";
                return predicate;
            }
            return null;
        }, allOrNone -> null);

        if (predicateString == null) {
            break;
        }
        // IN restriction only on last clustering column for Cassandra version = 2.1
        if (predicateString.contains(" IN (") && cassandraVersion.compareTo(VersionNumber.parse("2.2.0")) < 0
                && currentClusteringColumn != (clusteringColumns.size() - 1)) {
            break;
        }
        clusteringColumnSql.add(predicateString);
        domainsBuilder.put(columnHandle, domain);
        // Check for last clustering column should only be restricted by range condition
        if (predicateString.contains(">") || predicateString.contains("<")) {
            break;
        }
        currentClusteringColumn++;
    }
    List<String> clusteringColumnPredicates = clusteringColumnSql.build();

    return new ClusteringPushDownResult(domainsBuilder.build(),
            Joiner.on(" AND ").join(clusteringColumnPredicates));
}

From source file:io.prestosql.plugin.jdbc.QueryBuilder.java

public PreparedStatement buildSql(JdbcClient client, ConnectorSession session, Connection connection,
        String catalog, String schema, String table, List<JdbcColumnHandle> columns,
        TupleDomain<ColumnHandle> tupleDomain, Optional<String> additionalPredicate) throws SQLException {
    StringBuilder sql = new StringBuilder();

    String columnNames = columns.stream().map(JdbcColumnHandle::getColumnName).map(this::quote)
            .collect(joining(", "));

    sql.append("SELECT ");
    sql.append(columnNames);//from ww  w  . j a v  a2 s  .c  o m
    if (columns.isEmpty()) {
        sql.append("null");
    }

    sql.append(" FROM ");
    if (!isNullOrEmpty(catalog)) {
        sql.append(quote(catalog)).append('.');
    }
    if (!isNullOrEmpty(schema)) {
        sql.append(quote(schema)).append('.');
    }
    sql.append(quote(table));

    List<TypeAndValue> accumulator = new ArrayList<>();

    List<String> clauses = toConjuncts(client, session, columns, tupleDomain, accumulator);
    if (additionalPredicate.isPresent()) {
        clauses = ImmutableList.<String>builder().addAll(clauses).add(additionalPredicate.get()).build();
    }
    if (!clauses.isEmpty()) {
        sql.append(" WHERE ").append(Joiner.on(" AND ").join(clauses));
    }

    PreparedStatement statement = client.getPreparedStatement(connection, sql.toString());

    for (int i = 0; i < accumulator.size(); i++) {
        TypeAndValue typeAndValue = accumulator.get(i);
        int parameterIndex = i + 1;
        Type type = typeAndValue.getType();
        WriteFunction writeFunction = client.toPrestoType(session, typeAndValue.getTypeHandle())
                .orElseThrow(() -> new VerifyException(
                        format("Unsupported type %s with handle %s", type, typeAndValue.getTypeHandle())))
                .getWriteFunction();
        Class<?> javaType = type.getJavaType();
        Object value = typeAndValue.getValue();
        if (javaType == boolean.class) {
            ((BooleanWriteFunction) writeFunction).set(statement, parameterIndex, (boolean) value);
        } else if (javaType == long.class) {
            ((LongWriteFunction) writeFunction).set(statement, parameterIndex, (long) value);
        } else if (javaType == double.class) {
            ((DoubleWriteFunction) writeFunction).set(statement, parameterIndex, (double) value);
        } else if (javaType == Slice.class) {
            ((SliceWriteFunction) writeFunction).set(statement, parameterIndex, (Slice) value);
        } else {
            throw new VerifyException(format("Unexpected type %s with java type %s", type, javaType.getName()));
        }
    }

    return statement;
}

From source file:io.prestosql.plugin.jdbc.JdbcPageSink.java

private void appendColumn(Page page, int position, int channel) throws SQLException {
    Block block = page.getBlock(channel);
    int parameterIndex = channel + 1;

    if (block.isNull(position)) {
        statement.setObject(parameterIndex, null);
        return;/*from  w ww.  j ava  2 s . com*/
    }

    Type type = columnTypes.get(channel);
    Class<?> javaType = type.getJavaType();
    WriteFunction writeFunction = columnWriters.get(channel);
    if (javaType == boolean.class) {
        ((BooleanWriteFunction) writeFunction).set(statement, parameterIndex, type.getBoolean(block, position));
    } else if (javaType == long.class) {
        ((LongWriteFunction) writeFunction).set(statement, parameterIndex, type.getLong(block, position));
    } else if (javaType == double.class) {
        ((DoubleWriteFunction) writeFunction).set(statement, parameterIndex, type.getDouble(block, position));
    } else if (javaType == Slice.class) {
        ((SliceWriteFunction) writeFunction).set(statement, parameterIndex, type.getSlice(block, position));
    } else {
        throw new VerifyException(format("Unexpected type %s with java type %s", type, javaType.getName()));
    }
}

From source file:io.prestosql.plugin.raptor.legacy.systemtables.PreparedStatementBuilder.java

private static String toPredicate(int columnIndex, String columnName, Type type, Domain domain,
        Set<Integer> uuidColumnIndexes, List<ValueBuffer> bindValues) {
    if (domain.getValues().isAll()) {
        return domain.isNullAllowed() ? "TRUE" : columnName + " IS NOT NULL";
    }//from   w  w  w .  j a  va  2s .c  om
    if (domain.getValues().isNone()) {
        return domain.isNullAllowed() ? columnName + " IS NULL" : "FALSE";
    }

    return domain.getValues().getValuesProcessor().transform(ranges -> {
        // Add disjuncts for ranges
        List<String> disjuncts = new ArrayList<>();
        List<Object> singleValues = new ArrayList<>();

        // Add disjuncts for ranges
        for (Range range : ranges.getOrderedRanges()) {
            checkState(!range.isAll()); // Already checked
            if (range.isSingleValue()) {
                singleValues.add(range.getLow().getValue());
            } else {
                List<String> rangeConjuncts = new ArrayList<>();
                if (!range.getLow().isLowerUnbounded()) {
                    Object bindValue = getBindValue(columnIndex, uuidColumnIndexes, range.getLow().getValue());
                    switch (range.getLow().getBound()) {
                    case ABOVE:
                        rangeConjuncts.add(toBindPredicate(columnName, ">"));
                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                        break;
                    case EXACTLY:
                        rangeConjuncts.add(toBindPredicate(columnName, ">="));
                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                        break;
                    case BELOW:
                        throw new VerifyException("Low Marker should never use BELOW bound");
                    default:
                        throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
                    }
                }
                if (!range.getHigh().isUpperUnbounded()) {
                    Object bindValue = getBindValue(columnIndex, uuidColumnIndexes, range.getHigh().getValue());
                    switch (range.getHigh().getBound()) {
                    case ABOVE:
                        throw new VerifyException("High Marker should never use ABOVE bound");
                    case EXACTLY:
                        rangeConjuncts.add(toBindPredicate(columnName, "<="));
                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                        break;
                    case BELOW:
                        rangeConjuncts.add(toBindPredicate(columnName, "<"));
                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                        break;
                    default:
                        throw new AssertionError("Unhandled bound: " + range.getHigh().getBound());
                    }
                }
                // If rangeConjuncts is null, then the range was ALL, which should already have been checked for
                checkState(!rangeConjuncts.isEmpty());
                disjuncts.add("(" + Joiner.on(" AND ").join(rangeConjuncts) + ")");
            }
        }

        // Add back all of the possible single values either as an equality or an IN predicate
        if (singleValues.size() == 1) {
            disjuncts.add(toBindPredicate(columnName, "="));
            bindValues.add(ValueBuffer.create(columnIndex, type,
                    getBindValue(columnIndex, uuidColumnIndexes, getOnlyElement(singleValues))));
        } else if (singleValues.size() > 1) {
            disjuncts.add(columnName + " IN (" + Joiner.on(",").join(nCopies(singleValues.size(), "?")) + ")");
            for (Object singleValue : singleValues) {
                bindValues.add(ValueBuffer.create(columnIndex, type,
                        getBindValue(columnIndex, uuidColumnIndexes, singleValue)));
            }
        }

        // Add nullability disjuncts
        checkState(!disjuncts.isEmpty());
        if (domain.isNullAllowed()) {
            disjuncts.add(columnName + " IS NULL");
        }

        return "(" + Joiner.on(" OR ").join(disjuncts) + ")";
    },

            discreteValues -> {
                String values = Joiner.on(",").join(nCopies(discreteValues.getValues().size(), "?"));
                String predicate = columnName + (discreteValues.isWhiteList() ? "" : " NOT") + " IN (" + values
                        + ")";
                for (Object value : discreteValues.getValues()) {
                    bindValues.add(ValueBuffer.create(columnIndex, type,
                            getBindValue(columnIndex, uuidColumnIndexes, value)));
                }
                if (domain.isNullAllowed()) {
                    predicate = "(" + predicate + " OR " + columnName + " IS NULL)";
                }
                return predicate;
            },

            allOrNone -> {
                throw new IllegalStateException("Case should not be reachable");
            });
}

From source file:com.shieldsbetter.sbomg.Cli.java

private static Plan singleFilePlan(File absoluteInputFile, ProjectDescriptor d) throws OperationException {
    File absoluteProjectRoot = d.getRoot().getAbsoluteFile();
    String absoluteProjectRootPath = absoluteProjectRoot.getPath();
    if (!absoluteProjectRootPath.endsWith(File.separator)) {
        absoluteProjectRootPath += File.separator;
    }/* ww w.  j a  va 2 s . c om*/

    String inputFilePath = absoluteInputFile.getPath();

    if (!inputFilePath.startsWith(absoluteProjectRootPath)) {
        throw new VerifyException("Not a prefix?");
    }

    File projectRelativeInputFile = new File(inputFilePath.substring(absoluteProjectRootPath.length()));

    Plan p = new Plan();
    String packageSpec = d.getPackage(projectRelativeInputFile);
    p.addModel(absoluteInputFile, packageSpec,
            new File(new File(absoluteProjectRoot, d.getTargetDirectory().getPath()),
                    packageSpec.replace(".", File.separator)));
    return p;
}

From source file:io.prestosql.parquet.predicate.TupleDomainParquetPredicate.java

@VisibleForTesting
public static Domain getDomain(Type type, long rowCount, Statistics<?> statistics, ParquetDataSourceId id,
        String column, boolean failOnCorruptedParquetStatistics) throws ParquetCorruptionException {
    if (statistics == null || statistics.isEmpty()) {
        return Domain.all(type);
    }/*www  .  j  av  a  2  s  .c om*/

    if (statistics.getNumNulls() == rowCount) {
        return Domain.onlyNull(type);
    }

    boolean hasNullValue = statistics.getNumNulls() != 0L;

    if (statistics.genericGetMin() == null || statistics.genericGetMax() == null) {
        return Domain.create(ValueSet.all(type), hasNullValue);
    }

    if (type.equals(BOOLEAN) && statistics instanceof BooleanStatistics) {
        BooleanStatistics booleanStatistics = (BooleanStatistics) statistics;

        boolean hasTrueValues = !(booleanStatistics.getMax() == false && booleanStatistics.getMin() == false);
        boolean hasFalseValues = !(booleanStatistics.getMax() == true && booleanStatistics.getMin() == true);
        if (hasTrueValues && hasFalseValues) {
            return Domain.all(type);
        }
        if (hasTrueValues) {
            return Domain.create(ValueSet.of(type, true), hasNullValue);
        }
        if (hasFalseValues) {
            return Domain.create(ValueSet.of(type, false), hasNullValue);
        }
        // All nulls case is handled earlier
        throw new VerifyException("Impossible boolean statistics");
    }

    if ((type.equals(BIGINT) || type.equals(TINYINT) || type.equals(SMALLINT) || type.equals(INTEGER))
            && (statistics instanceof LongStatistics || statistics instanceof IntStatistics)) {
        ParquetIntegerStatistics parquetIntegerStatistics;
        if (statistics instanceof LongStatistics) {
            LongStatistics longStatistics = (LongStatistics) statistics;
            if (longStatistics.genericGetMin() > longStatistics.genericGetMax()) {
                failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, longStatistics);
                return Domain.create(ValueSet.all(type), hasNullValue);
            }
            parquetIntegerStatistics = new ParquetIntegerStatistics(longStatistics.genericGetMin(),
                    longStatistics.genericGetMax());
        } else {
            IntStatistics intStatistics = (IntStatistics) statistics;
            if (intStatistics.genericGetMin() > intStatistics.genericGetMax()) {
                failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, intStatistics);
                return Domain.create(ValueSet.all(type), hasNullValue);
            }
            parquetIntegerStatistics = new ParquetIntegerStatistics((long) intStatistics.getMin(),
                    (long) intStatistics.getMax());
        }
        if (isStatisticsOverflow(type, parquetIntegerStatistics)) {
            return Domain.create(ValueSet.all(type), hasNullValue);
        }
        return createDomain(type, hasNullValue, parquetIntegerStatistics);
    }

    if (type.equals(REAL) && statistics instanceof FloatStatistics) {
        FloatStatistics floatStatistics = (FloatStatistics) statistics;
        if (floatStatistics.genericGetMin() > floatStatistics.genericGetMax()) {
            failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, floatStatistics);
            return Domain.create(ValueSet.all(type), hasNullValue);
        }

        ParquetIntegerStatistics parquetStatistics = new ParquetIntegerStatistics(
                (long) floatToRawIntBits(floatStatistics.getMin()),
                (long) floatToRawIntBits(floatStatistics.getMax()));

        return createDomain(type, hasNullValue, parquetStatistics);
    }

    if (type.equals(DOUBLE) && statistics instanceof DoubleStatistics) {
        DoubleStatistics doubleStatistics = (DoubleStatistics) statistics;
        if (doubleStatistics.genericGetMin() > doubleStatistics.genericGetMax()) {
            failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, doubleStatistics);
            return Domain.create(ValueSet.all(type), hasNullValue);
        }
        ParquetDoubleStatistics parquetDoubleStatistics = new ParquetDoubleStatistics(
                doubleStatistics.genericGetMin(), doubleStatistics.genericGetMax());
        return createDomain(type, hasNullValue, parquetDoubleStatistics);
    }

    if (isVarcharType(type) && statistics instanceof BinaryStatistics) {
        BinaryStatistics binaryStatistics = (BinaryStatistics) statistics;
        Slice minSlice = Slices.wrappedBuffer(binaryStatistics.getMin().getBytes());
        Slice maxSlice = Slices.wrappedBuffer(binaryStatistics.getMax().getBytes());
        if (minSlice.compareTo(maxSlice) > 0) {
            failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, binaryStatistics);
            return Domain.create(ValueSet.all(type), hasNullValue);
        }
        ParquetStringStatistics parquetStringStatistics = new ParquetStringStatistics(minSlice, maxSlice);
        return createDomain(type, hasNullValue, parquetStringStatistics);
    }

    if (type.equals(DATE) && statistics instanceof IntStatistics) {
        IntStatistics intStatistics = (IntStatistics) statistics;
        if (intStatistics.genericGetMin() > intStatistics.genericGetMax()) {
            failWithCorruptionException(failOnCorruptedParquetStatistics, column, id, intStatistics);
            return Domain.create(ValueSet.all(type), hasNullValue);
        }
        ParquetIntegerStatistics parquetIntegerStatistics = new ParquetIntegerStatistics(
                (long) intStatistics.getMin(), (long) intStatistics.getMax());
        return createDomain(type, hasNullValue, parquetIntegerStatistics);
    }

    return Domain.create(ValueSet.all(type), hasNullValue);
}

From source file:org.sosy_lab.java_smt.solvers.z3.Z3TheoremProver.java

@Override
public <T> T allSat(AllSatCallback<T> callback, List<BooleanFormula> important)
        throws InterruptedException, SolverException {
    Preconditions.checkState(!closed);/*  ww  w .java 2  s  .  com*/

    // Unpack formulas to terms.
    long[] importantFormulas = new long[important.size()];
    int i = 0;
    for (BooleanFormula impF : important) {
        importantFormulas[i++] = Z3FormulaManager.getZ3Expr(impF);
    }

    try {
        Native.solverPush(z3context, z3solver);
    } catch (Z3Exception e) {
        throw creator.handleZ3Exception(e);
    }

    while (!isUnsat()) {
        long[] valuesOfModel = new long[importantFormulas.length];
        long z3model = Native.solverGetModel(z3context, z3solver);

        for (int j = 0; j < importantFormulas.length; j++) {
            long funcDecl = Native.getAppDecl(z3context, importantFormulas[j]);
            long valueOfExpr = Native.modelGetConstInterp(z3context, z3model, funcDecl);
            if (valueOfExpr == 0) {
                // In theory, this is a legal return value for modelGetConstInterp and means
                // that the value doesn't matter.
                // However, we have never seen this value so far except in case of shutdowns.
                creator.shutdownNotifier.shutdownIfNecessary();
                // If it ever happens in a legitimate usecase, we need to remove the following
                // exception and handle it by passing a partial model to the callback.
                throw new VerifyException(
                        "Z3 claims that the value of " + Native.astToString(z3context, importantFormulas[j])
                                + " does not matter in allSat call.");
            }

            if (isOP(z3context, valueOfExpr, Z3_decl_kind.Z3_OP_FALSE.toInt())) {
                valuesOfModel[j] = Native.mkNot(z3context, importantFormulas[j]);
                Native.incRef(z3context, valuesOfModel[j]);
            } else {
                valuesOfModel[j] = importantFormulas[j];
            }
        }

        callback.apply(new LongArrayBackedList<BooleanFormula>(valuesOfModel) {
            @Override
            protected BooleanFormula convert(long pE) {
                return creator.encapsulateBoolean(pE);
            }
        });

        long negatedModel = Native.mkNot(z3context,
                Native.mkAnd(z3context, valuesOfModel.length, valuesOfModel));
        Native.incRef(z3context, negatedModel);
        Native.solverAssert(z3context, z3solver, negatedModel);
    }

    // we pushed some levels on assertionStack, remove them and delete solver
    Native.solverPop(z3context, z3solver, 1);
    return callback.getResult();
}

From source file:io.prestosql.plugin.raptor.legacy.systemtables.ColumnRangesSystemTable.java

@Override
public ConnectorPageSource pageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session,
        TupleDomain<Integer> constraint) {
    String metadataSqlQuery = getColumnRangesMetadataSqlQuery(sourceTable, indexedRaptorColumns);
    List<Type> columnTypes = tableMetadata.getColumns().stream().map(ColumnMetadata::getType)
            .collect(toImmutableList());

    PageListBuilder pageListBuilder = new PageListBuilder(columnTypes);

    try (Connection connection = dbi.open().getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(metadataSqlQuery)) {
        if (resultSet.next()) {
            pageListBuilder.beginRow();// www.j a v a  2  s . c o m
            for (int i = 0; i < columnTypes.size(); ++i) {
                BlockBuilder blockBuilder = pageListBuilder.nextBlockBuilder();
                Type columnType = columnTypes.get(i);
                if (columnType.equals(BIGINT) || columnType.equals(DATE) || columnType.equals(TIMESTAMP)) {
                    long value = resultSet.getLong(i + 1);
                    if (!resultSet.wasNull()) {
                        columnType.writeLong(blockBuilder, value);
                    } else {
                        blockBuilder.appendNull();
                    }
                } else if (columnType.equals(BOOLEAN)) {
                    boolean value = resultSet.getBoolean(i + 1);
                    if (!resultSet.wasNull()) {
                        BOOLEAN.writeBoolean(blockBuilder, value);
                    } else {
                        blockBuilder.appendNull();
                    }
                } else {
                    throw new VerifyException("Unknown or unsupported column type: " + columnType);
                }
            }
        }
    } catch (SQLException | DBIException e) {
        throw metadataError(e);
    }

    return new FixedPageSource(pageListBuilder.build());
}

From source file:org.opendaylight.yangtools.triemap.INode.java

private static VerifyException invalidElement(final BasicNode elem) {
    throw new VerifyException("An INode can host only a CNode, a TNode or an LNode, not " + elem);
}