Search in sources :

Example 1 with CalcitePrepareImpl

use of org.apache.calcite.prepare.CalcitePrepareImpl in project calcite by apache.

the class Frameworks method withPrepare.

/**
 * Initializes a container then calls user-specified code with a planner
 * and statement.
 *
 * @param action Callback containing user-specified code
 * @return Return value from action
 */
public static <R> R withPrepare(PrepareAction<R> action) {
    try {
        final Properties info = new Properties();
        if (action.config.getTypeSystem() != RelDataTypeSystem.DEFAULT) {
            info.setProperty(CalciteConnectionProperty.TYPE_SYSTEM.camelName(), action.config.getTypeSystem().getClass().getName());
        }
        Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
        final CalciteServerStatement statement = connection.createStatement().unwrap(CalciteServerStatement.class);
        return new CalcitePrepareImpl().perform(statement, action);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CalcitePrepareImpl(org.apache.calcite.prepare.CalcitePrepareImpl) CalciteServerStatement(org.apache.calcite.server.CalciteServerStatement) Connection(java.sql.Connection) Properties(java.util.Properties)

Aggregations

Connection (java.sql.Connection)1 Properties (java.util.Properties)1 CalcitePrepareImpl (org.apache.calcite.prepare.CalcitePrepareImpl)1 CalciteServerStatement (org.apache.calcite.server.CalciteServerStatement)1