|
|
@ -4,17 +4,23 @@ import com.fanruan.cache.BeanCacheImpl; |
|
|
|
import com.fanruan.handler.DispatcherImpl; |
|
|
|
import com.fanruan.handler.DispatcherImpl; |
|
|
|
import com.fanruan.pojo.message.RpcRequest; |
|
|
|
import com.fanruan.pojo.message.RpcRequest; |
|
|
|
import com.fanruan.service.jdbc.AbstractBind; |
|
|
|
import com.fanruan.service.jdbc.AbstractBind; |
|
|
|
|
|
|
|
import com.fanruan.service.jdbc.ServiceBlob; |
|
|
|
|
|
|
|
import com.fanruan.service.jdbc.ServiceReader; |
|
|
|
|
|
|
|
import com.fanruan.service.jdbc.resultset.ServiceResultSet; |
|
|
|
import com.fanruan.service.jdbc.statement.ServiceStatement; |
|
|
|
import com.fanruan.service.jdbc.statement.ServiceStatement; |
|
|
|
|
|
|
|
import org.hsqldb.jdbc.JDBCBlob; |
|
|
|
|
|
|
|
import org.hsqldb.jdbc.JDBCClob; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.TestInstance; |
|
|
|
import org.junit.jupiter.api.TestInstance; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.io.Reader; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.*; |
|
|
|
import java.sql.ResultSet; |
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
import java.sql.Statement; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Yichen Dai |
|
|
|
* @author Yichen Dai |
|
|
@ -24,11 +30,17 @@ import java.sql.Statement; |
|
|
|
public class ResultSetTest extends BaseJDBCTest{ |
|
|
|
public class ResultSetTest extends BaseJDBCTest{ |
|
|
|
|
|
|
|
|
|
|
|
private Connection connection = null; |
|
|
|
private Connection connection = null; |
|
|
|
|
|
|
|
ResultSet resultSet = null; |
|
|
|
|
|
|
|
|
|
|
|
@BeforeAll |
|
|
|
@BeforeAll |
|
|
|
public void setUp() throws SQLException { |
|
|
|
public void setUp() throws SQLException { |
|
|
|
openSocket(); |
|
|
|
openSocket(); |
|
|
|
connection = getConnection(); |
|
|
|
connection = getConnection(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testDate() throws SQLException{ |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
statement.execute("create table DemoTable\n" + |
|
|
|
statement.execute("create table DemoTable\n" + |
|
|
|
" (\n" + |
|
|
|
" (\n" + |
|
|
@ -40,12 +52,8 @@ public class ResultSetTest extends BaseJDBCTest{ |
|
|
|
|
|
|
|
|
|
|
|
statement.executeUpdate("insert into DEMOTABLE(TESTTIME,TESTDATE,TESTSTAMP) " + |
|
|
|
statement.executeUpdate("insert into DEMOTABLE(TESTTIME,TESTDATE,TESTSTAMP) " + |
|
|
|
"values('15:50:37', '2022-09-07', '2022-09-07 15:50:37');"); |
|
|
|
"values('15:50:37', '2022-09-07', '2022-09-07 15:50:37');"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
this.resultSet = statement.executeQuery("select TestTime, TestDate, TestStamp from DemoTable;"); |
|
|
|
public void testDate() throws SQLException{ |
|
|
|
|
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery("select TestTime, TestDate, TestStamp from DemoTable;"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(resultSet.next()){ |
|
|
|
while(resultSet.next()){ |
|
|
|
Assertions.assertEquals("15:50:37", resultSet.getTime(1).toString()); |
|
|
|
Assertions.assertEquals("15:50:37", resultSet.getTime(1).toString()); |
|
|
@ -53,5 +61,115 @@ public class ResultSetTest extends BaseJDBCTest{ |
|
|
|
Assertions.assertEquals("2022-09-07 15:50:37.0", resultSet.getTimestamp(3).toString()); |
|
|
|
Assertions.assertEquals("2022-09-07 15:50:37.0", resultSet.getTimestamp(3).toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertFalse(resultSet.isClosed()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testGet() throws SQLException, IOException { |
|
|
|
|
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statement.execute("create table TestTable " + |
|
|
|
|
|
|
|
" (" + |
|
|
|
|
|
|
|
" testString varchar(20), " + |
|
|
|
|
|
|
|
" testBoolean BOOLEAN, " + |
|
|
|
|
|
|
|
" testByte NUMERIC(3), " + |
|
|
|
|
|
|
|
" testShort NUMERIC(5), " + |
|
|
|
|
|
|
|
" testInt INTEGER, " + |
|
|
|
|
|
|
|
" testLong BIGINT, " + |
|
|
|
|
|
|
|
" testFloat FLOAT, " + |
|
|
|
|
|
|
|
" testDouble DOUBLE, " + |
|
|
|
|
|
|
|
" testDecimal DECIMAL," + |
|
|
|
|
|
|
|
" testBlob BLOB(1024)," + |
|
|
|
|
|
|
|
" testClob varchar(100));" |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement prepareStatement = connection.prepareStatement("INSERT INTO TestTable VALUES( " + |
|
|
|
|
|
|
|
"?, " + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?, " + |
|
|
|
|
|
|
|
"?, " + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?," + |
|
|
|
|
|
|
|
"?);"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareStatement.setString(1, "testString"); |
|
|
|
|
|
|
|
prepareStatement.setBoolean(2, true); |
|
|
|
|
|
|
|
prepareStatement.setByte(3, Byte.MAX_VALUE); |
|
|
|
|
|
|
|
prepareStatement.setShort(4, Short.MAX_VALUE); |
|
|
|
|
|
|
|
prepareStatement.setInt(5, Integer.MAX_VALUE); |
|
|
|
|
|
|
|
prepareStatement.setLong(6, Long.MAX_VALUE); |
|
|
|
|
|
|
|
prepareStatement.setFloat(7, 0.2f); |
|
|
|
|
|
|
|
prepareStatement.setDouble(8, 0.2D); |
|
|
|
|
|
|
|
prepareStatement.setBigDecimal(9, new BigDecimal(1000)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] chuck = { |
|
|
|
|
|
|
|
(byte)0x0f, (byte)0x00, (byte)0x00, |
|
|
|
|
|
|
|
(byte)0x00, (byte)0x00, (byte)0x00 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blob blob = new JDBCBlob(chuck); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareStatement.setBlob(10, blob); |
|
|
|
|
|
|
|
prepareStatement.setClob(11, new JDBCClob("abcd")); |
|
|
|
|
|
|
|
prepareStatement.executeUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery("SELECT * FROM TestTable;"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resultSet.next(); |
|
|
|
|
|
|
|
Assertions.assertEquals("testString", resultSet.getString(1)); |
|
|
|
|
|
|
|
Assertions.assertEquals("testString", resultSet.getString("testString")); |
|
|
|
|
|
|
|
Assertions.assertEquals(true, resultSet.getBoolean(2)); |
|
|
|
|
|
|
|
Assertions.assertEquals(true, resultSet.getBoolean("testBoolean")); |
|
|
|
|
|
|
|
Assertions.assertEquals(Byte.MAX_VALUE, resultSet.getByte(3)); |
|
|
|
|
|
|
|
Assertions.assertEquals(Byte.MAX_VALUE, resultSet.getByte("testByte")); |
|
|
|
|
|
|
|
Assertions.assertEquals(Short.MAX_VALUE, resultSet.getShort(4)); |
|
|
|
|
|
|
|
Assertions.assertEquals(Short.MAX_VALUE, resultSet.getShort("testShort")); |
|
|
|
|
|
|
|
Assertions.assertEquals(Integer.MAX_VALUE, resultSet.getInt(5)); |
|
|
|
|
|
|
|
Assertions.assertEquals(Integer.MAX_VALUE, resultSet.getInt("testInt")); |
|
|
|
|
|
|
|
Assertions.assertEquals(Long.MAX_VALUE, resultSet.getLong(6)); |
|
|
|
|
|
|
|
Assertions.assertEquals(Long.MAX_VALUE, resultSet.getLong("testLong")); |
|
|
|
|
|
|
|
Assertions.assertEquals(0.2f, resultSet.getFloat(7)); |
|
|
|
|
|
|
|
Assertions.assertEquals(0.2f, resultSet.getFloat("testFloat")); |
|
|
|
|
|
|
|
Assertions.assertEquals(0.2d, resultSet.getDouble(8)); |
|
|
|
|
|
|
|
Assertions.assertEquals(0.2d, resultSet.getDouble("testDouble")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(1000, resultSet.getBigDecimal(9).intValue()); |
|
|
|
|
|
|
|
Assertions.assertEquals(1000, resultSet.getBigDecimal("testDecimal").intValue()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(chuck.length, resultSet.getBytes(10).length); |
|
|
|
|
|
|
|
Assertions.assertEquals(chuck.length, resultSet.getBytes("testBlob").length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(chuck[0], resultSet.getBinaryStream("testBlob").read()); |
|
|
|
|
|
|
|
Assertions.assertEquals(chuck[0], resultSet.getBinaryStream("testBlob").read()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals('a', resultSet.getAsciiStream(11).read()); |
|
|
|
|
|
|
|
Assertions.assertEquals('a', resultSet.getAsciiStream("testClob").read()); |
|
|
|
|
|
|
|
Assertions.assertEquals('a', resultSet.getCharacterStream(11).read()); |
|
|
|
|
|
|
|
Assertions.assertEquals('a', resultSet.getCharacterStream("testClob").read()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertNull(resultSet.getCursorName()); |
|
|
|
|
|
|
|
Assertions.assertNotNull(resultSet.getMetaData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testWrap() throws SQLException { |
|
|
|
|
|
|
|
String SQL_INSERT = "INSERT INTO EMPLOYEE VALUES 'Tim';"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Statement statement = connection.createStatement(); |
|
|
|
|
|
|
|
statement.execute(SQL_CREATE); |
|
|
|
|
|
|
|
statement.executeUpdate(SQL_INSERT); |
|
|
|
|
|
|
|
ResultSet resultSet = statement.executeQuery("select * from EMPLOYEE"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThrows(SQLException.class, () -> resultSet.unwrap(null)); |
|
|
|
|
|
|
|
Assertions.assertFalse(resultSet.isWrapperFor(null)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|