DataSqlSource.directQuery接口变动
This commit is contained in:
@@ -11,7 +11,7 @@ import java.sql.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.redkale.service.Local;
|
import org.redkale.service.Local;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
@@ -589,12 +589,15 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
* 直接本地执行SQL语句进行查询,远程模式不可用 <br>
|
* 直接本地执行SQL语句进行查询,远程模式不可用 <br>
|
||||||
* 通常用于复杂的关联查询 <br>
|
* 通常用于复杂的关联查询 <br>
|
||||||
*
|
*
|
||||||
|
* @param <V> 泛型
|
||||||
* @param sql SQL语句
|
* @param sql SQL语句
|
||||||
* @param consumer 回调函数
|
* @param handler 回调函数
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Local
|
@Local
|
||||||
@Override
|
@Override
|
||||||
public void directQuery(String sql, Consumer<ResultSet> consumer) {
|
public <V> V directQuery(String sql, Function<ResultSet, V> handler) {
|
||||||
final Connection conn = readPool.poll();
|
final Connection conn = readPool.poll();
|
||||||
try {
|
try {
|
||||||
if (logger.isLoggable(Level.FINEST)) logger.finest("direct query sql=" + sql);
|
if (logger.isLoggable(Level.FINEST)) logger.finest("direct query sql=" + sql);
|
||||||
@@ -602,9 +605,10 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
final Statement statement = conn.createStatement();
|
final Statement statement = conn.createStatement();
|
||||||
//final PreparedStatement statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
//final PreparedStatement statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||||
final ResultSet set = statement.executeQuery(sql);// ps.executeQuery();
|
final ResultSet set = statement.executeQuery(sql);// ps.executeQuery();
|
||||||
consumer.accept(set);
|
V rs = handler.apply(set);
|
||||||
set.close();
|
set.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
|
return rs;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.net.URL;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.*;
|
||||||
import org.redkale.service.Local;
|
import org.redkale.service.Local;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class DataMemorySource extends DataSqlSource<Void> {
|
|||||||
|
|
||||||
@Local
|
@Local
|
||||||
@Override
|
@Override
|
||||||
public void directQuery(String sql, Consumer<ResultSet> consumer) {
|
public <V> V directQuery(String sql, Function<ResultSet, V> handler) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
public abstract int[] directExecute(String... sqls);
|
public abstract int[] directExecute(String... sqls);
|
||||||
|
|
||||||
@Local
|
@Local
|
||||||
public abstract void directQuery(String sql, Consumer<ResultSet> consumer);
|
public abstract <V> V directQuery(String sql, Function<ResultSet, V> handler);
|
||||||
|
|
||||||
//是否异步, 为true则只能调用pollAsync方法,为false则只能调用poll方法
|
//是否异步, 为true则只能调用pollAsync方法,为false则只能调用poll方法
|
||||||
protected abstract boolean isAsync();
|
protected abstract boolean isAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user