use of org.apache.cayenne.ConfigurationException in project cayenne by apache.
the class XMLDataChannelDescriptorLoaderTest method testLoad_MissingConfig.
@Test
public void testLoad_MissingConfig() throws Exception {
// create and initialize loader instance to test
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);
try {
loader.load(new URLResource(new URL("file:///no_such_resource")));
fail("No exception was thrown on bad absent config name");
} catch (ConfigurationException e) {
// expected
}
}
use of org.apache.cayenne.ConfigurationException in project cayenne by apache.
the class XMLPoolingDataSourceFactory method getDataSource.
@Override
public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception {
DataSourceInfo descriptor = nodeDescriptor.getDataSourceDescriptor();
if (descriptor == null) {
String message = "Null dataSourceDescriptor for nodeDescriptor '" + nodeDescriptor.getName() + "'";
logger.info(message);
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();
}
use of org.apache.cayenne.ConfigurationException in project cayenne by apache.
the class DataSourceChildrenHandler method configureConnectionPool.
void configureConnectionPool(Attributes attributes) {
String min = attributes.getValue("min");
if (min != null) {
try {
dataSourceDescriptor.setMinConnections(Integer.parseInt(min));
} catch (NumberFormatException nfex) {
logger.info("Non-numeric 'min' attribute", nfex);
throw new ConfigurationException("Non-numeric 'min' attribute '%s'", nfex, min);
}
}
String max = attributes.getValue("max");
if (max != null) {
try {
dataSourceDescriptor.setMaxConnections(Integer.parseInt(max));
} catch (NumberFormatException nfex) {
logger.info("Non-numeric 'max' attribute", nfex);
throw new ConfigurationException("Non-numeric 'max' attribute '%s'", nfex, max);
}
}
}
use of org.apache.cayenne.ConfigurationException in project cayenne by apache.
the class XMLDataChannelDescriptorLoader method load.
@Override
public ConfigurationTree<DataChannelDescriptor> load(Resource configurationResource) throws ConfigurationException {
if (configurationResource == null) {
throw new NullPointerException("Null configurationResource");
}
URL configurationURL = configurationResource.getURL();
logger.info("Loading XML configuration resource from " + configurationURL);
final DataChannelDescriptor descriptor = new DataChannelDescriptor();
descriptor.setConfigurationSource(configurationResource);
descriptor.setName(nameMapper.configurationNodeName(DataChannelDescriptor.class, configurationResource));
try (InputStream in = configurationURL.openStream()) {
XMLReader parser = xmlReaderProvider.get();
LoaderContext loaderContext = new LoaderContext(parser, handlerFactory);
loaderContext.addDataMapListener(dataMap -> descriptor.getDataMaps().add(dataMap));
DataChannelHandler rootHandler = new DataChannelHandler(this, descriptor, loaderContext);
parser.setContentHandler(rootHandler);
parser.setErrorHandler(rootHandler);
InputSource input = new InputSource(in);
input.setSystemId(configurationURL.toString());
parser.parse(input);
loaderContext.dataChannelLoaded(descriptor);
} catch (Exception e) {
throw new ConfigurationException("Error loading configuration from %s", e, configurationURL);
}
// TODO: andrus 03/10/2010 - actually provide load failures here...
return new ConfigurationTree<>(descriptor, null);
}
use of org.apache.cayenne.ConfigurationException in project cayenne by apache.
the class Util method readDocument.
/**
* @since 4.1
* @param url to read
* @return org.w3c.dom.Document from the given URL
*/
public static Document readDocument(URL url) {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(false);
try {
DocumentBuilder domBuilder = documentBuilderFactory.newDocumentBuilder();
try (InputStream inputStream = url.openStream()) {
return domBuilder.parse(inputStream);
} catch (IOException | SAXException e) {
throw new ConfigurationException("Error loading configuration from %s", e, url);
}
} catch (ParserConfigurationException e) {
throw new ConfigurationException(e);
}
}
Aggregations