Search in sources :

Example 6 with DataSource

use of jdk.incubator.sql2.DataSource in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testInit.

// (expected = AtlasException.class)
@Test
public void testInit() throws AtlasException {
    File file = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "atlasmapping.json").toFile();
    DefaultAtlasContext ctx = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), file.toURI());
    ctx.init();
    DataSource dataSource = new DataSource();
    dataSource.setUri("URI");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri(null);
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:source");
    dataSource.setDataSourceType(DataSourceType.SOURCE);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:target");
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:target");
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    ctx = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping);
    ctx.getTargetModules().put("io.atlasmap.core.DefaultAtlasContext.constants.docId", new ConstantModule());
    ctx.init();
    @SuppressWarnings("unchecked") Map<String, AtlasModule> targetModules = spy(Map.class);
    when(targetModules.put(any(String.class), any(AtlasModule.class))).thenThrow(new RuntimeException("mockException"));
    ctx.setTargetModules(targetModules);
    ctx.init();
}
Also used : AtlasModule(io.atlasmap.spi.AtlasModule) File(java.io.File) DataSource(io.atlasmap.v2.DataSource) Test(org.junit.jupiter.api.Test)

Example 7 with DataSource

use of jdk.incubator.sql2.DataSource in project atlasmap by atlasmap.

the class BaseDefaultAtlasContextTest method init.

