Search in sources :

Example 1 with JdbcSchema

use of org.apache.calcite.adapter.jdbc.JdbcSchema in project calcite by apache.

the class ModelHandler method visit.

public void visit(JsonJdbcSchema jsonSchema) {
    checkRequiredAttributes(jsonSchema, "name");
    final SchemaPlus parentSchema = currentMutableSchema("jdbc schema");
    final DataSource dataSource = JdbcSchema.dataSource(jsonSchema.jdbcUrl, jsonSchema.jdbcDriver, jsonSchema.jdbcUser, jsonSchema.jdbcPassword);
    final JdbcSchema schema;
    if (jsonSchema.sqlDialectFactory == null || jsonSchema.sqlDialectFactory.isEmpty()) {
        schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema);
    } else {
        SqlDialectFactory factory = AvaticaUtils.instantiatePlugin(SqlDialectFactory.class, jsonSchema.sqlDialectFactory);
        schema = JdbcSchema.create(parentSchema, jsonSchema.name, dataSource, factory, jsonSchema.jdbcCatalog, jsonSchema.jdbcSchema);
    }
    final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema);
    populateSchema(jsonSchema, schemaPlus);
}
Also used : JdbcSchema(org.apache.calcite.adapter.jdbc.JdbcSchema) SqlDialectFactory(org.apache.calcite.sql.SqlDialectFactory) SchemaPlus(org.apache.calcite.schema.SchemaPlus) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)1 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 SqlDialectFactory (org.apache.calcite.sql.SqlDialectFactory)1