Search in sources :

Example 6 with IgniteJdbcThinDriver

use of org.apache.ignite.IgniteJdbcThinDriver in project ignite by apache.

the class LongDestroyDurableBackgroundTaskTest method batchQuery.

/**
 * Batch query.
 *
 * @param ignite Ignite instance.
 * @param qry SQL query.
 * @param batchArgs Batch arguments.
 * @throws Exception If failed.
 */
private void batchQuery(Ignite ignite, String qry, List<Object[]> batchArgs) throws Exception {
    String host = ignite.configuration().getLocalHost();
    int port = ignite.configuration().getClientConnectorConfiguration().getPort();
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(host + ":" + port))) {
        try (Connection conn = new IgniteJdbcThinDriver().connect("jdbc:ignite:thin://" + host, new Properties())) {
            PreparedStatement statement = conn.prepareStatement(qry);
            for (Object[] args : batchArgs) {
                for (int i = 1; i <= args.length; i++) statement.setObject(i, args[i - 1]);
                statement.addBatch();
                statement.clearParameters();
            }
            statement.executeBatch();
        }
    }
}
Also used : IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) IgniteClient(org.apache.ignite.client.IgniteClient) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Aggregations

Connection (java.sql.Connection)6 Properties (java.util.Properties)6 IgniteJdbcThinDriver (org.apache.ignite.IgniteJdbcThinDriver)6 IgniteClient (org.apache.ignite.client.IgniteClient)5 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)5 Test (org.junit.Test)5 PreparedStatement (java.sql.PreparedStatement)2 List (java.util.List)2 Set (java.util.Set)2 IgniteSystemProperties (org.apache.ignite.IgniteSystemProperties)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 Iterators (com.google.common.collect.Iterators)1 Field (java.lang.reflect.Field)1 ResultSet (java.sql.ResultSet)1 DateFormat (java.text.DateFormat)1 LocalTime (java.time.LocalTime)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1