use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class AlternatingRemoteMetaTest method testRemoteConnectionProperties.
@Test
public void testRemoteConnectionProperties() throws Exception {
ConnectionSpec.getDatabaseLock().lock();
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
String id = conn.id;
final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap;
assertFalse("remote connection map should start ignorant", m.containsKey(id));
// force creating a connection object on the remote side.
try (final Statement stmt = conn.createStatement()) {
assertTrue("creating a statement starts a local object.", m.containsKey(id));
assertTrue(stmt.execute("select count(1) from EMP"));
}
Connection remoteConn = getConnection(FullyRemoteJdbcMetaFactory.getInstance(), id);
final boolean defaultRO = remoteConn.isReadOnly();
final boolean defaultAutoCommit = remoteConn.getAutoCommit();
final String defaultCatalog = remoteConn.getCatalog();
final String defaultSchema = remoteConn.getSchema();
conn.setReadOnly(!defaultRO);
assertTrue("local changes dirty local state", m.get(id).isDirty());
assertEquals("remote connection has not been touched", defaultRO, remoteConn.isReadOnly());
conn.setAutoCommit(!defaultAutoCommit);
assertEquals("remote connection has not been touched", defaultAutoCommit, remoteConn.getAutoCommit());
// further interaction with the connection will force a sync
try (final Statement stmt = conn.createStatement()) {
assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit());
assertFalse("local values should be clean", m.get(id).isDirty());
}
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class RemoteMetaTest method testBigints.
@Test
public void testBigints() throws Exception {
final String table = "TESTBIGINTS";
ConnectionSpec.getDatabaseLock().lock();
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
assertFalse(stmt.execute("DROP TABLE IF EXISTS " + table));
assertFalse(stmt.execute("CREATE TABLE " + table + " (id BIGINT)"));
assertFalse(stmt.execute("INSERT INTO " + table + " values(10)"));
ResultSet results = conn.getMetaData().getColumns(null, null, table, null);
assertTrue(results.next());
assertEquals(table, results.getString(3));
// ordinal position
assertEquals(1L, results.getLong(17));
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class RemoteMetaTest method testRemoteColumnsMeta.
@Test
public void testRemoteColumnsMeta() throws Exception {
ConnectionSpec.getDatabaseLock().lock();
try {
// Verify all columns are retrieved, thus that frame-based fetching works correctly
// for columns
int rowCount = 0;
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
ResultSet rs = conn.getMetaData().getColumns(null, null, null, null);
while (rs.next()) {
rowCount++;
}
rs.close();
// The implicitly created statement should have been closed
assertTrue(rs.getStatement().isClosed());
}
// default fetch size is 100, we are well beyond it
assertTrue(rowCount > 900);
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class Driver method connect.
@Override
public Connection connect(String url, Properties info) throws SQLException {
AvaticaConnection conn = (AvaticaConnection) super.connect(url, info);
if (conn == null) {
// It's not an url for our driver
return null;
}
Service service = conn.getService();
// super.connect(...) should be creating a service and setting it in the AvaticaConnection
assert null != service;
service.apply(new Service.OpenConnectionRequest(conn.id, Service.OpenConnectionRequest.serializeProperties(info)));
return conn;
}
use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class AlternatingRemoteMetaTest method checkLargeQuery.
private void checkLargeQuery(int n) throws Exception {
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
final AvaticaStatement statement = conn.createStatement();
final String frenchDisko = "It said human existence is pointless\n" + "As acts of rebellious solidarity\n" + "Can bring sense in this world\n" + "La resistance!\n";
final String sql = "select '" + longString(frenchDisko, n) + "' as s from (values 'x')";
prepareAndExecuteInternal(conn, statement, sql, -1);
ResultSet rs = statement.getResultSet();
int count = 0;
while (rs.next()) {
count++;
}
assertThat(count, is(1));
rs.close();
statement.close();
conn.close();
}
}
Aggregations