package ru.ydn.wicket.wicketorientdb;

import org.apache.wicket.Application;
import org.apache.wicket.IApplicationListener;

import com.orientechnologies.orient.core.db.record.ODatabaseRecord;

public abstract class AbstractDataInstallator implements IApplicationListener
{
	@Override
	public void onAfterInitialized(Application application) {
		OrientDbWebApplication app = (OrientDbWebApplication)application;
		IOrientDbSettings settings = app.getOrientDbSettings();
		String username = settings.getDBInstallatorUserName();
		String password = settings.getDBInstallatorUserPassword();
		ODatabaseRecord db = DefaultODatabaseThreadLocalFactory.castToODatabaseRecord(settings.getDatabasePool().acquire(settings.getDBUrl(), username, password));
		db.begin();
		try
		{
			installData(db);
			db.commit();
		}
		catch(Exception ex)
		{
			db.rollback();
		}
		finally
		{
			db.close();
		}
	}
	
	protected abstract void installData(ODatabaseRecord db);

	@Override
	public void onBeforeDestroyed(Application application) {
		
	}

}

@@ -405,16 +405,282 @@
 cation;%0A
+%09%09ODatabaseRecord db = getDatabase(app);%0A%09%09db.begin();%0A%09%09try%0A%09%09%7B%0A%09%09%09installData(app, db);%0A%09%09%09db.commit();%0A%09%09%7D%0A%09%09catch(Exception ex)%0A%09%09%7B%0A%09%09%09db.rollback();%0A%09%09%7D%0A%09%09finally%0A%09%09%7B%0A%09%09%09db.close();%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected ODatabaseRecord getDatabase(OrientDbWebApplication app)%0A%09%7B%0A
 %09%09IOrien
@@ -849,36 +849,22 @@
 rd();%0A%09%09
-ODatabaseRecord db =
+return
  Default
@@ -995,153 +995,8 @@
 ));%0A
-%09%09db.begin();%0A%09%09try%0A%09%09%7B%0A%09%09%09installData(db);%0A%09%09%09db.commit();%0A%09%09%7D%0A%09%09catch(Exception ex)%0A%09%09%7B%0A%09%09%09db.rollback();%0A%09%09%7D%0A%09%09finally%0A%09%09%7B%0A%09%09%09db.close();%0A%09%09%7D%0A
 %09%7D%0A%09
@@ -1033,16 +1033,44 @@
 allData(
+OrientDbWebApplication app, 
 ODatabas

Allow child classes to obtain db