This commit is contained in:
@@ -207,7 +207,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Integer> clearTableDB(EntityInfo<T> info, String sql) {
|
protected <T> CompletableFuture<Integer> clearTableDB(EntityInfo<T> info, final String table, String sql) {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = writePool.poll();
|
conn = writePool.poll();
|
||||||
@@ -228,7 +228,7 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Integer> dropTableDB(EntityInfo<T> info, String sql) {
|
protected <T> CompletableFuture<Integer> dropTableDB(EntityInfo<T> info, final String table, String sql) {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = writePool.poll();
|
conn = writePool.poll();
|
||||||
@@ -237,6 +237,10 @@ public class DataJdbcSource extends DataSqlSource<Connection> {
|
|||||||
final Statement stmt = conn.createStatement();
|
final Statement stmt = conn.createStatement();
|
||||||
int c = stmt.executeUpdate(sql);
|
int c = stmt.executeUpdate(sql);
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
if (info.getTableStrategy() != null) {
|
||||||
|
String tablekey = table.indexOf('.') > 0 ? table : (conn.getCatalog() + '.' + table);
|
||||||
|
info.removeDisTable(tablekey);
|
||||||
|
}
|
||||||
return CompletableFuture.completedFuture(c);
|
return CompletableFuture.completedFuture(c);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (info.isTableNotExist(e)) return CompletableFuture.completedFuture(-1);
|
if (info.isTableNotExist(e)) return CompletableFuture.completedFuture(-1);
|
||||||
|
|||||||
@@ -94,12 +94,12 @@ public class DataMemorySource extends DataSqlSource<Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Integer> clearTableDB(EntityInfo<T> info, String sql) {
|
protected <T> CompletableFuture<Integer> clearTableDB(EntityInfo<T> info, final String table, String sql) {
|
||||||
return CompletableFuture.completedFuture(0);
|
return CompletableFuture.completedFuture(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Integer> dropTableDB(EntityInfo<T> info, String sql) {
|
protected <T> CompletableFuture<Integer> dropTableDB(EntityInfo<T> info, final String table, String sql) {
|
||||||
return CompletableFuture.completedFuture(0);
|
return CompletableFuture.completedFuture(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,10 +137,10 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
protected abstract <T> CompletableFuture<Integer> deleteDB(final EntityInfo<T> info, Flipper flipper, final String sql);
|
protected abstract <T> CompletableFuture<Integer> deleteDB(final EntityInfo<T> info, Flipper flipper, final String sql);
|
||||||
|
|
||||||
//清空表
|
//清空表
|
||||||
protected abstract <T> CompletableFuture<Integer> clearTableDB(final EntityInfo<T> info, final String sql);
|
protected abstract <T> CompletableFuture<Integer> clearTableDB(final EntityInfo<T> info, final String table, final String sql);
|
||||||
|
|
||||||
//删除表
|
//删除表
|
||||||
protected abstract <T> CompletableFuture<Integer> dropTableDB(final EntityInfo<T> info, final String sql);
|
protected abstract <T> CompletableFuture<Integer> dropTableDB(final EntityInfo<T> info, final String table, final String sql);
|
||||||
|
|
||||||
//更新纪录
|
//更新纪录
|
||||||
protected abstract <T> CompletableFuture<Integer> updateDB(final EntityInfo<T> info, T... entitys);
|
protected abstract <T> CompletableFuture<Integer> updateDB(final EntityInfo<T> info, T... entitys);
|
||||||
@@ -608,9 +608,10 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected <T> CompletableFuture<Integer> clearTableCompose(final EntityInfo<T> info, final FilterNode node) {
|
protected <T> CompletableFuture<Integer> clearTableCompose(final EntityInfo<T> info, final FilterNode node) {
|
||||||
String sql = "TRUNCATE TABLE " + info.getTable(node);
|
final String table = info.getTable(node);
|
||||||
|
String sql = "TRUNCATE TABLE " + table;
|
||||||
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " clearTable sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " clearTable sql=" + sql);
|
||||||
return clearTableDB(info, sql);
|
return clearTableDB(info, table, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------- dropTableCompose -----------------------------
|
//----------------------------- dropTableCompose -----------------------------
|
||||||
@@ -660,9 +661,10 @@ public abstract class DataSqlSource<DBChannel> extends AbstractService implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected <T> CompletableFuture<Integer> dropTableCompose(final EntityInfo<T> info, final FilterNode node) {
|
protected <T> CompletableFuture<Integer> dropTableCompose(final EntityInfo<T> info, final FilterNode node) {
|
||||||
String sql = "DROP TABLE " + info.getTable(node);
|
final String table = info.getTable(node);
|
||||||
|
String sql = "DROP TABLE " + table;
|
||||||
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " dropTable sql=" + sql);
|
if (info.isLoggable(logger, Level.FINEST, sql)) logger.finest(info.getType().getSimpleName() + " dropTable sql=" + sql);
|
||||||
return dropTableDB(info, sql);
|
return dropTableDB(info, table, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> int clearTableCache(final EntityInfo<T> info, FilterNode node) {
|
protected <T> int clearTableCache(final EntityInfo<T> info, FilterNode node) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.io.Serializable;
|
|||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@@ -95,7 +95,7 @@ public final class EntityInfo<T> {
|
|||||||
private final String tablecopySQL;
|
private final String tablecopySQL;
|
||||||
|
|
||||||
//用于存在database.table_20160202类似这种分布式表
|
//用于存在database.table_20160202类似这种分布式表
|
||||||
private final Set<String> tables = new HashSet<>();
|
private final Set<String> tables = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
//分表 策略
|
//分表 策略
|
||||||
private final DistributeTableStrategy<T> tableStrategy;
|
private final DistributeTableStrategy<T> tableStrategy;
|
||||||
@@ -522,6 +522,10 @@ public final class EntityInfo<T> {
|
|||||||
tables.add(tablekey);
|
tables.add(tablekey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean removeDisTable(String tablekey) {
|
||||||
|
return tables.remove(tablekey);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTableNotExistSqlStates2() {
|
public String getTableNotExistSqlStates2() {
|
||||||
return tablenotexistSqlstates;
|
return tablenotexistSqlstates;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user