public class GridJdbcDriver extends Object implements Driver
Driver allows to get distributed data from GridGain cache using standard SQL queries and standard JDBC API. It will automatically get only fields that you actually need from objects stored in cache.
Group by and sort by statements are applied separately
on each node, so result set will likely be incorrectly grouped or sorted
after results from multiple remote nodes are grouped together.
sum, max, avg, etc.
are also applied on each node. Therefore you will get several results
containing aggregated values, one for each node.
GridCacheAffinityKey
javadoc for more details.
Note that cache name is case sensitive and you have to always specify it in quotes.
GRIDGAIN_HOME/libs folder. So if you are using JDBC driver in any external tool,
you have to add main GridGain JAR will all dependencies to its classpath.
JDBC connection URL has the following pattern:
jdbc:gridgain://<hostname>:<port>/<cache_name>?nodeId=<UUID>
Note the following:
11211 is used (default for GridGain 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 |
|---|---|---|---|
| gg.client.protocol | Communication protocol (TCP or HTTP). |
TCP |
Yes |
| gg.client.connectTimeout | Socket connection timeout. | 0 (infinite timeout) |
Yes |
| gg.client.tcp.noDelay | Flag indicating whether TCP_NODELAY flag should be enabled for outgoing connections. | true |
Yes |
| gg.client.ssl.enabled | Flag indicating that SSL is needed for connection. |
false |
Yes |
| gg.client.ssl.protocol | SSL protocol (SSL or TLS). |
TLS |
Yes |
| gg.client.ssl.key.algorithm | Key manager algorithm. | SunX509 |
Yes |
| gg.client.ssl.keystore.location | Key store to be used by client to connect with GridGain topology. | No (if SSL is enabled) |
|
| gg.client.ssl.keystore.password | Key store password. | Yes | |
| gg.client.ssl.keystore.type | Key store type. | jks |
Yes |
| gg.client.ssl.truststore.location | Trust store to be used by client to connect with GridGain topology. | No (if SSL is enabled) |
|
| gg.client.ssl.truststore.password | Trust store password. | Yes | |
| gg.client.ssl.truststore.type | Trust store type. | jks |
Yes |
| gg.client.credentials | Client credentials used in authentication process. | Yes | |
| gg.client.cache.top |
Flag indicating that topology is cached internally. Cache will be refreshed in
the background with interval defined by gg.client.topology.refresh
property (see below).
|
false |
Yes |
| gg.client.topology.refresh | Topology cache refresh frequency (ms). | 2000 |
Yes |
| gg.client.idleTimeout | Maximum amount of time that connection can be idle before it is closed (ms). | 30000 |
Yes |
// Register JDBC driver.
Class.forName("org.gridgain.jdbc.GridJdbcDriver");
// Open JDBC connection.
Connection conn = DriverManager.getConnection("jdbc:gridgain://localhost/cache");
// 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");
...
}
| Constructor and Description |
|---|
GridJdbcDriver() |
| 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 Connection connect(String url, Properties props) throws SQLException
connect in interface DriverSQLExceptionpublic boolean acceptsURL(String url) throws SQLException
acceptsURL in interface DriverSQLExceptionpublic DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
getPropertyInfo in interface DriverSQLExceptionpublic int getMajorVersion()
getMajorVersion in interface Driverpublic int getMinorVersion()
getMinorVersion in interface Driverpublic boolean jdbcCompliant()
jdbcCompliant in interface Driverpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface DriverSQLFeatureNotSupportedExceptionCopyright © 2014. All rights reserved.