package ru.ydn.wicket.wicketorientdb;

import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.protocol.http.WebApplication;

import ru.ydn.wicket.wicketorientdb.security.WicketOrientDbAuthorizationStrategy;

import com.orientechnologies.orient.core.Orient;

public abstract class OrientDbWebApplication extends AuthenticatedWebApplication {
	private IOrientDbSettings orientDbSettings = new OrientDbSettings();

	@Override
	protected Class<? extends OrientDbWebSession> getWebSessionClass()
	{
		return OrientDbWebSession.class;
	}
	
	public IOrientDbSettings getOrientDbSettings()
	{
		return orientDbSettings;
	}
	
	public void setOrientDbSettings(IOrientDbSettings orientDbSettings)
	{
		this.orientDbSettings=orientDbSettings;
	}
	
	public static OrientDbWebApplication get()
    {
        return (OrientDbWebApplication) WebApplication.get();
    }

	@Override
	protected void init() {
		super.init();
		Orient.instance().registerThreadDatabaseFactory(new DefaultODatabaseThreadLocalFactory(this));
		getRequestCycleListeners().add(newTransactionRequestCycleListener());
		getRequestCycleListeners().add(new OrientDefaultExceptionsHandlingListener());
		getSecuritySettings().setAuthorizationStrategy(new WicketOrientDbAuthorizationStrategy(this));
	}
	
	protected TransactionRequestCycleListener newTransactionRequestCycleListener()
	{
		return new TransactionRequestCycleListener();
	}

}

@@ -32,16 +32,101 @@
 entdb;%0A%0A
+import org.apache.wicket.Application;%0Aimport org.apache.wicket.IApplicationListener;%0A
 import o
@@ -1381,16 +1381,326 @@
 this));%0A
+%09%09getApplicationListeners().add(new IApplicationListener() %7B%0A%09%09%09%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void onAfterInitialized(Application application) %7B%0A%09%09%09%09Orient.instance().removeShutdownHook();%0A%09%09%09%7D%0A%09%09%09@Override%0A%09%09%09public void onBeforeDestroyed(Application application) %7B%0A%09%09%09%09Orient.instance().shutdown();%0A%09%09%09%7D%0A%09%09%7D);%0A
 %09%7D%0A%09%0A%09pr

Fix for #5: Incorrect shutdown. Wicket should handle shutdown instead of Orient