thanks. it might not be complete yet, but i hope it's a good start at something simple.

<rant scope="general">
this rant isn't in response to you or anyone on this list... i'm just venting....

one of the many reasons i'm so sick of software lately is that nobody ever takes the time to think things through. that's why we've got all these stupid industry fads
and buzzwords and people naming classes "EntityBaseImplDelegate".

there is a time and a place for abstraction and flexibility. everything should not
be malleable.  everything should not be named abstractly.  EVERYTHING SHOULD
NOT BE AN INTERFACE!  is anyone out there listening to me!?  and the latest
buzzword should not be in every project. trying to blindly apply design patterns, interfaces and fancy abstractions is not always a sign of mature design. in fact,
it's often quite the opposite!  i'm reminded of this quote:

"Poor Faulkner. Does he really think big emotions come from big words? He
thinks I don't know the ten-dollar words. I know them all right. But there are
older and simpler and better words, and those are the ones I use."

  -- Ernest Hemmingway

there is no magic design pattern that when you apply it religiously makes everything better. everyone needs to stop looking for a better religion and realize that we've got limited tools, limited abilities and limited problems and that the first draft of anything is shit. it's the rewriting and the naming and the simplifying that makes something good. instead of trying to solve problems you don't have, try solving a simple one
that you do have and really nail it.

coding is like playing guitar. it takes FOREVER to make it look easy and sound great. and yet, everyone starts out by trying to play van halen's "eruption". i wish
the whole software industry would just learn to play the blues well first.
</rant>

Paul Diaconescu wrote:

Wow. This is really nice. / Paul

Jonathan Locke wrote:

i'm working on a hibernate wicket project myself right now and i've been
checking some stuff into wicket-contrib-database under wicket-stuff. i'm
not really developing this with other people yet, but it might be useful
anyway.

the motivation of this package is to hugely lower the entrypoint for
making db driven wicket apps.  although i can't help people learn this
right now, i'm willing to fix any important bugs because i'm using it.
otoh, i think/hope you'll find it pretty simple to understand anyway. to use, you do something like the following...

1. create DatabaseWebApplication subclass, set database and create
  custom session factory (which you probably need to do anyway)

public class VoiceTribeWebApplication extends DatabaseWebApplication
{
    public VoiceTribeWebApplication()
    {
        setDatabase(new VoiceTribeDatabase());
    }

    protected ISessionFactory getSessionFactory()
    {
        return new ISessionFactory()
        {
            public Session newSession()
            {
return new VoiceTribeWebSession(VoiceTribeWebApplication.this);
            }
        };
    }

    ...
}

2. create trivial DatabaseWebSession subclass returned by custom
session factory. again, you probably need to do this anyway for a real application that has something like a user that signs in...
  so no extra work here.

public class VoiceTribeWebSession extends DatabaseWebSession
{
    // Any session data here (like signed-in user)

    public VoiceTribeWebSession(VoiceTribeWebApplication application)
    {
        super(application);
    }

    ...
}

3. create database subclass.  call any subclass-specific configuration
  methods.  then call formatTables() to set up a fresh database (or
  don't if you don't want to start over each time)

public class VoiceTribeDatabase extends MySqlHibernateDatabase
{
    public VoiceTribeDatabase()
    {
final Configuration configuration = newAnnotationConfiguration();
        configuration.addClass(User.class);
        configuration.addClass(Commentary.class);
        configure(configuration);
        formatTables();
        populateTables();
    }

    private void populateTables()
{ final User jonathan = new User();
        jonathan.setFirstName("Jonathan");
        jonathan.setLastName("Locke");
final DatabaseSession session = newDatabaseSession();
        session.save(jonathan);
        session.close();
    }
}

4. create base web page to hold DAOs.

public class VoiceTribeWebPage extends DatabaseWebPage
{
    ...
protected final UserDao getUserDao()
    {
        return (UserDao)newDao(UserDao.class);
    }
}

5. create DAOA impl. for your particular database subtype
  (note, only find methods are required since save/update/etc
   are generic to any Database/DatabaseSession subclass)

public final class UserDao extends HibernateDao
{
    public User findUser(String email)
    {
        try
        {
            Query query = getHibernateSession().createQuery(
"from " + User.class.getName() + " as u where u.email = :email");
            query.setString("email", email);
            return (User)query.uniqueResult();
        }
        catch (Exception e)
        {
            throw new DatabaseException(e);
        }
    }

    public List findUsers()
    {
        return super.findAll(User.class);
    }
}

6. subclass your new base page with the DAOs in it and
  use them...  when you're ready to save/update/etc,
  there are generic methods in DatabaseWebPage.

public class UserEditPage extends VoiceTribeWebPage
{
    public UserEditPage()
    {
        final User user = getUserDao().findUser(...);
        if (user != null)
        {
            add(new UserEditForm(user));
        }
    }

    public class UserEditForm extends UploadForm
    {
        ...

        @Override
        protected void onSubmit()
        {
            User user = (User)getModelObject();

// Update using database associated with // application that created this web page
            update(user);
        }
    }
}




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to