io.ebean.config.ServerConfig Java Examples

The following examples show how to use io.ebean.config.ServerConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleConfig.java    From spring-data-ebean with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("SpringJavaAutowiringInspection")
@Bean
@Primary
public ServerConfig defaultEbeanServerConfig() {
  ServerConfig config = new ServerConfig();

  config.setDataSource(dataSource());
  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;
}
 
Example #2
Source File: EbeanFactoryBean.java    From example-springboot with Apache License 2.0 6 votes vote down vote up
@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();
    config.loadTestProperties();

    return EbeanServerFactory.create(config);
  }
 
Example #3
Source File: MainModule.java    From kyoko with MIT License 5 votes vote down vote up
@Singleton
@Provides
EbeanServer ebeanServer(EbeanClassRegistry registry, ModuleManager moduleManager) {
    var settings = Settings.instance();
    var config = new ServerConfig();
    config.setName("pg");

    var dataSource = new DataSourceConfig()
            .setDriver(settings.jdbcDriverClass())
            .setUrl(settings.databaseUrl())
            .setUsername(settings.jdbcUser())
            .setPassword(settings.jdbcPassword());

    config.setDataSourceConfig(dataSource);
    config.setDefaultServer(true);
    config.setDdlCreateOnly(true);

    registry.get().forEach(className -> {
        try {
            config.addClass(moduleManager.findClass(className.replace("/", ".")).asSubclass(DatabaseEntity.class));
        } catch (Exception e) {
            logger.error("Error registering database entity class: {}", className, e);
        }
    });

    return EbeanServerFactory.create(config);
}
 
Example #4
Source File: DefaultEbeanConfig.java    From play-ebean with Apache License 2.0 5 votes vote down vote up
private void setServerConfigDataSource(String key, ServerConfig serverConfig) {
    try {
        serverConfig.setDataSource(new WrappingDatasource(dbApi.getDatabase(key).getDataSource()));
    } catch(Exception e) {
        throw new ConfigException.BadValue(
                "ebean." + key,
                e.getMessage(),
                e
        );
    }
}
 
Example #5
Source File: DefaultEbeanConfig.java    From play-ebean with Apache License 2.0 5 votes vote down vote up
private void addModelClassesToServerConfig(String key, ServerConfig serverConfig, Set<String> classes) {
    for (String clazz: classes) {
        try {
            serverConfig.addClass(Class.forName(clazz, true, environment.classLoader()));
        } catch (Exception e) {
            throw new ConfigException.BadValue(
                "ebean." + key,
                "Cannot register class [" + clazz + "] in Ebean server",
                e
            );
        }
    }
}
 
Example #6
Source File: App2.java    From tutorials with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    ServerConfig cfg = new ServerConfig();
    cfg.setDefaultServer(true);
    Properties properties = new Properties();
    properties.put("ebean.db.ddl.generate", "true");
    properties.put("ebean.db.ddl.run", "true");
    properties.put("datasource.db.username", "sa");
    properties.put("datasource.db.password", "");
    properties.put("datasource.db.databaseUrl", "jdbc:h2:mem:app2");
    properties.put("datasource.db.databaseDriver", "org.h2.Driver");
    cfg.loadFromProperties(properties);
    EbeanServer server = EbeanServerFactory.create(cfg);

}
 
Example #7
Source File: EbeanConfig.java    From canal with Apache License 2.0 5 votes vote down vote up
@Bean("ebeanServer")
public EbeanServer ebeanServer(DataSource dataSource) {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setDefaultServer(true);
    serverConfig.setNamingConvention(new UnderscoreNamingConvention());
    List<String> packages = new ArrayList<>();
    packages.add("com.alibaba.otter.canal.admin.model");
    serverConfig.setPackages(packages);
    serverConfig.setName("ebeanServer");
    serverConfig.setDataSource(dataSource);
    serverConfig.setDatabaseSequenceBatchSize(1);
    serverConfig.setDdlGenerate(false);
    serverConfig.setDdlRun(false);
    return EbeanServerFactory.create(serverConfig);
}
 
Example #8
Source File: SampleConfig.java    From spring-data-ebean with Apache License 2.0 4 votes vote down vote up
@Bean
@Primary
public EbeanServer defaultEbeanServer(ServerConfig defaultEbeanServerConfig) {
  return EbeanServerFactory.create(defaultEbeanServerConfig);
}
 
Example #9
Source File: MyServerConfigStartup.java    From play-ebean with Apache License 2.0 4 votes vote down vote up
public void onStart(ServerConfig serverConfig) {
    serverConfig.setDatabaseSequenceBatchSize(1);
}
 
Example #10
Source File: DefaultEbeanConfig.java    From play-ebean with Apache License 2.0 4 votes vote down vote up
public DefaultEbeanConfig(String defaultServer, Map<String, ServerConfig> serverConfigs) {
    this.defaultServer = defaultServer;
    this.serverConfigs = serverConfigs;
}
 
Example #11
Source File: DefaultEbeanConfig.java    From play-ebean with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, ServerConfig> serverConfigs() {
    return serverConfigs;
}
 
Example #12
Source File: DefaultEbeanConfig.java    From play-ebean with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #13
Source File: SqlLimiterAutoConfigure.java    From sqlhelper with GNU Lesser General Public License v3.0 2 votes vote down vote up
@Override
public void preConfigure(ServerConfig serverConfig) {

}
 
Example #14
Source File: EbeanConfig.java    From play-ebean with Apache License 2.0 votes vote down vote up
Map<String, ServerConfig> serverConfigs();