yichen
2 years ago
33 changed files with 1269 additions and 134 deletions
@ -0,0 +1,89 @@
|
||||
package com.fanruan.agent.jdbc; |
||||
|
||||
import com.fanruan.annotation.BindClass; |
||||
|
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
import java.io.Reader; |
||||
import java.io.Writer; |
||||
import java.sql.Clob; |
||||
import java.sql.NClob; |
||||
import java.sql.SQLException; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:49 |
||||
*/ |
||||
@BindClass |
||||
public class AgentNClob implements NClob { |
||||
private NClob nClob; |
||||
|
||||
public AgentNClob(NClob nClob){ |
||||
this.nClob = nClob; |
||||
} |
||||
|
||||
@Override |
||||
public long length() throws SQLException { |
||||
return nClob.length(); |
||||
} |
||||
|
||||
@Override |
||||
public String getSubString(long pos, int length) throws SQLException { |
||||
return nClob.getSubString(pos, length); |
||||
} |
||||
|
||||
@Override |
||||
public Reader getCharacterStream() throws SQLException { |
||||
return new AgentReader(nClob.getCharacterStream()); |
||||
} |
||||
|
||||
@Override |
||||
public InputStream getAsciiStream() throws SQLException { |
||||
return new AgentInputStream(nClob.getAsciiStream()); |
||||
} |
||||
|
||||
@Override |
||||
public long position(String searchstr, long start) throws SQLException { |
||||
return nClob.position(searchstr, start); |
||||
} |
||||
|
||||
@Override |
||||
public long position(Clob searchstr, long start) throws SQLException { |
||||
return nClob.position(searchstr, start); |
||||
} |
||||
|
||||
@Override |
||||
public int setString(long pos, String str) throws SQLException { |
||||
return nClob.setString(pos, str); |
||||
} |
||||
|
||||
@Override |
||||
public int setString(long pos, String str, int offset, int len) throws SQLException { |
||||
return nClob.setString(pos, str, offset, len); |
||||
} |
||||
|
||||
@Override |
||||
public OutputStream setAsciiStream(long pos) throws SQLException { |
||||
return new AgentOutputStream(nClob.setAsciiStream(pos)); |
||||
} |
||||
|
||||
@Override |
||||
public Writer setCharacterStream(long pos) throws SQLException { |
||||
return new AgentWriter(nClob.setCharacterStream(pos)); |
||||
} |
||||
|
||||
@Override |
||||
public void truncate(long len) throws SQLException { |
||||
nClob.truncate(len); |
||||
} |
||||
|
||||
@Override |
||||
public void free() throws SQLException { |
||||
nClob.free(); |
||||
} |
||||
|
||||
@Override |
||||
public Reader getCharacterStream(long pos, long length) throws SQLException { |
||||
return new AgentReader(nClob.getCharacterStream(pos, length)); |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fanruan.agent.jdbc; |
||||
|
||||
import com.fanruan.annotation.BindClass; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:49 |
||||
*/ |
||||
@BindClass |
||||
public class AgentOutputStream extends OutputStream { |
||||
private OutputStream outputStream; |
||||
|
||||
public AgentOutputStream(OutputStream outputStream){ |
||||
this.outputStream = outputStream; |
||||
} |
||||
|
||||
@Override |
||||
public void write(int b) throws IOException { |
||||
this.outputStream.write(b); |
||||
} |
||||
|
||||
@Override |
||||
public void write(byte b[]) throws IOException { |
||||
outputStream.write(b); |
||||
} |
||||
|
||||
@Override |
||||
public void write(byte b[], int off, int len) throws IOException { |
||||
outputStream.write(b, off, len); |
||||
} |
||||
|
||||
@Override |
||||
public void flush() throws IOException { |
||||
outputStream.flush(); |
||||
} |
||||
|
||||
@Override |
||||
public void close() throws IOException { |
||||
outputStream.close(); |
||||
} |
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.fanruan.agent.jdbc; |
||||
|
||||
import com.fanruan.annotation.BindClass; |
||||
|
||||
import java.sql.RowId; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 17:31 |
||||
*/ |
||||
@BindClass |
||||
public class AgentRowId implements RowId { |
||||
RowId rowId; |
||||
|
||||
public AgentRowId(RowId rowId){ |
||||
this.rowId = rowId; |
||||
} |
||||
|
||||
@Override |
||||
public byte[] getBytes() { |
||||
return rowId.getBytes(); |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.fanruan.agent.jdbc; |
||||
|
||||
import com.fanruan.annotation.BindClass; |
||||
|
||||
import java.sql.SQLException; |
||||
import java.sql.Savepoint; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 16:39 |
||||
*/ |
||||
@BindClass |
||||
public class AgentSavepoint implements Savepoint { |
||||
Savepoint savepoint; |
||||
|
||||
public AgentSavepoint(Savepoint savepoint){ |
||||
this.savepoint = savepoint; |
||||
} |
||||
|
||||
@Override |
||||
public int getSavepointId() throws SQLException { |
||||
return savepoint.getSavepointId(); |
||||
} |
||||
|
||||
@Override |
||||
public String getSavepointName() throws SQLException { |
||||
return savepoint.getSavepointName(); |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.fanruan.agent.jdbc; |
||||
|
||||
import com.fanruan.annotation.BindClass; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.Writer; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:48 |
||||
*/ |
||||
@BindClass |
||||
public class AgentWriter extends Writer { |
||||
private Writer writer; |
||||
|
||||
public AgentWriter(Writer writer){ |
||||
this.writer = writer; |
||||
} |
||||
|
||||
@Override |
||||
public void write(int c) throws IOException { |
||||
writer.write(c); |
||||
} |
||||
|
||||
@Override |
||||
public void write(char cbuf[]) throws IOException { |
||||
writer.write(cbuf); |
||||
} |
||||
|
||||
@Override |
||||
public void write(char[] cbuf, int off, int len) throws IOException { |
||||
writer.write(cbuf, off, len); |
||||
} |
||||
|
||||
@Override |
||||
public void write(String str) throws IOException { |
||||
writer.write(str); |
||||
} |
||||
|
||||
@Override |
||||
public void write(String str, int off, int len) throws IOException { |
||||
writer.write(str, off, len); |
||||
} |
||||
|
||||
/** |
||||
* chain calling return this instead of new Agent Class |
||||
* @throws IOException |
||||
*/ |
||||
@Override |
||||
public Writer append(CharSequence csq) throws IOException { |
||||
writer.append(csq); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public Writer append(CharSequence csq, int start, int end) throws IOException { |
||||
writer.append(csq, start, end); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public Writer append(char c) throws IOException { |
||||
writer.append(c); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public void flush() throws IOException { |
||||
writer.flush(); |
||||
} |
||||
|
||||
@Override |
||||
public void close() throws IOException { |
||||
writer.close(); |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
package com.fanruan.service.jdbc; |
||||
|
||||
import com.fanruan.annotation.RemoteClass; |
||||
import com.fanruan.proxy.ProxyFactory; |
||||
|
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
import java.io.Reader; |
||||
import java.io.Writer; |
||||
import java.sql.Clob; |
||||
import java.sql.NClob; |
||||
import java.sql.SQLException; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:45 |
||||
*/ |
||||
@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentNClob") |
||||
public class ServiceNClob extends BasedBind implements NClob { |
||||
|
||||
@Override |
||||
public long length() throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public String getSubString(long pos, int length) throws SQLException { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Reader getCharacterStream() throws SQLException { |
||||
return (Reader) ProxyFactory.getProxy(ServiceReader.class, info); |
||||
} |
||||
|
||||
@Override |
||||
public InputStream getAsciiStream() throws SQLException { |
||||
return (InputStream) ProxyFactory.getProxy(ServiceInputStream.class, info); |
||||
} |
||||
|
||||
@Override |
||||
public long position(String searchstr, long start) throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public long position(Clob searchstr, long start) throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public int setString(long pos, String str) throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public int setString(long pos, String str, int offset, int len) throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public OutputStream setAsciiStream(long pos) throws SQLException { |
||||
return (OutputStream) ProxyFactory.getProxy(ServiceOutputStream.class, info); |
||||
} |
||||
|
||||
@Override |
||||
public Writer setCharacterStream(long pos) throws SQLException { |
||||
return (Writer) ProxyFactory.getProxy(ServiceWriter.class, info); |
||||
} |
||||
|
||||
@Override |
||||
public void truncate(long len) throws SQLException { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void free() throws SQLException { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public Reader getCharacterStream(long pos, long length) throws SQLException { |
||||
return (Reader) ProxyFactory.getProxy(ServiceReader.class, info); |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
package com.fanruan.service.jdbc; |
||||
|
||||
import com.fanruan.annotation.LocalMethod; |
||||
import com.fanruan.annotation.RemoteClass; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:47 |
||||
*/ |
||||
@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentOutputStream") |
||||
public class ServiceOutputStream extends OutputStream { |
||||
private String ID; |
||||
|
||||
@LocalMethod |
||||
public String getID(){ |
||||
return this.ID; |
||||
} |
||||
|
||||
@LocalMethod |
||||
public void setID(String ID){ |
||||
this.ID = ID; |
||||
} |
||||
|
||||
@Override |
||||
public void write(int b) throws IOException { |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public int hashCode(){ |
||||
return super.hashCode(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
return super.equals(obj); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
protected Object clone() throws CloneNotSupportedException { |
||||
return super.clone(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public String toString() { |
||||
return super.toString(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
protected void finalize() throws Throwable { |
||||
super.finalize(); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fanruan.service.jdbc; |
||||
|
||||
import com.fanruan.annotation.RemoteClass; |
||||
|
||||
import java.sql.RowId; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 17:30 |
||||
*/ |
||||
@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentRowId") |
||||
public class ServiceRowId extends BasedBind implements RowId { |
||||
|
||||
@Override |
||||
public byte[] getBytes() { |
||||
return new byte[0]; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.fanruan.service.jdbc; |
||||
|
||||
import com.fanruan.annotation.RemoteClass; |
||||
|
||||
import java.sql.SQLException; |
||||
import java.sql.Savepoint; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 16:38 |
||||
*/ |
||||
@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentSavepoint") |
||||
public class ServiceSavepoint extends BasedBind implements Savepoint { |
||||
|
||||
@Override |
||||
public int getSavepointId() throws SQLException { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public String getSavepointName() throws SQLException { |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,88 @@
|
||||
package com.fanruan.service.jdbc; |
||||
|
||||
import com.fanruan.annotation.LocalMethod; |
||||
import com.fanruan.annotation.RemoteClass; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.Writer; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 10:47 |
||||
*/ |
||||
@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentWrite") |
||||
public class ServiceWriter extends Writer { |
||||
private String ID; |
||||
|
||||
@LocalMethod |
||||
public String getID(){ |
||||
return this.ID; |
||||
} |
||||
|
||||
@LocalMethod |
||||
public void setID(String ID){ |
||||
this.ID = ID; |
||||
} |
||||
|
||||
@Override |
||||
public void write(char[] cbuf, int off, int len) throws IOException { |
||||
} |
||||
|
||||
@Override |
||||
public void flush() throws IOException { |
||||
} |
||||
|
||||
@Override |
||||
public void close() throws IOException { |
||||
|
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public int hashCode(){ |
||||
return super.hashCode(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public boolean equals(Object obj) { |
||||
return super.equals(obj); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
protected Object clone() throws CloneNotSupportedException { |
||||
return super.clone(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
public String toString() { |
||||
return super.toString(); |
||||
} |
||||
|
||||
@LocalMethod |
||||
@Override |
||||
protected void finalize() throws Throwable { |
||||
super.finalize(); |
||||
} |
||||
|
||||
/** |
||||
* chain calling return this instead of new Agent Class |
||||
* @throws IOException |
||||
*/ |
||||
@Override |
||||
public Writer append(CharSequence csq) throws IOException { |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public Writer append(CharSequence csq, int start, int end) throws IOException { |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public Writer append(char c) throws IOException { |
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fanruan; |
||||
|
||||
import com.fanruan.agent.jdbc.driver.AgentDriver; |
||||
import com.fanruan.service.jdbc.driver.ServiceDriver; |
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.BeforeAll; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.TestInstance; |
||||
|
||||
import java.sql.Driver; |
||||
import java.sql.DriverManager; |
||||
import java.sql.SQLException; |
||||
import java.sql.SQLFeatureNotSupportedException; |
||||
import java.util.Enumeration; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/9 16:44 |
||||
*/ |
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
||||
public class DriverTest{ |
||||
|
||||
@Test |
||||
public void test() throws SQLException, ClassNotFoundException { |
||||
Class.forName("com.fanruan.service.jdbc.driver.ServiceDriver"); |
||||
Enumeration<Driver> registeredDrivers = DriverManager.getDrivers(); |
||||
while (registeredDrivers.hasMoreElements()) { |
||||
Driver driver = registeredDrivers.nextElement(); |
||||
if(driver instanceof ServiceDriver){ |
||||
Assertions.assertEquals(0, driver.getPropertyInfo("jdbc:hsqldb:mem:test;sql.syntax_mys=true", null).length); |
||||
Assertions.assertEquals(ServiceDriver.DRIVER_VERSION_MAJOR, driver.getMajorVersion()); |
||||
Assertions.assertEquals(ServiceDriver.DRIVER_VERSION_MINOR, driver.getMinorVersion()); |
||||
Assertions.assertFalse(driver.jdbcCompliant()); |
||||
Assertions.assertThrows(SQLFeatureNotSupportedException.class, () -> driver.getParentLogger()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fanruan; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.BeforeAll; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.TestInstance; |
||||
|
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/13 16:31 |
||||
*/ |
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
||||
public class SavePointTest extends BaseJDBCTest{ |
||||
Connection connection = null; |
||||
|
||||
@BeforeAll |
||||
public void setUp() throws SQLException { |
||||
openSocket(); |
||||
this.connection = getConnection(); |
||||
} |
||||
|
||||
@Test |
||||
void testSavePoint() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
connection.setAutoCommit(false); |
||||
Assertions.assertThrows(SQLException.class, () -> connection.setSavepoint()); |
||||
Assertions.assertThrows(SQLException.class, () -> connection.setSavepoint("")); |
||||
Assertions.assertThrows(SQLException.class, () -> connection.rollback()); |
||||
Assertions.assertThrows(SQLException.class, () -> connection.rollback(new FakeSavepoint())); |
||||
Assertions.assertThrows(SQLException.class, () -> connection.releaseSavepoint(new FakeSavepoint())); |
||||
} |
||||
} |
@ -0,0 +1,171 @@
|
||||
package com.fanruan; |
||||
|
||||
import org.junit.jupiter.api.*; |
||||
|
||||
import java.sql.*; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/6 9:17 |
||||
*/ |
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
||||
public class StatementTest extends BaseJDBCTest{ |
||||
|
||||
Connection connection = null; |
||||
Statement statement = null; |
||||
|
||||
@BeforeAll |
||||
public void setUp() throws SQLException { |
||||
openSocket(); |
||||
connection = getConnection(); |
||||
this.statement = connection.createStatement(); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetConnection() throws SQLException{ |
||||
Assertions.assertEquals(this.connection, statement.getConnection()); |
||||
} |
||||
|
||||
@Test |
||||
public void testFieldSize() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.setMaxFieldSize(1000); |
||||
// HSQLDB always returns zero, meaning there is no limit.
|
||||
Assertions.assertEquals(0, statement.getMaxFieldSize()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testMaxRows() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.setMaxRows(1000); |
||||
Assertions.assertEquals(1000, statement.getMaxRows()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testSet() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.setEscapeProcessing(false); |
||||
|
||||
statement.setCursorName("name"); |
||||
|
||||
statement.setPoolable(false); |
||||
|
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testQueryTimeout() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.setQueryTimeout(2000); |
||||
Assertions.assertEquals(2000, statement.getQueryTimeout()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testWarnings() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.clearWarnings(); |
||||
Assertions.assertNull(statement.getWarnings()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetResultSet() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
|
||||
String SQL_DROP_IF_EXIST = "DROP TABLE IF EXISTS EMPLOYEE;"; |
||||
|
||||
String SQL_INSERT = "INSERT INTO EMPLOYEE VALUES 'Tim';"; |
||||
|
||||
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));"; |
||||
|
||||
statement.execute(SQL_DROP_IF_EXIST); |
||||
statement.execute(SQL_CREATE); |
||||
statement.executeUpdate(SQL_INSERT); |
||||
|
||||
statement.execute("SELECT * FROM EMPLOYEE"); |
||||
|
||||
ResultSet resultSet = statement.getResultSet(); |
||||
Assertions.assertTrue(resultSet.next()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testDirection() throws SQLException { |
||||
Statement statement = connection.createStatement(); |
||||
// Starting with 2.0, HSQLDB accepts any valid value.
|
||||
statement.setFetchDirection(ResultSet.FETCH_FORWARD); |
||||
Assertions.assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testFetchSize() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
statement.setFetchSize(0); |
||||
|
||||
Assertions.assertEquals(0, statement.getFetchSize()); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testWrap() throws SQLException { |
||||
Assertions.assertFalse(statement.isWrapperFor(null)); |
||||
Assertions.assertThrows(SQLException.class, () -> statement.unwrap(null)); |
||||
} |
||||
|
||||
@Test |
||||
public void testExecuteBatch() throws SQLException{ |
||||
String SQL_DROP_IF_EXIST = "DROP TABLE IF EXISTS EMPLOYEE;"; |
||||
|
||||
String SQL_INSERT = "INSERT INTO EMPLOYEE VALUES 'Tim';"; |
||||
|
||||
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));"; |
||||
|
||||
Statement statement = connection.createStatement(); |
||||
statement.execute(SQL_DROP_IF_EXIST); |
||||
statement.execute(SQL_CREATE); |
||||
statement.clearBatch(); |
||||
|
||||
statement.addBatch(SQL_INSERT); |
||||
statement.addBatch(SQL_INSERT); |
||||
statement.addBatch(SQL_INSERT); |
||||
|
||||
int[] count = statement.executeBatch(); |
||||
|
||||
Assertions.assertEquals(3, count.length); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetResultSetInfo() throws SQLException { |
||||
Statement statement = connection.createStatement(); |
||||
|
||||
// HSQLDB supports CONCUR_READ_ONLY and CONCUR_UPDATABLE concurrency.
|
||||
Assertions.assertEquals(ResultSet.CONCUR_READ_ONLY, statement.getResultSetConcurrency()); |
||||
|
||||
// HSQLDB 1.7.0 and later versions support TYPE_FORWARD_ONLY and TYPE_SCROLL_INSENSITIVE.
|
||||
Assertions.assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType()); |
||||
|
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
public void testGenerateKeys() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
Assertions.assertEquals(0, getSizeOfResultSet(statement.getGeneratedKeys())); |
||||
closeSQLObjects(statement); |
||||
} |
||||
|
||||
@Test |
||||
void testHoldability() throws SQLException{ |
||||
Statement statement = connection.createStatement(); |
||||
|
||||
// HSQLDB returns true for both alternatives.
|
||||
Assertions.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, statement.getResultSetHoldability()); |
||||
|
||||
closeSQLObjects(statement); |
||||
} |
||||
} |
Loading…
Reference in new issue