@@ -0,0 +1,1692 @@
+package ru.ydn.wicket.wicketorientdb.utils;%0A%0Aimport java.io.Serializable;%0A%0Aimport ru.ydn.wicket.wicketorientdb.DefaultODatabaseThreadLocalFactory;%0Aimport ru.ydn.wicket.wicketorientdb.IOrientDbSettings;%0Aimport ru.ydn.wicket.wicketorientdb.OrientDbWebApplication;%0Aimport ru.ydn.wicket.wicketorientdb.OrientDbWebSession;%0A%0Aimport com.orientechnologies.orient.core.db.ODatabase;%0Aimport com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;%0Aimport com.orientechnologies.orient.core.db.record.ODatabaseRecord;%0A%0Apublic abstract class DBClosure%3CV%3E implements Serializable%0A%7B%0A%09private final String dbUrl;%0A%09private final String username;%0A%09private final String password;%0A%09%0A%09public DBClosure()%0A%09%7B%0A%09%09IOrientDbSettings settings = getSettings();%0A%09%09this.dbUrl = settings.getDBUrl();%0A%09%09this.username = settings.getDBInstallatorUserName();%0A%09%09this.password = settings.getDBInstallatorUserPassword();%0A%09%7D%0A%09%0A%09public DBClosure(String dbUrl, String username, String password)%0A%09%7B%0A%09%09this.dbUrl = dbUrl;%0A%09%09this.username = username;%0A%09%09this.password = password;%0A%09%7D%0A%09%0A%09public final V execute()%0A%09%7B%0A%09%09ODatabaseRecord db = null;%0A%09%09ODatabaseRecord oldDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();%0A%09%09try%0A%09%09%7B%0A%09%09%09db = DefaultODatabaseThreadLocalFactory.castToODatabaseRecord(getSettings().getDatabasePool().acquire(dbUrl, username, password));%0A%09%09%09return execute(db);%0A%09%09%7D %0A%09%09finally%0A%09%09%7B%0A%09%09%09if(db!=null) db.close();%0A%09%09%09if(oldDb!=null) ODatabaseRecordThreadLocal.INSTANCE.set(oldDb);%0A%09%09%09else ODatabaseRecordThreadLocal.INSTANCE.remove();%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected IOrientDbSettings getSettings()%0A%09%7B%0A%09%09return OrientDbWebApplication.get().getOrientDbSettings();%0A%09%7D%0A%09%0A%09protected abstract V execute(ODatabaseRecord db);%0A%7D%0A

Add ability to execute some code on admin DB, if required