本文整理汇总了Java中io.ebean.config.ServerConfig.setDefaultServer方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConfig.setDefaultServer方法的具体用法?Java ServerConfig.setDefaultServer怎么用?Java ServerConfig.setDefaultServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.ebean.config.ServerConfig
的用法示例。
在下文中一共展示了ServerConfig.setDefaultServer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultEbeanServerConfig
import io.ebean.config.ServerConfig; //导入方法依赖的package包/类
@SuppressWarnings("SpringJavaAutowiringInspection")
@Bean
@Primary
public ServerConfig defaultEbeanServerConfig() {
ServerConfig config = new ServerConfig();
config.setDataSource(dataSource());
config.addPackage("org.springframework.data.ebean.sample.domain");
config.setExternalTransactionManager(new SpringJdbcTransactionManager());
config.loadFromProperties();
config.setDefaultServer(true);
config.setRegister(true);
config.setAutoCommitMode(false);
config.setExpressionNativeIlike(true);
config.setCurrentUserProvider(new CurrentUserProvider() {
@Override
public Object currentUser() {
return "test"; // just for test, can rewrite to get the currentUser from threadLocal
}
});
return config;
}
示例2: getObject
import io.ebean.config.ServerConfig; //导入方法依赖的package包/类
@Override
public EbeanServer getObject() throws Exception {
ServerConfig config = new ServerConfig();
config.setName("db");
config.setCurrentUserProvider(currentUser);
// // set the spring's datasource and transaction manager.
// config.setDataSource(dataSource);
// config.setExternalTransactionManager(new SpringAwareJdbcTransactionManager());
config.loadFromProperties();
// set as default and register so that Model can be
// used if desired for save() and update() etc
config.setDefaultServer(true);
config.setRegister(true);
return EbeanServerFactory.create(config);
}
示例3: get
import io.ebean.config.ServerConfig; //导入方法依赖的package包/类
@Override
public EbeanServer get() {
String datasourceUrl = mConfiguration.getString(SERVER_CONFIG_PREFIX + "url");
String datasourceUsername = mConfiguration.getString(SERVER_CONFIG_PREFIX + "username");
String datasourcePassword = mConfiguration.getString(SERVER_CONFIG_PREFIX + "password");
String datasourceDriver = mConfiguration.getString(SERVER_CONFIG_PREFIX + "driver");
String databaseName = mConfiguration.getString(SERVER_CONFIG_PREFIX + "name");
String platformName = mConfiguration.getString(SERVER_CONFIG_PREFIX + "platformName");
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setUrl(datasourceUrl);
dataSourceConfig.setDriver(datasourceDriver);
dataSourceConfig.setUsername(datasourceUsername);
dataSourceConfig.setPassword(datasourcePassword);
dataSourceConfig.setHeartbeatFreqSecs(60);
dataSourceConfig.setHeartbeatTimeoutSeconds(30);
dataSourceConfig.setMinConnections(3);
dataSourceConfig.setMaxConnections(30);
dataSourceConfig.setLeakTimeMinutes(1);
dataSourceConfig.setMaxInactiveTimeSecs(30);
dataSourceConfig.setWaitTimeoutMillis(1000 * 60);
dataSourceConfig.setTrimPoolFreqSecs(60);
dataSourceConfig.setCaptureStackTrace(true);
ArrayList<Class<?>> models = new ArrayList<>();
models.add(Credentials.class);
models.add(Message.class);
models.add(PayloadElement.class);
models.add(Recipient.class);
models.add(PlatformFailure.class);
models.add(Task.class);
ServerConfig serverConfig = new ServerConfig();
serverConfig.setDataSourceConfig(dataSourceConfig);
serverConfig.setName(databaseName);
serverConfig.setDatabasePlatformName(platformName);
serverConfig.setRegister(true);
serverConfig.setDefaultServer(true);
serverConfig.setUpdatesDeleteMissingChildren(false);
serverConfig.setClasses(models);
serverConfig.setDdlGenerate(false);
serverConfig.setUpdateChangesOnly(false);
return EbeanServerFactory.create(serverConfig);
}
示例4: configure
import io.ebean.config.ServerConfig; //导入方法依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
ServerConfig config = new ServerConfig();
config.setName(name);
Config cprops = conf.getConfig("ebean");
if (conf.hasPath("ebean." + name)) {
cprops = conf.getConfig("ebean." + name)
.withFallback(cprops)
.withoutPath(name);
}
Properties props = props(cprops);
ContainerConfig container = new ContainerConfig();
container.loadFromProperties(props);
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
config.setDataSource(ds);
config.setContainerConfig(container);
config.loadFromProperties(props);
config.setDefaultServer(cprops.getBoolean("defaultServer"));
config.setRegister(cprops.getBoolean("register"));
if (callback != null) {
callback.accept(config, conf);
}
List<String> packages = config.getPackages();
if (packages == null || packages.size() == 0) {
packages = ImmutableList.of(conf.getString("application.ns"));
}
config.setPackages(packages);
PKG.get().addAll(packages);
EbeanManaged ebean = new EbeanManaged(conf, config);
env.onStart(ebean::start);
env.onStop(ebean::stop);
/** Bind db key: */
Consumer<Key<EbeanServer>> provider = k -> binder.bind(k).toProvider(ebean);
ServiceKey keys = env.serviceKey();
keys.generate(EbeanServer.class, name, provider);
// Run enhancer once per JVM
env.onStart(runEnhancer());
}
示例5: parse
import io.ebean.config.ServerConfig; //导入方法依赖的package包/类
/**
* Reads the configuration and creates config for Ebean servers.
*
* @return a config for Ebean servers.
*/
public EbeanConfig parse() {
EbeanParsedConfig ebeanConfig = EbeanParsedConfig.parseFromConfig(config);
Map<String, ServerConfig> serverConfigs = new HashMap<>();
for (Map.Entry<String, List<String>> entry: ebeanConfig.getDatasourceModels().entrySet()) {
String key = entry.getKey();
ServerConfig serverConfig = new ServerConfig();
serverConfig.setName(key);
serverConfig.loadFromProperties();
setServerConfigDataSource(key, serverConfig);
if (!ebeanConfig.getDefaultDatasource().equals(key)) {
serverConfig.setDefaultServer(false);
}
Set<String> classes = getModelClasses(entry);
addModelClassesToServerConfig(key, serverConfig, classes);
serverConfigs.put(key, serverConfig);
}
return new DefaultEbeanConfig(ebeanConfig.getDefaultDatasource(), serverConfigs);
}