public class JdbcSchema extends Object implements Schema
Schema that is backed by a JDBC data source.
The tables in the JDBC data source appear to be tables in this schema; queries against this schema are executed against those tables, pushing down as much as possible of the query logic to SQL.
| Modifier and Type | Class and Description |
|---|---|
static class |
JdbcSchema.Factory
Schema factory that creates a
JdbcSchema. |
Schema.TableType| Modifier and Type | Field and Description |
|---|---|
(package private) String |
catalog |
(package private) JdbcConvention |
convention |
(package private) DataSource |
dataSource |
SqlDialect |
dialect |
(package private) String |
schema |
private boolean |
snapshot |
private com.google.common.collect.ImmutableMap<String,JdbcTable> |
tableMap |
| Modifier | Constructor and Description |
|---|---|
|
JdbcSchema(DataSource dataSource,
SqlDialect dialect,
JdbcConvention convention,
String catalog,
String schema)
Creates a JDBC schema.
|
private |
JdbcSchema(DataSource dataSource,
SqlDialect dialect,
JdbcConvention convention,
String catalog,
String schema,
com.google.common.collect.ImmutableMap<String,JdbcTable> tableMap) |
| Modifier and Type | Method and Description |
|---|---|
private static void |
close(Connection connection,
Statement statement,
ResultSet resultSet) |
private com.google.common.collect.ImmutableMap<String,JdbcTable> |
computeTables() |
static JdbcSchema |
create(SchemaPlus parentSchema,
String name,
DataSource dataSource,
SqlDialectFactory dialectFactory,
String catalog,
String schema) |
static JdbcSchema |
create(SchemaPlus parentSchema,
String name,
DataSource dataSource,
String catalog,
String schema) |
static JdbcSchema |
create(SchemaPlus parentSchema,
String name,
Map<String,Object> operand)
Creates a JdbcSchema, taking credentials from a map.
|
static SqlDialect |
createDialect(DataSource dataSource)
Deprecated.
Use
createDialect(SqlDialectFactory, DataSource) instead |
static SqlDialect |
createDialect(SqlDialectFactory dialectFactory,
DataSource dataSource)
Returns a suitable SQL dialect for the given data source.
|
static DataSource |
dataSource(String url,
String driverClassName,
String username,
String password)
Creates a JDBC data source with the given specification.
|
DataSource |
getDataSource() |
Expression |
getExpression(SchemaPlus parentSchema,
String name)
Returns the expression by which this schema can be referenced in generated
code.
|
Set<String> |
getFunctionNames()
Returns the names of the functions in this schema.
|
protected com.google.common.collect.Multimap<String,Function> |
getFunctions() |
Collection<Function> |
getFunctions(String name)
Returns a list of functions in this schema with the given name, or
an empty list if there is no such function.
|
(package private) RelProtoDataType |
getRelDataType(DatabaseMetaData metaData,
String catalogName,
String schemaName,
String tableName) |
(package private) RelProtoDataType |
getRelDataType(String catalogName,
String schemaName,
String tableName) |
Schema |
getSubSchema(String name)
Returns a sub-schema with a given name, or null.
|
Set<String> |
getSubSchemaNames()
Returns the names of this schema's child schemas.
|
Table |
getTable(String name)
Returns a table with a given name, or null if not found.
|
private com.google.common.collect.ImmutableMap<String,JdbcTable> |
getTableMap(boolean force) |
Set<String> |
getTableNames()
Returns the names of the tables in this schema.
|
boolean |
isMutable()
Returns whether the user is allowed to create new tables, functions
and sub-schemas in this schema, in addition to those returned automatically
by methods such as
Schema.getTable(String). |
private RelDataType |
parseTypeString(RelDataTypeFactory typeFactory,
String typeString)
Given "INTEGER", returns BasicSqlType(INTEGER).
|
Schema |
snapshot(SchemaVersion version)
Returns the snapshot of this schema as of the specified time.
|
private RelDataType |
sqlType(RelDataTypeFactory typeFactory,
int dataType,
int precision,
int scale,
String typeString) |
final DataSource dataSource
final String catalog
final String schema
public final SqlDialect dialect
final JdbcConvention convention
private final boolean snapshot
public JdbcSchema(DataSource dataSource, SqlDialect dialect, JdbcConvention convention, String catalog, String schema)
dataSource - Data sourcedialect - SQL dialectconvention - Calling conventioncatalog - Catalog name, or nullschema - Schema name patternprivate JdbcSchema(DataSource dataSource, SqlDialect dialect, JdbcConvention convention, String catalog, String schema, com.google.common.collect.ImmutableMap<String,JdbcTable> tableMap)
public static JdbcSchema create(SchemaPlus parentSchema, String name, DataSource dataSource, String catalog, String schema)
public static JdbcSchema create(SchemaPlus parentSchema, String name, DataSource dataSource, SqlDialectFactory dialectFactory, String catalog, String schema)
public static JdbcSchema create(SchemaPlus parentSchema, String name, Map<String,Object> operand)
parentSchema - Parent schemaname - Nameoperand - Map of property/value pairs@Deprecated public static SqlDialect createDialect(DataSource dataSource)
createDialect(SqlDialectFactory, DataSource) insteaddataSource - The data sourcepublic static SqlDialect createDialect(SqlDialectFactory dialectFactory, DataSource dataSource)
public static DataSource dataSource(String url, String driverClassName, String username, String password)
public boolean isMutable()
SchemaSchema.getTable(String).
Even if this method returns true, the maps are not modified. Calcite stores the defined objects in a wrapper object.
public Schema snapshot(SchemaVersion version)
Schemapublic DataSource getDataSource()
public Expression getExpression(SchemaPlus parentSchema, String name)
SchemagetExpression in interface SchemaparentSchema - Parent schemaname - Name of this schemapublic final Collection<Function> getFunctions(String name)
SchemagetFunctions in interface Schemaname - Name of functionpublic final Set<String> getFunctionNames()
SchemagetFunctionNames in interface Schemapublic Table getTable(String name)
Schemaprivate com.google.common.collect.ImmutableMap<String,JdbcTable> getTableMap(boolean force)
RelProtoDataType getRelDataType(String catalogName, String schemaName, String tableName) throws SQLException
SQLExceptionRelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName, String schemaName, String tableName) throws SQLException
SQLExceptionprivate RelDataType sqlType(RelDataTypeFactory typeFactory, int dataType, int precision, int scale, String typeString)
private RelDataType parseTypeString(RelDataTypeFactory typeFactory, String typeString)
public Set<String> getTableNames()
SchemagetTableNames in interface Schemapublic Schema getSubSchema(String name)
SchemagetSubSchema in interface Schemaname - Sub-schema namepublic Set<String> getSubSchemaNames()
SchemagetSubSchemaNames in interface Schemaprivate static void close(Connection connection, Statement statement, ResultSet resultSet)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.