No, you're certainly not stupid, it is not there. Sorry about that. You
can get it from Wicket stuff's CVS. I allways forget that there are a
lot of people who don't immediately start checking out projects from CVS
(as I do).

I've attached the two source files that matter. Have fun.

Eelco

Christian Essl wrote:

Thank you for your prompt reply.

I've been looking already for the cdapp, but I could not find it. I looked at the sf downlaod page of Wicket and Wicket-Stuff and there seems to be no download for wicket-contrib-examples. The only thing I found was the running example at wicket-library - but no link to download. Propably I am just too stupid to find it. Can you give me a link?

Browsing the api I found a factory method for RequestCycle but this is on Session (newRequestCycle) and is documented as wicket internal. Is this the right method?

Thanks,
Christian

On Wed, 06 Jul 2005 14:00:25 +0200, Eelco Hillenius <[EMAIL PROTECTED]> wrote:

You can create your own RequestCycle implementation for this. Override the factory method in (Web)Application to acchieve this.

See the cdapp example (wicket-contrib-examples of Wicket Stuff) for an example of this (CdAppRequestCycle, CdAppRequestCycle).

Eelco


Christian Essl wrote:

Hi,

I want to bind the current Session to a thread-local for the current request.

Is there a callback method which indicates a request-start and end.

Looking at the WicketServlet IMO I could use WebApplication.newWebrequest() and override WebResponse.close(). However this seems a bit hacky. Is there a better way?

Thanks,
Christian


___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de



-------------------------------------------------------
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





/*
 * $Id: CdApplication.java,v 1.3 2005/04/26 21:29:17 eelco12 Exp $ $Revision:
 * 1.1 $ $Date: 2005/04/26 21:29:17 $
 * 
 * ==================================================================== Licensed
 * under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package wicket.examples.cdapp;

import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import wicket.ApplicationSettings;
import wicket.IRequestCycleFactory;
import wicket.ISessionFactory;
import wicket.Request;
import wicket.RequestCycle;
import wicket.Response;
import wicket.Session;
import wicket.examples.WicketExampleApplication;
import wicket.examples.cdapp.util.DatabaseUtil;
import wicket.protocol.http.WebRequest;
import wicket.protocol.http.WebSession;

/**
 * Wicket test application.
 * 
 * @author Eelco Hillenius
 */
public class CdApplication extends WicketExampleApplication implements ISessionFactory
{
	/** Logger. */
	private static Log log = LogFactory.getLog(CdApplication.class);

	/** hibernate session factory. */
	private final SessionFactory sessionFactory;

	/**
	 * custom request cycle factory.
	 */
	private IRequestCycleFactory requestCycleFactory = new IRequestCycleFactory()
	{
		public RequestCycle newRequestCycle(Session session, Request request, Response response)
		{
			return new CdAppRequestCycle((WebSession)session, (WebRequest)request, response, sessionFactory);
		}
		
	};

	/**
	 * Constructor
	 */
	public CdApplication()
	{
		super();
		try
		{
			final Configuration configuration = new Configuration();
			configuration.configure();
			// build hibernate SessionFactory for this application instance
			sessionFactory = configuration.buildSessionFactory();
			// create database
			new DatabaseUtil(configuration).createDatabase();
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}

		ApplicationSettings settings = getSettings();
		settings.setThrowExceptionOnMissingResource(false);
		getPages().setHomePage(Home.class);

		setSessionFactory(this);
	}

	/**
	 * @see wicket.ISessionFactory#newSession()
	 */
	public Session newSession()
	{
		return new WebSession(CdApplication.this)
		{
			/**
			 * @see wicket.protocol.http.WebSession#getRequestCycleFactory()
			 */
			protected IRequestCycleFactory getRequestCycleFactory()
			{
				return requestCycleFactory;
			}
		};
	}
}
/*
 * $Id: CdAppRequestCycle.java,v 1.2 2005/05/21 16:11:17 eelco12 Exp $
 * $Revision: 1.2 $
 * $Date: 2005/05/21 16:11:17 $
 *
 * ====================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wicket.examples.cdapp;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import wicket.Response;
import wicket.protocol.http.WebRequest;
import wicket.protocol.http.WebRequestCycle;
import wicket.protocol.http.WebSession;

/**
 * Special request cycle for this application that opens and closes a hibernate session
 * for each request.
 */
public final class CdAppRequestCycle extends WebRequestCycle
{
	/** the Hibernate session factory. */
	private final SessionFactory sessionFactory;

	/** the current hibernate session. */
	private Session session = null;

	/**
	 * Construct.
	 * @param session session object
	 * @param request request object
	 * @param response response object
	 * @param sessionFactory hibernate session factory
	 */
	public CdAppRequestCycle(WebSession session,
			WebRequest request, Response response, SessionFactory sessionFactory)
	{
		super(session, request, response);
		this.sessionFactory = sessionFactory;
	}

	/**
	 * @see wicket.RequestCycle#onEndRequest()
	 */
	protected void onEndRequest()
	{
		if(session != null)
		{
			try
			{
				session.close();
			}
			catch (HibernateException e)
			{
				throw new RuntimeException(e);
			}
			finally
			{
				session = null;
			}
		}
	}

	/**
	 * Gets the hibernate session for this request.
	 * @return the session
	 */
	public Session getHibernateSession()
	{
		if(session == null)
		{
			try
			{
				// lazy load the session
				session = sessionFactory.openSession();
			}
			catch (HibernateException e)
			{
				throw new RuntimeException(e);
			}
		}
		return session;
	}
}

Reply via email to