Search in sources :

Example 1 with JournaledEngine

use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.

the class MemoryDatabase method createJournaledEngine.

private JournaledEngine createJournaledEngine(PluginFactory factory, PersistentFactory persistentFactory) throws ClassNotFoundException {
    if (cached) {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

            @Override
            protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
            }
        };
        CachedEngine cachedEngine = new CachedEngine(journaledEngine2);
        for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
        this.engine = cachedEngine;
        return journaledEngine2;
    } else {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
        this.engine = journaledEngine2;
        return journaledEngine2;
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) PluginFactory(com.ramussoft.common.PluginFactory) Plugin(com.ramussoft.common.Plugin)

Example 2 with JournaledEngine

use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.

the class LightClient method getEngine.

@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
    try {
        Journal journal = new Journal(null, -1l);
        journal.setEnable(false);
        final JournaledEngine journaledEngine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(null), accessor);
        Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Engine.class, Journaled.class }, new InvocationHandler() {

            private Journaled journaled = new Journaled() {

                boolean started = false;

                @Override
                public void undoUserTransaction() {
                }

                @Override
                public void startUserTransaction() {
                    started = true;
                }

                @Override
                public void setNoUndoPoint() {
                }

                @Override
                public void setEnable(boolean b) {
                }

                @Override
                public void rollbackUserTransaction() {
                    started = false;
                }

                @Override
                public void removeJournalListener(JournalListener listener) {
                }

                @Override
                public void redoUserTransaction() {
                }

                @Override
                public boolean isUserTransactionStarted() {
                    return started;
                }

                @Override
                public boolean isEnable() {
                    return false;
                }

                @Override
                public JournalListener[] getJournalListeners() {
                    return new JournalListener[] {};
                }

                @Override
                public void commitUserTransaction() {
                    started = false;
                }

                @Override
                public void close() {
                }

                @Override
                public boolean canUndo() {
                    return false;
                }

                @Override
                public boolean canRedo() {
                    return false;
                }

                @Override
                public void addJournalListener(JournalListener listener) {
                }

                @Override
                public long getBranch() {
                    return -1l;
                }
            };

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if (method.getDeclaringClass().equals(Journaled.class))
                    return method.invoke(journaled, args);
                return method.invoke(journaledEngine, args);
            }
        });
        return engine;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) JournalListener(com.ramussoft.common.journal.event.JournalListener) Journal(com.ramussoft.common.journal.Journal) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Journaled(com.ramussoft.common.journal.Journaled) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine)

Example 3 with JournaledEngine

use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.

the class EngineFactory method createJournaledEngine.

public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
    try {
        JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
        suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        suits.add(new IDEF0PluginProvider());
        Properties ps = getPropeties();
        if (ps != null) {
            String suitNames = ps.getProperty("AdditionalSuits");
            if (suitNames != null)
                PluginFactory.loadAdditionalSuits(suitNames, suits);
            canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
        }
        suits.addAll(getAdditionalSuits());
        createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
        factory = createPluginFactory(suits);
        String prefix = "ramus_";
        impl = new ServerIEngineImpl(0, template, prefix, factory);
        accessor = impl.getAccessor();
        persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
        persistentFactory.rebuild();
        checkIfGroupsExists();
        Engine result;
        Journaled journaled;
        if (cachedData == null) {
            JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
            result = journaledEngine2;
            journaled = journaledEngine2.getJournal();
        } else {
            JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

                @Override
                protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
                }
            };
            journaled = engine.getJournal();
            CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
            for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
            result = cachedEngine;
        }
        EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
        log = new Log(result, journaled) {

            protected Event createEvent(String type, UpdateEventCallback callback) {
                String user = "admin";
                if (impl.getServerAccessRules() != null)
                    user = impl.getServerAccessRules().getUser().getLogin();
                long id = impl.nextValue("qualifiers_log_seq");
                return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
            }
        };
        log.addExtension(engineLogExtension);
        log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) UniversalPersistentFactory(com.ramussoft.core.persistent.UniversalPersistentFactory) EngineLogExtension(com.ramussoft.common.logger.EngineLogExtension) Log(com.ramussoft.common.logger.Log) ILog(com.ramussoft.common.logger.ILog) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) Properties(java.util.Properties) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) UpdateEventCallback(com.ramussoft.common.logger.UpdateEventCallback) Journaled(com.ramussoft.common.journal.Journaled) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) Event(com.ramussoft.common.logger.Event) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin) PersistentsPlugin(com.ramussoft.core.persistent.PersistentsPlugin) AbstractPlugin(com.ramussoft.common.AbstractPlugin)

Example 4 with JournaledEngine

use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.

the class ClientServiceImpl method replaceElements.

@Override
public byte[] replaceElements(Element[] oldElements, Element newElement) {
    Journal journal;
    Engine engine = server.getEngine();
    if (engine instanceof JournaledEngine) {
        journal = ((JournaledEngine) engine).getJournal();
    } else {
        journal = ((JournaledEngine) ((CachedEngine) engine).getSource()).getJournal();
    }
    synchronized (server) {
        try {
            journal.startUserTransaction();
            server.getEngine().replaceElements(oldElements, newElement);
            journal.commitUserTransaction();
            byte[] remove = server.getCalls().remove(Thread.currentThread());
            journal.undoUserTransaction();
            return remove;
        } catch (Exception e) {
            server.getCalls().remove(Thread.currentThread());
            journal.rollbackUserTransaction();
            throw new RuntimeException(e);
        }
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Journal(com.ramussoft.common.journal.Journal) InternetSyncJournal(com.ramussoft.net.common.internet.InternetSyncJournal) Engine(com.ramussoft.common.Engine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with JournaledEngine

use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.

the class StartCommand method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        System.setProperty("catalina.base", args[0]);
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        Properties ps = EngineFactory.getPropeties();
        String command = args[1];
        String fileName = (String) ps.get(command);
        EngineFactory engineFactory = new EngineFactory();
        engineFactory.createJournaledEngine(new DirectoryJournalFactory(null));
        final Engine engine1 = (Engine) SuperEngineFactory.createTransactionalEngine(engineFactory.journaledEngine, ((JournaledEngine) ((CachedEngine) engineFactory.journaledEngine).getSource()).getJournal());
        engine.getContext().setAttribute("engine", engine1, ScriptContext.ENGINE_SCOPE);
        engine.eval(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
        System.exit(0);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) SuperEngineFactory(com.ramussoft.common.journal.SuperEngineFactory) InputStreamReader(java.io.InputStreamReader) ScriptEngineManager(javax.script.ScriptEngineManager) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) ScriptEngine(javax.script.ScriptEngine) FileInputStream(java.io.FileInputStream) ScriptException(javax.script.ScriptException) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) ScriptEngine(javax.script.ScriptEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine)

Aggregations

JournaledEngine (com.ramussoft.common.journal.JournaledEngine)6 Engine (com.ramussoft.common.Engine)4 CachedEngine (com.ramussoft.common.cached.CachedEngine)4 PluginFactory (com.ramussoft.common.PluginFactory)3 DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)3 AccessRules (com.ramussoft.common.AccessRules)2 IEngine (com.ramussoft.common.IEngine)2 Plugin (com.ramussoft.common.Plugin)2 PluginProvider (com.ramussoft.common.PluginProvider)2 Journal (com.ramussoft.common.journal.Journal)2 Journaled (com.ramussoft.common.journal.Journaled)2 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)2 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)2 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 AbstractPlugin (com.ramussoft.common.AbstractPlugin)1 SuperEngineFactory (com.ramussoft.common.journal.SuperEngineFactory)1