Search in sources :

Example 16 with Resource

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());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) Injector(org.apache.cayenne.di.Injector) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 17 with Resource

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"));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeService(org.apache.cayenne.project.upgrade.UpgradeService) Injector(org.apache.cayenne.di.Injector) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Example 18 with Resource

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);
}
Also used : Resource(org.apache.cayenne.resource.Resource) DataMap(org.apache.cayenne.map.DataMap)

Example 19 with Resource

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);
}
Also used : Resource(org.apache.cayenne.resource.Resource) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Properties(java.util.Properties)

Example 20 with Resource

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);
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Resource(org.apache.cayenne.resource.Resource) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

Resource (org.apache.cayenne.resource.Resource)21 URLResource (org.apache.cayenne.resource.URLResource)13 URL (java.net.URL)11 Test (org.junit.Test)11 Injector (org.apache.cayenne.di.Injector)8 DataMap (org.apache.cayenne.map.DataMap)7 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)6 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)6 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)5 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)5 File (java.io.File)4 ConfigurationNameMapper (org.apache.cayenne.configuration.ConfigurationNameMapper)4 DefaultConfigurationNameMapper (org.apache.cayenne.configuration.DefaultConfigurationNameMapper)4 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)4 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)4 DIBootstrap (org.apache.cayenne.di.DIBootstrap)4 Module (org.apache.cayenne.di.Module)4 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)4 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)4 Assert (org.junit.Assert)4