use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DbImporterTask method execute.
@Override
public void execute() {
config.setFiltersConfig(new FiltersConfigBuilder(reverseEngineering).build());
validateAttributes();
Logger logger = new AntLogger(this);
config.setLogger(logger);
config.setSkipRelationshipsLoading(reverseEngineering.getSkipRelationshipsLoading());
config.setSkipPrimaryKeyLoading(reverseEngineering.getSkipPrimaryKeyLoading());
config.setTableTypes(reverseEngineering.getTableTypes());
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
DbImportConfigurationValidator validator = new DbImportConfigurationValidator(reverseEngineering, config, injector);
try {
validator.validate();
} catch (Exception ex) {
throw new BuildException(ex.getMessage(), ex);
}
try {
injector.getInstance(DbImportAction.class).execute(config);
} catch (Exception ex) {
Throwable th = Util.unwindException(ex);
String message = "Error importing database schema";
if (th.getLocalizedMessage() != null) {
message += ": " + th.getLocalizedMessage();
}
log(message, Project.MSG_ERR);
throw new BuildException(message, th);
} finally {
injector.shutdown();
}
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DbGeneratorTaskTest method testSetAdapter.
@Test
public void testSetAdapter() throws Exception {
DataSource ds = mock(DataSource.class);
Injector injector = DIBootstrap.createInjector(new ToolsModule(mock(Logger.class)));
DbGeneratorTask task = new DbGeneratorTask();
DbAdapter autoAdapter = task.getAdapter(injector, ds);
assertTrue(autoAdapter instanceof AutoAdapter);
task.setAdapter(SQLServerAdapter.class.getName());
DbAdapter sqlServerAdapter = task.getAdapter(injector, ds);
assertTrue(sqlServerAdapter instanceof SQLServerAdapter);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DefaultDataRowStoreFactoryIT method testGetDataRowStoreWithParameters.
@Test
public void testGetDataRowStoreWithParameters() {
final DataDomain DOMAIN = new DataDomain("test");
final EventManager EVENT_MANAGER = new DefaultEventManager();
final int CACHE_SIZE = 500;
Module testModule = binder -> {
binder.bind(DataDomain.class).toInstance(DOMAIN);
binder.bind(EventManager.class).toInstance(EVENT_MANAGER);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
ServerModule.setSnapshotCacheSize(binder, CACHE_SIZE);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataRowStore dataStore = injector.getInstance(DataRowStoreFactory.class).createDataRowStore("test");
assertNotNull(dataStore);
assertEquals(dataStore.maximumSize(), CACHE_SIZE);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class BaseContextTest method testAttachToRuntimeIfNeeded.
@Test
public void testAttachToRuntimeIfNeeded() {
final DataChannel channel = mock(DataChannel.class);
final QueryCache cache = mock(QueryCache.class);
Module testModule = binder -> {
binder.bind(DataChannel.class).toInstance(channel);
binder.bind(QueryCache.class).toInstance(cache);
};
Injector injector = DIBootstrap.createInjector(testModule);
BaseContext context = new MockBaseContext();
assertNull(context.channel);
assertNull(context.queryCache);
Injector oldInjector = CayenneRuntime.getThreadInjector();
try {
CayenneRuntime.bindThreadInjector(injector);
assertTrue(context.attachToRuntimeIfNeeded());
assertSame(channel, context.channel);
assertFalse(context.attachToRuntimeIfNeeded());
assertFalse(context.attachToRuntimeIfNeeded());
} finally {
CayenneRuntime.bindThreadInjector(oldInjector);
}
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class CayenneRuntimeTest method testBindThreadInjector.
@Test
public void testBindThreadInjector() {
Injector injector = mock(Injector.class);
assertNull(CayenneRuntime.getThreadInjector());
try {
CayenneRuntime.bindThreadInjector(injector);
assertSame(injector, CayenneRuntime.getThreadInjector());
} finally {
CayenneRuntime.bindThreadInjector(null);
}
assertNull(CayenneRuntime.getThreadInjector());
}
Aggregations