@Test public void testImportWithFieldChanged() throws Exception { DbImportConfiguration config = mock(DbImportConfiguration.class); when(config.getTargetDataMap()).thenReturn(FILE_STUB); when(config.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate()); when(config.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration()); when(config.createNameGenerator()).thenReturn(new DefaultObjectNameGenerator(NoStemStemmer.getInstance())); when(config.createMeaningfulPKFilter()).thenReturn(NamePatternMatcher.EXCLUDE_ALL); DbLoader dbLoader = new DbLoader(mockAdapter, mockConnection, config.getDbLoaderConfig(), mockDelegate, mockNameGenerator) { @Override public DataMap load() throws SQLException { DataMap dataMap = new DataMap(); new DataMapBuilder(dataMap).with( dbEntity("ARTGROUP").attributes( dbAttr("GROUP_ID").typeInt().primaryKey(), dbAttr("NAME").typeVarchar(100).mandatory(), dbAttr("NAME_01").typeVarchar(100).mandatory(), dbAttr("PARENT_GROUP_ID").typeInt() )).with( objEntity("org.apache.cayenne.testdo.testmap", "ArtGroup", "ARTGROUP").attributes( objAttr("name").type(String.class).dbPath("NAME") )); return dataMap; } }; final boolean[] haveWeTriedToSave = {false}; DefaultDbImportAction action = buildDbImportAction( new FileProjectSaver(Collections.<ProjectExtension>emptyList()) { @Override public void save(Project project) { haveWeTriedToSave[0] = true; DataMap rootNode = (DataMap) project.getRootNode(); assertEquals(1, rootNode.getObjEntities().size()); assertEquals(1, rootNode.getDbEntityMap().size()); DbEntity entity = rootNode.getDbEntity("ARTGROUP"); assertNotNull(entity); assertEquals(4, entity.getAttributes().size()); assertNotNull(entity.getAttribute("NAME_01")); } }, new DataMapLoader() { @Override public DataMap load(Resource configurationResource) throws CayenneRuntimeException { return new DataMapBuilder().with( dbEntity("ARTGROUP").attributes( dbAttr("GROUP_ID").typeInt().primaryKey(), dbAttr("NAME").typeVarchar(100).mandatory(), dbAttr("PARENT_GROUP_ID").typeInt() )).with( objEntity("org.apache.cayenne.testdo.testmap", "ArtGroup", "ARTGROUP").attributes( objAttr("name").type(String.class).dbPath("NAME") )).build(); } }, dbLoader ); action.execute(config); assertTrue("We should try to save.", haveWeTriedToSave[0]); }
@Override public void execute(DbImportConfiguration config) throws Exception { commit(config, loadDataMap(config)); }
DefaultDbImportAction implements DbImportAction { @Override public void execute(DbImportConfiguration config) throws Exception { commit(config, loadDataMap(config)); } }
DefaultDbImportAction implements DbImportAction { @Override public void execute(DbImportConfiguration config) throws Exception { commit(config, loadDataMap(config)); } DefaultDbImportAction(@Inject Logger logger,
                                 @Inject ProjectSaver projectSaver,
                                 @Inject DataSourceFactory dataSourceFactory,
                                 @Inject DbAdapterFactory adapterFactory,
                                 @Inject DataMapLoader mapLoader,
                                 @Inject MergerTokenFactoryProvider mergerTokenFactoryProvider,
                                 @Inject DataChannelDescriptorLoader dataChannelDescriptorLoader,
                                 @Inject DataChannelMetaData metaData); }
DefaultDbImportAction implements DbImportAction { @Override public void execute(DbImportConfiguration config) throws Exception { commit(config, loadDataMap(config)); } DefaultDbImportAction(@Inject Logger logger,
                                 @Inject ProjectSaver projectSaver,
                                 @Inject DataSourceFactory dataSourceFactory,
                                 @Inject DbAdapterFactory adapterFactory,
                                 @Inject DataMapLoader mapLoader,
                                 @Inject MergerTokenFactoryProvider mergerTokenFactoryProvider,
                                 @Inject DataChannelDescriptorLoader dataChannelDescriptorLoader,
                                 @Inject DataChannelMetaData metaData); static void flattenManyToManyRelationships(DataMap map, Collection<ObjEntity> loadedObjEntities,
                                                         ObjectNameGenerator objectNameGenerator); @Override void execute(DbImportConfiguration config); boolean hasTokensToImport(Collection<MergerToken> tokens); }
DefaultDbImportAction implements DbImportAction { @Override public void execute(DbImportConfiguration config) throws Exception { commit(config, loadDataMap(config)); } DefaultDbImportAction(@Inject Logger logger,
                                 @Inject ProjectSaver projectSaver,
                                 @Inject DataSourceFactory dataSourceFactory,
                                 @Inject DbAdapterFactory adapterFactory,
                                 @Inject DataMapLoader mapLoader,
                                 @Inject MergerTokenFactoryProvider mergerTokenFactoryProvider,
                                 @Inject DataChannelDescriptorLoader dataChannelDescriptorLoader,
                                 @Inject DataChannelMetaData metaData); static void flattenManyToManyRelationships(DataMap map, Collection<ObjEntity> loadedObjEntities,
                                                         ObjectNameGenerator objectNameGenerator); @Override void execute(DbImportConfiguration config); boolean hasTokensToImport(Collection<MergerToken> tokens);  }