packageme.silentdoer.connectionpool.pool;import java.sql.*;importjava.util.Map;importjava.util.Properties;importjava.util.concurrent.Executor;/***@authorsilentdoer
*@version1.0
* @description the description
* @date 4/30/18 3:37 PM*/
public class MyConnection implementsConnection{private intconnIdentify;privateConnection conn;private boolean closed = false;//如果不是通过MyDataPool创建的此对象则此属性为null;
private MyPoolDataSource dataSource; //重要
private voidcheckState(){if(this.closed){throw new IllegalStateException("Connection已经close");
}
}
@Overridepublic Statement createStatement() throwsSQLException {this.checkState();return this.conn.createStatement();
}
@Overridepublic PreparedStatement prepareStatement(String s) throwsSQLException {this.checkState();return this.conn.prepareStatement(s);
}
@Overridepublic CallableStatement prepareCall(String s) throwsSQLException {this.checkState();return this.prepareCall(s);
}
@Overridepublic String nativeSQL(String s) throwsSQLException {return null;
}
@Overridepublic void setAutoCommit(boolean b) throwsSQLException {this.checkState();this.conn.setAutoCommit(b);
}
@Overridepublic boolean getAutoCommit() throwsSQLException {this.checkState();return this.conn.getAutoCommit();
}