Search in sources :

Example 1 with DataMapMerger

use of org.apache.cayenne.dbsync.merge.DataMapMerger 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)

Aggregations

IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 DataSource (javax.sql.DataSource)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataMapMerger (org.apache.cayenne.dbsync.merge.DataMapMerger)1 MergerTokenFactory (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory)1 DefaultObjectNameGenerator (org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator)1 DbLoader (org.apache.cayenne.dbsync.reverse.dbload.DbLoader)1 DbLoaderConfiguration (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)1 LoggingDbLoaderDelegate (org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate)1 FiltersConfig (org.apache.cayenne.dbsync.reverse.filters.FiltersConfig)1 DataMap (org.apache.cayenne.map.DataMap)1