com.avaje.ebean.EbeanServer Java Examples

The following examples show how to use com.avaje.ebean.EbeanServer. 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: DbDiffCommand.java    From dropwizard-experiment with MIT License 7 votes vote down vote up
@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
    // The existing database with migrations managed by Liquibase.
    DataSourceFactory outdatedDb = configuration.getDatabaseConfig();

    try (CloseableLiquibase outdatedLiquibase = createLiquibase(outdatedDb)) {
        // A temporary database that starts out empty and then gets the autogenerated Ebean table definitions applied.
        DataSourceFactory freshDb = EbeanConfigUtils.clone(outdatedDb);
        String url = outdatedDb.getUrl();
        freshDb.setUrl(url.substring(0, url.lastIndexOf("/")) + "/migrationdiff");

        // Creating the Ebean server makes it apply its table definitions to the database immediately.
        ServerConfig serverConfig = EbeanConfigUtils.createServerConfig(freshDb);
        serverConfig.setDdlGenerate(true);
        serverConfig.setDdlRun(true);
        EbeanServer ebeanServer = EbeanServerFactory.create(serverConfig);

        try (CloseableLiquibase freshLiquibase = createLiquibase(freshDb)) {
            // Create and print the differences between the two databases, i.e. a migration that should be applied to update to the newest Ebean definitions.
            DiffResult diff = outdatedLiquibase.diff(freshLiquibase.getDatabase(), outdatedLiquibase.getDatabase(), CompareControl.STANDARD);
            DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diff, new DiffOutputControl(false, false, true));
            diffToChangeLog.print(System.out);
        }
    }
}
 
Example #2
Source File: TodoListHK2Binder.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
@Override
    protected void configure() {
        bind(environment.metrics()).to(MetricRegistry.class);
        bind(ebeanBundle.getEbeanServer()).to(EbeanServer.class);

//        bindFactory(rabbitMqBundle.getQueueFactory("username", User.class))
//            .to(new TypeLiteral<MessageQueue<User>>() {})
//            .named("username");

        bindFactory(WidgetCrudFactory.class).to(new TypeLiteral<CrudService<Widget>>(){});

        // guice
//        bind(EmailService.class).toProvider(EmailServiceProvider.class);
//        bind(new TypeLiteral<HasSendGridConfiguration>(){}).toInstance(configuration);
    }
 
Example #3
Source File: OAuth2AuthorizationPasswordRequest.java    From dropwizard-experiment with MIT License 5 votes vote down vote up
@Override
public Optional<User> getValidUser(EbeanServer db) {
    User user = db.find(User.class).where().eq("username", username).findUnique();

    if (user != null && user.getPassword().equalsPlaintext(password)) {
        return Optional.of(user);
    } else {
        return Optional.absent();
    }
}
 
Example #4
Source File: EBeanDataRepositoryImpl.java    From java-persistence-frameworks-comparison with MIT License 4 votes vote down vote up
@Autowired
public EBeanDataRepositoryImpl(EbeanServer ebean) {
    this.ebean = ebean;
}
 
Example #5
Source File: DbTestsApplication.java    From java-persistence-frameworks-comparison with MIT License 4 votes vote down vote up
@Bean
public EbeanServer ebeanServer(ServerConfig serverConfig) {
    return EbeanServerFactory.create(serverConfig);
}
 
Example #6
Source File: WidgetCrudFactory.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public WidgetCrudFactory(EbeanServer db) {
    this.db = db;
}
 
Example #7
Source File: TodoListResource.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public TodoListResource(EbeanServer db) {
    super(new CrudService<>(TodoList.class, db));
}
 
Example #8
Source File: PasswordResetService.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public PasswordResetService(EbeanServer db, EmailService email) {
    this.db = db;
    this.email = email;
}
 
Example #9
Source File: EmailVerificationResource.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public EmailVerificationResource(EbeanServer db, PasswordResetService service) {
    this.db = db;
    this.service = service;
}
 
Example #10
Source File: UserResource.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public UserResource(EbeanServer db) {
    this.db = db;
}
 
Example #11
Source File: CrudService.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public CrudService(Class<T> type, EbeanServer db) {
    this.type = type;
    this.db = db;
}
 
Example #12
Source File: EbeanBundle.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
/**
 * Get the configured EbeanServer.
 * Only available after bundles have been initialized.
 */
public EbeanServer getEbeanServer() {
    Preconditions.checkNotNull(ebeanServer, "Ebean server not created yet (this happens during 'run' i.e. after 'initialize').");
    return ebeanServer;
}
 
Example #13
Source File: OAuth2AccessTokenResource.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Inject
public OAuth2AccessTokenResource(EbeanServer db) {
    this.db = db;
}
 
Example #14
Source File: LukkitPlugin.java    From Lukkit with MIT License 4 votes vote down vote up
public EbeanServer getDatabase() {
    // Deprecated
    return null;
}
 
Example #15
Source File: OAuth2AuthorizationRequest.java    From dropwizard-experiment with MIT License votes vote down vote up
Optional<User> getValidUser(EbeanServer db);