Search in sources :

Example 1 with FiltersConfig

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfig in project cayenne by apache.

the class DbImporterOldMojoConfigurationTest method testLoadSchema2.

public void testLoadSchema2() throws Exception {
    FiltersConfig filters = getCdbImport("pom-schema-2.xml").createConfig(mock(Logger.class)).getDbLoaderConfig().getFiltersConfig();
    TreeSet<IncludeTableFilter> includes = new TreeSet<>();
    includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
    TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
    excludes.add(PatternFilter.pattern("^ETL_.*"));
    assertEquals(filters.tableFilter(null, "NHL_STATS"), new TableFilter(includes, excludes));
}
Also used : Pattern(java.util.regex.Pattern) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) TreeSet(java.util.TreeSet) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) Logger(org.slf4j.Logger)

Example 2 with FiltersConfig

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfig in project cayenne by apache.

the class MergerOptions method prepareMigrator.

/**
 * check database and create the {@link List} of {@link MergerToken}s
 */
protected void prepareMigrator() {
    try {
        adapter = connectionInfo.makeAdapter(getApplication().getClassLoadingService());
        MergerTokenFactory mergerTokenFactory = mergerTokenFactoryProvider.get(adapter);
        tokens.setMergerTokenFactory(mergerTokenFactory);
        FiltersConfig filters = FiltersConfig.create(defaultCatalog, defaultSchema, TableFilter.everything(), PatternFilter.INCLUDE_NOTHING);
        DataMapMerger merger = DataMapMerger.builder(mergerTokenFactory).filters(filters).build();
        DbLoaderConfiguration config = new DbLoaderConfiguration();
        config.setFiltersConfig(filters);
        DataSource dataSource = connectionInfo.makeDataSource(getApplication().getClassLoadingService());
        DataMap dbImport;
        try (Connection conn = dataSource.getConnection()) {
            dbImport = new DbLoader(adapter, conn, config, new LoggingDbLoaderDelegate(LoggerFactory.getLogger(DbLoader.class)), new DefaultObjectNameGenerator(NoStemStemmer.getInstance())).load();
        } catch (SQLException e) {
            throw new CayenneRuntimeException("Can't doLoad dataMap from db.", e);
        }
        tokens.setTokens(merger.createMergeTokens(dataMap, dbImport));
    } catch (Exception ex) {
        reportError("Error loading adapter", ex);
    }
}
Also used : LoggingDbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) MergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration) DataSource(javax.sql.DataSource) DataMap(org.apache.cayenne.map.DataMap) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) DataMapMerger(org.apache.cayenne.dbsync.merge.DataMapMerger) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) DbLoader(org.apache.cayenne.dbsync.reverse.dbload.DbLoader)

Example 3 with FiltersConfig

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfig in project cayenne by apache.

the class DataMapMergerTest method testProcedures.

@Test
public void testProcedures() {
    DataMap dataMap1 = dataMap().with(procedure("proc1").callParameters(new ProcedureParameter("test"))).build();
    DataMap dataMap2 = dataMap().build();
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.include("proc1");
    FiltersConfig filtersConfig = FiltersConfig.create(null, null, null, patternFilter);
    DataMapMerger merger = DataMapMerger.builder(factory()).filters(filtersConfig).build();
    assertEquals(1, merger.createMergeTokens(dataMap1, dataMap2).size());
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 4 with FiltersConfig

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfig in project cayenne by apache.

the class DbImporterMojoConfigurationTest method testLoadSchema2.

@Test
public void testLoadSchema2() throws Exception {
    DbImporterMojo dbImporterMojo = getCdbImport("pom-schema-2.xml");
    DbImportConfiguration dbImportConfiguration = dbImporterMojo.createConfig(mock(Logger.class));
    dbImportConfiguration.setFiltersConfig(new FiltersConfigBuilder(dbImporterMojo.getReverseEngineering()).build());
    FiltersConfig filters = dbImportConfiguration.getDbLoaderConfig().getFiltersConfig();
    TreeSet<IncludeTableFilter> includes = new TreeSet<>();
    includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
    TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
    excludes.add(PatternFilter.pattern("^ETL_.*"));
    assertEquals(filters.tableFilter(null, "NHL_STATS"), new TableFilter(includes, excludes));
}
Also used : Pattern(java.util.regex.Pattern) PatternFilter(org.apache.cayenne.dbsync.reverse.filters.PatternFilter) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) FiltersConfigBuilder(org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) TableFilter(org.apache.cayenne.dbsync.reverse.filters.TableFilter) TreeSet(java.util.TreeSet) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) IncludeTableFilter(org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with FiltersConfig

use of org.apache.cayenne.dbsync.reverse.filters.FiltersConfig in project cayenne by apache.

the class MergeCase method createMergeTokens.

protected List<MergerToken> createMergeTokens(String tableFilterInclude) {
    FiltersConfig filters = FiltersConfig.create(null, null, TableFilter.include(tableFilterInclude), PatternFilter.INCLUDE_NOTHING);
    DbLoaderConfiguration loaderConfiguration = new DbLoaderConfiguration();
    loaderConfiguration.setFiltersConfig(filters);
    DataMap dbImport;
    try (Connection conn = node.getDataSource().getConnection()) {
        dbImport = new DbLoader(node.getAdapter(), conn, loaderConfiguration, new LoggingDbLoaderDelegate(LoggerFactory.getLogger(DbLoader.class)), new DefaultObjectNameGenerator(NoStemStemmer.getInstance())).load();
    } catch (SQLException e) {
        throw new CayenneRuntimeException("Can't doLoad dataMap from db.", e);
    }
    List<MergerToken> tokens = merger().filters(filters).build().createMergeTokens(map, dbImport);
    return filter(tokens);
}
Also used : LoggingDbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) SQLException(java.sql.SQLException) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) Connection(java.sql.Connection) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DbLoader(org.apache.cayenne.dbsync.reverse.dbload.DbLoader) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

FiltersConfig (org.apache.cayenne.dbsync.reverse.filters.FiltersConfig)5 PatternFilter (org.apache.cayenne.dbsync.reverse.filters.PatternFilter)3 DataMap (org.apache.cayenne.map.DataMap)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 TreeSet (java.util.TreeSet)2 Pattern (java.util.regex.Pattern)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)2 DbLoader (org.apache.cayenne.dbsync.reverse.dbload.DbLoader)2 DbLoaderConfiguration (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)2 LoggingDbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate)2 IncludeTableFilter (org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter)2 TableFilter (org.apache.cayenne.dbsync.reverse.filters.TableFilter)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 IOException (java.io.IOException)1 DataSource (javax.sql.DataSource)1 DataMapMerger (org.apache.cayenne.dbsync.merge.DataMapMerger)1 MergerTokenFactory (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory)1