Permalink
Browse files

Minor fixes

  • Loading branch information...
daitangio committed Jul 2, 2017
1 parent b3ff92d commit 8012f38a43d03dca168d60b06d26be146f36a53c
@@ -45,7 +45,7 @@
protected boolean _traceOrphanedObjects = false;
// Row-Packet size defines the number of rows that is
// transported in one packet
protected int _rowPacketSize = 200;
protected int _rowPacketSize = 1000;
// Encoding for strings
protected String _charset = "ISO-8859-1";
// Compression
@@ -15,88 +15,92 @@
*/
public class SQLExceptionHelper {
public static SQLException wrap(Throwable t) {
if (isExceptionGeneric(t)) {
if (t instanceof SQLException) {
return (SQLException)t;
}
return new SQLException(t.getMessage(), t);
}
return wrapThrowable(t);
}
public static SQLException wrap(SQLException ex) {
if (isSQLExceptionGeneric(ex)) {
// yes a bit misleading but since this exception is already OK
// for transport, its much simplier just to return it
return ex;
}
else {
return wrapSQLException(ex);
}
}
private static boolean isExceptionGeneric(Throwable ex) {
boolean exceptionIsGeneric = true;
Throwable loop = ex;
while (loop != null && exceptionIsGeneric) {
exceptionIsGeneric =
java.io.Serializable.class.isAssignableFrom(loop.getClass()) ||
java.io.Externalizable.class.isAssignableFrom(loop.getClass());
loop = loop.getCause();
}
return exceptionIsGeneric;
}
private static boolean isSQLExceptionGeneric(SQLException ex) {
boolean exceptionIsGeneric = true;
Iterator<Throwable> it = ex.iterator();
while (it.hasNext() && exceptionIsGeneric) {
Throwable t = it.next();
exceptionIsGeneric =
java.io.Serializable.class.isAssignableFrom(t.getClass()) ||
java.io.Externalizable.class.isAssignableFrom(t.getClass());
}
return exceptionIsGeneric;
}
private static SQLException wrapSQLException(SQLException ex) {
SQLException ex2 =
new SQLException(ex.getMessage(), ex.getSQLState(),
ex.getErrorCode(), wrap(ex.getCause()));
if (ex.getNextException() != null) {
ex2.setNextException(wrap(ex.getNextException()));
}
return ex2;
}
private static SQLException wrapThrowable(Throwable t) {
SQLException wrapped = null;
if (t instanceof SQLException) {
wrapped = wrapSQLException((SQLException)t);
} else {
wrapped = new SQLException(t.getMessage(), wrap(t.getCause()));
}
// REVIEW: doing some evil hackeration here, but only because I believe
// that those that change stack traces deserve a special place in hell
// If your code can be hacked by stack trace info, it deserves to
// be hacked and will be cracked anyway
wrapped.setStackTrace(wrapped.getStackTrace());
return wrapped;
}
public static SQLException wrap(Throwable t) {
if (isExceptionGeneric(t)) {
if (t instanceof SQLException) {
return (SQLException)t;
}
return new SQLException(t.getMessage(), t);
}
return wrapThrowable(t);
}
public static SQLException wrap(SQLException ex) {
if (ex==null ||
// some driver may extend SQLException, but the client JRE may not have this class
// filter out such classes
(ex.getClass().getName().startsWith("java.sql.") &&
isSQLExceptionGeneric(ex))) {
// yes a bit misleading but since this exception is already OK
// for transport, its much simplier just to return it
return ex;
}
else {
return wrapSQLException(ex);
}
}
private static boolean isExceptionGeneric(Throwable ex) {
boolean exceptionIsGeneric = true;
Throwable loop = ex;
while (loop != null && exceptionIsGeneric) {
exceptionIsGeneric =
java.io.Serializable.class.isAssignableFrom(loop.getClass()) ||
java.io.Externalizable.class.isAssignableFrom(loop.getClass());
loop = loop.getCause();
}
return exceptionIsGeneric;
}
private static boolean isSQLExceptionGeneric(SQLException ex) {
boolean exceptionIsGeneric = true;
Iterator<Throwable> it = ex.iterator();
while (it.hasNext() && exceptionIsGeneric) {
Throwable t = it.next();
exceptionIsGeneric =
java.io.Serializable.class.isAssignableFrom(t.getClass()) ||
java.io.Externalizable.class.isAssignableFrom(t.getClass());
}
return exceptionIsGeneric;
}
private static SQLException wrapSQLException(SQLException ex) {
SQLException ex2 =
new SQLException(ex.getMessage(), ex.getSQLState(),
ex.getErrorCode(), wrap(ex.getCause()));
if (ex.getNextException() != null) {
ex2.setNextException(wrap(ex.getNextException()));
}
return ex2;
}
private static SQLException wrapThrowable(Throwable t) {
SQLException wrapped = null;
if (t instanceof SQLException) {
wrapped = wrapSQLException((SQLException)t);
} else {
wrapped = new SQLException(t.getMessage(), wrap(t.getCause()));
}
// REVIEW: doing some evil hackeration here, but only because I believe
// that those that change stack traces deserve a special place in hell
// If your code can be hacked by stack trace info, it deserves to
// be hacked and will be cracked anyway
wrapped.setStackTrace(wrapped.getStackTrace());
return wrapped;
}
}
@@ -57,7 +57,11 @@ public void test1_SimpleCreate() throws InstantiationException, IllegalAccessExc
connVJdbc.setAutoCommit(false);
createTestData(connVJdbc);
ResultSet rs=connVJdbc.createStatement().executeQuery("select count(*) from Address");
rs.next();
String count=(""+rs.getObject(1));
connVJdbc.commit();
assertEquals(NUMBER_OF_ADDRESSES+"", count);
}
@Test

0 comments on commit 8012f38

Please sign in to comment.