There may be a way to do that with type listeners, but I haven't tried anything along those lines myself.

On 11/21/2013 08:53 AM, Todd Nine wrote:
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]
<mailto:[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(
        
MvccEntitySerializationStrateg__y.class).to(__MvccEntitySerializationStrateg__yImpl.class);


                  bind(
        
MvccLogEntrySerializationStrat__egy.class).to(__MvccLogEntrySerializationStrat__egyImpl.class);

                  //how do I bind both of the impls above to a
        Collection<Migration>

              }

        }

        Do I need to also add the MvccEntitySerializationStrateg__yImpl and
        theMvccLogEntrySerializationSt__rategyImpl 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.

Reply via email to