數據庫幾個中間件的關系及大致原理 - mybatis、druid、shading-jdbc


mysql架構示意圖:

 

最原始的JDBC實現(mysql-connctor-java): 加載JDBC驅動程序 → 建立數據庫連接Connection → 創建執行SQL的語句Statement(preparedStatement) → 處理執行結果ResultSet → 釋放資源

 

DataSource->Connection->Statement

 

DataSource的核心方法:

public interface DataSource extends CommonDataSource,Wrapper {

  Connection getConnection() throws SQLException;

  Connection getConnection(String username, String password)
  throws SQLException;
}

Connection核心api:

public interface Connection extends Wrapper, AutoCloseable {

  Statement createStatement() throws SQLException;

  PreparedStatement prepareStatement(String sql) throws SQLException;

  CallableStatement prepareCall(String sql) throws SQLException;

  void setAutoCommit(boolean autoCommit) throws SQLException;

  boolean getAutoCommit() throws SQLException;

  void commit() throws SQLException;

  void rollback() throws SQLException;

  void close() throws SQLException;

  boolean isClosed() throws SQLException;
}

Statement核心API定義,執行靜態的sql:

public interface Statement extends Wrapper, AutoCloseable {

  ResultSet executeQuery(String sql) throws SQLException;

  int executeUpdate(String sql) throws SQLException;

  void close() throws SQLException;

  boolean execute(String sql, String columnNames[]) throws SQLException;

  boolean isClosed() throws SQLException;

  public boolean isCloseOnCompletion() throws SQLException;

}


ibatis的核心應該是重寫statement

sharding-jdbc核心應該也是對statement

druid核心應該是Connection

各個中間件通過Statement的execute向下遞歸調用

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM