Thanks for the help Marshall, This is a very rudimentary version of migration. It's basically an idempotent, "does this Column Family exist", so order isn't important. Thanks for your help, I wasn't sure if there was some automatic way to pick up a class that is being mapped to an interface that also implements the "Migration" interface.
On Thu, Nov 21, 2013 at 9:26 AM, Marshall Pierce <[email protected]>wrote: > On 11/20/2013 05:52 PM, Todd Nine wrote: > >> Hi guys, >> I have several classes which interact with Cassandra. All of the >> implementations implement both the I/O interface required (similar to a >> DAO) and a Migrator interface. I want to be able to have an >> implementation that is simply a MigrationManager interface. For this >> interface, I would have the following impl. >> >> >> /** >> * @author tnine >> */ >> public class MigrationManagerImpl implements MigrationManager { >> >> private final Set<Migration> migrations; >> >> >> @Inject >> public MigrationManagerImpl( final Set<Migration> migrations ) { >> this.migrations = migrations; >> } >> >> >> @Override >> public void migrate() { >> >> for(Migration migration: migrations){ >> for( ColumnFamilyDefinition cf : >> migration.getColumnFamilies()) { >> //do migration here. >> } >> } >> } >> } >> >> >> >> I'm new to Guice, it seems much cleaner and more deterministic/easier to >> user than Spring. I'm trying to keep all my low level I/O components in >> their own Module. To do what I need above, how would I set this up in >> my module? I've tried this. >> >> >> >> public class CollectionModule extends AbstractModule{ >> >> /** >> * The location of the properties file >> */ >> private static final String CASS_PROPS = "cassandra.properties"; >> >> >> >> >> @Override >> protected void configure() { >> >> //bind our cassandra properties >> Names.bindProperties(binder(), PropertyUtils.loadFromClassPath( >> CASS_PROPS)); >> >> //Load the cassandra url if set on the system properties >> Names.bindProperties( binder(), >> PropertyUtils.loadSystemProperties( >> AstynaxKeyspaceProvider.getRuntimeOptions() ) ); >> >> //bind our keyspace to the AstynaxKeyspaceProvider >> bind(Keyspace.class).toProvider(AstynaxKeyspaceProvider.class ); >> >> >> bind( >> MvccEntitySerializationStrategy.class).to(MvccEntitySerializationStrateg >> yImpl.class); >> >> >> bind( >> MvccLogEntrySerializationStrategy.class).to( >> MvccLogEntrySerializationStrategyImpl.class); >> >> //how do I bind both of the impls above to a >> Collection<Migration> >> >> } >> >> } >> >> Do I need to also add the MvccEntitySerializationStrategyImpl and >> theMvccLogEntrySerializationStrategyImpl classes to a Multibindings for >> the Migration interface? >> >> Thanks, >> Todd >> >> > > A Multibinding will get you a Set<Migration> just as you have in your > MigrationManagerImpl, so that's the way to go. > > Given the fact that you're working with migrations, I'm guessing order may > be important, so note that the Set is not necessarily going to iterate in > the order you bound the implementations. > > -Marshall > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/groups/opt_out.
