diff --git a/docs/releasenotes.md b/docs/releasenotes.md index a63429da27..b75c372ddf 100644 --- a/docs/releasenotes.md +++ b/docs/releasenotes.md @@ -3,17 +3,19 @@ ## [3.9.1](https://github.com/p6spy/p6spy/compare/p6spy-3.9.0...master) (Unreleased) Improvements: +* [issue 501](https://github.com/p6spy/p6spy/pull/501) Database dialect dependent binary data representation. +* [issue 493](https://github.com/p6spy/p6spy/pull/493) Added `ResultSetInformation.getResultMap()`. Defects resolved: -## [3.9.0](https://github.com/p6spy/p6spy/compare/p6spy-3.8.7...3.9.0) (Unreleased) +## [3.9.0](https://github.com/p6spy/p6spy/compare/p6spy-3.8.7...3.9.0) (2020-04-04) Improvements: * [issue 497](https://github.com/p6spy/p6spy/pull/497) Added `Statement` into `StatementInformation`. Defects resolved: -## [3.8.7](https://github.com/p6spy/p6spy/compare/p6spy-3.8.6...3.8.7) (Unreleased) +## [3.8.7](https://github.com/p6spy/p6spy/compare/p6spy-3.8.6...3.8.7) (2019-12-23) Improvements: * [issue #492](https://github.com/p6spy/p6spy/pull/492) The `file.encoding` system property is used by default to read the configuration file, can be overriden using `-Dspy.properties.charset`. diff --git a/src/main/java/com/p6spy/engine/common/ResultSetInformation.java b/src/main/java/com/p6spy/engine/common/ResultSetInformation.java index 77be8db67c..dc0617a71a 100644 --- a/src/main/java/com/p6spy/engine/common/ResultSetInformation.java +++ b/src/main/java/com/p6spy/engine/common/ResultSetInformation.java @@ -18,6 +18,7 @@ package com.p6spy.engine.common; import java.sql.ResultSet; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -47,7 +48,6 @@ public ResultSetInformation(final StatementInformation statementInformation) { public void generateLogMessage() { if (lastRowLogged != currRow) { P6LogQuery.log(Category.RESULTSET, this); - resultMap.clear(); lastRowLogged = currRow; } } @@ -58,6 +58,7 @@ public int getCurrRow() { public void incrementCurrRow() { this.currRow++; + this.resultMap.clear(); } public void setColumnValue(String columnName, Object value) { @@ -84,6 +85,16 @@ public String getSqlWithValues() { return sb.toString(); } + /** + * Returns column/value map for the last row read. + * + * NOTE: Only values that were retrieved from {@link ResultSet} + * ({@link ResultSet#getString(int)}, {@link ResultSet#getBoolean(int)}, etc.) will be returned. + */ + public Map getResultMap() { + return Collections.unmodifiableMap(resultMap); + } + public StatementInformation getStatementInformation() { return statementInformation; } diff --git a/src/main/java/com/p6spy/engine/wrapper/ResultSetWrapper.java b/src/main/java/com/p6spy/engine/wrapper/ResultSetWrapper.java index df5aee2461..40f538d5ad 100644 --- a/src/main/java/com/p6spy/engine/wrapper/ResultSetWrapper.java +++ b/src/main/java/com/p6spy/engine/wrapper/ResultSetWrapper.java @@ -71,6 +71,14 @@ public ResultSetWrapper(ResultSet delegate, ResultSetInformation resultSetInform resultSetInformation.setResultSet(delegate); } + public ResultSet getDelegate() { + return delegate; + } + + public ResultSetInformation getResultSetInformation() { + return resultSetInformation; + } + @Override public boolean next() throws SQLException { SQLException e = null; diff --git a/src/test/java/com/p6spy/engine/event/CompoundJdbcEventListenerTest.java b/src/test/java/com/p6spy/engine/event/CompoundJdbcEventListenerTest.java index fbb47caa38..da8a3198cf 100644 --- a/src/test/java/com/p6spy/engine/event/CompoundJdbcEventListenerTest.java +++ b/src/test/java/com/p6spy/engine/event/CompoundJdbcEventListenerTest.java @@ -17,7 +17,8 @@ */ package com.p6spy.engine.event; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; @@ -157,7 +158,7 @@ public JdbcEventListener createJdbcEventListener() { wrappedCallableStatement = CallableStatementWrapper.wrap(mockedCallableStatement, callableStatementInformation, mockedJdbcListener); wrappedResultSet = ResultSetWrapper.wrap(mockedResultSet, resultSetInformation, mockedJdbcListener); - + P6SpyDriver.setJdbcEventListenerFactory(new JdbcEventListenerFactory() { @Override public JdbcEventListener createJdbcEventListener() { @@ -349,9 +350,8 @@ public void testStatementOnAfterExecuteUpdate() throws SQLException { public void testPreparedStatementOnBeforeExecuteQuery() throws SQLException { wrappedPreparedStatement.executeQuery(); verify(mockedJdbcListener).onBeforeExecuteQuery(eq(preparedStatementInformation)); - assertTrue(preparedStatementInformation.getStatement() != wrappedPreparedStatement); - assertTrue(preparedStatementInformation.getStatement() == - (PreparedStatement) ((P6Proxy) wrappedPreparedStatement).unwrapP6SpyProxy()); + assertNotSame(preparedStatementInformation.getStatement(), wrappedPreparedStatement); + assertSame(preparedStatementInformation.getStatement(), ((P6Proxy) wrappedPreparedStatement).unwrapP6SpyProxy()); } @Test @@ -380,7 +380,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNull() throws SQLExc verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), any(), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNullWithTypeName() throws SQLException { wrappedPreparedStatement.setNull(0, 0, "foo"); @@ -394,70 +394,70 @@ public void testPreparedStatementOnAfterPreparedStatementSetBoolean() throws SQL verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(false), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetByte() throws SQLException { wrappedPreparedStatement.setByte(0, (byte) 0); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq((byte) 0), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetShort() throws SQLException { wrappedPreparedStatement.setShort(0, (short) 0); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq((short) 0), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetInt() throws SQLException { wrappedPreparedStatement.setInt(0, 0); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(0), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetLong() throws SQLException { wrappedPreparedStatement.setLong(0, 0L); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(0L), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetFloat() throws SQLException { wrappedPreparedStatement.setFloat(0, 0.0f); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(0.0f), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetDouble() throws SQLException { wrappedPreparedStatement.setDouble(0, 0.0); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(0.0), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetBigDecimal() throws SQLException { wrappedPreparedStatement.setBigDecimal(0, new BigDecimal(0)); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(new BigDecimal(0)), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetString() throws SQLException { wrappedPreparedStatement.setString(0, "foo"); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq("foo"), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetBytes() throws SQLException { wrappedPreparedStatement.setBytes(0, new byte[0]); verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(new byte[0]), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetDate() throws SQLException { final Date date = mock(Date.class); @@ -465,7 +465,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetDate() throws SQLExc verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(date), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetDateWithCalendar() throws SQLException { final Date date = mock(Date.class); @@ -474,7 +474,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetDateWithCalendar() t verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(date), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetTime() throws SQLException { final Time time = mock(Time.class); @@ -482,7 +482,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetTime() throws SQLExc verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(time), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetTimeWithCalendar() throws SQLException { final Time time = mock(Time.class); @@ -491,7 +491,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetTimeWithCalendar() t verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(time), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetTimestamp() throws SQLException { final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); @@ -499,7 +499,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetTimestamp() throws S verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(timestamp), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetTimestampWithCalendar() throws SQLException { final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); @@ -508,7 +508,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetTimestampWithCalenda verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(timestamp), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetAsciiStream() throws SQLException { final InputStream is = mock(InputStream.class); @@ -516,7 +516,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetAsciiStream() throws verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetAsciiStreamWithIntLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -524,7 +524,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetAsciiStreamWithIntLe verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetAsciiStreamWithLongLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -532,7 +532,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetAsciiStreamWithLongL verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetUnicodeStream() throws SQLException { final InputStream is = mock(InputStream.class); @@ -548,7 +548,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetBinaryStream() throw verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetBinaryStreamWithIntLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -556,7 +556,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetBinaryStreamWithIntL verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetBinaryStreamWithLongLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -564,7 +564,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetBinaryStreamWithLong verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetObject() throws SQLException { final Object object = new Object(); @@ -572,7 +572,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetObject() throws SQLE verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetObjectWithTargetType() throws SQLException { final Object object = new Object(); @@ -580,7 +580,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetObjectWithTargetType verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetObjectWithTargetTypeAndScaleOrLenght() throws SQLException { final Object object = new Object(); @@ -588,7 +588,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetObjectWithTargetType verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetCharacterStream() throws SQLException { final Reader reader = mock(Reader.class); @@ -596,7 +596,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetCharacterStream() th verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetCharacterStreamWithIntLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -604,7 +604,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetCharacterStreamWithI verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetCharacterStreamWithLongLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -612,7 +612,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetCharacterStreamWithL verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetRef() throws SQLException { final Ref ref = mock(Ref.class); @@ -620,7 +620,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetRef() throws SQLExce verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(ref), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetBlob() throws SQLException { final Blob blob = mock(Blob.class); @@ -628,7 +628,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetBlob() throws SQLExc verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(blob), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetClob() throws SQLException { final Clob clob = mock(Clob.class); @@ -636,7 +636,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetClob() throws SQLExc verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(clob), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetClobWithReader() throws SQLException { final Reader reader = mock(Reader.class); @@ -644,7 +644,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetClobWithReader() thr verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetClobWithReaderAndLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -652,7 +652,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetClobWithReaderAndLen verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetArray() throws SQLException { final Array array = mock(Array.class); @@ -660,7 +660,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetArray() throws SQLEx verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(array), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetURL() throws SQLException, MalformedURLException { final URL url = new URL("http://google.com"); @@ -668,7 +668,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetURL() throws SQLExce verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(url), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetRowId() throws SQLException { final RowId rowId = mock(RowId.class); @@ -676,7 +676,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetRowId() throws SQLEx verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(rowId), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNString() throws SQLException { final RowId rowId = mock(RowId.class); @@ -684,7 +684,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNString() throws SQL verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(rowId), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNCharacterStream() throws SQLException { final Reader reader = mock(Reader.class); @@ -692,7 +692,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNCharacterStream() t verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNCharacterStreamWithLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -700,7 +700,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNCharacterStreamWith verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNClob() throws SQLException { final NClob nClob = mock(NClob.class); @@ -708,7 +708,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNClob() throws SQLEx verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(nClob), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNClobWithReader() throws SQLException { final Reader reader = mock(Reader.class); @@ -716,7 +716,7 @@ public void testPreparedStatementOnAfterPreparedStatementSetNClobWithReader() th verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testPreparedStatementOnAfterPreparedStatementSetNClobWithReaderAndLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -732,14 +732,14 @@ public void testPreparedStatementOnAfterPreparedStatementSetSQLXML() throws SQLE verify(mockedJdbcListener).onAfterPreparedStatementSet(eq(preparedStatementInformation), eq(0), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNull() throws SQLException { wrappedCallableStatement.setNull(null, 0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), any(), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNullWithTypeName() throws SQLException { wrappedCallableStatement.setNull(null, 0, "foo"); @@ -753,70 +753,70 @@ public void testCallableStatementOnAfterCallableStatementSetBoolean() throws SQL verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(false), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetByte() throws SQLException { wrappedCallableStatement.setByte(null, (byte) 0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq((byte) 0), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetShort() throws SQLException { wrappedCallableStatement.setShort(null, (short) 0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq((short) 0), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetInt() throws SQLException { wrappedCallableStatement.setInt(null, 0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(0), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetLong() throws SQLException { wrappedCallableStatement.setLong(null, 0L); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(0L), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetFloat() throws SQLException { wrappedCallableStatement.setFloat(null, 0.0f); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(0.0f), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetDouble() throws SQLException { wrappedCallableStatement.setDouble(null, 0.0); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(0.0), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBigDecimal() throws SQLException { wrappedCallableStatement.setBigDecimal(null, new BigDecimal(0)); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(new BigDecimal(0)), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetString() throws SQLException { wrappedCallableStatement.setString(null, "foo"); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq("foo"), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBytes() throws SQLException { wrappedCallableStatement.setBytes(null, new byte[0]); verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(new byte[0]), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetDate() throws SQLException { final Date date = mock(Date.class); @@ -824,7 +824,7 @@ public void testCallableStatementOnAfterCallableStatementSetDate() throws SQLExc verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(date), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetDateWithCalendar() throws SQLException { final Date date = mock(Date.class); @@ -833,7 +833,7 @@ public void testCallableStatementOnAfterCallableStatementSetDateWithCalendar() t verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(date), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetTime() throws SQLException { final Time time = mock(Time.class); @@ -841,7 +841,7 @@ public void testCallableStatementOnAfterCallableStatementSetTime() throws SQLExc verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(time), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetTimeWithCalendar() throws SQLException { final Time time = mock(Time.class); @@ -850,7 +850,7 @@ public void testCallableStatementOnAfterCallableStatementSetTimeWithCalendar() t verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(time), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetTimestamp() throws SQLException { final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); @@ -858,7 +858,7 @@ public void testCallableStatementOnAfterCallableStatementSetTimestamp() throws S verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(timestamp), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetTimestampWithCalendar() throws SQLException { final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); @@ -867,7 +867,7 @@ public void testCallableStatementOnAfterCallableStatementSetTimestampWithCalenda verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(timestamp), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetAsciiStream() throws SQLException { final InputStream is = mock(InputStream.class); @@ -875,7 +875,7 @@ public void testCallableStatementOnAfterCallableStatementSetAsciiStream() throws verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetAsciiStreamWithIntLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -883,7 +883,7 @@ public void testCallableStatementOnAfterCallableStatementSetAsciiStreamWithIntLe verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetAsciiStreamWithLongLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -891,7 +891,7 @@ public void testCallableStatementOnAfterCallableStatementSetAsciiStreamWithLongL verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBinaryStream() throws SQLException { final InputStream is = mock(InputStream.class); @@ -899,7 +899,7 @@ public void testCallableStatementOnAfterCallableStatementSetBinaryStream() throw verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBinaryStreamWithIntLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -907,7 +907,7 @@ public void testCallableStatementOnAfterCallableStatementSetBinaryStreamWithIntL verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBinaryStreamWithLongLength() throws SQLException { final InputStream is = mock(InputStream.class); @@ -915,7 +915,7 @@ public void testCallableStatementOnAfterCallableStatementSetBinaryStreamWithLong verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(is), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetObject() throws SQLException { final Object object = new Object(); @@ -923,7 +923,7 @@ public void testCallableStatementOnAfterCallableStatementSetObject() throws SQLE verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetObjectWithTargetType() throws SQLException { final Object object = new Object(); @@ -931,7 +931,7 @@ public void testCallableStatementOnAfterCallableStatementSetObjectWithTargetType verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetObjectWithTargetTypeAndScaleOrLenght() throws SQLException { final Object object = new Object(); @@ -939,7 +939,7 @@ public void testCallableStatementOnAfterCallableStatementSetObjectWithTargetType verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(object), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetCharacterStream() throws SQLException { final Reader reader = mock(Reader.class); @@ -947,7 +947,7 @@ public void testCallableStatementOnAfterCallableStatementSetCharacterStream() th verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetCharacterStreamWithIntLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -955,7 +955,7 @@ public void testCallableStatementOnAfterCallableStatementSetCharacterStreamWithI verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetCharacterStreamWithLongLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -963,7 +963,7 @@ public void testCallableStatementOnAfterCallableStatementSetCharacterStreamWithL verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetBlob() throws SQLException { final Blob blob = mock(Blob.class); @@ -971,7 +971,7 @@ public void testCallableStatementOnAfterCallableStatementSetBlob() throws SQLExc verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(blob), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetClob() throws SQLException { final Clob clob = mock(Clob.class); @@ -979,7 +979,7 @@ public void testCallableStatementOnAfterCallableStatementSetClob() throws SQLExc verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(clob), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetClobWithReader() throws SQLException { final Reader reader = mock(Reader.class); @@ -987,7 +987,7 @@ public void testCallableStatementOnAfterCallableStatementSetClobWithReader() thr verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetClobWithReaderAndLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -995,7 +995,7 @@ public void testCallableStatementOnAfterCallableStatementSetClobWithReaderAndLen verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetURL() throws SQLException, MalformedURLException { final URL url = new URL("http://google.com"); @@ -1003,7 +1003,7 @@ public void testCallableStatementOnAfterCallableStatementSetURL() throws SQLExce verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(url), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetRowId() throws SQLException { final RowId rowId = mock(RowId.class); @@ -1011,7 +1011,7 @@ public void testCallableStatementOnAfterCallableStatementSetRowId() throws SQLEx verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(rowId), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNString() throws SQLException { final RowId rowId = mock(RowId.class); @@ -1019,7 +1019,7 @@ public void testCallableStatementOnAfterCallableStatementSetNString() throws SQL verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(rowId), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNCharacterStream() throws SQLException { final Reader reader = mock(Reader.class); @@ -1027,7 +1027,7 @@ public void testCallableStatementOnAfterCallableStatementSetNCharacterStream() t verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNCharacterStreamWithLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -1035,7 +1035,7 @@ public void testCallableStatementOnAfterCallableStatementSetNCharacterStreamWith verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNClob() throws SQLException { final NClob nClob = mock(NClob.class); @@ -1043,7 +1043,7 @@ public void testCallableStatementOnAfterCallableStatementSetNClob() throws SQLEx verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(nClob), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNClobWithReader() throws SQLException { final Reader reader = mock(Reader.class); @@ -1051,7 +1051,7 @@ public void testCallableStatementOnAfterCallableStatementSetNClobWithReader() th verify(mockedJdbcListener).onAfterCallableStatementSet(eq(callableStatementInformation), ArgumentMatchers.isNull(), eq(reader), ArgumentMatchers.isNull()); } - + @Test public void testCallableStatementOnAfterCallableStatementSetNClobWithReaderAndLength() throws SQLException { final Reader reader = mock(Reader.class); @@ -1068,7 +1068,7 @@ public void testCallableStatementOnAfterCallableStatementSetSQLXML() throws SQLE ArgumentMatchers.isNull()); } - + @Test public void testConnectionOnAfterConnectionClose() throws SQLException { wrappedConnection.close(); @@ -1117,9 +1117,9 @@ public void testConnectionOnAfterConnectionSetAutoCommitWithException() throws S public void testResultSetOnBeforeResultSetNext() throws SQLException { wrappedResultSet.next(); verify(mockedJdbcListener).onBeforeResultSetNext(eq(resultSetInformation)); - assertTrue(resultSetInformation.getResultSet() != wrappedResultSet); - assertTrue(resultSetInformation.getResultSet() == - (ResultSet) ((P6Proxy) wrappedResultSet).unwrapP6SpyProxy()); + assertNotSame(resultSetInformation.getResultSet(), wrappedResultSet); + assertSame(resultSetInformation.getResultSet(), ((P6Proxy) wrappedResultSet).unwrapP6SpyProxy()); + assertSame(resultSetInformation.getResultSet(), ((ResultSetWrapper) wrappedResultSet).getDelegate()); } private ConnectionInformation connectionInformationWithConnection() { diff --git a/src/test/java/com/p6spy/engine/test/ResultSetInformationTest.java b/src/test/java/com/p6spy/engine/test/ResultSetInformationTest.java index 9b5476d68b..9385ec2af7 100644 --- a/src/test/java/com/p6spy/engine/test/ResultSetInformationTest.java +++ b/src/test/java/com/p6spy/engine/test/ResultSetInformationTest.java @@ -18,15 +18,20 @@ package com.p6spy.engine.test; import com.p6spy.engine.common.ConnectionInformation; +import com.p6spy.engine.common.ResultSetInformation; import com.p6spy.engine.spy.P6SpyDriver; +import com.p6spy.engine.wrapper.ResultSetWrapper; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.IOException; +import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; @@ -47,4 +52,36 @@ public void testResultSetInformation() throws Exception { assertNotEquals(P6SpyDriver.class, connectionInformation.getDriver().getClass()); assertTrue(connectionInformation.getTimeToGetConnectionNs() > 0); } + + @Test + public void testResultSetResults() throws SQLException { + ResultSetWrapper resultSet = executeQuery("select * from customers where id in (1,2) order by id"); + ResultSetInformation resultSetInformation = resultSet.getResultSetInformation(); + assertSame(resultSet.getDelegate(), resultSetInformation.getResultSet()); + + resultSet.next(); + resultSet.getInt(1); + resultSet.getString(2); + resultSet.getString("name"); + + assertEquals(3, resultSetInformation.getResultMap().size()); + assertEquals(1, resultSetInformation.getResultMap().get("1").getValue()); + assertEquals("david", resultSetInformation.getResultMap().get("2").getValue()); + assertEquals("david", resultSetInformation.getResultMap().get("name").getValue()); + + resultSet.next(); + resultSet.getInt(1); + resultSet.getString("name"); + + assertEquals(2, resultSetInformation.getResultMap().size()); + assertEquals(2, resultSetInformation.getResultMap().get("1").getValue()); + assertEquals("mary", resultSetInformation.getResultMap().get("name").getValue()); + } + + private ResultSetWrapper executeQuery(String sql) throws SQLException { + Statement statement = connection.createStatement(); + ResultSet resultSet = statement.executeQuery(sql); + assertTrue("ResultSet must've been wrapped into ResultSetWrapper", resultSet instanceof ResultSetWrapper); + return (ResultSetWrapper) resultSet; + } }