Search in sources :

Example 1 with SqlDialectFactory

use of org.apache.calcite.sql.SqlDialectFactory in project calcite by apache.

the class JdbcSchema method create.

/**
 * Creates a JdbcSchema, taking credentials from a map.
 *
 * @param parentSchema Parent schema
 * @param name Name
 * @param operand Map of property/value pairs
 * @return A JdbcSchema
 */
public static JdbcSchema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {
    DataSource dataSource;
    try {
        final String dataSourceName = (String) operand.get("dataSource");
        if (dataSourceName != null) {
            dataSource = AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName);
        } else {
            final String jdbcUrl = (String) operand.get("jdbcUrl");
            final String jdbcDriver = (String) operand.get("jdbcDriver");
            final String jdbcUser = (String) operand.get("jdbcUser");
            final String jdbcPassword = (String) operand.get("jdbcPassword");
            dataSource = dataSource(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error while reading dataSource", e);
    }
    String jdbcCatalog = (String) operand.get("jdbcCatalog");
    String jdbcSchema = (String) operand.get("jdbcSchema");
    String sqlDialectFactory = (String) operand.get("sqlDialectFactory");
    if (sqlDialectFactory == null || sqlDialectFactory.isEmpty()) {
        return JdbcSchema.create(parentSchema, name, dataSource, jdbcCatalog, jdbcSchema);
    } else {
        SqlDialectFactory factory = AvaticaUtils.instantiatePlugin(SqlDialectFactory.class, sqlDialectFactory);
        return JdbcSchema.create(parentSchema, name, dataSource, factory, jdbcCatalog, jdbcSchema);
    }
}
Also used : SqlDialectFactory(org.apache.calcite.sql.SqlDialectFactory) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 2 with SqlDialectFactory

use of org.apache.calcite.sql.SqlDialectFactory 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)2 SqlDialectFactory (org.apache.calcite.sql.SqlDialectFactory)2 SQLException (java.sql.SQLException)1 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1