Search in sources :

Example 1 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerStatementTest method prepareUnsupportedStatementTest.

private CloudSpannerStatement prepareUnsupportedStatementTest() throws SQLException {
    thrown.expect(SQLFeatureNotSupportedException.class);
    CloudSpannerConnection connection = createConnection();
    CloudSpannerStatement statement = connection.createStatement();
    return statement;
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection)

Example 2 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerTransactionTest method testInterfaceMethods.

/**
 * Run some simple tests for methods that are needed for the interface, but
 * do not do anything
 *
 * @throws SQLException
 */
@Test
public void testInterfaceMethods() throws SQLException {
    CloudSpannerConnection connection = CloudSpannerTestObjects.createConnection();
    try (CloudSpannerTransaction tx = new CloudSpannerTransaction(null, connection)) {
        Assert.assertNull(tx.read(null, null, null));
        Assert.assertNull(tx.readUsingIndex(null, null, null, null));
        Assert.assertNull(tx.readRow(null, null, null));
        Assert.assertNull(tx.readRowUsingIndex(null, null, null, null));
        Assert.assertNull(tx.analyzeQuery(null, null));
    }
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test)

Example 3 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class DeleteWorker method createSelect.

private static Select createSelect(CloudSpannerConnection connection, Delete delete) throws SQLException {
    TableKeyMetaData table = connection.getTable(CloudSpannerDriver.unquoteIdentifier(delete.getTable().getName()));
    List<String> keyCols = table.getKeyColumns().stream().map(x -> CloudSpannerDriver.quoteIdentifier(delete.getTable().getName()) + "." + CloudSpannerDriver.quoteIdentifier(x)).collect(Collectors.toList());
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ").append(String.join(", ", keyCols));
    sql.append("\nFROM ").append(CloudSpannerDriver.quoteIdentifier(delete.getTable().getName()));
    sql.append("\nWHERE ").append(delete.getWhere().toString());
    try {
        return (Select) CCJSqlParserUtil.parse(sql.toString());
    } catch (JSQLParserException e) {
        throw new CloudSpannerSQLException("Could not parse generated SELECT statement: " + sql, Code.INVALID_ARGUMENT);
    }
}
Also used : TableKeyMetaData(nl.topicus.jdbc.MetaDataStore.TableKeyMetaData) CCJSqlParserUtil(net.sf.jsqlparser.parser.CCJSqlParserUtil) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Table(net.sf.jsqlparser.schema.Table) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException) Collectors(java.util.stream.Collectors) JSQLParserException(net.sf.jsqlparser.JSQLParserException) TableKeyMetaData(nl.topicus.jdbc.MetaDataStore.TableKeyMetaData) SQLException(java.sql.SQLException) List(java.util.List) Select(net.sf.jsqlparser.statement.select.Select) CloudSpannerDriver(nl.topicus.jdbc.CloudSpannerDriver) Code(com.google.rpc.Code) Delete(net.sf.jsqlparser.statement.delete.Delete) JSQLParserException(net.sf.jsqlparser.JSQLParserException) Select(net.sf.jsqlparser.statement.select.Select) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException)

Example 4 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerXAConnectionTest method createSubject.

private CloudSpannerXAConnection createSubject() throws SQLException {
    CloudSpannerConnection conn = CloudSpannerTestObjects.createConnection();
    CloudSpannerXAConnection res = new CloudSpannerXAConnection(conn);
    return res;
}
Also used : CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) ICloudSpannerConnection(nl.topicus.jdbc.ICloudSpannerConnection)

Example 5 with CloudSpannerConnection

use of nl.topicus.jdbc.CloudSpannerConnection in project spanner-jdbc by olavloite.

the class CloudSpannerXADataSourceTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    CloudSpannerXADataSource subject = new CloudSpannerXADataSource();
    CloudSpannerDataSourceTest.setCommonDataSourceTestProperties(subject);
    subject.setCreateXATable(false);
    CloudSpannerXAConnection connection = subject.getXAConnection();
    assertNotNull(connection);
    assertNotNull(subject.getDescription());
    Connection con = connection.getConnection();
    Assert.assertTrue(con.isWrapperFor(CloudSpannerConnection.class));
    CloudSpannerConnection cloudSpannerConnection = con.unwrap(CloudSpannerConnection.class);
    CloudSpannerDataSourceTest.testCommonDataSourceTestProperties(cloudSpannerConnection);
}
Also used : CloudSpannerXADataSource(nl.topicus.jdbc.CloudSpannerXADataSource) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Connection(java.sql.Connection) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test) CloudSpannerDataSourceTest(nl.topicus.jdbc.CloudSpannerDataSourceTest)

Aggregations

CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)37 Test (org.junit.Test)22 UnitTest (nl.topicus.jdbc.test.category.UnitTest)17 ResultSet (java.sql.ResultSet)11 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 IntegrationTest (nl.topicus.jdbc.test.category.IntegrationTest)5 SQLException (java.sql.SQLException)4 Returns (org.mockito.internal.stubbing.answers.Returns)4 TableKeyMetaData (nl.topicus.jdbc.MetaDataStore.TableKeyMetaData)3 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)3 Select (net.sf.jsqlparser.statement.select.Select)2 CloudSpannerDataSourceTest (nl.topicus.jdbc.CloudSpannerDataSourceTest)2 CloudSpannerDatabaseMetaData (nl.topicus.jdbc.CloudSpannerDatabaseMetaData)2 CloudSpannerXADataSource (nl.topicus.jdbc.CloudSpannerXADataSource)2 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Code (com.google.rpc.Code)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 PropertyVetoException (java.beans.PropertyVetoException)1