@BeforeEach
public void init() throws AtlasException {
    mapping = AtlasTestData.generateAtlasMapping();
    context = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping) {

        protected void init() {
        // hijack initialization
        }
    };
    previewContext = new DefaultAtlasPreviewContext(DefaultAtlasContextFactory.getInstance());
    sourceModule = mockAtlasModule();
    DataSource sds = new DataSource();
    sds.setDataSourceType(DataSourceType.SOURCE);
    sourceModule.setDataSource(sds);
    targetModule = mockAtlasModule();
    DataSource tds = new DataSource();
    tds.setDataSourceType(DataSourceType.TARGET);
    targetModule.setDataSource(tds);
    context.getSourceModules().put(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, sourceModule);
    context.getTargetModules().put(AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID, targetModule);
    ConstantModule constantModule = new ConstantModule();
    constantModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getSourceModules().put(AtlasConstants.CONSTANTS_DOCUMENT_ID, constantModule);
    PropertyModule sourcePropertyModule = new PropertyModule(new DefaultAtlasPropertyStrategy());
    sourcePropertyModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getSourceModules().put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, sourcePropertyModule);
    PropertyModule targetPropertyModule = new PropertyModule(new DefaultAtlasPropertyStrategy());
    targetPropertyModule.setConversionService(DefaultAtlasConversionService.getInstance());
    context.getTargetModules().put(AtlasConstants.PROPERTIES_TARGET_DOCUMENT_ID, targetPropertyModule);
    recreateSession();
}
Also used : DataSource(io.atlasmap.v2.DataSource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with DataSource

use of jdk.incubator.sql2.DataSource in project atlasmap by atlasmap.

the class BaseMarshallerTest method generateMultiSourceMapping.

protected AtlasMapping generateMultiSourceMapping() {
    AtlasMapping mapping = generateSeparateAtlasMapping();
    DataSource source1 = new DataSource();
    source1.setUri("xml:foo1");
    source1.setDataSourceType(DataSourceType.SOURCE);
    source1.setId("xml1");
    DataSource source2 = new DataSource();
    source2.setUri("xml:foo2");
    source2.setDataSourceType(DataSourceType.SOURCE);
    source2.setId("xml2");
    DataSource target = new DataSource();
    target.setUri("xml:bar");
    target.setDataSourceType(DataSourceType.TARGET);
    target.setId("target1");
    mapping.getDataSource().add(source1);
    mapping.getDataSource().add(source2);
    mapping.getDataSource().add(target);
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().get(0).setDocId("xml1");
    fm.getOutputField().get(0).setDocId("target1");
    fm.getOutputField().get(1).setDocId("target1");
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Example 9 with DataSource

use of jdk.incubator.sql2.DataSource in project atlasmap by atlasmap.

the class DefaultAtlasContext method init.

/**
 * TODO: For dynamic re-load. This needs lock()
 *
 * @throws AtlasException failed to initialize
 */
protected synchronized void init() throws AtlasException {
    if (this.initialized) {
        return;
    }
    registerJmx(this);
    if (this.atlasMappingUri != null) {
        this.admHandler = new ADMArchiveHandler(factory.getClassLoader());
        this.admHandler.setIgnoreLibrary(true);
        this.admHandler.load(Paths.get(this.atlasMappingUri));
        this.dataSourceMetadataMap = this.admHandler.getDataSourceMetadataMap();
    }
    if (this.admHandler == null || this.admHandler.getMappingDefinition() == null) {
        LOG.warn("AtlasMap context cannot initialize without mapping definition, ignoring:" + " Mapping URI={}", this.atlasMappingUri);
        return;
    }
    sourceModules.clear();
    ConstantModule constant = new ConstantModule();
    constant.setConversionService(factory.getConversionService());
    constant.setFieldActionService(factory.getFieldActionService());
    sourceModules.put(AtlasConstants.CONSTANTS_DOCUMENT_ID, constant);
    PropertyModule property = new PropertyModule(factory.getPropertyStrategy());
    property.setConversionService(factory.getConversionService());
    property.setFieldActionService(factory.getFieldActionService());
    property.setMode(AtlasModuleMode.SOURCE);
    sourceModules.put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, property);
    targetModules.clear();
    property = new PropertyModule(factory.getPropertyStrategy());
    property.setConversionService(factory.getConversionService());
    property.setFieldActionService(factory.getFieldActionService());
    property.setMode(AtlasModuleMode.TARGET);
    targetModules.put(AtlasConstants.PROPERTIES_TARGET_DOCUMENT_ID, property);
    lookupTables.clear();
    if (admHandler.getMappingDefinition().getLookupTables() != null && admHandler.getMappingDefinition().getLookupTables().getLookupTable() != null) {
        for (LookupTable table : admHandler.getMappingDefinition().getLookupTables().getLookupTable()) {
            lookupTables.put(table.getName(), table);
        }
    }
    AtlasModuleInfoRegistry moduleInfoRegistry = factory.getModuleInfoRegistry();
    for (DataSource ds : admHandler.getMappingDefinition().getDataSource()) {
        AtlasModuleInfo moduleInfo = moduleInfoRegistry.lookupByUri(ds.getUri());
        if (moduleInfo == null) {
            LOG.error("Cannot find module info for the DataSource uri '{}'", ds.getUri());
            continue;
        }
        if (ds.getDataSourceType() != DataSourceType.SOURCE && ds.getDataSourceType() != DataSourceType.TARGET) {
            LOG.error("Unsupported DataSource type '{}'", ds.getDataSourceType());
            continue;
        }
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            docId = ds.getDataSourceType() == DataSourceType.SOURCE ? AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID : AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID;
        }
        if (ds.getDataSourceType() == DataSourceType.SOURCE && sourceModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), ds.getId());
            continue;
        }
        if (ds.getDataSourceType() == DataSourceType.TARGET && targetModules.containsKey(docId)) {
            LOG.error("Duplicated {} DataSource ID '{}' was detected, ignoring...", ds.getDataSourceType(), docId);
            continue;
        }
        try {
            AtlasModule module = moduleInfo.getModuleClass().getDeclaredConstructor().newInstance();
            module.setClassLoader(factory.getClassLoader());
            module.setConversionService(factory.getConversionService());
            module.setFieldActionService(factory.getFieldActionService());
            module.setDataSource(ds);
            if (ds.getDataSourceType() == DataSourceType.SOURCE) {
                getSourceModules().put(docId, module);
            } else if (ds.getDataSourceType() == DataSourceType.TARGET) {
                getTargetModules().put(docId, module);
            }
            if (this.dataSourceMetadataMap != null) {
                DataSourceKey dskey = new DataSourceKey(ds.getDataSourceType() == DataSourceType.SOURCE, docId);
                DataSourceMetadata meta = this.dataSourceMetadataMap.get(dskey);
                if (meta != null) {
                    module.setDataSourceMetadata(meta);
                }
            }
            module.init();
        } catch (Exception t) {
            LOG.error("Unable to initialize {} module: {}", ds.getDataSourceType(), moduleInfo);
            LOG.error(t.getMessage(), t);
            throw new AtlasException(String.format("Unable to initialize %s module: %s", ds.getDataSourceType(), moduleInfo.toString()), t);
        }
    }
    initialized = true;
}
Also used : AtlasException(io.atlasmap.api.AtlasException) AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasException(io.atlasmap.api.AtlasException) DataSource(io.atlasmap.v2.DataSource) AtlasModule(io.atlasmap.spi.AtlasModule) AtlasModuleInfo(io.atlasmap.spi.AtlasModuleInfo) DataSourceKey(io.atlasmap.v2.DataSourceKey) DataSourceMetadata(io.atlasmap.v2.DataSourceMetadata) AtlasModuleInfoRegistry(io.atlasmap.spi.AtlasModuleInfoRegistry) LookupTable(io.atlasmap.v2.LookupTable)

