Skip to content

Commit df8f566

Browse files
committed
CAY-2469 Allow validationQuery to be set in domain.xml
1 parent 399fc83 commit df8f566

File tree

4 files changed

+152
-1
lines changed

4 files changed

+152
-1
lines changed

cayenne-server/src/main/java/org/apache/cayenne/configuration/server/XMLPoolingDataSourceFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Except
7272
return DataSourceBuilder.url(descriptor.getDataSourceUrl()).driver(driver).userName(descriptor.getUserName())
7373
.password(descriptor.getPassword())
7474
.pool(descriptor.getMinConnections(), descriptor.getMaxConnections())
75+
.validationQuery(descriptor.getValidationQuery())
7576
.maxQueueWaitTime(maxQueueWaitTime).build();
7677
}
7778

cayenne-server/src/main/java/org/apache/cayenne/configuration/xml/DataSourceChildrenHandler.java

+5
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,10 @@ void configureConnectionPool(Attributes attributes) {
169169
throw new ConfigurationException("Non-numeric 'max' attribute '%s'", nfex, max);
170170
}
171171
}
172+
173+
String validationQuery = attributes.getValue("validationQuery");
174+
if (validationQuery != null) {
175+
dataSourceDescriptor.setValidationQuery(validationQuery);
176+
}
172177
}
173178
}

cayenne-server/src/main/java/org/apache/cayenne/conn/DataSourceInfo.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class DataSourceInfo implements Cloneable, Serializable, XMLSerializable
6060
protected String passwordSourceFilename = "";
6161
protected final String passwordSourceModel = "Not Applicable";
6262
protected String passwordSourceUrl = "";
63+
protected String validationQuery = null;
6364

6465
@Override
6566
public boolean equals(Object obj) {
@@ -130,6 +131,10 @@ public boolean equals(Object obj) {
130131
return false;
131132
}
132133

134+
if (!Util.nullSafeEquals(this.validationQuery, dsi.validationQuery)) {
135+
return false;
136+
}
137+
133138
return true;
134139
}
135140

@@ -139,7 +144,7 @@ public int hashCode() {
139144
dataSourceUrl, adapterClassName, minConnections,
140145
maxConnections, passwordEncoderClass, passwordEncoderKey,
141146
passwordLocation, passwordSourceFilename, passwordSourceModel,
142-
passwordSourceUrl);
147+
passwordSourceUrl, validationQuery);
143148
}
144149

145150
/**
@@ -155,6 +160,7 @@ public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) {
155160
encoder.start("connectionPool")
156161
.attribute("min", minConnections)
157162
.attribute("max", String.valueOf(maxConnections))
163+
.attribute("validationQuery", validationQuery)
158164
.end();
159165

160166
encoder.start("login").attribute("userName", userName);
@@ -219,6 +225,14 @@ public int getMaxConnections() {
219225
return maxConnections;
220226
}
221227

228+
public void setValidationQuery(String validationQuery) {
229+
this.validationQuery = validationQuery;
230+
}
231+
232+
public String getValidationQuery() {
233+
return validationQuery;
234+
}
235+
222236
public void setUserName(String userName) {
223237
this.userName = userName;
224238
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
20+
21+
<xs:schema targetNamespace="http://cayenne.apache.org/schema/10/domain"
22+
elementFormDefault="qualified" version="10"
23+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
24+
xmlns:cay="http://cayenne.apache.org/schema/10/domain">
25+
26+
<xs:element name="domain">
27+
<xs:complexType>
28+
<xs:sequence>
29+
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:property"/>
30+
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:map"/>
31+
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:node"/>
32+
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/>
33+
</xs:sequence>
34+
<xs:attribute name="project-version" use="required" type="xs:string"/>
35+
</xs:complexType>
36+
</xs:element>
37+
38+
<xs:element name="property">
39+
<xs:annotation>
40+
<xs:documentation>A generic property used by other elements.</xs:documentation>
41+
</xs:annotation>
42+
<xs:complexType>
43+
<xs:attribute name="name" use="required" type="xs:string"/>
44+
<xs:attribute name="value" use="required" type="xs:string"/>
45+
</xs:complexType>
46+
</xs:element>
47+
48+
<xs:element name="map">
49+
<xs:annotation>
50+
<xs:documentation>Link to an external file with data map.</xs:documentation>
51+
</xs:annotation>
52+
<xs:complexType>
53+
<xs:attribute name="name" use="required" type="xs:string"/>
54+
</xs:complexType>
55+
</xs:element>
56+
57+
<xs:element name="node">
58+
<xs:annotation>
59+
<xs:documentation>Data node description.</xs:documentation>
60+
</xs:annotation>
61+
<xs:complexType>
62+
<xs:sequence>
63+
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:map-ref"/>
64+
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:data-source"/>
65+
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/>
66+
</xs:sequence>
67+
<xs:attribute name="name" use="required" type="xs:string"/>
68+
<xs:attribute name="factory" use="required" type="xs:string"/>
69+
<xs:attribute name="adapter" type="xs:string"/>
70+
<xs:attribute name="schema-update-strategy" type="xs:string"/>
71+
<xs:attribute name="parameters" type="xs:string"/>
72+
</xs:complexType>
73+
</xs:element>
74+
75+
<xs:element name="map-ref">
76+
<xs:annotation>
77+
<xs:documentation>A reference to a map.</xs:documentation>
78+
</xs:annotation>
79+
<xs:complexType>
80+
<xs:attribute name="name" use="required" type="xs:string"/>
81+
</xs:complexType>
82+
</xs:element>
83+
84+
<xs:element name="data-source">
85+
<xs:annotation>
86+
<xs:documentation>Data source configuration.</xs:documentation>
87+
</xs:annotation>
88+
<xs:complexType>
89+
<xs:sequence>
90+
<xs:element minOccurs="0" maxOccurs="1" ref="cay:driver"/>
91+
<xs:element minOccurs="0" maxOccurs="1" ref="cay:url"/>
92+
<xs:element minOccurs="0" maxOccurs="1" ref="cay:connectionPool"/>
93+
<xs:element minOccurs="0" maxOccurs="1" ref="cay:login"/>
94+
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax"/>
95+
</xs:sequence>
96+
</xs:complexType>
97+
</xs:element>
98+
99+
<xs:element name="driver">
100+
<xs:complexType>
101+
<xs:attribute name="value" type="xs:string"/>
102+
</xs:complexType>
103+
</xs:element>
104+
105+
<xs:element name="url">
106+
<xs:complexType>
107+
<xs:attribute name="value" type="xs:string"/>
108+
</xs:complexType>
109+
</xs:element>
110+
111+
<xs:element name="connectionPool">
112+
<xs:complexType>
113+
<xs:attribute name="min" type="xs:int"/>
114+
<xs:attribute name="max" type="xs:int"/>
115+
<xs:attribute name="validationQuery" type="xs:string"/>
116+
</xs:complexType>
117+
</xs:element>
118+
119+
<xs:element name="login">
120+
<xs:complexType>
121+
<xs:attribute name="userName" type="xs:string"/>
122+
<xs:attribute name="password" type="xs:string"/>
123+
<xs:attribute name="passwordLocation" type="xs:string"/>
124+
<xs:attribute name="passwordSource" type="xs:string"/>
125+
<xs:attribute name="encoderClass" type="xs:string"/>
126+
<xs:attribute name="encoderKey" type="xs:string"/>
127+
<xs:attribute name="encoderSalt" type="xs:string"/>
128+
</xs:complexType>
129+
</xs:element>
130+
131+
</xs:schema>

0 commit comments

Comments
 (0)