修改SourceChangeable类接口

This commit is contained in:
Redkale
2022-12-05 20:04:10 +08:00
parent 709d320a5a
commit e01cb1b94d
7 changed files with 70 additions and 50 deletions

View File

@@ -1754,6 +1754,7 @@ public final class Application {
void updateSourceProperties(Properties sourceChangeCache) {
if (sourceChangeCache == null || sourceChangeCache.isEmpty()) return;
synchronized (sourceProperties) {
boolean same = true;
for (Map.Entry<Object, Object> en : sourceChangeCache.entrySet()) {
String key = en.getKey().toString();
@@ -1776,10 +1777,14 @@ public final class Application {
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 (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(events.toArray(new ResourceEvent[events.size()]));
((AbstractCacheSource) source).onChange(old == null ? conf : old, events.toArray(new ResourceEvent[events.size()]));
});
}
AnyValue sourceNode = redNode.getAnyValue("datasource");
@@ -1790,14 +1795,19 @@ public final class Application {
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);
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(events.toArray(new ResourceEvent[events.size()]));
((AbstractDataSource) source).onChange(old == null ? conf : old, events.toArray(new ResourceEvent[events.size()]));
});
}
sourceProperties.putAll(sourceChangeCache);
}
}
private static String generateHelp() {
return ""

View File

@@ -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) {

View File

@@ -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());

View File

@@ -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) {

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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);
}