Search in sources :

Example 1 with IgniteJdbcThinDataSource

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

the class JdbcThinDataSourceSelfTest method testJndi.

/**
 * @throws Exception If failed.
 */
@Test
public void testJndi() throws Exception {
    IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    InitialContext ic = getInitialContext();
    ic.bind("ds/test", ids);
    IgniteJdbcThinDataSource ds = (IgniteJdbcThinDataSource) ic.lookup("ds/test");
    assertTrue("Cannot looking up DataSource from JNDI", ds != null);
    assertEquals(ids.getUrl(), ds.getUrl());
}
Also used : IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 2 with IgniteJdbcThinDataSource

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

the class JdbcThinDataSourceSelfTest method testSqlHints.

/**
 * @throws Exception If failed.
 */
@Test
public void testSqlHints() throws Exception {
    IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertFalse(io.connectionProperties().isAutoCloseServerCursor());
            assertFalse(io.connectionProperties().isCollocated());
            assertFalse(io.connectionProperties().isEnforceJoinOrder());
            assertFalse(io.connectionProperties().isLazy());
            assertFalse(io.connectionProperties().isDistributedJoins());
            assertFalse(io.connectionProperties().isReplicatedOnly());
        }
    }
    ids.setAutoCloseServerCursor(true);
    ids.setCollocated(true);
    ids.setEnforceJoinOrder(true);
    ids.setLazy(true);
    ids.setDistributedJoins(true);
    ids.setReplicatedOnly(true);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertTrue(io.connectionProperties().isAutoCloseServerCursor());
            assertTrue(io.connectionProperties().isCollocated());
            assertTrue(io.connectionProperties().isEnforceJoinOrder());
            assertTrue(io.connectionProperties().isLazy());
            assertTrue(io.connectionProperties().isDistributedJoins());
            assertTrue(io.connectionProperties().isReplicatedOnly());
        }
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Test(org.junit.Test)

Example 3 with IgniteJdbcThinDataSource

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

the class JdbcThinDataSourceSelfTest method testSocketBuffers.

/**
 * @throws Exception If failed.
 */
@Test
public void testSocketBuffers() throws Exception {
    final IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    ids.setSocketReceiveBuffer(111);
    ids.setSocketSendBuffer(111);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) {
            assertEquals(111, io.connectionProperties().getSocketReceiveBuffer());
            assertEquals(111, io.connectionProperties().getSocketSendBuffer());
        }
    }
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ids.setSocketReceiveBuffer(-1);
            ids.getConnection();
            return null;
        }
    }, SQLException.class, "Property cannot be lower than 0 [name=socketReceiveBuffer, value=-1]");
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            ids.setSocketReceiveBuffer(1024);
            ids.setSocketSendBuffer(-1);
            ids.getConnection();
            return null;
        }
    }, SQLException.class, "Property cannot be lower than 0 [name=socketSendBuffer, value=-1]");
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 4 with IgniteJdbcThinDataSource

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

the class JDBCThinDriver method connectionFromDatasource.

public Connection connectionFromDatasource() throws SQLException {
    // tag::connection-from-data-source[]
    // Or open connection via DataSource.
    IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    ids.setDistributedJoins(true);
    Connection conn = ids.getConnection();
    return conn;
}
Also used : Connection(java.sql.Connection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource)

Example 5 with IgniteJdbcThinDataSource

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

the class JdbcThinDataSourceSelfTest method testTcpNoDelay.

/**
 * @throws Exception If failed.
 */
@Test
public void testTcpNoDelay() throws Exception {
    IgniteJdbcThinDataSource ids = new IgniteJdbcThinDataSource();
    ids.setUrl("jdbc:ignite:thin://127.0.0.1");
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) assertTrue(io.connectionProperties().isTcpNoDelay());
    }
    ids.setTcpNoDelay(false);
    try (Connection conn = ids.getConnection()) {
        for (JdbcThinTcpIo io : ios(conn)) assertFalse(io.connectionProperties().isTcpNoDelay());
    }
}
Also used : Connection(java.sql.Connection) JdbcThinConnection(org.apache.ignite.internal.jdbc.thin.JdbcThinConnection) IgniteJdbcThinDataSource(org.apache.ignite.IgniteJdbcThinDataSource) JdbcThinTcpIo(org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo) Test(org.junit.Test)

Aggregations

IgniteJdbcThinDataSource (org.apache.ignite.IgniteJdbcThinDataSource)7 Test (org.junit.Test)6 Connection (java.sql.Connection)4 JdbcThinConnection (org.apache.ignite.internal.jdbc.thin.JdbcThinConnection)3 JdbcThinTcpIo (org.apache.ignite.internal.jdbc.thin.JdbcThinTcpIo)3 SQLException (java.sql.SQLException)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1