use of org.apache.cayenne.resource.Resource in project cayenne by apache.
the class CompatibilityDataMapLoaderIT method testLoad.
@Test
public void testLoad() throws Exception {
Injector injector = getInjector();
DataMapLoader loader = injector.getInstance(DataMapLoader.class);
assertTrue(loader instanceof CompatibilityDataMapLoader);
URL resourceUrl = getClass().getResource("../../project/compatibility/test-map-v6.map.xml");
Resource resource = new URLResource(resourceUrl);
DataMap dataMap = loader.load(resource);
assertNotNull(dataMap);
assertEquals(1, dataMap.getDbEntities().size());
assertEquals(1, dataMap.getObjEntities().size());
assertNotNull(dataMap.getObjEntity("Artist"));
assertNotNull(dataMap.getDbEntity("Artist"));
assertEquals(2, dataMap.getDbEntity("Artist").getAttributes().size());
}
use of org.apache.cayenne.resource.Resource in project cayenne by apache.
the class CompatibilityUpgradeServiceIT method testUpgradeStandAloneDataMapDom.
@Test
public void testUpgradeStandAloneDataMapDom() throws Exception {
Injector injector = getInjector();
CompatibilityUpgradeService upgradeService = (CompatibilityUpgradeService) injector.getInstance(UpgradeService.class);
DocumentProvider documentProvider = injector.getInstance(DocumentProvider.class);
URL dataMapUrl = getClass().getResource("test-map-v6.map.xml");
Document dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNull(dataMapDocument);
Resource resource = new URLResource(dataMapUrl);
upgradeService.upgradeDataMap(resource);
dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNotNull(dataMapDocument);
assertEquals("10", dataMapDocument.getDocumentElement().getAttribute("project-version"));
}
use of org.apache.cayenne.resource.Resource in project cayenne by apache.
the class DataChannelChildrenHandler method addMap.
private void addMap(Attributes attributes) {
String dataMapName = attributes.getValue("name");
Resource baseResource = descriptor.getConfigurationSource();
String dataMapLocation = xmlDataChannelDescriptorLoader.nameMapper.configurationLocation(DataMap.class, dataMapName);
Resource dataMapResource = baseResource.getRelativeResource(dataMapLocation);
logger.info("Loading XML DataMap resource from " + dataMapResource.getURL());
DataMap dataMap = xmlDataChannelDescriptorLoader.dataMapLoader.load(dataMapResource);
dataMap.setName(dataMapName);
dataMap.setLocation(dataMapLocation);
dataMap.setConfigurationSource(dataMapResource);
dataMap.setDataChannelDescriptor(descriptor);
descriptor.getDataMaps().add(dataMap);
}
use of org.apache.cayenne.resource.Resource in project cayenne by apache.
the class DBCPDataSourceFactory method getDataSource.
@Override
public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception {
String location = nodeDescriptor.getParameters();
if (location == null) {
logger.debug("No explicit DBCP2 config location, will use default location: " + DBCP2_PROPERTIES);
location = DBCP2_PROPERTIES;
}
Resource baseConfiguration = nodeDescriptor.getConfigurationSource();
if (baseConfiguration == null) {
throw new CayenneRuntimeException("Null 'configurationSource' for nodeDescriptor '%s'", nodeDescriptor.getName());
}
Resource dbcp2Configuration = baseConfiguration.getRelativeResource(location);
if (dbcp2Configuration == null) {
throw new CayenneRuntimeException("Missing DBCP2 configuration '%s' for nodeDescriptor '%s'", location, nodeDescriptor.getName());
}
Properties properties = getProperties(dbcp2Configuration);
if (logger.isDebugEnabled()) {
logger.debug("DBCP2 Properties: " + properties);
}
return BasicDataSourceFactory.createDataSource(properties);
}
use of org.apache.cayenne.resource.Resource in project cayenne by apache.
the class DbImportProjectSaver method save.
@Override
public void save(Project project) {
DataMap dataMap = (DataMap) project.getRootNode();
if (projectController.getCurrentDataMap() != null) {
projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.REMOVE));
projectController.fireDataMapEvent(new DataMapEvent(Application.getFrame(), dataMap, MapEvent.ADD));
} else {
DataChannelDescriptor currentDomain = (DataChannelDescriptor) projectController.getProject().getRootNode();
Resource baseResource = currentDomain.getConfigurationSource();
// a new DataMap, so need to set configuration source for it
if (baseResource != null) {
Resource dataMapResource = baseResource.getRelativeResource(nameMapper.configurationLocation(dataMap));
dataMap.setConfigurationSource(dataMapResource);
}
projectController.addDataMap(Application.getFrame(), dataMap);
}
}
Aggregations