On Wed, Feb 25, 2009 at 12:05 AM, Praveena Manvi
<[email protected]> wrote:
> I guess the question which persistence technology is better suited to take
> maximum advantage of Guice?
> I guess JPA is already mature in terms of using annotation & dependcy
> injection. There is lot of scope for using the same for iBatis, BTW Clinton
> Begin (Author of iBatis) never liked the idea of Java5/Generics etc..  :)

Just to clarify, Clinton isn't against "progress," he's just upset
with how they implemented things in Java5. To view some of his posts
on the topic:

His two big nasties...
 * http://www.clintonbegin.com/2008/02/clintons-java-5-rant.html
 * http://www.clintonbegin.com/2008/05/re-java-haters-gtfo.html

Help understanding that he's not out to get Java...
 * http://www.clintonbegin.com/2008/02/party-like-its-2002.html
 * http://www.clintonbegin.com/2008/05/re-would-type-inference-help-java_15.html
 * http://www.clintonbegin.com/2008/02/backward-compatibilitybe-damned.html


> Rick-> Could you please help us to understand how Guice was used with iBatis
> (if you have integrated both).

There really wasn't much to it from how I did things. It was just so
simple. (Someone later pointed out though that I should be using
Guice2 private modules for this below, but for now what I have is
working.)

Here's how I'm currently doing things (and if things are poor or could
be done better, someone just pipe up and I'll fix it). In my case I
needed to go against two different DBs, but if you just have one
things are even easier. Since I have different DBs, I have daos that
use one db extends from the appropriate DB dao. If you just have one
DB you are going against, a single BaseDAO below with the injected
SqlMapClient is fine. ) I'm showing multiple datasource usage below:

If format looks bad below, I pasted it here: http://pastie.org/399721

//module class - DaoUtil not shown below just does the typical load of
sqlMap client from a config file

public class OndpServicesModule extends AbstractModule {

�...@override
   protected void configure() {

       SqlMapClient guiSqlClient =
DaoUtil.loadSqlMapClient("sqlMapConfig-gui.xml");
       SqlMapClient ndaSqlClient =
DaoUtil.loadSqlMapClient("sqlMapConfig-nda.xml");

       
bind(SqlMapClient.class).annotatedWith(Names.named("GUI")).toInstance(guiSqlClient);
       
bind(SqlMapClient.class).annotatedWith(Names.named("NDA")).toInstance(ndaSqlClient);
   }
}


public abstract class BaseDAO {
   protected Log log = LogFactory.getLog(this.getClass());

   //injected in setter of implementing class (ie GuiDAO, NdaDAO, etc.)
   protected SqlMapClient sqlMapClient;

   //method to return the thread's instance for use in service
classes, if you need transactions
   public SqlMapClient getSqlMapClient() {
       return this.sqlMapClient;
   }
}

//I have another one of these NdaBaseDAO that has @Named("NDA")
datasource as well.
public abstract class GuiBaseDAO extends BaseDAO {

  �...@inject
   protected void setSqlMapClient(@Named("GUI") SqlMapClient sqlMapClient) {
       this.sqlMapClient = sqlMapClient;
   }

}


//A typical DAO example:
public class DemographicDAO extends GuiBaseDAO {

   public List<EDSDemographic> getDefaultDemographicData(Integer
sampleTypeKey, List<Integer> tierIDs ) throws SQLException {
       Map<String, Object> props = new HashMap<String, Object>(2);
       props.put("sampleTypeKey", sampleTypeKey);
       props.put("tierIDs", tierIDs);
       return 
sqlMapClient.queryForList("Demographic.edsDemographicDefaultValues",
props);
   }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to