Java Code Examples for java.sql.DataTruncation

The following examples show how to use java.sql.DataTruncation. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Create DataTruncation object indicating a truncation on read
 */
@Test
public void test() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 2
/**
 * Create DataTruncation object indicating a truncation on write
 */
@Test
public void test1() {
    onRead = false;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(WRITE_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 3
/**
 * Create DataTruncation object indicating a truncation on read with a
 * Throwable
 */
@Test
public void test2() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && cause.equals(e.getCause().toString())
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 4
/**
 * Create DataTruncation object indicating a truncation on read with null
 * specified for the Throwable
 */
@Test
public void test3() {
    onRead = true;;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, null);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 5
/**
 * Create DataTruncation object indicating a truncation on read and you can
 * pass a -1 for the index
 */
@Test
public void test4() {
    onRead = true;
    int negIndex = -1;
    DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == negIndex);
}
 
Example 6
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * for-each loop
 */
@Test
public void test11() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(dtmsgs[num++].equals(e.getMessage()));
    }
}
 
Example 7
/**
 * Assert that data returned from the server was truncated, and that the
 * proper warning came with the result.
 *
 * @param expectedRow the expected values
 * @param actualRow   the actual values returned
 * @param index       the expected column/parameter index in the warning
 * @param parameter   whether the values came from a procedure parameter
 * @param read        whether the values came from a read operation
 * @param dataSize    the expected full size of the truncated value
 * @param transferSize the expected size of the value after truncation
 * @param warning     the received warning
 */
private static void assertDataTruncation(
        String[] expectedRow, String[] actualRow,
        int index, boolean parameter, boolean read,
        int dataSize, int transferSize, SQLWarning warning) {
    assertEquals("Wrong number of columns",
                 expectedRow.length, actualRow.length);
    assertNotNull("Expected data truncation warning", warning);
    for (int i = 0; i < expectedRow.length; i++) {
        assertEquals("column #" + (i + 1), expectedRow[i], actualRow[i]);

        if (warning instanceof DataTruncation) {
            DataTruncation dt = (DataTruncation) warning;
            assertEquals("index", index, dt.getIndex());
            assertEquals("parameter", parameter, dt.getParameter());
            assertEquals("read", read, dt.getRead());
            assertEquals("dataSize", dataSize, dt.getDataSize());
            assertEquals("transferSize", transferSize, dt.getTransferSize());
        } else {
            fail("Unexpected warning", warning);
        }

        assertNull("Chained warnings not expected on network client",
                   warning.getNextWarning());
    }
}
 
Example 8
/**
 * Create DataTruncation object indicating a truncation on read
 */
@Test
public void test() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 9
/**
 * Create DataTruncation object indicating a truncation on write
 */
@Test
public void test1() {
    onRead = false;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(WRITE_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 10
/**
 * Create DataTruncation object indicating a truncation on read with a
 * Throwable
 */
@Test
public void test2() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && cause.equals(e.getCause().toString())
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 11
/**
 * Create DataTruncation object indicating a truncation on read with null
 * specified for the Throwable
 */
@Test
public void test3() {
    onRead = true;;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, null);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 12
/**
 * Create DataTruncation object indicating a truncation on read and you can
 * pass a -1 for the index
 */
@Test
public void test4() {
    onRead = true;
    int negIndex = -1;
    DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == negIndex);
}
 
Example 13
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * for-each loop
 */
@Test
public void test11() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(dtmsgs[num++].equals(e.getMessage()));
    }
}
 
Example 14
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(dtmsgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 15
Source Project: jdk8u60   Source File: DataTruncationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create DataTruncation object indicating a truncation on read with a
 * Throwable
 */
@Test
public void test2() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && cause.equals(e.getCause().toString())
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 16
Source Project: jdk8u60   Source File: DataTruncationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create DataTruncation object indicating a truncation on read with null
 * specified for the Throwable
 */
@Test
public void test3() {
    onRead = true;;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, null);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 17
Source Project: jdk8u60   Source File: DataTruncationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create DataTruncation object indicating a truncation on read and you can
 * pass a -1 for the index
 */
@Test
public void test4() {
    onRead = true;
    int negIndex = -1;
    DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == negIndex);
}
 
Example 18
Source Project: jdk8u60   Source File: DataTruncationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * for-each loop
 */
@Test
public void test11() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(dtmsgs[num++].equals(e.getMessage()));
    }
}
 
Example 19
Source Project: jdk8u60   Source File: DataTruncationTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(dtmsgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 20
/**
 * Create DataTruncation object indicating a truncation on read
 */
@Test
public void test() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 21
/**
 * Create DataTruncation object indicating a truncation on write
 */
@Test
public void test1() {
    onRead = false;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(WRITE_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 22
/**
 * Create DataTruncation object indicating a truncation on read with a
 * Throwable
 */
@Test
public void test2() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && cause.equals(e.getCause().toString())
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 23
/**
 * Create DataTruncation object indicating a truncation on read with null
 * specified for the Throwable
 */
@Test
public void test3() {
    onRead = true;;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, null);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 24
/**
 * Create DataTruncation object indicating a truncation on read and you can
 * pass a -1 for the index
 */
@Test
public void test4() {
    onRead = true;
    int negIndex = -1;
    DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == negIndex);
}
 
Example 25
/**
 * Serialize a DataTruncation and make sure you can read it back properly
 */
@Test
public void test5() throws Exception {
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex1 = createSerializedException(e);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 26
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * for-each loop
 */
@Test
public void test11() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(dtmsgs[num++].equals(e.getMessage()));
    }
}
 
Example 27
/**
 * Validate that the ordering of the returned Exceptions is correct using
 * traditional while loop
 */
@Test
public void test12() {
    DataTruncation ex = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t1);
    DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(dtmsgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
Example 28
/**
 * Create DataTruncation object indicating a truncation on read
 */
@Test
public void test() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && e.getCause() == null
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 29
/**
 * Create DataTruncation object indicating a truncation on read with a
 * Throwable
 */
@Test
public void test2() {
    onRead = true;
    DataTruncation e = new DataTruncation(index, parameter, onRead,
            dataSize, transferSize, t);
    assertTrue(e.getMessage().equals(dtReason)
            && e.getSQLState().equals(READ_TRUNCATION)
            && cause.equals(e.getCause().toString())
            && e.getErrorCode() == dterrorCode
            && e.getParameter() == parameter
            && e.getRead() == onRead
            && e.getDataSize() == dataSize
            && e.getTransferSize() == transferSize
            && e.getIndex() == index);
}
 
Example 30
public void setString(String value) throws SQLException {
    if (value == null) {
        setNull();
        return;
    }
    byte[] data = getDatatypeCoder().encodeString(value);

    if (data.length > fieldDescriptor.getLength() && !isSystemTable(fieldDescriptor.getOriginalTableName())) {
        // special handling for the LIKE ? queries with CHAR(1) fields
        if (!(value.length() <= fieldDescriptor.getLength() + 2
                && (value.charAt(0) == '%' || value.charAt(value.length() - 1) == '%'))) {
            throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, data.length,
                    fieldDescriptor.getLength());
        }
    }
    setFieldData(data);
}