修改SourceChangeable类接口
This commit is contained in:
@@ -1754,49 +1754,59 @@ public final class Application {
|
||||
|
||||
void updateSourceProperties(Properties sourceChangeCache) {
|
||||
if (sourceChangeCache == null || sourceChangeCache.isEmpty()) return;
|
||||
boolean same = true;
|
||||
for (Map.Entry<Object, Object> en : sourceChangeCache.entrySet()) {
|
||||
String key = en.getKey().toString();
|
||||
if (key.startsWith("redkale.datasource.") || key.startsWith("redkale.datasource[")
|
||||
|| key.startsWith("redkale.cachesource.") || key.startsWith("redkale.cachesource[")) {
|
||||
if (!Objects.equals(en.getValue(), sourceProperties.get(key))) {
|
||||
same = false;
|
||||
synchronized (sourceProperties) {
|
||||
boolean same = true;
|
||||
for (Map.Entry<Object, Object> en : sourceChangeCache.entrySet()) {
|
||||
String key = en.getKey().toString();
|
||||
if (key.startsWith("redkale.datasource.") || key.startsWith("redkale.datasource[")
|
||||
|| key.startsWith("redkale.cachesource.") || key.startsWith("redkale.cachesource[")) {
|
||||
if (!Objects.equals(en.getValue(), sourceProperties.get(key))) {
|
||||
same = false;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("source properties contains illegal key: " + key);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("source properties contains illegal key: " + key);
|
||||
}
|
||||
}
|
||||
if (same) return; //无内容改变
|
||||
AnyValue redNode = AnyValue.loadFromProperties(sourceChangeCache).getAnyValue("redkale");
|
||||
AnyValue cacheNode = redNode.getAnyValue("cachesource");
|
||||
if (cacheNode != null) {
|
||||
cacheNode.forEach(null, (name, conf) -> {
|
||||
CacheSource source = Utility.find(cacheSources, s -> Objects.equals(s.resourceName(), name));
|
||||
if (source == null) return;
|
||||
List<ResourceEvent> events = new ArrayList<>();
|
||||
AnyValue old = findSourceConfig(name, "cachesource");
|
||||
conf.forEach((k, v) -> {
|
||||
events.add(ResourceEvent.create(k, v, old == null ? null : old.getValue(k)));
|
||||
if (old != null) ((DefaultAnyValue) old).setValue(k, v);
|
||||
if (same) return; //无内容改变
|
||||
AnyValue redNode = AnyValue.loadFromProperties(sourceChangeCache).getAnyValue("redkale");
|
||||
AnyValue cacheNode = redNode.getAnyValue("cachesource");
|
||||
if (cacheNode != null) {
|
||||
cacheNode.forEach(null, (name, conf) -> {
|
||||
CacheSource source = Utility.find(cacheSources, s -> Objects.equals(s.resourceName(), name));
|
||||
if (source == null) return;
|
||||
List<ResourceEvent> events = new ArrayList<>();
|
||||
AnyValue old = findSourceConfig(name, "cachesource");
|
||||
conf.forEach((k, v) -> {
|
||||
if (old != null) {
|
||||
events.add(ResourceEvent.create(k, v, old.getValue(k)));
|
||||
((DefaultAnyValue) old).setValue(k, v);
|
||||
} else {
|
||||
events.add(ResourceEvent.create(k, v, null));
|
||||
}
|
||||
});
|
||||
((AbstractCacheSource) source).onChange(old == null ? conf : old, events.toArray(new ResourceEvent[events.size()]));
|
||||
});
|
||||
((AbstractCacheSource) source).onChange(events.toArray(new ResourceEvent[events.size()]));
|
||||
});
|
||||
}
|
||||
AnyValue sourceNode = redNode.getAnyValue("datasource");
|
||||
if (sourceNode != null) {
|
||||
sourceNode.forEach(null, (name, conf) -> {
|
||||
DataSource source = Utility.find(dataSources, s -> Objects.equals(s.resourceName(), name));
|
||||
if (source == null) return;
|
||||
List<ResourceEvent> events = new ArrayList<>();
|
||||
AnyValue old = findSourceConfig(name, "datasource");
|
||||
conf.forEach((k, v) -> {
|
||||
events.add(ResourceEvent.create(k, v, old == null ? null : old.getValue(k)));
|
||||
if (old != null) ((DefaultAnyValue) old).setValue(k, v);
|
||||
}
|
||||
AnyValue sourceNode = redNode.getAnyValue("datasource");
|
||||
if (sourceNode != null) {
|
||||
sourceNode.forEach(null, (name, conf) -> {
|
||||
DataSource source = Utility.find(dataSources, s -> Objects.equals(s.resourceName(), name));
|
||||
if (source == null) return;
|
||||
List<ResourceEvent> events = new ArrayList<>();
|
||||
AnyValue old = findSourceConfig(name, "datasource");
|
||||
conf.forEach((k, v) -> {
|
||||
if (old != null) {
|
||||
events.add(ResourceEvent.create(k, v, old.getValue(k)));
|
||||
((DefaultAnyValue) old).setValue(k, v);
|
||||
} else {
|
||||
events.add(ResourceEvent.create(k, v, null));
|
||||
}
|
||||
});
|
||||
((AbstractDataSource) source).onChange(old == null ? conf : old, events.toArray(new ResourceEvent[events.size()]));
|
||||
});
|
||||
((AbstractDataSource) source).onChange(events.toArray(new ResourceEvent[events.size()]));
|
||||
});
|
||||
}
|
||||
sourceProperties.putAll(sourceChangeCache);
|
||||
}
|
||||
sourceProperties.putAll(sourceChangeCache);
|
||||
}
|
||||
|
||||
private static String generateHelp() {
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(ResourceEvent[] events) {
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events) {
|
||||
}
|
||||
|
||||
public static boolean acceptsConf(AnyValue config) {
|
||||
|
||||
@@ -49,8 +49,8 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(ResourceEvent[] events) {
|
||||
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events) {
|
||||
//@TODO 待实现
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1141,7 +1141,7 @@ public class DataJdbcSource extends DataSqlSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(ResourceEvent[] events) {
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events) {
|
||||
for (ResourceEvent event : events) {
|
||||
if (event.name().equals(DATA_SOURCE_CONNECTTIMEOUT_SECONDS) || event.name().endsWith("." + DATA_SOURCE_CONNECTTIMEOUT_SECONDS)) {
|
||||
this.connectTimeoutSeconds = Integer.decode(event.newValue().toString());
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DataMemorySource extends DataSqlSource implements SearchSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(ResourceEvent[] events) {
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events) {
|
||||
}
|
||||
|
||||
public static boolean acceptsConf(AnyValue config) {
|
||||
|
||||
@@ -119,6 +119,11 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
|
||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readConfProps.getProperty(DATA_SOURCE_CACHEMODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events) {
|
||||
//@TODO 待实现
|
||||
}
|
||||
|
||||
//解密可能存在的加密字段, 可重载
|
||||
protected void decryptProperties(Properties props) {
|
||||
|
||||
@@ -150,10 +155,6 @@ public abstract class DataSqlSource extends AbstractDataSource implements Functi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(ResourceEvent[] events) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (readConfProps == null) return getClass().getSimpleName() + "{}"; //compileMode模式下会为null
|
||||
|
||||
@@ -1400,9 +1400,18 @@ public final class EntityInfo<T> {
|
||||
return DataResultSet.getRowColumnValue(this, attr, index, columnLabel);
|
||||
}
|
||||
|
||||
//判断当前行值是否为null
|
||||
/**
|
||||
* 判断当前行值是否为null
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean wasNull();
|
||||
|
||||
/**
|
||||
* 获取字段名集合,尽量不要多次调用
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<String> getColumnLabels();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
package org.redkale.source;
|
||||
|
||||
import org.redkale.util.ResourceEvent;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 资源变更回调接口
|
||||
@@ -17,6 +17,6 @@ import org.redkale.util.ResourceEvent;
|
||||
*/
|
||||
public interface SourceChangeable {
|
||||
|
||||
public void onChange(ResourceEvent[] events);
|
||||
public void onChange(AnyValue newConf, ResourceEvent[] events);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user