/** * readObject is called to restore the state of the {@code SerialJavaObject} * from a stream. */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { ObjectInputStream.GetField fields1 = s.readFields(); @SuppressWarnings("unchecked") Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null); if (tmp != null) chain = new Vector<>(tmp); obj = fields1.get("obj", null); if (obj != null) { fields = obj.getClass().getFields(); if(hasStaticFields(fields)) throw new IOException("Located static fields in " + "object instance. Cannot serialize"); } else { throw new IOException("Object cannot be null!"); } }
@Test public void test07() { RowSetWarning ex = new RowSetWarning("Exception 1"); ex.initCause(t1); RowSetWarning ex1 = new RowSetWarning("Exception 2"); RowSetWarning ex2 = new RowSetWarning("Exception 3"); ex2.initCause(t2); ex.setNextException(ex1); ex.setNextException(ex2); int num = 0; SQLException sqe = ex; while (sqe != null) { assertTrue(msgs[num++].equals(sqe.getMessage())); Throwable c = sqe.getCause(); while (c != null) { assertTrue(msgs[num++].equals(c.getMessage())); c = c.getCause(); } sqe = sqe.getNextException(); } }
/** * Validate that the ordering of the returned RowSetWarning is correct using * traditional while loop */ @Test public void test09() { RowSetWarning ex = new RowSetWarning("Warning 1"); ex.initCause(t1); RowSetWarning ex1 = new RowSetWarning("Warning 2"); RowSetWarning ex2 = new RowSetWarning("Warning 3"); ex2.initCause(t2); ex.setNextWarning(ex1); ex.setNextWarning(ex2); int num = 0; RowSetWarning sqe = ex; while (sqe != null) { assertTrue(warnings[num++].equals(sqe.getMessage())); Throwable c = sqe.getCause(); while (c != null) { assertTrue(msgs[num++].equals(c.getMessage())); c = c.getCause(); } sqe = sqe.getNextWarning(); } }
@Test public void test11() throws Exception { RowSetWarning ex = new RowSetWarning("Warning 1"); ex.initCause(t1); RowSetWarning ex1 = new RowSetWarning("Warning 2"); RowSetWarning ex2 = new RowSetWarning("Warning 3"); ex2.initCause(t2); ex.setNextWarning(ex1); ex.setNextWarning(ex2); int num = 0; RowSetWarning sqe = createSerializedException(ex); while (sqe != null) { assertTrue(warnings[num++].equals(sqe.getMessage())); Throwable c = sqe.getCause(); while (c != null) { assertTrue(msgs[num++].equals(c.getMessage())); c = c.getCause(); } sqe = sqe.getNextWarning(); } }
public void testGetRowSetWarnings() throws Exception { JdbcRowSet jrs = newJdbcRowSet(); jrs.setCommand("SELECT * FROM USER_INFO"); jrs.setUrl(DERBY_URL); jrs.execute(); /* * TODO not sure when and how will cause RowSetWarning */ assertNull(jrs.getRowSetWarnings()); jrs.close(); jrs = newJdbcRowSet(); RowSetWarning warning = jrs.getRowSetWarnings(); super.assertNull(warning); // TODO Try to produce warnings. jrs.close(); // Checks for Exception after closing jrs. assertNull(rs.getWarnings()); assertNull(jrs.getRowSetWarnings()); }
/** * Constructor for <code>SerialJavaObject</code> helper class. * <p> * * @param obj the Java <code>Object</code> to be serialized * @throws SerialException if the object is found not to be serializable */ public SerialJavaObject(Object obj) throws SerialException { // if any static fields are found, an exception // should be thrown // get Class. Object instance should always be available Class<?> c = obj.getClass(); // determine if object implements Serializable i/f if (!(obj instanceof java.io.Serializable)) { setWarning(new RowSetWarning("Warning, the object passed to the constructor does not implement Serializable")); } // can only determine public fields (obviously). If // any of these are static, this should invalidate // the action of attempting to persist these fields // in a serialized form fields = c.getFields(); if (hasStaticFields(fields)) { throw new SerialException("Located static fields in " + "object instance. Cannot serialize"); } this.obj = obj; }
/** * Registers the given warning. */ private void setWarning(RowSetWarning e) { if (chain == null) { chain = new Vector<>(); } chain.add(e); }
@Test public void test01() { RowSetWarning ex = new RowSetWarning(); assertTrue(ex.getMessage() == null && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0); }
@Test public void test02() { RowSetWarning ex = new RowSetWarning(reason); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState() == null && ex.getCause() == null && ex.getErrorCode() == 0); }
@Test public void test03() { RowSetWarning ex = new RowSetWarning(reason, state); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == 0); }
@Test public void test04() { RowSetWarning ex = new RowSetWarning(reason, state, errorCode); assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && ex.getCause() == null && ex.getErrorCode() == errorCode); }
@Test public void test05() throws Exception { RowSetWarning e = new RowSetWarning(reason, state, errorCode); e.initCause(t); RowSetWarning ex1 = createSerializedException(e); assertTrue(reason.equals(ex1.getMessage()) && ex1.getSQLState().equals(state) && cause.equals(ex1.getCause().toString()) && ex1.getErrorCode() == errorCode); }
@Test public void test06() { RowSetWarning ex = new RowSetWarning("Exception 1"); ex.initCause(t1); RowSetWarning ex1 = new RowSetWarning("Exception 2"); RowSetWarning ex2 = new RowSetWarning("Exception 3"); ex2.initCause(t2); ex.setNextException(ex1); ex.setNextException(ex2); int num = 0; for (Throwable e : ex) { assertTrue(msgs[num++].equals(e.getMessage())); } }