Search in sources :

Example 1 with IHookPosition

use of ru.ydn.wicket.wicketorientdb.components.IHookPosition in project wicket-orientdb by OrienteerBAP.

the class OrientDbWebApplication method init.

@Override
protected void init() {
    super.init();
    Orient.instance().registerThreadDatabaseFactory(new DefaultODatabaseThreadLocalFactory(this));
    Orient.instance().addDbLifecycleListener(new ODatabaseLifecycleListener() {

        private ORecordHook createHook(Class<? extends ORecordHook> clazz, ODatabaseInternal iDatabase) {
            if (!(iDatabase instanceof ODatabaseDocument))
                return null;
            try {
                return (ORecordHook) clazz.getConstructor(ODatabaseDocument.class).newInstance(iDatabase);
            } catch (Exception e) {
                try {
                    return (ORecordHook) clazz.newInstance();
                } catch (Exception e1) {
                    throw new IllegalStateException("Can't initialize hook " + clazz.getName(), e);
                }
            }
        }

        @Override
        public void onOpen(ODatabaseInternal iDatabase) {
            registerHooks(iDatabase);
        }

        @Override
        public void onCreate(ODatabaseInternal iDatabase) {
            registerHooks(iDatabase);
            // Fix for "feature" appeared in OrientDB 2.1.1
            // Issue: https://github.com/orientechnologies/orientdb/issues/4906
            fixOrientDBRights(iDatabase);
        }

        public void registerHooks(ODatabaseInternal iDatabase) {
            Set<ORecordHook> hooks = iDatabase.getHooks().keySet();
            List<Class<? extends ORecordHook>> hooksToRegister = new ArrayList<Class<? extends ORecordHook>>(getOrientDbSettings().getORecordHooks());
            for (ORecordHook hook : hooks) {
                if (hooksToRegister.contains(hook.getClass()))
                    hooksToRegister.remove(hook.getClass());
            }
            for (Class<? extends ORecordHook> oRecordHookClass : hooksToRegister) {
                ORecordHook hook = createHook(oRecordHookClass, iDatabase);
                if (hook != null) {
                    if (hook instanceof IHookPosition) {
                        iDatabase.registerHook(hook, ((IHookPosition) hook).getPosition());
                    } else {
                        iDatabase.registerHook(hook);
                    }
                }
            }
        }

        @Override
        public void onClose(ODatabaseInternal iDatabase) {
        /*NOP*/
        }

        @Override
        public void onDrop(ODatabaseInternal iDatabase) {
        /*NOP*/
        }

        public PRIORITY getPriority() {
            return PRIORITY.REGULAR;
        }

        @Override
        public void onCreateClass(ODatabaseInternal iDatabase, OClass iClass) {
        /*NOP*/
        }

        @Override
        public void onDropClass(ODatabaseInternal iDatabase, OClass iClass) {
        /*NOP*/
        }

        @Override
        public void onLocalNodeConfigurationRequest(ODocument arg0) {
        /*NOP*/
        }
    });
    getRequestCycleListeners().add(newTransactionRequestCycleListener());
    getRequestCycleListeners().add(new OrientDefaultExceptionsHandlingListener());
    getSecuritySettings().setAuthorizationStrategy(new WicketOrientDbAuthorizationStrategy(this));
    getApplicationListeners().add(new IApplicationListener() {

        @Override
        public void onAfterInitialized(Application application) {
            Orient.instance().startup();
            Orient.instance().removeShutdownHook();
        }

        @Override
        public void onBeforeDestroyed(Application application) {
            Orient.instance().shutdown();
        }
    });
    getAjaxRequestTargetListeners().add(new FixFormEncTypeListener());
    // workaround to support changing system users passwords in web interface
    getOrientDbSettings().getORecordHooks().add(OUserCatchPasswordHook.class);
    PropertyResolver.setLocator(this, new ODocumentPropertyLocator(new PropertyResolver.CachingPropertyLocator(new PropertyResolver.DefaultPropertyLocator())));
}
Also used : Set(java.util.Set) ODocumentPropertyLocator(ru.ydn.wicket.wicketorientdb.utils.ODocumentPropertyLocator) IHookPosition(ru.ydn.wicket.wicketorientdb.components.IHookPosition) PropertyResolver(org.apache.wicket.core.util.lang.PropertyResolver) FixFormEncTypeListener(ru.ydn.wicket.wicketorientdb.utils.FixFormEncTypeListener) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ArrayList(java.util.ArrayList) List(java.util.List) ODatabaseLifecycleListener(com.orientechnologies.orient.core.db.ODatabaseLifecycleListener) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) InvocationTargetException(java.lang.reflect.InvocationTargetException) ODatabaseInternal(com.orientechnologies.orient.core.db.ODatabaseInternal) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) WicketOrientDbAuthorizationStrategy(ru.ydn.wicket.wicketorientdb.security.WicketOrientDbAuthorizationStrategy) IApplicationListener(org.apache.wicket.IApplicationListener) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) AuthenticatedWebApplication(org.apache.wicket.authroles.authentication.AuthenticatedWebApplication) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication)

Aggregations

ODatabaseInternal (com.orientechnologies.orient.core.db.ODatabaseInternal)1 ODatabaseLifecycleListener (com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Application (org.apache.wicket.Application)1 IApplicationListener (org.apache.wicket.IApplicationListener)1 AuthenticatedWebApplication (org.apache.wicket.authroles.authentication.AuthenticatedWebApplication)1 PropertyResolver (org.apache.wicket.core.util.lang.PropertyResolver)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 IHookPosition (ru.ydn.wicket.wicketorientdb.components.IHookPosition)1 WicketOrientDbAuthorizationStrategy (ru.ydn.wicket.wicketorientdb.security.WicketOrientDbAuthorizationStrategy)1 FixFormEncTypeListener (ru.ydn.wicket.wicketorientdb.utils.FixFormEncTypeListener)1 ODocumentPropertyLocator (ru.ydn.wicket.wicketorientdb.utils.ODocumentPropertyLocator)1