Class SQLManagerImpl

  • All Implemented Interfaces:
    SQLManager

    public class SQLManagerImpl
    extends java.lang.Object
    implements SQLManager
    • Field Detail

      • executorPool

        protected java.util.concurrent.ExecutorService executorPool
    • Constructor Detail

      • SQLManagerImpl

        public SQLManagerImpl​(@NotNull
                              @NotNull javax.sql.DataSource dataSource)
      • SQLManagerImpl

        public SQLManagerImpl​(@NotNull
                              @NotNull javax.sql.DataSource dataSource,
                              @Nullable
                              @Nullable java.lang.String name)
      • SQLManagerImpl

        public SQLManagerImpl​(@NotNull
                              @NotNull javax.sql.DataSource dataSource,
                              @NotNull
                              @NotNull org.slf4j.Logger logger,
                              @Nullable
                              @Nullable java.lang.String name)
    • Method Detail

      • setDebugMode

        public void setDebugMode​(@NotNull
                                 @NotNull java.util.function.Supplier<@NotNull java.lang.Boolean> debugMode)
        Description copied from interface: SQLManager
        设定是否启用调试模式。 启用调试模式后,会在每次执行SQL语句时,调用 SQLManager.getDebugHandler() 来输出调试信息。
        Specified by:
        setDebugMode in interface SQLManager
        Parameters:
        debugMode - 是否启用调试模式
      • getLogger

        public org.slf4j.Logger getLogger()
        Specified by:
        getLogger in interface SQLManager
      • getDataSource

        @NotNull
        public @NotNull javax.sql.DataSource getDataSource()
        Description copied from interface: SQLManager
        得到连接池源
        Specified by:
        getDataSource in interface SQLManager
        Returns:
        DataSource
      • getConnection

        @NotNull
        public @NotNull java.sql.Connection getConnection()
                                                   throws java.sql.SQLException
        Description copied from interface: SQLManager
        得到一个数据库连接实例
        Specified by:
        getConnection in interface SQLManager
        Returns:
        Connection
        Throws:
        java.sql.SQLException - 见 DataSource.getConnection()
      • getActiveQuery

        @NotNull
        public @NotNull java.util.Map<java.util.UUID,​SQLQuery> getActiveQuery()
        Description copied from interface: SQLManager
        得到正使用的查询。
        Specified by:
        getActiveQuery in interface SQLManager
        Returns:
        查询列表
      • executeSQL

        public java.lang.Integer executeSQL​(java.lang.String sql)
        Description copied from interface: SQLManager
        执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法) 该方法使用 Statement 实现,请注意SQL注入风险!
        Specified by:
        executeSQL in interface SQLManager
        Parameters:
        sql - SQL语句内容
        Returns:
        更新的行数
        See Also:
        SQLUpdateAction
      • executeSQL

        public java.lang.Integer executeSQL​(java.lang.String sql,
                                            java.lang.Object[] params)
        Description copied from interface: SQLManager
        执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
        Specified by:
        executeSQL in interface SQLManager
        Parameters:
        sql - SQL语句内容
        params - SQL语句中 ? 的对应参数
        Returns:
        更新的行数
        See Also:
        PreparedSQLUpdateAction
      • executeSQLBatch

        public java.util.List<java.lang.Integer> executeSQLBatch​(java.lang.String sql,
                                                                 java.lang.Iterable<java.lang.Object[]> paramsBatch)
        Description copied from interface: SQLManager
        执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
        Specified by:
        executeSQLBatch in interface SQLManager
        Parameters:
        sql - SQL语句内容
        paramsBatch - SQL语句中对应?的参数组
        Returns:
        对应参数返回的行数
        See Also:
        PreparedSQLUpdateBatchAction
      • executeSQLBatch

        public java.util.List<java.lang.Integer> executeSQLBatch​(@NotNull
                                                                 @NotNull java.lang.String sql,
                                                                 java.lang.String... moreSQL)
        Description copied from interface: SQLManager
        执行多条不需要返回结果的SQL。 该方法使用 Statement 实现,请注意SQL注入风险!
        Specified by:
        executeSQLBatch in interface SQLManager
        Parameters:
        sql - SQL语句内容
        moreSQL - 更多SQL语句内容
        Returns:
        对应参数返回的行数
        See Also:
        SQLUpdateBatchAction
      • executeSQLBatch

        @Nullable
        public @Nullable java.util.List<java.lang.Integer> executeSQLBatch​(@NotNull
                                                                           @NotNull java.lang.Iterable<java.lang.String> sqlBatch)
        Description copied from interface: SQLManager
        执行多条不需要返回结果的SQL。
        Specified by:
        executeSQLBatch in interface SQLManager
        Parameters:
        sqlBatch - SQL语句内容
        Returns:
        对应参数返回的行数
      • fetchMetadata

        public <R> java.util.concurrent.CompletableFuture<R> fetchMetadata​(@NotNull
                                                                           @NotNull SQLBiFunction<java.sql.DatabaseMetaData,​java.sql.Connection,​R> reader)
        Description copied from interface: SQLManager
        获取并操作 DatabaseMetaData 以得到需要的数据库消息。
        Specified by:
        fetchMetadata in interface SQLManager
        Type Parameters:
        R - 最终结果的返回类型
        Parameters:
        reader - 操作与读取的方法
        Returns:
        最终结果,通过 CompletableFuture.get() 可阻塞并等待结果返回。
      • fetchMetadata

        public <R> java.util.concurrent.CompletableFuture<R> fetchMetadata​(@NotNull
                                                                           @NotNull SQLBiFunction<java.sql.DatabaseMetaData,​java.sql.Connection,​java.sql.ResultSet> supplier,
                                                                           @NotNull
                                                                           @NotNull SQLFunction<@NotNull java.sql.ResultSet,​R> reader)
        Description copied from interface: SQLManager
        获取并操作 DatabaseMetaData 提供的指定 ResultSet 以得到需要的数据库消息。
        该方法会自动关闭 ResultSet
        Specified by:
        fetchMetadata in interface SQLManager
        Type Parameters:
        R - 最终结果的返回类型
        Parameters:
        supplier - 操作 DatabaseMetaData 以提供信息所在的 ResultSet
        reader - 读取 ResultSet 中指定信息的方法
        Returns:
        最终结果,通过 CompletableFuture.get() 可阻塞并等待结果返回。