package backends
Provides database wrappers and connectivity for MySQL, Postgres, Oracle, and SQLite JDBC drivers.
Overview
The support for individual databases is broken out into several classes:
- A edu.chop.cbmi.dataExpress.backends.SqlBackend which is the wrapper around the various JDBC method calls
- A edu.chop.cbmi.dataExpress.backends.SqlDialect that contains the database-specific SQL quirks and implementation details
- A edu.chop.cbmi.dataExpress.backends.SqlBackendProvider (optional) that allows a third-party backend to be supplied outside DataExpress
The SqlBackend for the corresponding database is the primary means of establishing a datsbase connection when using DataExpress. However, It is important to note that it is generally easier, and safer to use the edu.chop.cbmi.dataExpress.backends.SqlBackendFactory to establish the necessary backend and set up the connection
In general the SQLDialect and BackendProvider are used as part of a SQLBackend, and not directly.
Usage
The edu.chop.cbmi.dataExpress.backends.SqlBackend requires properties to fully configure itself. Typically these are loaded from a file, but can also be supplied through a standard java.util.Properties object. The SQL backend has very simple requirements for properties files. They must contain the following keys:
: The class name for the actual database driverdriverClassName: This is the URI required by the database driver. It is passed through directly to JDBC so you are free to specify schemas and other information herejdbcUri: The username to authenticate against the database (not required for non-authenticated RDBMS systems such as SQLite) -username: The password for accessing the databasepassword
DataExpress will pass along any other properties it finds directly to JDBC, so in cases where a database requires specific connection configuration (e.g. to enable SSL for Postgres), those settings can be passed along.
In some cases, DataExpress will set specific properties on the connection to ensure predictable behavior. Most of these have been empirically determined by our testing given the narrow use cases for DataExpress. Where possible, we have made it possible for you to override these defaults in your own configuration file, however this is generally not recommended.
scala> import edu.chop.cbmi.dataExpress.backends._ import edu.chop.cbmi.dataExpress.backends._ scala> val backend = SqlBackendFactory "src/test/resources/sqlite_test.properties" backend: edu.chop.cbmi.dataExpress.backends.SqlBackend = SqlBackend({jdbcUri=jdbc:sqlite:target/source.sqlite},SqLiteDialect,org.sqlite.JDBC) scala> backend connect res0: java.sql.Connection = org.sqlite.Conn@7168f171 scala> backend execute """CREATE TABLE de_test(id INTEGER, first_name VARCHAR, last_name VARCHAR)""" res1: Boolean = false scala> backend commit res3: Boolean = false scala> backend executeQuery "select count(*) from de_test" res4: java.sql.ResultSet = org.sqlite.RS@3b070e76 scala> res4.getInt(1) res5: Int = 0
- Note
The SQL backends return jdbc ResultSets which are typically a little more "low-level" than what you would probably want for ETL purporses. The edu.chop.cbmi.dataExpress.dataModels.sql.SqlRelation is a much more convenient object to use for ETL.
- Alphabetic
- By Inheritance
- backends
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
class
MySqlBackend extends SqlBackend
Backend for accessing MySQL databases.
Backend for accessing MySQL databases. This will use a connection properties file that should look something like the following:
driverClassName=com.mysql.jdbc.Driver jdbcUri=jdbc:mysql://server_address:server_port/schema_name user=username password=password jdbcCompliantTruncation=false
-
class
OracleBackend extends SqlBackend
Backend for accessing Oracle databases.
Backend for accessing Oracle databases. This will use a connection properties file that should look something like the following:
driverClassName=jdbc.driver.OracleDriver jdbcUri=jdbc:oracle:thin:@//server_address:server_port user=username schema=schema_name password=passwordIf you must use an SID, the following is the format for the URI line:
jdbc:oracle:thin:@host:port:SID}}
-
class
OracleServiceProvider extends SqlBackendProvider
Service provider class for Oracle that allows runtime class loading of the Oracle driver
-
class
PostgresBackend extends SqlBackend
Backend for accessing Postgres databases.
Backend for accessing Postgres databases. This will use a connection properties file that should look something like the following:
driverClassName=org.postgresql.Driver jdbcUri=dbc:postgresql://server_address:server_port/schema_name user=username schema=schemaname password=passwordNote that if you are using a self-signed cert for Postgres SSL connection, you may also need
ssl=true sslfactory=org.postgresql.ssl.NonValidatingFactoryThe above is less secure, so it's not recommended unless you are operating on your own trusted network.
-
class
SqLiteBackend extends SqlBackend
Backend for accessing Sqlite databases.
Backend for accessing Sqlite databases. This will use a connection properties file that should look something like the following:
jdbcUri=jdbc:sqlite:filename_of_the_sqlite_database
-
case class
SqlBackend(connectionProperties: Properties, sqlDialect: SqlDialect, driverClassName: String) extends Product with Serializable
Wrapper around JDBC that simplifies the mechanics of interacting with databases in an RDBMS-neutral way.
Wrapper around JDBC that simplifies the mechanics of interacting with databases in an RDBMS-neutral way.
Instances of SqlBacked should normally be instantiated via edu.chop.cbmi.dataExpress.backends.SqlBackendFactory
-
trait
SqlBackendProvider extends AnyRef
Provides a mechanism to get a SqlBackend by supplying the necessary parameters at runtime
-
trait
SqlDialect extends AnyRef
This trait is to be used when constructing new SQL backends for DataExpress.
This trait is to be used when constructing new SQL backends for DataExpress. It provides basic SQL syntax for supported databases. This trait allows for customization of the SQL Syntax used in each RDBMS, while keeping the DataExpress API as generic as possible. More importantly, this trait provides baseline JDBC -> DataExpress type mappings which can be used across most database implementations.
-
class
SqlQueryCache extends AnyRef
While the JDBC spec encourages individual drivers to handle their own query cache, this behavior is not guaranteed.
While the JDBC spec encourages individual drivers to handle their own query cache, this behavior is not guaranteed. This class exists to provide consistent cache functionality across all drivers in DataExpress
-
class
SqlServerBackend extends SqlBackend
Backend for accessing SqlServer databases.
Backend for accessing SqlServer databases. This will use a connection properties file that should look something like the following:
driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbcUri=jdbc:sqlserver://server_address:server_port database=database_name user=user_name password=password - class SqlServerServiceProvider extends SqlBackendProvider
Value Members
-
object
GenericSqlDialect extends SqlDialect with Product with Serializable
This is a "generic" implementation of a edu.chop.cbmi.dataExpress.backends.SqlDialect.
This is a "generic" implementation of a edu.chop.cbmi.dataExpress.backends.SqlDialect. It is designed to work reasonably well in databases that conform to the SQL standard. In general, this object should only be used as a last resort when attempting to connect to an unsupported database.
-
object
MySqlDialect extends SqlDialect with Product with Serializable
SQL dialect for MySQL
SQL dialect for MySQL
-
object
OracleSqlDialect extends SqlDialect with Product with Serializable
SQL dialect for Oracle
SQL dialect for Oracle
-
object
PostgresSqlDialect extends SqlDialect with Product with Serializable
SQL dialect for Postgres
SQL dialect for Postgres
-
object
SqLiteDialect extends SqlDialect with Product with Serializable
SQL dialect for SQLite
SQL dialect for SQLite
-
object
SqlBackendFactory
Factory for edu.chop.cbmi.dataExpress.backends.SqlBackendFactory
-
object
SqlQueryCache
Factory for edu.chop.cbmi.dataExpress.backends.SqlQueryCache instances
- object SqlServerSqlDialect extends SqlDialect with Product with Serializable