本文整理汇总了Java中org.apache.cayenne.configuration.server.ServerRuntime类的典型用法代码示例。如果您正苦于以下问题:Java ServerRuntime类的具体用法?Java ServerRuntime怎么用?Java ServerRuntime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerRuntime类属于org.apache.cayenne.configuration.server包,在下文中一共展示了ServerRuntime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideLinkRestRuntime
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Singleton
@Provides
LinkRestRuntime provideLinkRestRuntime(
Injector injector,
Set<LrFeatureProvider> featureProviders,
Set<LinkRestAdapter> adapters) {
LinkRestBuilder builder;
Binding<ServerRuntime> binding = injector.getExistingBinding(Key.get(ServerRuntime.class));
if (binding == null) {
builder = new LinkRestBuilder().cayenneService(new PojoCayennePersister());
} else {
ServerRuntime cayenneRuntime = binding.getProvider().get();
builder = new LinkRestBuilder().cayenneRuntime(cayenneRuntime);
}
featureProviders.forEach(builder::feature);
adapters.forEach(builder::adapter);
return builder.build();
}
示例2: tablesInInsertOrder
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
static Table[] tablesInInsertOrder(BQRuntime runtime, Collection<DbEntity> dbEntities) {
// note: do not obtain sorter from Cayenne DI. It is not a singleton and will come
// uninitialized
ServerRuntime serverRuntime = runtime.getInstance(ServerRuntime.class);
EntitySorter sorter = serverRuntime.getDataDomain().getEntitySorter();
List<DbEntity> list = new ArrayList<>(dbEntities);
sorter.sortDbEntities(list, false);
DatabaseChannel channel = DatabaseChannel.get(runtime);
Table[] tables = new Table[list.size()];
for (int i = 0; i < tables.length; i++) {
tables[i] = createTableModel(channel, list.get(i));
}
return tables;
}
示例3: cayenneBuilder
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
/**
* Creates and returns a preconfigured {@link ServerRuntimeBuilder} with
* Cayenne config, name, Java8 integration module and a DataSource. Override
* to add custom modules, extra projects, etc.
*
* @param dataSourceFactory injected Bootique {@link DataSourceFactory}
* @return a {@link ServerRuntimeBuilder} that can be extended in
* subclasses.
*/
protected ServerRuntimeBuilder cayenneBuilder(DataSourceFactory dataSourceFactory) {
// building our own Cayenne extensions module...
return ServerRuntime.builder(name).addModule(binder -> {
// provide schema creation hook
if (createSchema) {
binder.bind(SchemaUpdateStrategyFactory.class).toInstance(descriptor -> new CreateIfNoSchemaStrategy());
}
DefaultDataSourceName defaultDataSourceName = defaultDataSourceName(dataSourceFactory);
binder.bind(Key.get(DefaultDataSourceName.class)).toInstance(defaultDataSourceName);
binder.bindList(DataMapConfig.class).addAll(maps);
// provide default DataNode
// TODO: copied from Cayenne, as the corresponding provider is not public or rather
// until https://issues.apache.org/jira/browse/CAY-2095 is implemented
binder.bind(DataDomain.class).toProvider(SyntheticNodeDataDomainProvider.class);
// Bootique DataSource hooks...
BQCayenneDataSourceFactory bqCayenneDSFactory =
new BQCayenneDataSourceFactory(dataSourceFactory, datasource, maps);
binder.bind(org.apache.cayenne.configuration.server.DataSourceFactory.class).toInstance(bqCayenneDSFactory);
});
}
示例4: testCreateCayenneRuntime_NoName
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testCreateCayenneRuntime_NoName() {
ServerRuntimeFactory factory = new ServerRuntimeFactory();
factory.setDatasource("ds1");
ServerRuntime runtime = factory.createCayenneRuntime(mockDSFactory, Collections.emptyList());
try {
DataDomain domain = runtime.getDataDomain();
assertEquals("cayenne", domain.getName());
assertEquals(1, domain.getDataNodes().size());
assertNotNull(domain.getDefaultNode());
assertEquals("cayenne", domain.getDefaultNode().getName());
} finally {
runtime.shutdown();
}
}
示例5: testCreateCayenneRuntime_Name
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testCreateCayenneRuntime_Name() {
ServerRuntimeFactory factory = new ServerRuntimeFactory();
factory.setConfigs(asList("cayenne-project1.xml"));
factory.setDatasource("ds1");
factory.setName("me");
ServerRuntime runtime = factory.createCayenneRuntime(mockDSFactory, Collections.emptyList());
try {
DataDomain domain = runtime.getDataDomain();
assertEquals("me", domain.getName());
assertEquals(1, domain.getDataNodes().size());
assertNotNull(domain.getDefaultNode());
assertEquals("me", domain.getDefaultNode().getName());
} finally {
runtime.shutdown();
}
}
示例6: testCreateCayenneRuntime_Configs
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testCreateCayenneRuntime_Configs() {
ServerRuntimeFactory factory = new ServerRuntimeFactory();
factory.setDatasource("ds1");
factory.setConfigs(asList("cayenne-project2.xml", "cayenne-project1.xml"));
ServerRuntime runtime = factory.createCayenneRuntime(mockDSFactory, Collections.emptyList());
try {
DataDomain domain = runtime.getDataDomain();
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity"));
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity2"));
} finally {
runtime.shutdown();
}
}
示例7: testConfig_ExplicitMaps_SharedDatasource
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testConfig_ExplicitMaps_SharedDatasource() {
ServerRuntime runtime = testFactory.app("--config=classpath:config_explicit_maps.yml")
.autoLoadModules()
.createRuntime()
.getInstance(ServerRuntime.class);
DataDomain domain = runtime.getDataDomain();
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity"));
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity2"));
// trigger a DB op
SQLSelect.dataRowQuery("map1", "SELECT * FROM db_entity").select(runtime.newContext());
SQLSelect.dataRowQuery("map2", "SELECT * FROM db_entity2").select(runtime.newContext());
}
示例8: testConfig_ExplicitMaps_DifferentDatasources
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testConfig_ExplicitMaps_DifferentDatasources() {
ServerRuntime runtime = testFactory.app("--config=classpath:config_explicit_maps_2.yml")
.autoLoadModules()
.createRuntime()
.getInstance(ServerRuntime.class);
DataDomain domain = runtime.getDataDomain();
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity"));
assertNotNull(domain.getEntityResolver().getDbEntity("db_entity2"));
// trigger a DB op
SQLSelect.dataRowQuery("map1", "SELECT * FROM db_entity").select(runtime.newContext());
SQLSelect.dataRowQuery("map2", "SELECT * FROM db_entity2").select(runtime.newContext());
}
示例9: testDefaultDataSource
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testDefaultDataSource() throws SQLException {
ServerRuntime runtime = testFactory.app("--config=classpath:noconfig.yml")
.autoLoadModules()
.createRuntime()
.getInstance(ServerRuntime.class);
DataDomain domain = runtime.getDataDomain();
assertNotNull(domain.getDataNode("cayenne"));
try(Connection c = domain.getDataNode("cayenne").getDataSource().getConnection();) {
DatabaseMetaData md = c.getMetaData();
assertEquals("jdbc:derby:target/derby/bqjdbc_noconfig", md.getURL());
}
}
示例10: testUndefinedDataSource
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testUndefinedDataSource() throws SQLException {
ServerRuntime runtime = testFactory.app("--config=classpath:noconfig_2ds.yml")
.autoLoadModules()
.createRuntime()
.getInstance(ServerRuntime.class);
try {
runtime.getDataDomain();
}
catch (DataDomainLoadException e) {
assertTrue(e.getCause().getMessage()
.startsWith("Can't map Cayenne DataSource: 'cayenne.datasource' is missing."));
}
}
示例11: testUnmatchedDataSource
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testUnmatchedDataSource() throws SQLException {
ServerRuntime runtime = testFactory.app("--config=classpath:noconfig_2ds_unmatched.yml")
.autoLoadModules()
.createRuntime()
.getInstance(ServerRuntime.class);
try {
runtime.getDataDomain();
fail();
}
catch (DataDomainLoadException e) {
String message = e.getCause().getMessage();
assertEquals("No configuration present for DataSource named 'ds3'", message);
}
}
示例12: testContributeModules
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Test
public void testContributeModules() {
Module guiceModule = b -> {
org.apache.cayenne.di.Module cayenneModule = (cb) -> cb.bind(CayenneModuleIT.class).toInstance(this);
CayenneModule.extend(b).addModule(cayenneModule);
};
ServerRuntime runtime = testFactory.app("--config=classpath:fullconfig.yml")
.autoLoadModules()
.module(guiceModule)
.createRuntime()
.getInstance(ServerRuntime.class);
assertSame(this, runtime.getInjector().getInstance(CayenneModuleIT.class));
}
示例13: beforeClass
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
InvalidationHandler invalidationHandler = type -> {
if (type.getAnnotation(CacheGroups.class) != null) {
return null;
}
return p -> asList(new CacheGroupDescriptor("cayenne1"), new CacheGroupDescriptor("nocayenne1"));
};
TEST_RUNTIME = TEST_FACTORY.app("-c", "classpath:bq1.yml")
.autoLoadModules()
.module(b -> CayenneJCacheModule.extend(b).addInvalidationHandler(invalidationHandler))
.createRuntime();
SERVER_RUNTIME = TEST_RUNTIME.getInstance(ServerRuntime.class);
}
示例14: before
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Before
public void before() {
ds1 = mock(DataSource.class);
ds2 = mock(DataSource.class);
DataNode dn1 = mock(DataNode.class);
when(dn1.getName()).thenReturn("dn1");
when(dn1.getDataSource()).thenReturn(ds1);
DataNode dn2 = mock(DataNode.class);
when(dn2.getName()).thenReturn("dn2");
when(dn2.getDataSource()).thenReturn(ds2);
DataDomain domain = new DataDomain("dd");
domain.addNode(dn1);
domain.addNode(dn2);
ServerRuntime runtime = mock(ServerRuntime.class);
when(runtime.getDataDomain()).thenReturn(domain);
cayenneService = new TargetCayenneService(runtime);
}
示例15: configure
import org.apache.cayenne.configuration.server.ServerRuntime; //导入依赖的package包/类
@Override
public Application configure() {
EntityResolver mockResolver = mock(EntityResolver.class);
DataChannel mockChannel = mock(DataChannel.class);
when(mockChannel.getEntityResolver()).thenReturn(mockResolver);
ServerRuntime runtime = mock(ServerRuntime.class);
when(runtime.getChannel()).thenReturn(mockChannel);
Feature lrFeature = LinkRestBuilder.build(runtime);
Feature testFeature = new Feature() {
@Override
public boolean configure(FeatureContext context) {
context.register(ExceptionResource.class);
return true;
}
};
return new ResourceConfig().register(testFeature).register(lrFeature);
}