From beef09925bfe82e7a42ab4688e4a7339896df73a Mon Sep 17 00:00:00 2001 From: yichen Date: Wed, 31 Aug 2022 20:44:42 +0800 Subject: [PATCH] Add method annotation to help filter dispatch --- .../com/fanruan/annotation/LocalMethod.java | 13 + .../fanruan/annotation/NotImplemented.java | 16 + .../exception/NotImplementedException.java | 8 + .../proxy/interceptor/Interceptor.java | 54 +- .../proxy/interceptor/InterceptorUtils.java | 86 +- .../fanruan/service/jdbc/AbstractBind.java | 42 + .../com/fanruan/service/jdbc/BasedBind.java | 61 + .../fanruan/service/jdbc/ServiceArray.java | 71 ++ .../com/fanruan/service/jdbc/ServiceBlob.java | 73 ++ .../com/fanruan/service/jdbc/ServiceClob.java | 83 ++ .../{ => jdbc}/ServiceDataBaseMetaData.java | 17 +- .../jdbc/ServiceParameterMetaData.java | 69 ++ .../fanruan/service/jdbc/ServiceStruct.java | 29 + .../jdbc/connection/ServiceConnection.java | 86 +- .../service/jdbc/driver/ServiceDriver.java | 18 +- .../jdbc/resultset/ServiceResultSet.java | 23 +- .../statement/ServiceCallableStatement.java | 1090 +++++++++++++++++ .../statement/ServicePreparedStatement.java | 22 +- .../jdbc/statement/ServiceStatement.java | 22 +- 19 files changed, 1680 insertions(+), 203 deletions(-) create mode 100644 service/src/main/java/com/fanruan/annotation/LocalMethod.java create mode 100644 service/src/main/java/com/fanruan/annotation/NotImplemented.java create mode 100644 service/src/main/java/com/fanruan/exception/NotImplementedException.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/AbstractBind.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/BasedBind.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/ServiceArray.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/ServiceBlob.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/ServiceClob.java rename service/src/main/java/com/fanruan/service/{ => jdbc}/ServiceDataBaseMetaData.java (98%) create mode 100644 service/src/main/java/com/fanruan/service/jdbc/ServiceParameterMetaData.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/ServiceStruct.java create mode 100644 service/src/main/java/com/fanruan/service/jdbc/statement/ServiceCallableStatement.java diff --git a/service/src/main/java/com/fanruan/annotation/LocalMethod.java b/service/src/main/java/com/fanruan/annotation/LocalMethod.java new file mode 100644 index 0000000..ba4c4ba --- /dev/null +++ b/service/src/main/java/com/fanruan/annotation/LocalMethod.java @@ -0,0 +1,13 @@ +package com.fanruan.annotation; + +import java.lang.annotation.*; + +/** + * @author Yichen Dai + * @date 2022/8/31 18:34 + */ +@Inherited +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface LocalMethod { +} diff --git a/service/src/main/java/com/fanruan/annotation/NotImplemented.java b/service/src/main/java/com/fanruan/annotation/NotImplemented.java new file mode 100644 index 0000000..5a2dc4a --- /dev/null +++ b/service/src/main/java/com/fanruan/annotation/NotImplemented.java @@ -0,0 +1,16 @@ +package com.fanruan.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * mark the method not implement + * @author Yichen Dai + * @date 2022/8/31 10:30 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface NotImplemented { +} diff --git a/service/src/main/java/com/fanruan/exception/NotImplementedException.java b/service/src/main/java/com/fanruan/exception/NotImplementedException.java new file mode 100644 index 0000000..c15e67d --- /dev/null +++ b/service/src/main/java/com/fanruan/exception/NotImplementedException.java @@ -0,0 +1,8 @@ +package com.fanruan.exception; + +/** + * @author Yichen Dai + * @date 2022/8/31 10:36 + */ +public class NotImplementedException extends RuntimeException{ +} diff --git a/service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java b/service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java index 065a016..7de75e0 100644 --- a/service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java +++ b/service/src/main/java/com/fanruan/proxy/interceptor/Interceptor.java @@ -2,13 +2,12 @@ package com.fanruan.proxy.interceptor; import com.corundumstudio.socketio.SocketIOClient; -import com.fanruan.annotation.RemoteClass; import com.fanruan.ServerStater; import com.fanruan.cache.ClientCache; import com.fanruan.cache.ClientWrapper; import com.fanruan.cache.LockAndCondition; import com.fanruan.pojo.message.RpcRequest; -import com.fanruan.utils.Commons; +import com.fanruan.service.jdbc.AbstractBind; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; import org.apache.logging.log4j.LogManager; @@ -41,7 +40,8 @@ public class Interceptor implements MethodInterceptor { @Override public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { - if(InterceptorUtils.isInExcludedList(method.getName())){ + if(InterceptorUtils.isNotImplemented(method) || + InterceptorUtils.isLocalMethod(method)){ return methodProxy.invokeSuper(o, objects); } // Parameters injection of class MyDriver's construction method will be delayed util the first "connect" method was intercepted @@ -55,38 +55,9 @@ public class Interceptor implements MethodInterceptor { if(client == null){ client = ClientCache.getClient(agentId, dbName); } - logger.debug("start invoke " + method.getName()); - RpcRequest rpcRequest = new RpcRequest(); - rpcRequest - .setID(Commons.getID()) - .setMethodName(method.getName()) - .setArgs(objects) - .setArgTypes(getArgTypes(objects)); - - // get RPC class name from annotation - // if null, send the name of this clazz - if(clazz.isAnnotationPresent(RemoteClass.class)){ - RemoteClass annotation = clazz.getAnnotation(RemoteClass.class); - rpcRequest.setServiceClassName(annotation.remoteClassName()); - }else{ - rpcRequest.setServiceClassName(clazz.getName()); - } - -// // Some instance need to be bound one-to-one, to make sure the operator happen in service -// // will be deliver to this specific corresponding instance. -// if(InterceptorUtils.isInBindList(o)){ -// rpcRequest.setBinding(true); -// } - - // IDtoInvoke is an unique ID to identify an one-to-one binding relation. - // It comes from rpcRequest in which the instance in the agent is created. - String idToInvoke = InterceptorUtils.getInvokeHelper(o, "getID", String.class); - - if(idToInvoke != null){ - rpcRequest.setIDToInvoke(idToInvoke); - } + RpcRequest rpcRequest = InterceptorUtils.generateRequest(clazz, o, method, objects); FutureTask futureTask = new FutureTask<>( () -> { @@ -113,7 +84,7 @@ public class Interceptor implements MethodInterceptor { ServerStater.threadPool.submit(futureTask); Object res = futureTask.get(); - // res is not null, it indicates the response carries data. + // res is not null, it indicates the response carries data. // if the type of res is primitive type, An error will occur when using cast(), just return them directly. // And the data carried by response will never be the instance need to be bound. if(res != null){ @@ -123,25 +94,14 @@ public class Interceptor implements MethodInterceptor { return res; } - Object returnObj = methodProxy.invokeSuper(o, objects); // If the return instance is corresponding with another instance in agent, set the binding ID. if (InterceptorUtils.isInBindList(returnObj)){ - InterceptorUtils.setInvokeHelper(returnObj, "setID", rpcRequest.getID()); + AbstractBind ab = (AbstractBind) returnObj; + ab.setID(rpcRequest.getID()); } return returnObj; } - - - - public Class[] getArgTypes(Object[] objects){ - int n = objects.length; - Class[] argTypes = new Class[n]; - for(int i=0; i clazz, Object o, Method method, Object[] objects){ + + + RpcRequest rpcRequest = new RpcRequest(); + rpcRequest + .setID(Commons.getID()) + .setMethodName(method.getName()) + .setArgs(objects) + .setArgTypes(method.getParameterTypes()); + + // get RPC class name from annotation + // if null, send the name of this clazz + if(clazz.isAnnotationPresent(RemoteClass.class)){ + RemoteClass annotation = clazz.getAnnotation(RemoteClass.class); + rpcRequest.setServiceClassName(annotation.remoteClassName()); + }else{ + rpcRequest.setServiceClassName(clazz.getName()); + } + + // IDtoInvoke is an unique ID to identify an one-to-one binding relation. + // It comes from rpcRequest in which the instance in the agent is created. + AbstractBind ab = (AbstractBind) o; + String idToInvoke = ab.getID(); + + if(idToInvoke != null){ + rpcRequest.setIDToInvoke(idToInvoke); } + return rpcRequest; } - public static T getInvokeHelper(Object o, String methodName, Class T){ - try { - Method method = o.getClass().getDeclaredMethod(methodName); - T res = (T) method.invoke(o); - return res; - } catch (Exception e) { - e.printStackTrace(); + public static boolean isNotImplemented(Method method) { + if(method.isAnnotationPresent(NotImplemented.class)){ + return true; } - return null; + return false; } + public static boolean isLocalMethod(Method method) { + if(method.isAnnotationPresent(LocalMethod.class)){ + return true; + } + return false; + } } diff --git a/service/src/main/java/com/fanruan/service/jdbc/AbstractBind.java b/service/src/main/java/com/fanruan/service/jdbc/AbstractBind.java new file mode 100644 index 0000000..ca4d508 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/AbstractBind.java @@ -0,0 +1,42 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.LocalMethod; + +import java.util.Properties; + +/** + * @author Yichen Dai + * @date 2022/8/25 16:56 + */ +public abstract class AbstractBind{ + + private String ID; + + protected Properties info; + + /** + * These corresponding code is to make the format correct, because the getID() + * will be called, even if the filed is never not null. + * @return ID + */ + public String getID(){ + return this.ID; + } + + /** + * These corresponding code is to make the format correct, because the getID() + * will be called, even if the filed is never not null. + * @return ID + */ + public void setID(String ID){ + this.ID = ID; + } + + /** + * Set info to bind class generated by this class + * @param info properties need to bind with agent + */ + public void setInfo(Properties info){ + this.info = info; + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/BasedBind.java b/service/src/main/java/com/fanruan/service/jdbc/BasedBind.java new file mode 100644 index 0000000..f6e6691 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/BasedBind.java @@ -0,0 +1,61 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.LocalMethod; +import com.fanruan.service.jdbc.AbstractBind; + +import java.util.Properties; + +/** + * @author Yichen Dai + * @date 2022/8/31 20:35 + */ +public class BasedBind extends AbstractBind { + + @LocalMethod + @Override + public String getID() { + return super.getID(); + } + + @LocalMethod + @Override + public void setID(String ID) { + super.setID(ID); + } + + @LocalMethod + @Override + public void setInfo(Properties info) { + super.setInfo(info); + } + + @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(); + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/ServiceArray.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceArray.java new file mode 100644 index 0000000..b23ae26 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceArray.java @@ -0,0 +1,71 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.RemoteClass; + +import java.sql.Array; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +/** + * @author Yichen Dai + * @date 2022/8/31 16:51 + */ +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentArray") +public class ServiceArray extends BasedBind implements Array { + + @Override + public String getBaseTypeName() throws SQLException { + return null; + } + + @Override + public int getBaseType() throws SQLException { + return 0; + } + + @Override + public Object getArray() throws SQLException { + return null; + } + + @Override + public Object getArray(Map> map) throws SQLException { + return null; + } + + @Override + public Object getArray(long index, int count) throws SQLException { + return null; + } + + @Override + public Object getArray(long index, int count, Map> map) throws SQLException { + return null; + } + + @Override + public ResultSet getResultSet() throws SQLException { + return null; + } + + @Override + public ResultSet getResultSet(Map> map) throws SQLException { + return null; + } + + @Override + public ResultSet getResultSet(long index, int count) throws SQLException { + return null; + } + + @Override + public ResultSet getResultSet(long index, int count, Map> map) throws SQLException { + return null; + } + + @Override + public void free() throws SQLException { + + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/ServiceBlob.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceBlob.java new file mode 100644 index 0000000..8325b72 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceBlob.java @@ -0,0 +1,73 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.RemoteClass; +import com.fanruan.service.jdbc.AbstractBind; + +import java.io.InputStream; +import java.io.OutputStream; +import java.sql.Blob; +import java.sql.SQLException; + +/** + * @author Yichen Dai + * @date 2022/8/29 20:32 + */ + +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentBlob") +public class ServiceBlob extends BasedBind implements Blob { + + @Override + public long length() throws SQLException { + return 0; + } + + @Override + public byte[] getBytes(long pos, int length) throws SQLException { + return new byte[0]; + } + + @Override + public InputStream getBinaryStream() throws SQLException { + return null; + } + + @Override + public long position(byte[] pattern, long start) throws SQLException { + return 0; + } + + @Override + public long position(Blob pattern, long start) throws SQLException { + return 0; + } + + @Override + public int setBytes(long pos, byte[] bytes) throws SQLException { + return 0; + } + + @Override + public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException { + return 0; + } + + @Override + public OutputStream setBinaryStream(long pos) throws SQLException { + return null; + } + + @Override + public void truncate(long len) throws SQLException { + + } + + @Override + public void free() throws SQLException { + + } + + @Override + public InputStream getBinaryStream(long pos, long length) throws SQLException { + return null; + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/ServiceClob.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceClob.java new file mode 100644 index 0000000..0423d51 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceClob.java @@ -0,0 +1,83 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.RemoteClass; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.sql.Clob; +import java.sql.SQLException; + +/** + * @author Yichen Dai + * @date 2022/8/29 20:24 + */ +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentClob") +public class ServiceClob extends BasedBind implements Clob { + + @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 null; + } + + @Override + public InputStream getAsciiStream() throws SQLException { + return null; + } + + @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 null; + } + + @Override + public Writer setCharacterStream(long pos) throws SQLException { + return null; + } + + @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 null; + } +} diff --git a/service/src/main/java/com/fanruan/service/ServiceDataBaseMetaData.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceDataBaseMetaData.java similarity index 98% rename from service/src/main/java/com/fanruan/service/ServiceDataBaseMetaData.java rename to service/src/main/java/com/fanruan/service/jdbc/ServiceDataBaseMetaData.java index 56a4adc..cc05524 100644 --- a/service/src/main/java/com/fanruan/service/ServiceDataBaseMetaData.java +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceDataBaseMetaData.java @@ -1,17 +1,19 @@ -package com.fanruan.service; +package com.fanruan.service.jdbc; +import com.fanruan.annotation.LocalMethod; +import com.fanruan.annotation.RemoteClass; import com.fanruan.service.jdbc.driver.ServiceDriver; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.RowIdLifetime; -import java.sql.SQLException; +import java.sql.*; +import java.util.Map; /** - * @author 85065 + * @author Yichen Dai */ -public class ServiceDataBaseMetaData implements java.sql.DatabaseMetaData{ +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentDataBaseMetaData") +public class ServiceDataBaseMetaData extends BasedBind implements java.sql.DatabaseMetaData{ + @Override public boolean allProceduresAreCallable() throws SQLException { return false; @@ -752,6 +754,7 @@ public class ServiceDataBaseMetaData implements java.sql.DatabaseMetaData{ return null; } + @LocalMethod @Override public Connection getConnection() throws SQLException { return null; diff --git a/service/src/main/java/com/fanruan/service/jdbc/ServiceParameterMetaData.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceParameterMetaData.java new file mode 100644 index 0000000..1d3786e --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceParameterMetaData.java @@ -0,0 +1,69 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.RemoteClass; + +import java.sql.ParameterMetaData; +import java.sql.SQLException; + +/** + * @author Yichen Dai + * @date 2022/8/25 11:13 + */ +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentParameterMetaData") +public class ServiceParameterMetaData extends BasedBind implements ParameterMetaData { + + @Override + public int getParameterCount() throws SQLException { + return 0; + } + + @Override + public int isNullable(int param) throws SQLException { + return 0; + } + + @Override + public boolean isSigned(int param) throws SQLException { + return false; + } + + @Override + public int getPrecision(int param) throws SQLException { + return 0; + } + + @Override + public int getScale(int param) throws SQLException { + return 0; + } + + @Override + public int getParameterType(int param) throws SQLException { + return 0; + } + + @Override + public String getParameterTypeName(int param) throws SQLException { + return null; + } + + @Override + public String getParameterClassName(int param) throws SQLException { + return null; + } + + @Override + public int getParameterMode(int param) throws SQLException { + return 0; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/ServiceStruct.java b/service/src/main/java/com/fanruan/service/jdbc/ServiceStruct.java new file mode 100644 index 0000000..78c009f --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/ServiceStruct.java @@ -0,0 +1,29 @@ +package com.fanruan.service.jdbc; + +import com.fanruan.annotation.RemoteClass; + +import java.sql.SQLException; +import java.sql.Struct; +import java.util.Map; + +/** + * @author Yichen Dai + * @date 2022/8/31 17:03 + */ +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.AgentStruct") +public class ServiceStruct extends BasedBind implements Struct { + @Override + public String getSQLTypeName() throws SQLException { + return null; + } + + @Override + public Object[] getAttributes() throws SQLException { + return new Object[0]; + } + + @Override + public Object[] getAttributes(Map> map) throws SQLException { + return new Object[0]; + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java b/service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java index e42a676..890c981 100644 --- a/service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java +++ b/service/src/main/java/com/fanruan/service/jdbc/connection/ServiceConnection.java @@ -2,12 +2,17 @@ package com.fanruan.service.jdbc.connection; import com.corundumstudio.socketio.SocketIOClient; +import com.fanruan.annotation.NotImplemented; import com.fanruan.annotation.RemoteClass; import com.fanruan.cache.ClientCache; -import com.fanruan.service.ServiceDataBaseMetaData; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; +import com.fanruan.service.jdbc.ServiceDataBaseMetaData; +import com.fanruan.service.jdbc.statement.ServiceCallableStatement; import com.fanruan.service.jdbc.statement.ServicePreparedStatement; import com.fanruan.service.jdbc.statement.ServiceStatement; import com.fanruan.proxy.ProxyFactory; +import com.fanruan.exception.NotImplementedException; import java.sql.*; import java.util.Map; @@ -18,30 +23,11 @@ import java.util.concurrent.Executor; * @author Yichen Dai */ @RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.connection.AgentConnection") -public class ServiceConnection implements Connection { - private String ID; - - private Properties info; - private boolean autoCommit = true; - SocketIOClient client; +public class ServiceConnection extends BasedBind implements Connection { public ServiceConnection(){ } - public void setID(String ID){ - this.ID = ID; - } - - public String getID(){ - return this.ID; - } - - public void setInfo(Properties info){ - this.info = info; - client = ClientCache.getClient(info.getProperty("agentID"), info.getProperty("agentDBName")); - } - - @Override public Statement createStatement(){ ServiceStatement st = (ServiceStatement) ProxyFactory.getProxy(ServiceStatement.class, info); @@ -52,15 +38,15 @@ public class ServiceConnection implements Connection { @Override public PreparedStatement prepareStatement(String sql) throws SQLException { ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); - // 将需要准备的sql 加入 properties 中, 将用以标识生成的 ResultSet - info.setProperty("PreparedSQL", sql); pst.setInfo(info); return pst; } @Override public CallableStatement prepareCall(String sql) throws SQLException { - return null; + ServiceCallableStatement cst = (ServiceCallableStatement) ProxyFactory.getProxy(ServiceCallableStatement.class, info); + cst.setInfo(info); + return cst; } @Override @@ -70,12 +56,11 @@ public class ServiceConnection implements Connection { @Override public void setAutoCommit(boolean autoCommit) throws SQLException { - this.autoCommit = autoCommit; } @Override public boolean getAutoCommit() throws SQLException { - return autoCommit; + return true; } @Override @@ -90,17 +75,16 @@ public class ServiceConnection implements Connection { @Override public void close() throws SQLException { - client.disconnect(); } @Override public boolean isClosed() throws SQLException { - return client.isChannelOpen(); + return true; } @Override public DatabaseMetaData getMetaData() throws SQLException { - return new ServiceDataBaseMetaData(); + return (DatabaseMetaData) ProxyFactory.getProxy(ServiceDataBaseMetaData.class, info); } @Override @@ -145,17 +129,23 @@ public class ServiceConnection implements Connection { @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return null; + ServiceStatement st = (ServiceStatement) ProxyFactory.getProxy(ServiceStatement.class, info); + st.setInfo(info); + return st; } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return null; + ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); + pst.setInfo(info); + return pst; } @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return null; + ServiceCallableStatement cst = (ServiceCallableStatement) ProxyFactory.getProxy(ServiceCallableStatement.class, info); + cst.setInfo(info); + return cst; } @Override @@ -200,32 +190,44 @@ public class ServiceConnection implements Connection { @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + ServiceStatement st = (ServiceStatement) ProxyFactory.getProxy(ServiceStatement.class, info); + st.setInfo(info); + return st; } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); + pst.setInfo(info); + return pst; } @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + ServiceCallableStatement cst = (ServiceCallableStatement) ProxyFactory.getProxy(ServiceCallableStatement.class, info); + cst.setInfo(info); + return cst; } @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return null; + ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); + pst.setInfo(info); + return pst; } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return null; + ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); + pst.setInfo(info); + return pst; } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return null; + ServicePreparedStatement pst = (ServicePreparedStatement) ProxyFactory.getProxy(ServicePreparedStatement.class, info); + pst.setInfo(info); + return pst; } @Override @@ -309,12 +311,14 @@ public class ServiceConnection implements Connection { } @Override + @NotImplemented public T unwrap(Class iface) throws SQLException { - return null; + throw new NotImplementedException(); } @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; + + public boolean isWrapperFor(Class iface) throws NotImplementedException { + return true; } } diff --git a/service/src/main/java/com/fanruan/service/jdbc/driver/ServiceDriver.java b/service/src/main/java/com/fanruan/service/jdbc/driver/ServiceDriver.java index 6ba34bf..3db83a7 100644 --- a/service/src/main/java/com/fanruan/service/jdbc/driver/ServiceDriver.java +++ b/service/src/main/java/com/fanruan/service/jdbc/driver/ServiceDriver.java @@ -1,6 +1,8 @@ package com.fanruan.service.jdbc.driver; import com.fanruan.annotation.RemoteClass; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; import com.fanruan.service.jdbc.connection.ServiceConnection; import com.fanruan.proxy.ProxyFactory; @@ -13,11 +15,10 @@ import java.util.logging.Logger; * @author Yichen Dai */ @RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.driver.AgentDriver") -public class ServiceDriver implements Driver { +public class ServiceDriver extends BasedBind implements Driver { static public final int DRIVER_VERSION_MAJOR = 1; static public final int DRIVER_VERSION_MINOR = 1; - private String ID; //依靠静态函数块注册驱动 static{ @@ -29,19 +30,6 @@ public class ServiceDriver implements Driver { } - /** - * These corresponding code is to make the format correct, because the getID() - * will be called, even if the filed is never not null. - * @return ID - */ - public String getID(){ - return this.ID; - } - - public void setID(String ID){ - this.ID = ID; - } - @Override public Connection connect(String url, Properties info){ String dbName = info.getProperty("agentDBName"); diff --git a/service/src/main/java/com/fanruan/service/jdbc/resultset/ServiceResultSet.java b/service/src/main/java/com/fanruan/service/jdbc/resultset/ServiceResultSet.java index 16b4864..104212b 100644 --- a/service/src/main/java/com/fanruan/service/jdbc/resultset/ServiceResultSet.java +++ b/service/src/main/java/com/fanruan/service/jdbc/resultset/ServiceResultSet.java @@ -2,6 +2,8 @@ package com.fanruan.service.jdbc.resultset; import com.fanruan.annotation.RemoteClass; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; import java.io.InputStream; import java.io.Reader; @@ -16,26 +18,7 @@ import java.util.Map; * @author Yichen Dai */ @RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.resultset.AgentResultSet") -public class ServiceResultSet implements ResultSet { - - private String sql; - private String ID; - - public String getID(){ - return this.ID; - } - - public void setID(String ID){ - this.ID = ID; - } - - public void setSql(String sql){ - this.sql = sql; - } - - public String getSql(){ - return this.sql; - } +public class ServiceResultSet extends BasedBind implements ResultSet { @Override public boolean next() throws SQLException { diff --git a/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceCallableStatement.java b/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceCallableStatement.java new file mode 100644 index 0000000..7d63b66 --- /dev/null +++ b/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceCallableStatement.java @@ -0,0 +1,1090 @@ +package com.fanruan.service.jdbc.statement; + +import com.fanruan.annotation.RemoteClass; +import com.fanruan.proxy.ProxyFactory; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; +import com.fanruan.service.jdbc.ServiceParameterMetaData; +import com.fanruan.service.jdbc.resultset.ServiceResultSet; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.Calendar; +import java.util.Map; +import java.util.Properties; + +/** + * @author Yichen Dai + * @date 2022/8/24 16:22 + */ + +@RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.statement.AgentCallableStatement") +public class ServiceCallableStatement extends BasedBind implements CallableStatement { + + public ServiceCallableStatement() {} + + @Override + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { + + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { + + } + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(int parameterIndex) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(int parameterIndex) throws SQLException { + return false; + } + + @Override + public byte getByte(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public short getShort(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public int getInt(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public long getLong(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public float getFloat(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public double getDouble(int parameterIndex) throws SQLException { + return 0; + } + + @Override + public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(int parameterIndex) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Time getTime(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(int parameterIndex) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(int parameterIndex, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Blob getBlob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Date getDate(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { + + } + + @Override + public void registerOutParameter(String parameterName, int sqlType) throws SQLException { + + } + + @Override + public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { + + } + + @Override + public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { + + } + + @Override + public URL getURL(int parameterIndex) throws SQLException { + return null; + } + + @Override + public void setURL(String parameterName, URL val) throws SQLException { + + } + + @Override + public void setNull(String parameterName, int sqlType) throws SQLException { + + } + + @Override + public void setBoolean(String parameterName, boolean x) throws SQLException { + + } + + @Override + public void setByte(String parameterName, byte x) throws SQLException { + + } + + @Override + public void setShort(String parameterName, short x) throws SQLException { + + } + + @Override + public void setInt(String parameterName, int x) throws SQLException { + + } + + @Override + public void setLong(String parameterName, long x) throws SQLException { + + } + + @Override + public void setFloat(String parameterName, float x) throws SQLException { + + } + + @Override + public void setDouble(String parameterName, double x) throws SQLException { + + } + + @Override + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { + + } + + @Override + public void setString(String parameterName, String x) throws SQLException { + + } + + @Override + public void setBytes(String parameterName, byte[] x) throws SQLException { + + } + + @Override + public void setDate(String parameterName, Date x) throws SQLException { + + } + + @Override + public void setTime(String parameterName, Time x) throws SQLException { + + } + + @Override + public void setTimestamp(String parameterName, Timestamp x) throws SQLException { + + } + + @Override + public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException { + + } + + @Override + public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException { + + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { + + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { + + } + + @Override + public void setObject(String parameterName, Object x) throws SQLException { + + } + + @Override + public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException { + + } + + @Override + public void setDate(String parameterName, Date x, Calendar cal) throws SQLException { + + } + + @Override + public void setTime(String parameterName, Time x, Calendar cal) throws SQLException { + + } + + @Override + public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException { + + } + + @Override + public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { + + } + + @Override + public String getString(String parameterName) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(String parameterName) throws SQLException { + return false; + } + + @Override + public byte getByte(String parameterName) throws SQLException { + return 0; + } + + @Override + public short getShort(String parameterName) throws SQLException { + return 0; + } + + @Override + public int getInt(String parameterName) throws SQLException { + return 0; + } + + @Override + public long getLong(String parameterName) throws SQLException { + return 0; + } + + @Override + public float getFloat(String parameterName) throws SQLException { + return 0; + } + + @Override + public double getDouble(String parameterName) throws SQLException { + return 0; + } + + @Override + public byte[] getBytes(String parameterName) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(String parameterName) throws SQLException { + return null; + } + + @Override + public Time getTime(String parameterName) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String parameterName) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String parameterName) throws SQLException { + return null; + } + + @Override + public Clob getClob(String parameterName) throws SQLException { + return null; + } + + @Override + public Array getArray(String parameterName) throws SQLException { + return null; + } + + @Override + public Date getDate(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public URL getURL(String parameterName) throws SQLException { + return null; + } + + @Override + public RowId getRowId(int parameterIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String parameterName) throws SQLException { + return null; + } + + @Override + public void setRowId(String parameterName, RowId x) throws SQLException { + + } + + @Override + public void setNString(String parameterName, String value) throws SQLException { + + } + + @Override + public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { + + } + + @Override + public void setNClob(String parameterName, NClob value) throws SQLException { + + } + + @Override + public void setClob(String parameterName, Reader reader, long length) throws SQLException { + + } + + @Override + public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void setNClob(String parameterName, Reader reader, long length) throws SQLException { + + } + + @Override + public NClob getNClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String parameterName) throws SQLException { + return null; + } + + @Override + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { + + } + + @Override + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String parameterName) throws SQLException { + return null; + } + + @Override + public String getNString(int parameterIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String parameterName) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public void setBlob(String parameterName, Blob x) throws SQLException { + + } + + @Override + public void setClob(String parameterName, Clob x) throws SQLException { + + } + + @Override + public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException { + + } + + @Override + public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException { + + } + + @Override + public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException { + + } + + @Override + public void setAsciiStream(String parameterName, InputStream x) throws SQLException { + + } + + @Override + public void setBinaryStream(String parameterName, InputStream x) throws SQLException { + + } + + @Override + public void setCharacterStream(String parameterName, Reader reader) throws SQLException { + + } + + @Override + public void setNCharacterStream(String parameterName, Reader value) throws SQLException { + + } + + @Override + public void setClob(String parameterName, Reader reader) throws SQLException { + + } + + @Override + public void setBlob(String parameterName, InputStream inputStream) throws SQLException { + + } + + @Override + public void setNClob(String parameterName, Reader reader) throws SQLException { + + } + + @Override + public T getObject(int parameterIndex, Class type) throws SQLException { + return null; + } + + @Override + public T getObject(String parameterName, Class type) throws SQLException { + return null; + } + + @Override + public ResultSet executeQuery() throws SQLException { + ServiceResultSet rs = (ServiceResultSet) ProxyFactory.getProxy(ServiceResultSet.class, info); + return rs; + } + + @Override + public int executeUpdate() throws SQLException { + return 0; + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException { + + } + + @Override + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + + } + + @Override + public void setByte(int parameterIndex, byte x) throws SQLException { + + } + + @Override + public void setShort(int parameterIndex, short x) throws SQLException { + + } + + @Override + public void setInt(int parameterIndex, int x) throws SQLException { + + } + + @Override + public void setLong(int parameterIndex, long x) throws SQLException { + + } + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException { + + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + + } + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + + } + + @Override + public void setString(int parameterIndex, String x) throws SQLException { + + } + + @Override + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + + } + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException { + + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void clearParameters() throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + + } + + @Override + public boolean execute() throws SQLException { + return false; + } + + @Override + public void addBatch() throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException { + + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + + } + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + + } + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + + } + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + return (ParameterMetaData) ProxyFactory.getProxy(ServiceParameterMetaData.class, info); + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + + } + + @Override + public void setNString(int parameterIndex, String value) throws SQLException { + + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, NClob value) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { + + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Reader reader) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + + } + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + ServiceResultSet rs = (ServiceResultSet) ProxyFactory.getProxy(ServiceResultSet.class, info); + return rs; + } + + @Override + public int executeUpdate(String sql) throws SQLException { + return 0; + } + + @Override + public void close() throws SQLException { + + } + + @Override + public int getMaxFieldSize() throws SQLException { + return 0; + } + + @Override + public void setMaxFieldSize(int max) throws SQLException { + + } + + @Override + public int getMaxRows() throws SQLException { + return 0; + } + + @Override + public void setMaxRows(int max) throws SQLException { + + } + + @Override + public void setEscapeProcessing(boolean enable) throws SQLException { + + } + + @Override + public int getQueryTimeout() throws SQLException { + return 0; + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException { + + } + + @Override + public void cancel() throws SQLException { + + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public void setCursorName(String name) throws SQLException { + + } + + @Override + public boolean execute(String sql) throws SQLException { + return false; + } + + @Override + public ResultSet getResultSet() throws SQLException { + return null; + } + + @Override + public int getUpdateCount() throws SQLException { + return 0; + } + + @Override + public boolean getMoreResults() throws SQLException { + return false; + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public int getResultSetConcurrency() throws SQLException { + return 0; + } + + @Override + public int getResultSetType() throws SQLException { + return 0; + } + + @Override + public void addBatch(String sql) throws SQLException { + + } + + @Override + public void clearBatch() throws SQLException { + + } + + @Override + public int[] executeBatch() throws SQLException { + return new int[0]; + } + + @Override + public Connection getConnection() throws SQLException { + return null; + } + + @Override + public boolean getMoreResults(int current) throws SQLException { + return false; + } + + @Override + public ResultSet getGeneratedKeys() throws SQLException { + return null; + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + return 0; + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return false; + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return false; + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + return false; + } + + @Override + public int getResultSetHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public void setPoolable(boolean poolable) throws SQLException { + + } + + @Override + public boolean isPoolable() throws SQLException { + return false; + } + + @Override + public void closeOnCompletion() throws SQLException { + + } + + @Override + public boolean isCloseOnCompletion() throws SQLException { + return false; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/service/src/main/java/com/fanruan/service/jdbc/statement/ServicePreparedStatement.java b/service/src/main/java/com/fanruan/service/jdbc/statement/ServicePreparedStatement.java index 96b8d67..9574881 100644 --- a/service/src/main/java/com/fanruan/service/jdbc/statement/ServicePreparedStatement.java +++ b/service/src/main/java/com/fanruan/service/jdbc/statement/ServicePreparedStatement.java @@ -1,6 +1,8 @@ package com.fanruan.service.jdbc.statement; import com.fanruan.annotation.RemoteClass; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; import com.fanruan.service.jdbc.resultset.ServiceResultSet; import com.fanruan.proxy.ProxyFactory; @@ -16,24 +18,7 @@ import java.util.Properties; * @author Yichen Dai */ @RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.statement.AgentPreparedStatement") -public class ServicePreparedStatement implements PreparedStatement { - - private Properties info; - - private String ID; - - public ServicePreparedStatement() {} - - public String getID(){ - return this.ID; - } - - public void setID(String ID){ - this.ID = ID; - } - - public void setInfo(Properties info) {this.info = info;} - +public class ServicePreparedStatement extends BasedBind implements PreparedStatement { @Override public ResultSet executeQuery() throws SQLException { @@ -41,7 +26,6 @@ public class ServicePreparedStatement implements PreparedStatement { throw new SQLException("This Statement is closed."); } ServiceResultSet rs = (ServiceResultSet) ProxyFactory.getProxy(ServiceResultSet.class, info); - rs.setSql(info.getProperty("PreparedSQL")); return rs; } diff --git a/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceStatement.java b/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceStatement.java index 0ced871..d841237 100644 --- a/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceStatement.java +++ b/service/src/main/java/com/fanruan/service/jdbc/statement/ServiceStatement.java @@ -1,6 +1,8 @@ package com.fanruan.service.jdbc.statement; import com.fanruan.annotation.RemoteClass; +import com.fanruan.service.jdbc.AbstractBind; +import com.fanruan.service.jdbc.BasedBind; import com.fanruan.service.jdbc.resultset.ServiceResultSet; import com.fanruan.proxy.ProxyFactory; @@ -11,24 +13,7 @@ import java.util.Properties; * @author Yichen Dai */ @RemoteClass(remoteClassName = "com.fanruan.agent.jdbc.statement.AgentStatement") -public class ServiceStatement implements Statement { - private Properties info; - - private String ID; - - public ServiceStatement() {} - - public String getID(){ - return this.ID; - } - - public void setID(String ID){ - this.ID = ID; - } - - public void setInfo(Properties info){ - this.info = info; - } +public class ServiceStatement extends BasedBind implements Statement { @Override public ResultSet executeQuery(String sql) throws SQLException { @@ -36,7 +21,6 @@ public class ServiceStatement implements Statement { throw new SQLException("This Statement is closed."); } ServiceResultSet rs = (ServiceResultSet) ProxyFactory.getProxy(ServiceResultSet.class, info); - rs.setSql(sql); return rs; }