java.sql.DataTruncation Java Examples

The following examples show how to use java.sql.DataTruncation. 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
Source File: DataTruncationTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: DataTruncationTests.java    From jdk8u-jdk with 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 #3
Source File: FBBinaryField.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void setBinaryStreamInternal(InputStream in, long length) throws SQLException {
    if (in == null) {
        setNull();
        return;
    }

    if (length > fieldDescriptor.getLength()) {
        throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length,
                fieldDescriptor.getLength());
    }

    try {
        setBytes(IOUtils.toBytes(in, (int) length));
    } catch (IOException ioex) {
        throw new TypeConversionException(BINARY_STREAM_CONVERSION_ERROR);
    }
}
 
Example #4
Source File: DataTruncationTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: DataTruncationTests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: DataTruncationTests.java    From jdk8u_jdk with 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 #7
Source File: DataTruncationTests.java    From jdk8u_jdk with 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 #8
Source File: DataTruncationTests.java    From jdk8u_jdk with 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 #9
Source File: FBBinaryField.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void setCharacterStreamInternal(Reader in, long length) throws SQLException {
    if (in == null) {
        setNull();
        return;
    }

    if (length > fieldDescriptor.getLength()) {
        throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length,
                fieldDescriptor.getLength());
    }

    try {
        setString(IOUtils.toString(in, (int) length));
    } catch (IOException ioex) {
        throw new TypeConversionException(CHARACTER_STREAM_CONVERSION_ERROR);
    }
}
 
Example #10
Source File: DataTruncationTests.java    From jdk8u_jdk with 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 #11
Source File: DataTruncationTests.java    From jdk8u_jdk with 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 #12
Source File: DataTruncationTests.java    From hottub with 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 #13
Source File: DataTruncationTests.java    From jdk8u-jdk with 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 #14
Source File: DataTruncationTests.java    From jdk8u-jdk with 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 #15
Source File: DataTruncationTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #16
Source File: DataTruncationTests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #17
Source File: DataTruncationTests.java    From openjdk-jdk9 with 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 #18
Source File: DataTruncationTests.java    From openjdk-jdk9 with 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 File: DataTruncationTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #20
Source File: DataTruncationTests.java    From openjdk-jdk9 with 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 #21
Source File: DataTruncationTests.java    From openjdk-jdk9 with 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 #22
Source File: DataTruncationTests.java    From openjdk-jdk9 with 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 #23
Source File: DataTruncationTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #24
Source File: DataTruncationTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #25
Source File: DataTruncationTests.java    From openjdk-jdk8u-backup with 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 #26
Source File: DataTruncationTests.java    From openjdk-jdk8u-backup with 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 #27
Source File: DataTruncationTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #28
Source File: DataTruncationTests.java    From openjdk-jdk8u-backup with 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 #29
Source File: FBWorkaroundStringField.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
}
 
Example #30
Source File: DataTruncationTests.java    From openjdk-jdk8u-backup with 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);
}