package com.passbook;

import com.passbook.core.Device;
import com.passbook.core.Registration;
import com.passbook.db.DeviceDAO;
import com.passbook.db.RegistrationDAO;
import com.passbook.resources.PassbookDevicesResource;
import com.passbook.resources.PassbookLogResource;
import com.passbook.resources.PassbookPassesResource;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.db.DatabaseConfiguration;
import com.yammer.dropwizard.hibernate.HibernateBundle;

public class PassbookService extends Service<PassbookConfiguration> {

    private final HibernateBundle<PassbookConfiguration> hibernate =
            new HibernateBundle<PassbookConfiguration>(Device.class, Registration.class) {
                @Override
                public DatabaseConfiguration getDatabaseConfiguration(final PassbookConfiguration configuration) {
                    return configuration.getDatabaseConfiguration();
                }
            };

    public static void main(String[] args) throws Exception {
        new PassbookService().run(args);
    }

    @Override
    public void initialize(Bootstrap<PassbookConfiguration> bootstrap) {
        bootstrap.addBundle(hibernate);
    }

    @Override
    public void run(PassbookConfiguration configuration, Environment environment) throws Exception {
        final DeviceDAO deviceDAO = new DeviceDAO(hibernate.getSessionFactory());
        final RegistrationDAO registrationDAO = new RegistrationDAO(hibernate.getSessionFactory());

        environment.addResource(new PassbookDevicesResource(deviceDAO, registrationDAO));
        environment.addResource(new PassbookPassesResource(deviceDAO));
        environment.addResource(new PassbookLogResource());
    }
}

@@ -566,16 +566,74 @@
 eBundle;
+%0Aimport com.yammer.dropwizard.migrations.MigrationsBundle;
 %0A%0Apublic
@@ -1337,16 +1337,311 @@
 ernate);
+%0A%0A        bootstrap.addBundle(new MigrationsBundle%3CPassbookConfiguration%3E() %7B%0A            @Override%0A            public DatabaseConfiguration getDatabaseConfiguration(PassbookConfiguration configuration) %7B%0A                return configuration.getDatabaseConfiguration();%0A            %7D%0A        %7D);
 %0A    %7D%0A%0A

add migrations bundle