下面列出了怎么用java.sql.DataTruncation的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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()));
}
}
/**
* 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());
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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()));
}
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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()));
}
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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()));
}
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
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);
}