private方法改成protected,方便重载
This commit is contained in:
@@ -31,26 +31,26 @@ import org.redkale.util.*;
|
||||
@ResourceType(DataSource.class)
|
||||
public class DataJdbcSource extends AbstractService implements DataSource, Service, DataCacheListener, Function<Class, EntityInfo>, AutoCloseable, Resourcable {
|
||||
|
||||
private static final Flipper FLIPPER_ONE = new Flipper(1);
|
||||
protected static final Flipper FLIPPER_ONE = new Flipper(1);
|
||||
|
||||
final Logger logger = Logger.getLogger(DataJdbcSource.class.getSimpleName());
|
||||
protected final Logger logger = Logger.getLogger(DataJdbcSource.class.getSimpleName());
|
||||
|
||||
final AtomicBoolean debug = new AtomicBoolean(logger.isLoggable(Level.FINEST));
|
||||
protected final AtomicBoolean debug = new AtomicBoolean(logger.isLoggable(Level.FINEST));
|
||||
|
||||
final String name;
|
||||
protected final String name;
|
||||
|
||||
final URL conf;
|
||||
protected final URL conf;
|
||||
|
||||
final boolean cacheForbidden;
|
||||
protected final boolean cacheForbidden;
|
||||
|
||||
private final PoolJdbcSource readPool;
|
||||
protected final PoolJdbcSource readPool;
|
||||
|
||||
private final PoolJdbcSource writePool;
|
||||
protected final PoolJdbcSource writePool;
|
||||
|
||||
@Resource(name = "$")
|
||||
private DataCacheListener cacheListener;
|
||||
protected DataCacheListener cacheListener;
|
||||
|
||||
private final BiFunction<DataSource, Class, List> fullloader = (s, t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
protected final BiFunction<DataSource, Class, List> fullloader = (s, t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
|
||||
public DataJdbcSource(String unitName, Properties readprop, Properties writeprop) {
|
||||
this.name = unitName;
|
||||
@@ -71,15 +71,15 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
writePool.close();
|
||||
}
|
||||
|
||||
private Connection createReadSQLConnection() {
|
||||
protected Connection createReadSQLConnection() {
|
||||
return readPool.poll();
|
||||
}
|
||||
|
||||
private <T> Connection createWriteSQLConnection() {
|
||||
protected <T> Connection createWriteSQLConnection() {
|
||||
return writePool.poll();
|
||||
}
|
||||
|
||||
private void closeSQLConnection(final Connection sqlconn) {
|
||||
protected void closeSQLConnection(final Connection sqlconn) {
|
||||
if (sqlconn == null) return;
|
||||
try {
|
||||
sqlconn.close();
|
||||
@@ -93,7 +93,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return loadEntityInfo(t);
|
||||
}
|
||||
|
||||
private <T> EntityInfo<T> loadEntityInfo(Class<T> clazz) {
|
||||
protected <T> EntityInfo<T> loadEntityInfo(Class<T> clazz) {
|
||||
return EntityInfo.load(clazz, this.cacheForbidden, this.readPool.props, this, fullloader);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.runAsync(() -> insert(values), getExecutor());
|
||||
}
|
||||
|
||||
private <T> void insert(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
protected <T> void insert(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
if (values.length == 0) return;
|
||||
try {
|
||||
if (!info.isVirtualEntity()) {
|
||||
@@ -251,7 +251,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
}
|
||||
}
|
||||
|
||||
private <T> PreparedStatement createInsertPreparedStatement(final Connection conn, final String sql,
|
||||
protected <T> PreparedStatement createInsertPreparedStatement(final Connection conn, final String sql,
|
||||
final EntityInfo<T> info, T... values) throws SQLException {
|
||||
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
||||
final PreparedStatement prestmt = info.autoGenerated ? conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) : conn.prepareStatement(sql);
|
||||
@@ -358,7 +358,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> delete(clazz, ids), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int delete(final Connection conn, final EntityInfo<T> info, Serializable... keys) {
|
||||
protected <T> int delete(final Connection conn, final EntityInfo<T> info, Serializable... keys) {
|
||||
if (keys.length == 0) return -1;
|
||||
int c = -1;
|
||||
int c2 = 0;
|
||||
@@ -430,7 +430,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> delete(clazz, flipper, node), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int delete(final Connection conn, final EntityInfo<T> info, final Flipper flipper, final FilterNode node) {
|
||||
protected <T> int delete(final Connection conn, final EntityInfo<T> info, final Flipper flipper, final FilterNode node) {
|
||||
int c = -1;
|
||||
try {
|
||||
if (!info.isVirtualEntity()) {
|
||||
@@ -521,7 +521,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> update(values), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int update(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
protected <T> int update(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
try {
|
||||
Class clazz = info.getType();
|
||||
int c = -1;
|
||||
@@ -617,7 +617,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(clazz, id, column, value), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumn(Connection conn, final EntityInfo<T> info, Serializable id, String column, final Serializable value) {
|
||||
protected <T> int updateColumn(Connection conn, final EntityInfo<T> info, Serializable id, String column, final Serializable value) {
|
||||
try {
|
||||
int c = -1;
|
||||
if (!info.isVirtualEntity()) {
|
||||
@@ -684,7 +684,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(clazz, column, value, node), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumn(Connection conn, final EntityInfo<T> info, String column, final Serializable value, FilterNode node) {
|
||||
protected <T> int updateColumn(Connection conn, final EntityInfo<T> info, String column, final Serializable value, FilterNode node) {
|
||||
try {
|
||||
int c = -1;
|
||||
if (!info.isVirtualEntity()) {
|
||||
@@ -766,7 +766,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(clazz, id, values), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final Serializable id, final ColumnValue... values) {
|
||||
protected <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final Serializable id, final ColumnValue... values) {
|
||||
if (values == null || values.length < 1) return -1;
|
||||
try {
|
||||
StringBuilder setsql = new StringBuilder();
|
||||
@@ -882,7 +882,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(clazz, node, flipper, values), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
protected <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
if (values == null || values.length < 1) return -1;
|
||||
try {
|
||||
StringBuilder setsql = new StringBuilder();
|
||||
@@ -992,7 +992,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(bean, selects), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final SelectColumn selects) {
|
||||
protected <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final SelectColumn selects) {
|
||||
if (bean == null || selects == null) return -1;
|
||||
try {
|
||||
final Class<T> clazz = (Class<T>) bean.getClass();
|
||||
@@ -1068,7 +1068,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> updateColumn(bean, node, selects), getExecutor());
|
||||
}
|
||||
|
||||
private <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final FilterNode node, final SelectColumn selects) {
|
||||
protected <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final FilterNode node, final SelectColumn selects) {
|
||||
if (bean == null || node == null || selects == null) return -1;
|
||||
try {
|
||||
final Class<T> clazz = (Class<T>) bean.getClass();
|
||||
@@ -1877,7 +1877,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> queryColumnSheet(selectedColumn, clazz, flipper, node), getExecutor());
|
||||
}
|
||||
|
||||
private <T, V extends Serializable> Sheet<V> queryColumnSheet(final boolean needtotal, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
protected <T, V extends Serializable> Sheet<V> queryColumnSheet(final boolean needtotal, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
Sheet<T> sheet = querySheet(true, needtotal, clazz, SelectColumn.createIncludes(selectedColumn), flipper, node);
|
||||
final Sheet<V> rs = new Sheet<>();
|
||||
if (sheet.isEmpty()) return rs;
|
||||
@@ -2083,7 +2083,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return CompletableFuture.supplyAsync(() -> querySheet(clazz, selects, flipper, node), getExecutor());
|
||||
}
|
||||
|
||||
private <T> Sheet<T> querySheet(final boolean readcache, final boolean needtotal, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
protected <T> Sheet<T> querySheet(final boolean readcache, final boolean needtotal, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
final EntityCache<T> cache = info.getCache();
|
||||
if (readcache && cache != null && cache.isFullLoaded()) {
|
||||
@@ -2134,7 +2134,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
}
|
||||
}
|
||||
|
||||
private static StringBuilder multisplit(char ch1, char ch2, String split, StringBuilder sb, String str, int from) {
|
||||
protected static StringBuilder multisplit(char ch1, char ch2, String split, StringBuilder sb, String str, int from) {
|
||||
if (str == null) return sb;
|
||||
int pos1 = str.indexOf(ch1, from);
|
||||
if (pos1 < 0) return sb;
|
||||
@@ -2145,7 +2145,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, Servi
|
||||
return multisplit(ch1, ch2, split, sb, str, pos2 + 1);
|
||||
}
|
||||
|
||||
private int[] directExecute(final Connection conn, String... sqls) {
|
||||
protected int[] directExecute(final Connection conn, String... sqls) {
|
||||
if (sqls.length == 0) return new int[0];
|
||||
try {
|
||||
conn.setReadOnly(false);
|
||||
|
||||
Reference in New Issue
Block a user