io.ebean.EbeanServerFactory Java Examples

The following examples show how to use io.ebean.EbeanServerFactory. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: EbeanDynamicEvolutions.java    From play-ebean with Apache License 2.0 4 votes vote down vote up
/**
 * Initialise the Ebean servers.
 */
public void start() {
    config.serverConfigs().forEach((key, serverConfig) -> servers.put(key, EbeanServerFactory.create(serverConfig)));
}