public class IgniteJdbcDriver extends Object implements Driver
Driver allows to get distributed data from Ignite cache using standard SQL queries and standard JDBC API. It will automatically get only fields that you actually need from objects stored in cache.
AffinityKey
javadoc for more details.
Note that cache name is case sensitive and you have to always specify it in quotes.
IGNITE_HOME/libs
folder. So if you are using JDBC driver in any external tool,
you have to add main Ignite JAR will all dependencies to its classpath.
jdbc:ignite:cfg://[<params>@]<config_url>
.<config_url>
represents any valid URL which points to Ignite configuration file. It is required.<params>
are optional and have the following format: param1=value1:param2=value2:...:paramN=valueN
.cache
- cache name. If it is not defined than default cache will be used.nodeId
- ID of node where query will be executed.
It can be useful for querying through local caches.
If node with provided ID doesn't exist, exception is thrown.
local
- query will be executed only on local node. Use this parameter with nodeId
parameter.
Default value is false
.
collocated
- flag that used for optimization purposes. Whenever Ignite executes
a distributed query, it sends sub-queries to individual cluster members.
If you know in advance that the elements of your query selection are collocated
together on the same node, usually based on some affinity-key, Ignite
can make significant performance and network optimizations.
Default value is false
.
JDBC connection URL has the following pattern:
jdbc:ignite://<hostname>:<port>/<cache_name>?nodeId=<UUID>
Note the following:
11211
is used (default for Ignite client).<cache_name>
empty if you are connecting to default cache.nodeId
parameter if you want to specify node where to execute
your queries. Note that local and replicated caches will be queried locally on
this node while partitioned cache is queried distributively. If node ID is not
provided, random node is used. If node with provided ID doesn't exist,
exception is thrown.
Properties
object passed to
DriverManager.getConnection(String, Properties)
method:
Name | Description | Default | Optional |
---|---|---|---|
ignite.client.protocol | Communication protocol (TCP or HTTP ). |
TCP |
Yes |
ignite.client.connectTimeout | Socket connection timeout. | 0 (infinite timeout) |
Yes |
ignite.client.tcp.noDelay | Flag indicating whether TCP_NODELAY flag should be enabled for outgoing connections. | true |
Yes |
ignite.client.ssl.enabled | Flag indicating that SSL is needed for connection. |
false |
Yes |
ignite.client.ssl.protocol | SSL protocol (SSL or TLS ). |
TLS |
Yes |
ignite.client.ssl.key.algorithm | Key manager algorithm. | SunX509 |
Yes |
ignite.client.ssl.keystore.location | Key store to be used by client to connect with Ignite topology. | No (if SSL is enabled) |
|
ignite.client.ssl.keystore.password | Key store password. | Yes | |
ignite.client.ssl.keystore.type | Key store type. | jks |
Yes |
ignite.client.ssl.truststore.location | Trust store to be used by client to connect with Ignite topology. | No (if SSL is enabled) |
|
ignite.client.ssl.truststore.password | Trust store password. | Yes | |
ignite.client.ssl.truststore.type | Trust store type. | jks |
Yes |
ignite.client.credentials | Client credentials used in authentication process. | Yes | |
ignite.client.cache.top |
Flag indicating that topology is cached internally. Cache will be refreshed in
the background with interval defined by ignite.client.topology.refresh
property (see below).
|
false |
Yes |
ignite.client.topology.refresh | Topology cache refresh frequency (ms). | 2000 |
Yes |
ignite.client.idleTimeout | Maximum amount of time that connection can be idle before it is closed (ms). | 30000 |
Yes |
// Register JDBC driver. Class.forName("org.apache.ignite.IgniteJdbcDriver"); // Open JDBC connection. Connection conn = DriverManager.getConnection("jdbc:ignite:cfg//cache=persons@file:///etc/configs/ignite-jdbc.xml"); // Query persons' names ResultSet rs = conn.createStatement().executeQuery("select name from Person"); while (rs.next()) { String name = rs.getString(1); ... } // Query persons with specific age PreparedStatement stmt = conn.prepareStatement("select name, age from Person where age = ?"); stmt.setInt(1, 30); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String name = rs.getString("name"); int age = rs.getInt("age"); ... }
Modifier and Type | Field and Description |
---|---|
static String |
CFG_URL_PREFIX
Config URL prefix.
|
static int |
DFLT_PORT
Default port.
|
static String |
PROP_CACHE
Cache name property name.
|
static String |
PROP_CFG
Cache name property name.
|
static String |
PROP_COLLOCATED
Collocated property name.
|
static String |
PROP_HOST
Hostname property name.
|
static String |
PROP_LOCAL
Local property name.
|
static String |
PROP_NODE_ID
Node ID property name.
|
static String |
PROP_PORT
Port number property name.
|
static String |
URL_PREFIX
URL prefix.
|
Constructor and Description |
---|
IgniteJdbcDriver() |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptsURL(String url) |
Connection |
connect(String url,
Properties props) |
int |
getMajorVersion() |
int |
getMinorVersion() |
Logger |
getParentLogger() |
DriverPropertyInfo[] |
getPropertyInfo(String url,
Properties info) |
boolean |
jdbcCompliant() |
public static final String PROP_HOST
public static final String PROP_PORT
public static final String PROP_CACHE
public static final String PROP_NODE_ID
public static final String PROP_LOCAL
public static final String PROP_COLLOCATED
public static final String PROP_CFG
public static final String URL_PREFIX
public static final String CFG_URL_PREFIX
public static final int DFLT_PORT
public Connection connect(String url, Properties props) throws SQLException
connect
in interface Driver
SQLException
public boolean acceptsURL(String url) throws SQLException
acceptsURL
in interface Driver
SQLException
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
getPropertyInfo
in interface Driver
SQLException
public int getMajorVersion()
getMajorVersion
in interface Driver
public int getMinorVersion()
getMinorVersion
in interface Driver
public boolean jdbcCompliant()
jdbcCompliant
in interface Driver
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface Driver
SQLFeatureNotSupportedException
Follow @ApacheIgnite
Ignite Fabric : ver. 1.5.0.final Release Date : December 29 2015