use of com.mysql.cj.jdbc.JdbcStatement in project aws-mysql-jdbc by awslabs.
the class QueryAttributesTest method plainStatementWithQueryAttributesInMultiHost.
/**
* Tests whether proxied plain statement objects created in multi-host connections handle query attributes correctly.
*
* @throws Exception
*/
@Test
void plainStatementWithQueryAttributesInMultiHost() throws Exception {
// Failover connection.
Connection testConn = getFailoverConnection();
Statement testStmt = testConn.createStatement();
assertTrue(JdbcStatement.class.isInstance(testStmt));
JdbcStatement testJdbcStmt = (JdbcStatement) testStmt;
testJdbcStmt.setAttribute("qa", "MySQL Connector/J");
this.rs = testStmt.executeQuery("SELECT mysql_query_attribute_string('qa')");
assertTrue(this.rs.next());
assertEquals("MySQL Connector/J", this.rs.getString(1));
assertFalse(this.rs.next());
testConn.close();
// Loadbalanced connection.
testConn = getLoadBalancedConnection();
testStmt = testConn.createStatement();
assertTrue(JdbcStatement.class.isInstance(testStmt));
testJdbcStmt = (JdbcStatement) testStmt;
testJdbcStmt.setAttribute("qa", "MySQL Connector/J");
this.rs = testStmt.executeQuery("SELECT mysql_query_attribute_string('qa')");
assertTrue(this.rs.next());
assertEquals("MySQL Connector/J", this.rs.getString(1));
assertFalse(this.rs.next());
testConn.close();
// Replication connection.
testConn = getSourceReplicaReplicationConnection();
testStmt = testConn.createStatement();
assertTrue(JdbcStatement.class.isInstance(testStmt));
testJdbcStmt = (JdbcStatement) testStmt;
testJdbcStmt.setAttribute("qa", "MySQL Connector/J");
this.rs = testStmt.executeQuery("SELECT mysql_query_attribute_string('qa')");
assertTrue(this.rs.next());
assertEquals("MySQL Connector/J", this.rs.getString(1));
assertFalse(this.rs.next());
testConn.close();
}
use of com.mysql.cj.jdbc.JdbcStatement in project aws-mysql-jdbc by awslabs.
the class QueryAttributesTest method multiQueriesWithAttributesInPlainStatement.
/**
* Tests if query attributes hold in plain statements with multi-queries.
*
* @throws Exception
*/
@Test
public void multiQueriesWithAttributesInPlainStatement() throws Exception {
Properties props = new Properties();
props.setProperty(PropertyKey.allowMultiQueries.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();
assertTrue(JdbcStatement.class.isInstance(testStmt));
JdbcStatement testJdbcStmt = (JdbcStatement) testStmt;
testJdbcStmt.setAttribute("qa01", "MySQL Connector/J");
testJdbcStmt.setAttribute("qa02", "8.0.26");
this.rs = testStmt.executeQuery("SELECT mysql_query_attribute_string('qa01') AS qa01; SELECT mysql_query_attribute_string('qa02') AS qa02;");
assertTrue(this.rs.next());
assertEquals("MySQL Connector/J", this.rs.getString("qa01"));
assertFalse(this.rs.next());
assertTrue(testStmt.getMoreResults());
this.rs = testStmt.getResultSet();
assertTrue(this.rs.next());
assertEquals("8.0.26", this.rs.getString("qa02"));
assertFalse(this.rs.next());
testConn.close();
}
use of com.mysql.cj.jdbc.JdbcStatement in project aws-mysql-jdbc by awslabs.
the class UtilsTest method testIsJdbcInterface.
/**
* Tests Util.isJdbcInterface()
*/
@Test
public void testIsJdbcInterface() {
// Classes directly or indirectly implementing JDBC interfaces.
assertTrue(Util.isJdbcInterface(ClientPreparedStatement.class));
assertTrue(Util.isJdbcInterface(StatementImpl.class));
assertTrue(Util.isJdbcInterface(JdbcStatement.class));
assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
JdbcStatement s = (JdbcStatement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { JdbcStatement.class }, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
});
assertTrue(Util.isJdbcInterface(s.getClass()));
// Classes not implementing JDBC interfaces.
assertFalse(Util.isJdbcInterface(Util.class));
assertFalse(Util.isJdbcInterface(UtilsTest.class));
}
Aggregations