Spring + MongoDb

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring + MongoDb

Jeff Schneller
Has anyone implemented wicket with spring and mongodb.  I saw there was a project back in June about scala, wicket, spring, and mongodb but the scala portion is a bit confusing.  

Looking for a sample implementation/configuration to get going with.  

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Martin Grigorov-4
Hi,

Here is the Scala project you mention:
https://github.com/brunoborges/gamboa-project
If Scala confuses you then all you need is to find pure Java example
of Spring-Data-Mongodb and another one that uses Spring
services/repositories from Wicket (e.g. Phonebook example in
wicketstuff).

On Mon, Dec 12, 2011 at 6:18 AM, Jeff Schneller <[hidden email]> wrote:
> Has anyone implemented wicket with spring and mongodb.  I saw there was a project back in June about scala, wicket, spring, and mongodb but the scala portion is a bit confusing.
>
> Looking for a sample implementation/configuration to get going with.
>
> Thanks.
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Martijn Dashorst
Administrator
In reply to this post by Jeff Schneller
I've written a project with the plain mongodb java driver. Not too bad
IMO. I don't think there's a need to use spring-data-mongodb.

The code is currently closed, but I aim to open up some things in the
new year. In the mean time, here's my MongoRequestCycleListener:

import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;

import com.mongodb.DB;

public class MongoRequestCycleListener extends AbstractRequestCycleListener
                implements MongoProvider {
        private static final ThreadLocal<DB> db = new ThreadLocal<DB>();

        private final MongoProvider provider;

        public MongoRequestCycleListener(MongoProvider provider) {
                this.provider = provider;
        }

        @Override
        public DB getDB() {
                DB db = MongoRequestCycleListener.db.get();
                assert db != null;
                return db;
        }

        @Override
        public void onBeginRequest(RequestCycle cycle) {
                DB threadLocalDB = provider.getDB();
                threadLocalDB.requestStart();
                db.set(threadLocalDB);
        }

        @Override
        public void onEndRequest(RequestCycle cycle) {
                DB db2 = db.get();
                if (db2 != null) {
                        db2.requestDone();
                        db.remove();
                }
        }
}

and the MongoProvider interface:

import com.mongodb.DB;

public interface MongoProvider {
        public DB getDB();
}

Now all you need to do is inject a mongo provider into your services
and you can get the DB. For example:

public List<User> byName(String name) {
    DBCollection users = provider.getDB().getCollection("Users");
    DBObject result = users.find(new BasicDBObject("name", name));
    // ... convert result in list of users.
    return convertedList;
}

In onBeginRequest() I start a 'mongo transaction' and in onEndRequest
I close that transaction. It is not a transaction in the common SQL
world sense, but should suffice.

Martijn

On Mon, Dec 12, 2011 at 6:18 AM, Jeff Schneller <[hidden email]> wrote:
> Has anyone implemented wicket with spring and mongodb.  I saw there was a project back in June about scala, wicket, spring, and mongodb but the scala portion is a bit confusing.
>
> Looking for a sample implementation/configuration to get going with.
>
> Thanks.
>



--
Become a Wicket expert, learn from the best: http://wicketinaction.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Jeff Schneller
In reply to this post by Martin Grigorov-4
Right.  I have spring setup with services.  The issue I am having is Spring-Data-Mongodb uses additional Spring annotations.  Do those work with Wicket?  As Martijn suggested I could just use the mongodb without the spring-data layer.  Will I run into problems in the future if I go this route?  

Any examples of spring-data annotations being used with wicket and not just the wicket annotation of @SpringBean or the JPA annotations?



On Monday, December 12, 2011 at 3:50 AM, Martin Grigorov wrote:

> Hi,
>
> Here is the Scala project you mention:
> https://github.com/brunoborges/gamboa-project
> If Scala confuses you then all you need is to find pure Java example
> of Spring-Data-Mongodb and another one that uses Spring
> services/repositories from Wicket (e.g. Phonebook example in
> wicketstuff).
>
> On Mon, Dec 12, 2011 at 6:18 AM, Jeff Schneller <[hidden email] (mailto:[hidden email])> wrote:
> > Has anyone implemented wicket with spring and mongodb.  I saw there was a project back in June about scala, wicket, spring, and mongodb but the scala portion is a bit confusing.
> >
> > Looking for a sample implementation/configuration to get going with.
> >
> > Thanks.
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email] (mailto:[hidden email])
> For additional commands, e-mail: [hidden email] (mailto:[hidden email])
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Uwe Schäfer-2
On 12/13/2011 05:28 AM, Jeff Schneller wrote:
> As Martijn suggested I could just use the mongodb without the spring-data layer.  Will I run into problems in the future if I go this route?

you could also use morphia with/or without spring

cu uwe

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Jeff Schneller
How stable is morphia?  is it ready for production use?  Have you used it with wicket?

--  
Jeff Schneller
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Tuesday, December 13, 2011 at 3:31 PM, Uwe Schäfer wrote:

> On 12/13/2011 05:28 AM, Jeff Schneller wrote:
> > As Martijn suggested I could just use the mongodb without the spring-data layer. Will I run into problems in the future if I go this route?
>  
>  
> you could also use morphia with/or without spring
>  
> cu uwe
>  
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email] (mailto:[hidden email])
> For additional commands, e-mail: [hidden email] (mailto:[hidden email])
>  
>  


Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Uwe Schäfer-2
On 12/14/2011 06:51 AM, Jeff Schneller wrote:
> How stable is morphia?

it did not change much for about a year now. it has its warts, but it
works. (just like mongodb)

it has 10gen backing, as scott is a 10gen employee.

yes, we´re using it with wicket for almost 2 years now.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Spring + MongoDb

Bruno Borges
In reply to this post by Martin Grigorov-4
Just to let you all know that the Gamboa Project has moved to individual
repositories under the organization Gamboa at http://github.com/gamboa

There are Wicket+Scala archetypes for MongoDB, CouchDB and Java EE 6 (JPA).

The Wicket DSL for Scala is now available too under the wicket-scala
project at wicketstuff.

Martin, thanks for sharing =)

*Bruno Borges*
(21) 7672-7099
*www.brunoborges.com*



On Mon, Dec 12, 2011 at 6:50 AM, Martin Grigorov <[hidden email]>wrote:

> Hi,
>
> Here is the Scala project you mention:
> https://github.com/brunoborges/gamboa-project
> If Scala confuses you then all you need is to find pure Java example
> of Spring-Data-Mongodb and another one that uses Spring
> services/repositories from Wicket (e.g. Phonebook example in
> wicketstuff).
>
> On Mon, Dec 12, 2011 at 6:18 AM, Jeff Schneller <[hidden email]> wrote:
> > Has anyone implemented wicket with spring and mongodb.  I saw there was
> a project back in June about scala, wicket, spring, and mongodb but the
> scala portion is a bit confusing.
> >
> > Looking for a sample implementation/configuration to get going with.
> >
> > Thanks.
> >
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>