Date: 2004-06-07T03:05:19
Editor: MarkoKocic <[EMAIL PROTECTED]>
Wiki: Jakarta HiveMind Wiki
Page: Examples
URL: http://wiki.apache.org/jakarta-hivemind/Examples
no comment
Change Log:
------------------------------------------------------------------------------
@@ -43,3 +43,73 @@
}
}
}}}
+
+----
+MarkoKocic:
+Ok, here's how to fetch Cayenne DataContext. Is there a better way?
+{{{
+hivemodule.sdl
+module (id=markko.hivemind version="1.0.0") {
+ service-point(id=CayenneService
interface=markko.hivemind.CayenneService) {
+ create-instance(class=markko.hivemind.CayenneServiceImpl)
+ interceptor (service-id=hivemind.LoggingInterceptor)
+ }
+
+ service-point(id=DataService interface=markko.hivemind.DataService) {
+ invoke-factory (service-id=hivemind.BuilderFactory)
{
+ construct (class=markko.hivemind.DataServiceImpl)
{
+ set-service (property=cayenneService
service-id=CayenneService)
+ }
+ }
+ interceptor (service-id=hivemind.LoggingInterceptor)
+ }
+}
+
+public interface CayenneService {
+ public DataContext getDataContext ();
+}
+
+public class CayenneServiceImpl implements CayenneService {
+ static {
+
Configuration.bootstrapSharedConfiguration(CayenneService.class);
+ }
+
+ public DataContext getDataContext() {
+ return
Configuration.getSharedConfiguration().getDomain().createDataContext();
+ }
+}
+
+public interface DataService {
+ public Korisnik authenticate(String username, String password);
+}
+
+public class DataServiceImpl implements DataService {
+
+ private CayenneService _cs;
+ public void setCayenneService(CayenneService cs) {
+ _cs = cs;
+ }
+ private DataContext getDataContext() {
+ return _cs.getDataContext();
+ }
+
+ public Korisnik authenticate(String username, String password) {
+ DataContext ctx = getDataContext();
+
+ Map params = new HashMap();
+ params.put("username", username);
+ params.put("password", password);
+ Expression qual = Expression.fromString("username = $username
and password = $password").expWithParameters(params);
+
+ SelectQuery query = new SelectQuery(Korisnik.class, qual);
+
+ List list = ctx.performQuery(query);
+ log.debug("size=" + list.size());
+ if (list.size() == 1)
+ return (Korisnik) list.get(0);
+ else
+ return null;
+ }
+}
+
+}}}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]