Search in sources :

Example 56 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project calcite-avatica by apache.

the class JdbcResultSet method getValue.

private static Object getValue(ResultSet resultSet, int type, int j, Calendar calendar) throws SQLException {
    switch(type) {
        case Types.BIGINT:
            final long aLong = resultSet.getLong(j + 1);
            return aLong == 0 && resultSet.wasNull() ? null : aLong;
        case Types.INTEGER:
            final int anInt = resultSet.getInt(j + 1);
            return anInt == 0 && resultSet.wasNull() ? null : anInt;
        case Types.SMALLINT:
            final short aShort = resultSet.getShort(j + 1);
            return aShort == 0 && resultSet.wasNull() ? null : aShort;
        case Types.TINYINT:
            final byte aByte = resultSet.getByte(j + 1);
            return aByte == 0 && resultSet.wasNull() ? null : aByte;
        case Types.DOUBLE:
        case Types.FLOAT:
            final double aDouble = resultSet.getDouble(j + 1);
            return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
        case Types.REAL:
            final float aFloat = resultSet.getFloat(j + 1);
            return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
        case Types.DATE:
            final Date aDate = resultSet.getDate(j + 1, calendar);
            return aDate == null ? null : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
        case Types.TIME:
            final Time aTime = resultSet.getTime(j + 1, calendar);
            return aTime == null ? null : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
        case Types.TIMESTAMP:
            final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
            return aTimestamp == null ? null : aTimestamp.getTime();
        case Types.ARRAY:
            final Array array = resultSet.getArray(j + 1);
            if (null == array) {
                return null;
            }
            try {
                // Recursively extracts an Array using its ResultSet-representation
                return extractUsingResultSet(array, calendar);
            } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
                // assumes a non-nested array (depends on the db if that's a valid assumption)
                return extractUsingArray(array, calendar);
            }
        case Types.STRUCT:
            Struct struct = resultSet.getObject(j + 1, Struct.class);
            Object[] attrs = struct.getAttributes();
            List<Object> list = new ArrayList<>(attrs.length);
            for (Object o : attrs) {
                list.add(o);
            }
            return list;
        default:
            return resultSet.getObject(j + 1);
    }
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) ArrayList(java.util.ArrayList) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Struct(java.sql.Struct) Array(java.sql.Array)

Example 57 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project phoenix by apache.

the class SQLParser method nextStatement.

/**
     * Parses the input as a series of semicolon-terminated SQL statements.
     * @throws SQLException 
     */
public BindableStatement nextStatement(ParseNodeFactory factory) throws SQLException {
    try {
        parser.resetBindCount();
        parser.setParseNodeFactory(factory);
        BindableStatement statement = parser.nextStatement();
        return statement;
    } catch (RecognitionException e) {
        throw PhoenixParserException.newException(e, parser.getTokenNames());
    } catch (UnsupportedOperationException e) {
        throw new SQLFeatureNotSupportedException(e);
    } catch (RuntimeException e) {
        if (e.getCause() instanceof SQLException) {
            throw (SQLException) e.getCause();
        }
        throw PhoenixParserException.newException(e, parser.getTokenNames());
    }
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) RecognitionException(org.antlr.runtime.RecognitionException)

Example 58 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project spanner-jdbc by olavloite.

the class CloudSpannerConnectionPoolDataSourceTest method createDataSourceTest.

@Test
public void createDataSourceTest() throws SQLException {
    CloudSpannerConnectionPoolDataSource subject = new CloudSpannerConnectionPoolDataSource();
    subject.setProjectId("helpful-adroit-123456");
    subject.setInstanceId("test-instance");
    subject.setDatabase("test");
    subject.setPvtKeyPath("C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner-key.json");
    subject.setPvtKeyPath(null);
    subject.setOauthAccessToken("TEST");
    subject.setSimulateProductName("PostgreSQL");
    subject.setAllowExtendedMode(true);
    subject.setLoginTimeout(10);
    subject.setDefaultAutoCommit(false);
    subject.setLogWriter(new PrintWriter(System.out));
    Assert.assertEquals("ConnectionPoolDataSource from " + nl.topicus.jdbc.CloudSpannerDriver.getVersion(), subject.getDescription());
    PooledConnection con = subject.getPooledConnection();
    Assert.assertNotNull(con);
    ICloudSpannerConnection connection = (ICloudSpannerConnection) con.getConnection();
    Assert.assertEquals("jdbc:cloudspanner://localhost", connection.getUrl());
    Assert.assertEquals("PostgreSQL", connection.getProductName());
    Assert.assertEquals("helpful-adroit-123456", connection.getSuppliedProperties().getProperty("Project"));
    Assert.assertEquals("test-instance", connection.getSuppliedProperties().getProperty("Instance"));
    Assert.assertEquals("test", connection.getSuppliedProperties().getProperty("Database"));
    Assert.assertEquals("TEST", connection.getSuppliedProperties().getProperty("OAuthAccessToken"));
    Assert.assertTrue(connection.isAllowExtendedMode());
    Assert.assertEquals(subject.isDefaultAutoCommit(), connection.getAutoCommit());
    PooledConnection con2 = subject.getPooledConnection("TEST", "TEST");
    Assert.assertNotNull(con2);
    boolean exception = false;
    try {
        subject.getParentLogger();
    } catch (SQLFeatureNotSupportedException e) {
        exception = true;
    }
    Assert.assertTrue(exception);
}
Also used : PooledConnection(javax.sql.PooledConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) PrintWriter(java.io.PrintWriter) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test)

Aggregations

SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)58 SQLException (java.sql.SQLException)21 Connection (java.sql.Connection)14 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 PreparedStatement (java.sql.PreparedStatement)13 Statement (java.sql.Statement)11 ResultSet (java.sql.ResultSet)10 Test (org.junit.Test)7 Properties (java.util.Properties)4 CallableStatement (java.sql.CallableStatement)3 DruidPooledCallableStatement (com.alibaba.druid.pool.DruidPooledCallableStatement)2 DruidPooledResultSet (com.alibaba.druid.pool.DruidPooledResultSet)2 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)2 Method (java.lang.reflect.Method)2 Date (java.sql.Date)2 SQLDataException (java.sql.SQLDataException)2 Savepoint (java.sql.Savepoint)2 Vector (java.util.Vector)2 UnitTest (nl.topicus.jdbc.test.category.UnitTest)2