The Apache MetaModel JDBC module is built such that we use as much of the powerful SQL capabilities of JDBC databases as possible (see Query execution strategies). So as such the module does little, except translate JDBC into the MetaModel API, but on the other hand it provides a single interface which translates into any of the many SQL dialects that are out there.
Features of the connector includes:
- Full implementation of DataContext and UpdateableDataContext.
- Mapping of MetaModel's data types to the particular set of data types available for the database. For instance MetaModel's STRING will be automatically converted to 'VARCHAR', 'TEXT' etc. depending on the database.
- Automatic formatting and narrowing of values when interacting with the database.
- Contains specialization and optimization for many databases, including:
- Microsoft SQL Server
- IBM DB2
- Apache Hive
- Apache Derby
- Support for JDBC batch operations when you use BatchUpdateScript.
- Support for reusable prepared statements (as Compiled queries in MetaModel).
- Works with single
Connections or connection pools (
Creating from plain old java code - JdbcDataContext
This is really simple - if you have a JDBC based
Connection or a
DataSource, simply pass it to new
Creating from properties - JdbcDataContextFactory
The JDBC connector can also be driven by properties via MetaModel's DataContextFactory SPI:
final DataContextPropertiesImpl properties = new DataContextPropertiesImpl();
DataContext dataContext = DataContextFactoryRegistryImpl.getDefaultInstance().createDataContext(properties);
The following table outlines all the relevant properties for this style of instantiation:
|Must be set to 'jdbc' or else another type of DataContext will be constructed.|
|The JDBC URL to use.|
|The JDBC driver class name.|
|The username to use when connecting.|
|The password to use when connecting.|
|A comma-separated list of table types to include in JDBC metadata discovery.|
|The JDBC 'catalog' value|
Additional behaviour configurationThe module contains a few features that are specific to the JDBC interactions. These are all configured as Java system properties.
|System property||Default value||Description|
|Whether or not to automatically convert CLOBs into |
|Whether or not using the JDBC batch API should be allowed. Set to "true" or "false" to override the default dynamic behavior.|
|The maximum number of open prepared statements to keep in a pool for the compiled queries.|
|The minimum idle timeout before a prepared statement is marked as evictable.|
|The time between eviction runs in the compiled queries pool.|