Browse Source

增加jdbc接入接出的校验配置项

zhourui 5 years ago
parent
commit
d7722b1f6c

+ 18 - 0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSource.java

@@ -31,6 +31,8 @@ public class ExternalDataSource extends ConfigObject {
 		this.statFilter = DEFAULT_STATFILTER;
 		this.slowSqlMillis = DEFAULT_SLOWSQLMILLIS;
 		this.transactionIsolation = DEFAULT_TRANSACTIONISOLATION;
+		this.testConnectionOnCheckin = DEFAULT_TESTCONNECTIONONCHECKIN;
+		this.testConnectionOnCheckout = DEFAULT_TESTCONNECTIONONCHECKOUT;
 	}
 
 	public static ExternalDataSource defaultInstance() {
@@ -68,6 +70,10 @@ public class ExternalDataSource extends ConfigObject {
 	private String logLevel = DEFAULT_LOGLEVEL;
 	@FieldDescribe("事务隔离级别:default,none,read-committed,read-uncommitted,repeatable-read,serializable.默认使用default(数据库设置的事务级别).")
 	private String transactionIsolation;
+	@FieldDescribe("测试入池连接.")
+	private Boolean testConnectionOnCheckin;
+	@FieldDescribe("测试出池连接.")
+	private Boolean testConnectionOnCheckout;
 
 	public static final Integer DEFAULT_MAXTOTAL = 50;
 
@@ -83,6 +89,18 @@ public class ExternalDataSource extends ConfigObject {
 
 	public static final String DEFAULT_TRANSACTIONISOLATION = "default";
 
+	public static final Boolean DEFAULT_TESTCONNECTIONONCHECKIN = true;
+
+	public static final Boolean DEFAULT_TESTCONNECTIONONCHECKOUT = true;
+
+	public Boolean getTestConnectionOnCheckin() {
+		return this.testConnectionOnCheckin == null ? DEFAULT_TESTCONNECTIONONCHECKIN : this.testConnectionOnCheckin;
+	}
+
+	public Boolean getTestConnectionOnCheckout() {
+		return this.testConnectionOnCheckout == null ? DEFAULT_TESTCONNECTIONONCHECKOUT : this.testConnectionOnCheckout;
+	}
+
 	public String getTransactionIsolation() {
 		return StringUtils.isEmpty(this.transactionIsolation) ? DEFAULT_TRANSACTIONISOLATION
 				: this.transactionIsolation;

+ 14 - 0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalDataSources.java

@@ -124,4 +124,18 @@ public class ExternalDataSources extends CopyOnWriteArrayList<ExternalDataSource
 		return null;
 	}
 
+	public Boolean getTestConnectionOnCheckin() {
+		for (ExternalDataSource o : this) {
+			return o.getTestConnectionOnCheckin();
+		}
+		return null;
+	}
+
+	public Boolean getTestConnectionOnCheckout() {
+		for (ExternalDataSource o : this) {
+			return o.getTestConnectionOnCheckout();
+		}
+		return null;
+	}
+
 }

+ 1 - 1
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/ResponseFactory.java

@@ -128,7 +128,7 @@ public class ResponseFactory {
 				Integer maxAge = maxAgeDefault(result.getData());
 				if (null != maxAge) {
 					CacheControl cacheControl = new CacheControl();
-					cacheControl.setMaxAge(3600 * 4);
+					cacheControl.setMaxAge(maxAge);
 					return Response.ok(result.toJson()).cacheControl(cacheControl).build();
 				} else {
 					EntityTag tag = new EntityTag(etagDefault(result.getData()));

+ 2 - 2
o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java

@@ -149,8 +149,8 @@ public class ResourceFactory {
 			dataSource.setMaxPoolSize(ds.getMaxTotal());
 			dataSource.setMinPoolSize(ds.getMaxIdle());
 			// 增加校验
-			dataSource.setTestConnectionOnCheckin(true);
-			dataSource.setTestConnectionOnCheckout(true);
+			dataSource.setTestConnectionOnCheckin(ds.getTestConnectionOnCheckin());
+			dataSource.setTestConnectionOnCheckout(ds.getTestConnectionOnCheckout());
 			dataSource.setAcquireIncrement(2);
 			if (BooleanUtils.isTrue(ds.getStatEnable())) {
 				dataSource.setFilters(ds.getStatFilter());

+ 1 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/form/V2Get.java

@@ -103,6 +103,7 @@ class V2Get extends BaseAction {
 		});
 		wo.setRelatedFormMap(_relatedForm.get());
 		wo.setRelatedScriptMap(_relatedScript.get());
+		wo.setMaxAge(3600 * 24);
 		return wo;
 	}
 

+ 1 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/form/V2GetMobile.java

@@ -103,6 +103,7 @@ class V2GetMobile extends BaseAction {
 		});
 		wo.setRelatedFormMap(_relatedForm.get());
 		wo.setRelatedScriptMap(_relatedScript.get());
+		wo.setMaxAge(3600 * 24);
 		return wo;
 	}