Browse Source

save point

pull/1/head
yichen 2 years ago
parent
commit
6cd3dc1ff7
  1. 15
      service/src/main/java/com/fanruan/annotation/BindArg.java
  2. 2
      service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java
  3. 1
      service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java
  4. 2
      test/src/test/java/TestSuite.java
  5. 1
      test/src/test/java/com/fanruan/CallableStatementTest.java
  6. 25
      test/src/test/java/com/fanruan/ConnectionTest.java
  7. 20
      test/src/test/java/com/fanruan/DatabaseMetaDataTest.java
  8. 4
      test/src/test/java/com/fanruan/PrepareStatementTest.java
  9. 165
      test/src/test/java/com/fanruan/ResultSetTest.java
  10. 24
      test/src/test/java/com/fanruan/SavePointTest.java
  11. 1
      test/src/test/java/com/fanruan/TestUtil.java

15
service/src/main/java/com/fanruan/annotation/BindArg.java

@ -0,0 +1,15 @@
package com.fanruan.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Yichen Dai
* @date 2022/9/14 11:30
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface BindArg {
}

2
service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java

@ -37,8 +37,6 @@ public class Interceptor implements MethodInterceptor {
private SocketIOClient client;
private Properties info;
public Interceptor(){}
public Interceptor(Class<?> clazz, Properties info){
this.clazz = clazz;
this.info = info;

1
service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java

@ -1,6 +1,7 @@
package com.fanruan.service.jdbc.connection;
import com.fanruan.annotation.BindArg;
import com.fanruan.annotation.LocalMethod;
import com.fanruan.annotation.NotImplemented;
import com.fanruan.annotation.RemoteClass;

2
test/src/test/java/TestSuite.java

@ -12,5 +12,3 @@ import org.junit.platform.suite.api.Suite;
@Suite
public class TestSuite {
}

1
test/src/test/java/com/fanruan/CallableStatementTest.java

@ -53,6 +53,7 @@ public class CallableStatementTest extends BaseJDBCTest{
openSocket();
conn = getConnection();
statement = conn.createStatement();
statement.execute("DROP TABLE city IF EXISTS");
statement.executeUpdate("CREATE TABLE city (id INTEGER, name varchar(20)); ");
statement.executeUpdate("INSERT INTO city VALUES (1, '成都'), (2, '上海'); ");
statement.execute(deleteStoredProcedure);

25
test/src/test/java/com/fanruan/ConnectionTest.java

@ -221,29 +221,29 @@ public class ConnectionTest extends BaseJDBCTest{
@Test
void testCallableStatement() throws SQLException {
Statement statement = connection.createStatement();
statement.executeUpdate("CREATE TABLE city (id INTEGER, name varchar(20)); ");
statement.executeUpdate("INSERT INTO city VALUES (1, '成都'), (2, '上海'); ");
statement.execute("DROP TABLE citys IF EXISTS");
statement.executeUpdate("CREATE TABLE citys (id INTEGER, name varchar(20));");
statement.executeUpdate("INSERT INTO citys VALUES (1, '成都'), (2, '上海'); ");
CallableStatement cst1 = connection.prepareCall(
"CREATE PROCEDURE get_city_name(" +
"CREATE PROCEDURE get_citys_name(" +
"IN c_id INT, " +
"OUT city_name varchar(20)) " +
"OUT citys_name varchar(20)) " +
"READS SQL DATA " +
"BEGIN ATOMIC " +
" SELECT city.name INTO city_name FROM city WHERE id = c_id; " +
" SELECT citys.name INTO citys_name FROM citys WHERE id = c_id; " +
"END;",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.TYPE_FORWARD_ONLY
);
CallableStatement cst2 = connection.prepareCall(
"CREATE PROCEDURE get_city_name(" +
"CREATE PROCEDURE get_citys_name(" +
"IN c_id INT, " +
"OUT city_name varchar(20)) " +
"OUT citys_name varchar(20)) " +
"READS SQL DATA " +
"BEGIN ATOMIC " +
" SELECT city.name INTO city_name FROM city WHERE id = c_id; " +
" SELECT citys.name INTO citys_name FROM citys WHERE id = c_id; " +
"END;",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.TYPE_FORWARD_ONLY,
@ -317,6 +317,11 @@ public class ConnectionTest extends BaseJDBCTest{
Assertions.assertNotNull(connection.createClob());
Assertions.assertNotNull(connection.createBlob());
Assertions.assertNotNull(connection.createArrayOf("INTEGER", new Object[]{1}));
Assertions.assertNotNull(connection.createStruct("INTEGER", new Object[]{1}));
Assertions.assertThrows(SQLFeatureNotSupportedException.class, () -> {
serviceConnection.createStruct( "java.lang.String", new String[]{"hello"});
RpcRequest request = map.get(null);
request.setIDToInvoke(IDtoInvoke);
dispatcher.invokeAsRequest(request, beanCache);
});
}
}

20
test/src/test/java/com/fanruan/DatabaseMetaDataTest.java

@ -151,10 +151,7 @@ public class DatabaseMetaDataTest extends BaseJDBCTest{
ResultSet rs2 = metaData.getTablePrivileges("PUBLIC", "PUBLIC", "");
Assertions.assertEquals(0, getSizeOfResultSet(rs2));
ResultSet rs3 = metaData.getSuperTables("PUBLIC", "PUBLIC", "");
Assertions.assertEquals(0, getSizeOfResultSet(rs3));
closeSQLObjects(rs1, rs2, rs3);
closeSQLObjects(rs1, rs2);
}
@Test
@ -209,14 +206,10 @@ public class DatabaseMetaDataTest extends BaseJDBCTest{
@Test
void testGetUDTs() throws SQLException{
ResultSet rs1 = metaData.getUDTs("PUBLIC", "PUBLIC", "", new int[]{Types.STRUCT});
Assertions.assertEquals(0, getSizeOfResultSet(rs1));
ResultSet rs2 = metaData.getSuperTypes("PUBLIC", "PUBLIC", "");
Assertions.assertEquals(0, getSizeOfResultSet(rs2));
ResultSet rs = metaData.getUDTs("PUBLIC", "PUBLIC", "", new int[]{Types.STRUCT});
Assertions.assertEquals(0, getSizeOfResultSet(rs));
closeSQLObjects(rs1, rs2);
closeSQLObjects(rs);
}
@Test
@ -715,4 +708,9 @@ public class DatabaseMetaDataTest extends BaseJDBCTest{
closeSQLObjects(rs1, rs2);
}
@AfterAll
void tearDown() throws SQLException {
closeSQLObjects(conn);
}
}

4
test/src/test/java/com/fanruan/PrepareStatementTest.java

@ -31,6 +31,7 @@ public class PrepareStatementTest extends BaseJDBCTest{
openSocket();
this.connection = getConnection();
Statement statement = connection.createStatement();
statement.execute("DROP TABLE CITY IF EXISTS");
statement.executeUpdate("CREATE TABLE city (id INTEGER, name varchar(20)); ");
this.preparedStatement = connection.prepareStatement(
@ -524,6 +525,9 @@ public class PrepareStatementTest extends BaseJDBCTest{
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));";
Statement statement = connection.createStatement();
statement.execute("DROP TABLE IF EXISTS EMPLOYEE;");
PreparedStatement psDDL = connection.prepareStatement(SQL_CREATE);
psDDL.execute();

165
test/src/test/java/com/fanruan/ResultSetTest.java

@ -141,14 +141,57 @@ public class ResultSetTest extends BaseJDBCTest{
Assertions.assertEquals(chuck.length, resultSet.getBytes(10).length);
Assertions.assertEquals(chuck.length, resultSet.getBytes("testBlob").length);
InputStream in = null;
try {
in = resultSet.getBinaryStream("testBlob");
Assertions.assertEquals(chuck[0], in.read());
}finally {
in.close();
}
try {
in = resultSet.getBinaryStream(10);
Assertions.assertEquals(chuck[0], in.read());
}finally {
in.close();
}
try {
in = resultSet.getAsciiStream(11);
Assertions.assertEquals('a', in.read());
}finally {
in.close();
}
Assertions.assertEquals(chuck[0], resultSet.getBinaryStream("testBlob").read());
Assertions.assertEquals(chuck[0], resultSet.getBinaryStream("testBlob").read());
try {
in = resultSet.getAsciiStream("testClob");
Assertions.assertEquals('a', in.read());
}finally {
in.close();
}
try {
in = resultSet.getAsciiStream("testClob");
Assertions.assertEquals('a', in.read());
}finally {
in.close();
}
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());
Reader reader = null;
try {
reader = resultSet.getCharacterStream(11);
Assertions.assertEquals('a', reader.read());
}finally {
reader.close();
}
try {
reader = resultSet.getCharacterStream("testClob");
Assertions.assertEquals('a', reader.read());
}finally {
reader.close();
}
Assertions.assertNull(resultSet.getCursorName());
Assertions.assertNotNull(resultSet.getMetaData());
@ -163,6 +206,8 @@ public class ResultSetTest extends BaseJDBCTest{
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));";
Statement statement = connection.createStatement();
statement.execute("DROP TABLE IF EXISTS EMPLOYEE;");
statement.execute(SQL_CREATE);
statement.executeUpdate(SQL_INSERT);
ResultSet resultSet = statement.executeQuery("select * from EMPLOYEE");
@ -195,8 +240,28 @@ public class ResultSetTest extends BaseJDBCTest{
Assertions.assertEquals(blob1.length(), blob2.length());
Assertions.assertEquals(blob1.getBytes(1,1)[0], blob2.getBytes(1,1)[0]);
Assertions.assertEquals(blob1.getBinaryStream().read(), blob2.getBinaryStream().read());
Assertions.assertEquals(blob1.getBinaryStream(1, 6).read(), blob2.getBinaryStream(1, 6).read());
InputStream in1 = null;
InputStream in2 = null;
try {
in1 = blob1.getBinaryStream();
in2 = blob2.getBinaryStream();
Assertions.assertEquals(in1.read(), in2.read());
}finally {
in1.close();
in2.close();
}
try {
in1 = blob1.getBinaryStream(1, 6);
in2 = blob2.getBinaryStream(1, 6);
Assertions.assertEquals(in1.read(), in2.read());
}finally {
in1.close();
in2.close();
}
ServiceBlob serviceBlob = (ServiceBlob) blob2;
String IDtoInvoke = serviceBlob.getID();
@ -271,16 +336,48 @@ public class ResultSetTest extends BaseJDBCTest{
Assertions.assertEquals(clob1.length(), clob2.length());
Assertions.assertEquals(clob1.getSubString(1,2), clob1.getSubString(1,2));
Assertions.assertEquals(clob1.getCharacterStream().read(), clob2.getCharacterStream().read());
Assertions.assertEquals(clob1.getCharacterStream(1, 2).read(), clob2.getCharacterStream(1, 2).read());
Assertions.assertEquals(clob1.getCharacterStream().read(), clob2.getCharacterStream().read());
Assertions.assertEquals(clob1.getCharacterStream(1, 2).read(), clob2.getCharacterStream(1, 2).read());
Reader r1 = null;
Reader r2 = null;
try{
r1 = clob1.getCharacterStream();
r2 = clob2.getCharacterStream();
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
try{
r1 = clob1.getCharacterStream(1, 2);
r2 = clob2.getCharacterStream(1, 2);
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
try{
r1 = clob1.getCharacterStream();
r2 = clob2.getCharacterStream();
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
try{
r1 = clob1.getCharacterStream(1, 2);
r2 = clob2.getCharacterStream(1, 2);
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
Assertions.assertEquals(clob1.position("abcd", 1), clob2.position("abcd", 1));
Assertions.assertEquals(clob1.position(clob1, 1), clob2.position(clob1, 1));
clob2.getCharacterStream().close();
clob2.getAsciiStream().close();
ServiceClob serviceClob = (ServiceClob) clob2;
String IDtoInvoke = serviceClob.getID();
DispatcherImpl dispatcher = agent.dispatcherImpl;
@ -376,7 +473,7 @@ public class ResultSetTest extends BaseJDBCTest{
}
@Test
@Disabled("hsql not support")
@Disabled("hsql not support struct")
public void testStruct() throws SQLException {
}
@ -401,19 +498,30 @@ public class ResultSetTest extends BaseJDBCTest{
Assertions.assertEquals(nClob1.length(), nClob2.length());
Assertions.assertEquals(nClob1.getSubString(1,2), nClob2.getSubString(1,2));
nClob1.getCharacterStream().read();
Reader reader = nClob2.getCharacterStream();
reader.read();
// Assertions.assertEquals(nClob1.getCharacterStream().read(), nClob2.getCharacterStream().read());
Assertions.assertEquals(nClob1.getCharacterStream(1, 2).read(), nClob2.getCharacterStream(1, 2).read());
Assertions.assertEquals(nClob1.getCharacterStream().read(), nClob2.getCharacterStream().read());
Assertions.assertEquals(nClob1.getCharacterStream(1, 2).read(), nClob2.getCharacterStream(1, 2).read());
Reader r1 = null;
Reader r2 = null;
try{
r1 = nClob1.getCharacterStream();
r2 = nClob2.getCharacterStream();
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
try{
r1 = nClob1.getCharacterStream(1, 2);
r2 = nClob2.getCharacterStream(1, 2);
Assertions.assertEquals(r1.read(), r2.read());
}finally {
r1.close();
r2.close();
}
Assertions.assertEquals(nClob1.position("abcd", 1), nClob2.position("abcd", 1));
Assertions.assertEquals(nClob1.position(nClob1, 1), nClob2.position(nClob1, 1));
nClob2.getCharacterStream().close();
nClob2.getAsciiStream().close();
ServiceNClob serviceNClob = (ServiceNClob) nClob2;
String IDtoInvoke = serviceNClob.getID();
DispatcherImpl dispatcher = agent.dispatcherImpl;
@ -461,4 +569,9 @@ public class ResultSetTest extends BaseJDBCTest{
);
closeSQLObjects(statement, prepareStatement);
}
@AfterAll
void tearDown() throws SQLException{
closeSQLObjects(connection, resultSet);
}
}

24
test/src/test/java/com/fanruan/SavePointTest.java

@ -1,9 +1,6 @@
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 org.junit.jupiter.api.*;
import java.sql.*;
@ -21,14 +18,19 @@ public class SavePointTest extends BaseJDBCTest{
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()));
// }
@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()));
}
}

1
test/src/test/java/com/fanruan/TestUtil.java

@ -168,6 +168,7 @@ public class TestUtil extends BaseJDBCTest{
@Test
@Order(10)
@Disabled
void testErrorQuery() throws SQLException {
// 插入数据
ResultSet rs = st.executeQuery("SELECT * FROM TEACHER;");

Loading…
Cancel
Save