use of org.apache.cayenne.configuration.DataMapLoader 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.configuration.DataMapLoader in project cayenne by apache.
the class ImportDataMapAction method importDataMap.
protected void importDataMap() {
File dataMapFile = selectDataMap(Application.getFrame());
if (dataMapFile == null) {
return;
}
DataMap newMap;
try {
URL url = dataMapFile.toURI().toURL();
DataMapLoader loader = application.getInjector().getInstance(DataMapLoader.class);
newMap = loader.load(new URLResource(url));
ConfigurationNode root = getProjectController().getProject().getRootNode();
newMap.setName(NameBuilder.builder(newMap, root).baseName(newMap.getName()).name());
Resource baseResource = ((DataChannelDescriptor) root).getConfigurationSource();
if (baseResource != null) {
Resource dataMapResource = baseResource.getRelativeResource(nameMapper.configurationLocation(newMap));
newMap.setConfigurationSource(dataMapResource);
}
getProjectController().addDataMap(this, newMap);
} catch (Exception ex) {
logObj.info("Error importing DataMap.", ex);
JOptionPane.showMessageDialog(Application.getFrame(), "Error reading DataMap: " + ex.getMessage(), "Can't Open DataMap", JOptionPane.OK_OPTION);
}
}
Aggregations