Search in sources :

Example 6 with SerialException

use of javax.sql.rowset.serial.SerialException in project jdk8u_jdk by JetBrains.

the class SerialExceptionTests method test04.

/*
     * Validate that the ordering of the returned Exceptions is correct using
     * traditional while loop
     */
@Test
public void test04() {
    SQLException ex = new SerialException("Exception 1");
    ex.initCause(t1);
    SerialException ex1 = new SerialException("Exception 2");
    SerialException ex2 = new SerialException("Exception 3");
    ex2.initCause(t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    while (ex != null) {
        assertTrue(msgs[num++].equals(ex.getMessage()));
        Throwable c = ex.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        ex = ex.getNextException();
    }
}
Also used : SerialException(javax.sql.rowset.serial.SerialException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 7 with SerialException

use of javax.sql.rowset.serial.SerialException in project jdk8u_jdk by JetBrains.

the class SerialExceptionTests method test01.

/*
     * Create SerialException with no-arg constructor
     */
@Test
public void test01() {
    SerialException ex = new SerialException();
    assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0);
}
Also used : SerialException(javax.sql.rowset.serial.SerialException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 8 with SerialException

use of javax.sql.rowset.serial.SerialException in project sql-boot by sql-boot.

the class JdbcSqlQuery method getMapStream.

private Stream<Map<String, Object>> getMapStream(final String sqlText) {
    logger.info(sqlText);
    final SqlRowSet rowSet = new JdbcTemplate(dataSource).queryForRowSet(sqlText);
    Iterator<Map<String, Object>> iterator = new Iterator<Map<String, Object>>() {

        @Override
        public boolean hasNext() {
            return rowSet.next();
        }

        @Override
        public Map<String, Object> next() {
            return stream(rowSet.getMetaData().getColumnNames()).map(v -> {
                Object object = rowSet.getObject(v);
                if (object instanceof SerialClob) {
                    try {
                        return new SimpleEntry<>(v, (Object) ((SerialClob) object).getSubString(1, (int) ((SerialClob) object).length()));
                    } catch (SerialException e) {
                        e.printStackTrace();
                    }
                }
                return new SimpleEntry<>(v, object);
            }).collect(toMap(k -> k.getKey(), /*.toLowerCase()*/
            v -> ofNullable(v.getValue()).orElse(nullAlias), (a, b) -> a, LinkedHashMap::new));
        }
    };
    return stream(spliteratorUnknownSize(iterator, ORDERED), false);
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) Connection(java.sql.Connection) Iterator(java.util.Iterator) SerialClob(javax.sql.rowset.serial.SerialClob) Optional.ofNullable(java.util.Optional.ofNullable) TemplateGenerator(com.github.mgramin.sqlboot.template.generator.TemplateGenerator) SqlQuery(com.github.mgramin.sqlboot.sql.SqlQuery) ORDERED(java.util.Spliterator.ORDERED) BootException(com.github.mgramin.sqlboot.exceptions.BootException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) LinkedHashMap(java.util.LinkedHashMap) SelectStatementParser(com.github.mgramin.sqlboot.sql.parser.SelectStatementParser) Logger(org.apache.log4j.Logger) SQLException(java.sql.SQLException) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) SerialException(javax.sql.rowset.serial.SerialException) Map(java.util.Map) DataSource(javax.sql.DataSource) SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) SimpleEntry(java.util.AbstractMap.SimpleEntry) Arrays.stream(java.util.Arrays.stream) SerialException(javax.sql.rowset.serial.SerialException) Iterator(java.util.Iterator) SerialClob(javax.sql.rowset.serial.SerialClob) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) LinkedHashMap(java.util.LinkedHashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

SerialException (javax.sql.rowset.serial.SerialException)8 Test (org.testng.annotations.Test)6 BaseTest (util.BaseTest)6 SQLException (java.sql.SQLException)2 SerialClob (javax.sql.rowset.serial.SerialClob)2 BootException (com.github.mgramin.sqlboot.exceptions.BootException)1 SqlQuery (com.github.mgramin.sqlboot.sql.SqlQuery)1 SelectStatementParser (com.github.mgramin.sqlboot.sql.parser.SelectStatementParser)1 TemplateGenerator (com.github.mgramin.sqlboot.template.generator.TemplateGenerator)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Arrays.stream (java.util.Arrays.stream)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 ORDERED (java.util.Spliterator.ORDERED)1 Spliterators.spliteratorUnknownSize (java.util.Spliterators.spliteratorUnknownSize)1 Collectors.toMap (java.util.stream.Collectors.toMap)1