Skip to content

CAY-2469 Allow validationQuery to be set in domain.xml #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changes/New Features:

CAY-2446 Run Disjoint By Id queries outside of synchronized block
CAY-2447 Crypto support for LocalDateTime
CAY-2469 Allow maxQueueWaitTime and validationQuery to be set in XML project
CAY-2471 Support multiple XML project versions

Bug Fixes:
Expand Down Expand Up @@ -549,4 +550,4 @@ CAY-1804 Serialisation of long[] type was not working correctly.
CAY-1806 Error importing eomodel
CAY-1817 NPE during Validate Project
CAY-1827 EhCache region corresponding to a cache group loses its settings after 'removeGroup'
CAY-1832 Exception when modifying objects in postLoad callback
CAY-1832 Exception when modifying objects in postLoad callback
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.cayenne.project.ProjectModule;
import org.apache.cayenne.project.upgrade.UpgradeService;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V10;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V11;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V7;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V8;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V9;
Expand All @@ -49,6 +50,7 @@ public void configure(Binder binder) {
.add(UpgradeHandler_V7.class)
.add(UpgradeHandler_V8.class)
.add(UpgradeHandler_V9.class)
.add(UpgradeHandler_V10.class);
.add(UpgradeHandler_V10.class)
.add(UpgradeHandler_V11.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.cayenne.project.upgrade.UpgradeService;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V10;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V11;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V7;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V8;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V9;
Expand All @@ -59,7 +60,8 @@ public void configure(Binder binder) {
.add(UpgradeHandler_V7.class)
.add(UpgradeHandler_V8.class)
.add(UpgradeHandler_V9.class)
.add(UpgradeHandler_V10.class);
.add(UpgradeHandler_V10.class)
.add(UpgradeHandler_V11.class);

binder.bind(ProjectSaver.class).toInstance(mock(ProjectSaver.class));
binder.bind(DataChannelDescriptorLoader.class).toInstance(mock(DataChannelDescriptorLoader.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testUpgradeFullProjectDom() throws Exception {
Document domainDocument = documentProvider.getDocument(resourceUrl);

assertNotNull(domainDocument);
assertEquals("10", domainDocument.getDocumentElement().getAttribute("project-version"));
assertEquals("11", domainDocument.getDocumentElement().getAttribute("project-version"));

URL dataMapUrl = getClass().getResource("test-map-v6.map.xml");
Document dataMapDocument = documentProvider.getDocument(dataMapUrl);
Expand Down Expand Up @@ -87,4 +87,4 @@ public void testUpgradeStandAloneDataMapDom() throws Exception {
private Injector getInjector() {
return DIBootstrap.createInjector(new CompatibilityTestModule());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.cayenne.project.upgrade.UpgradeService;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V10;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V11;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V7;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V8;
import org.apache.cayenne.project.upgrade.handlers.UpgradeHandler_V9;
Expand Down Expand Up @@ -66,7 +67,8 @@ public void configure(Binder binder) {
.add(UpgradeHandler_V7.class)
.add(UpgradeHandler_V8.class)
.add(UpgradeHandler_V9.class)
.add(UpgradeHandler_V10.class);
.add(UpgradeHandler_V10.class)
.add(UpgradeHandler_V11.class);

contributeExtensions(binder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.apache.cayenne.project;

import org.apache.cayenne.CayenneRuntimeException;

/**
* Encapsulates compatible schema versions.
*/
public enum ProjectVersion {

VERSION_9(null,"9"),
VERSION_10("10","10"),
VERSION_11("11","10");

public final String domainSchemaVersion;
public final String modelMapSchemaVersion;

ProjectVersion(String domainSchemaVersion, String modelMapSchemaVersion) {
this.domainSchemaVersion = domainSchemaVersion;
this.modelMapSchemaVersion = modelMapSchemaVersion;
}

public ProjectVersion getProjectVersion(String version) {
switch (version) {
case "9":
return VERSION_9;
case "10":
return VERSION_10;
case "11":
return VERSION_11;
default:
throw new CayenneRuntimeException("Invalid project version: " + version);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ public class DefaultUpgradeService implements UpgradeService {

private static final Logger logger = LoggerFactory.getLogger(DefaultUpgradeService.class);

public static final String UNKNOWN_VERSION = "0";
public static final String MIN_SUPPORTED_VERSION = "6";
private static final String UNKNOWN_VERSION = "0";
private static final String MIN_INTERMEDIATE_SUPPORTED_VERSION = "6";
private static final String MIN_SUPPORTED_VERSION = "10";
private static final String MAX_SUPPORTED_VERSION = "11";

TreeMap<String, UpgradeHandler> handlers = new TreeMap<>(VersionComparator.INSTANCE);

Expand All @@ -110,28 +112,26 @@ public UpgradeMetaData getUpgradeType(Resource resource) {

String version = loadProjectVersion(resource);
metaData.setProjectVersion(version);
metaData.setSupportedVersion(String.valueOf(Project.VERSION));

int c1 = VersionComparator.INSTANCE.compare(version, MIN_SUPPORTED_VERSION);
int c1 = VersionComparator.INSTANCE.compare(version, MIN_INTERMEDIATE_SUPPORTED_VERSION);
if (c1 < 0) {
metaData.setIntermediateUpgradeVersion(MIN_SUPPORTED_VERSION);
metaData.setUpgradeType(UpgradeType.INTERMEDIATE_UPGRADE_NEEDED);
return metaData;
}

int c2 = VersionComparator.INSTANCE.compare(String.valueOf(Project.VERSION), version);
if (c2 < 0) {
if (VersionComparator.INSTANCE.compare(version, MIN_SUPPORTED_VERSION) < 0) {
metaData.setUpgradeType(UpgradeType.UPGRADE_NEEDED);
} else if (VersionComparator.INSTANCE.compare(version, MAX_SUPPORTED_VERSION) > 0) {
metaData.setUpgradeType(UpgradeType.DOWNGRADE_NEEDED);
} else if (c2 == 0) {
metaData.setUpgradeType(UpgradeType.UPGRADE_NOT_NEEDED);
} else {
metaData.setUpgradeType(UpgradeType.UPGRADE_NEEDED);
metaData.setUpgradeType(UpgradeType.UPGRADE_NOT_NEEDED);
}

return metaData;
}

protected List<UpgradeHandler> getHandlersForVersion(String version) {
boolean found = MIN_SUPPORTED_VERSION.equals(version);
boolean found = MIN_INTERMEDIATE_SUPPORTED_VERSION.equals(version);
List<UpgradeHandler> handlerList = new ArrayList<>();

for(Map.Entry<String, UpgradeHandler> entry : handlers.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class UpgradeMetaData {

protected UpgradeType upgradeType;
protected String projectVersion;
protected String supportedVersion;
protected String intermediateUpgradeVersion;

public UpgradeType getUpgradeType() {
return upgradeType;
Expand All @@ -47,20 +45,4 @@ public void setProjectVersion(String projectVersion) {
this.projectVersion = projectVersion;
}

public String getSupportedVersion() {
return supportedVersion;
}

public void setSupportedVersion(String supportedVersion) {
this.supportedVersion = supportedVersion;
}

public String getIntermediateUpgradeVersion() {
return intermediateUpgradeVersion;
}

public void setIntermediateUpgradeVersion(String intermediateUpgradeVersion) {
this.intermediateUpgradeVersion = intermediateUpgradeVersion;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
****************************************************************/

package org.apache.cayenne.project.upgrade.handlers;

import org.apache.cayenne.configuration.DataChannelDescriptor;
import org.apache.cayenne.project.upgrade.UpgradeUnit;
import org.w3c.dom.Element;

/**
* Upgrade handler for the project version "10" introduced by 4.1.M1 release.
* Changes highlight:
* - strict schema for domain (e.g. main project document)
* - new schema for data map allowing usage of additional elements (e.g. XML extensions)
*
* @since 4.1
*/
public class UpgradeHandler_V11 implements UpgradeHandler {

@Override
public String getVersion() {
return "11";
}

@Override
public void processProjectDom(UpgradeUnit upgradeUnit) {
Element domain = upgradeUnit.getDocument().getDocumentElement();
// introduce xml namespace and schema for domain
domain.setAttribute("xmlns","http://cayenne.apache.org/schema/11/domain");
domain.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
domain.setAttribute("xsi:schemaLocation", "http://cayenne.apache.org/schema/11/domain " +
"https://cayenne.apache.org/schema/11/domain.xsd");
// update version
domain.setAttribute("project-version", getVersion());
}

@Override
public void processDataMapDom(UpgradeUnit upgradeUnit) {
// noop
}

@Override
public void processModel(DataChannelDescriptor dataChannelDescriptor) {
// noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ public void getUpgradeType() throws Exception {
metaData = upgradeService.getUpgradeType(getResourceForVersion("6"));
assertEquals(UpgradeType.UPGRADE_NEEDED, metaData.getUpgradeType());

metaData = upgradeService.getUpgradeType(getResourceForVersion("9"));
assertEquals(UpgradeType.UPGRADE_NEEDED, metaData.getUpgradeType());

metaData = upgradeService.getUpgradeType(getResourceForVersion("10"));
assertEquals(UpgradeType.UPGRADE_NOT_NEEDED, metaData.getUpgradeType());

metaData = upgradeService.getUpgradeType(getResourceForVersion("11"));
assertEquals(UpgradeType.UPGRADE_NOT_NEEDED, metaData.getUpgradeType());

metaData = upgradeService.getUpgradeType(getResourceForVersion("12"));
assertEquals(UpgradeType.DOWNGRADE_NEEDED, metaData.getUpgradeType());
}

Expand Down Expand Up @@ -160,4 +166,4 @@ private Resource getResourceForVersion(String version) {
return new URLResource(getClass().getResource("handlers/cayenne-project-v"+version+".xml"));
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Fake version to test DefaultUpgradeService -->
<domain project-version="12"/>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.List;
import java.util.Map;

import static org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader.DEFAULT_PROJECT_VERSION;

/**
* A descriptor of a DataChannel normally loaded from XML configuration.
*
Expand All @@ -43,8 +45,8 @@ public class DataChannelDescriptor implements ConfigurationNode, Serializable, X
/**
* The namespace in which the data map XML file will be created.
*/
public static final String SCHEMA_XSD = "http://cayenne.apache.org/schema/10/domain";
public static final String SCHEMA_XSD_LOCATION = "https://cayenne.apache.org/schema/10/domain.xsd";
private String schemaXsd;
private String schemaXsdLocation;

protected String name;
protected Map<String, String> properties;
Expand All @@ -57,15 +59,16 @@ public DataChannelDescriptor() {
properties = new HashMap<>();
dataMaps = new ArrayList<>(5);
nodeDescriptors = new ArrayList<>(3);
setProjectVersion(DEFAULT_PROJECT_VERSION);
}

@Override
public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) {

encoder.start("domain")
.attribute("xmlns", SCHEMA_XSD)
.attribute("xmlns", schemaXsd)
.attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", true)
.attribute("xsi:schemaLocation", SCHEMA_XSD + " " + SCHEMA_XSD_LOCATION, true)
.attribute("xsi:schemaLocation", schemaXsd + " " + schemaXsdLocation, true)
.projectVersion();

if (!properties.isEmpty()) {
Expand Down Expand Up @@ -158,4 +161,13 @@ public String getDefaultNodeName() {
public void setDefaultNodeName(String defaultDataNodeName) {
this.defaultNodeName = defaultDataNodeName;
}

public String getSchemaXsd() {
return schemaXsd;
}

public void setProjectVersion(String projectVersion) {
this.schemaXsd = "http://cayenne.apache.org/schema/" + projectVersion + "/domain";
this.schemaXsdLocation = "https://cayenne.apache.org/schema/" + projectVersion + "/domain.xsd";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Except
throw new ConfigurationException(message);
}

long maxQueueWaitTime = properties.getLong(Constants.JDBC_MAX_QUEUE_WAIT_TIME,
UnmanagedPoolingDataSource.MAX_QUEUE_WAIT_DEFAULT);

Driver driver = objectFactory.newInstance(Driver.class, descriptor.getJdbcDriver());

return DataSourceBuilder.url(descriptor.getDataSourceUrl()).driver(driver).userName(descriptor.getUserName())
.password(descriptor.getPassword())
.pool(descriptor.getMinConnections(), descriptor.getMaxConnections())
.maxQueueWaitTime(maxQueueWaitTime).build();
.maxQueueWaitTime(descriptor.getMaxQueueWaitTime())
.validationQuery(descriptor.getValidationQuery())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ final class DataChannelHandler extends VersionAwareHandler {
super(loaderContext, DOMAIN_TAG);
this.xmlDataChannelDescriptorLoader = xmlDataChannelDescriptorLoader;
this.descriptor = dataChannelDescriptor;
setTargetNamespace(DataChannelDescriptor.SCHEMA_XSD);
}

@Override
protected ContentHandler createChildTagHandler(String namespaceURI, String localName,
String name, Attributes attributes) {

descriptor.setProjectVersion(attributes.getValue("project-version"));
setTargetNamespace(descriptor.getSchemaXsd());

if (localName.equals(DOMAIN_TAG)) {
return new DataChannelChildrenHandler(xmlDataChannelDescriptorLoader, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public DataMapHandler(NamespaceAwareNestedTagHandler parentHandler) {

public DataMapHandler(LoaderContext loaderContext) {
super(loaderContext);
setTargetNamespace(DataMap.SCHEMA_XSD);
}

@Override
Expand All @@ -68,6 +67,8 @@ protected boolean processElement(String namespaceURI, String localName,

case DATA_MAP_TAG:
this.dataMap = new DataMap();
dataMap.setProjectVersion(attributes.getValue("project-version"));
setTargetNamespace(dataMap.getSchemaXsd());
return true;
}

Expand Down
Loading