Example 10 with DataSource

use of jdk.incubator.sql2.DataSource in project atlasmap by atlasmap.

the class DefaultAtlasValidationService method validateMapping.

@Override
public List<Validation> validateMapping(AtlasMapping mapping) {
    if (mapping == null) {
        throw new IllegalArgumentException("Mapping definition must not be null");
    }
    List<Validation> validations = new ArrayList<>();
    Validators.MAPPING_NAME.get().validate(mapping.getName(), validations, null);
    List<DataSource> dataSources = mapping.getDataSource();
    for (DataSource ds : dataSources) {
        switch(ds.getDataSourceType()) {
            case SOURCE:
                Validators.DATASOURCE_SOURCE_URI.get().validate(ds.getUri(), validations, ds.getId());
                break;
            case TARGET:
                Validators.DATASOURCE_TARGET_URI.get().validate(ds.getUri(), validations, ds.getId());
                break;
            default:
                throw new IllegalArgumentException(String.format("Unknown DataSource type '%s'", ds.getDataSourceType()));
        }
    }
    validateFieldMappings(mapping.getMappings(), mapping.getLookupTables(), validations);
    return validations;
}
Also used : Validation(io.atlasmap.v2.Validation) ArrayList(java.util.ArrayList) DataSource(io.atlasmap.v2.DataSource)

Aggregations

DataSource (jdk.incubator.sql2.DataSource)96 Session (jdk.incubator.sql2.Session)88 Test (org.junit.Test)85 DataSource (io.atlasmap.v2.DataSource)54 ArrayList (java.util.ArrayList)50 AfterClass (org.junit.AfterClass)44 BeforeClass (org.junit.BeforeClass)44 TimeUnit (java.util.concurrent.TimeUnit)42 Collector (java.util.stream.Collector)36 ForkJoinPool (java.util.concurrent.ForkJoinPool)32 AdbaType (jdk.incubator.sql2.AdbaType)32 TestConfig (com.oracle.adbaoverjdbc.test.TestConfig)30 DataSourceFactory (jdk.incubator.sql2.DataSourceFactory)28 Assert (org.junit.Assert)28 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 List (java.util.List)23 CompletableFuture (java.util.concurrent.CompletableFuture)22 NoSuchElementException (java.util.NoSuchElementException)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 Column (jdk.incubator.sql2.Result.Column)18