Search in sources :

Example 1 with DirectoryJournalFactory

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

the class UserEngineFactory method createJournalFactory.

private DirectoryJournalFactory createJournalFactory() {
    String journalPath = tmpPath + File.separator + System.currentTimeMillis();
    File dir = new File(journalPath);
    dir.mkdirs();
    return new DirectoryJournalFactory(dir);
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) File(java.io.File)

Example 2 with DirectoryJournalFactory

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

the class EngineFactory method createTemplate.

private void createTemplate() {
    try {
        template = new JDBCTemplate(createConnection());
        try {
            template.executeResource("/com/ramussoft/jdbc/database.sql", "ramus_");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/jdbc/update1.sql", "ramus_");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/jdbc/update2.sql", "ramus_");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/jdbc/update3.sql", "ramus_");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/jdbc/update4.sql", "ramus_");
        } catch (Exception e) {
        }
        /*try {
				template.executeResource("/com/ramussoft/jdbc/update5.sql",
						"ramus_");

			} catch (Exception e) {
				e.printStackTrace();
			}*/
        try {
            template.executeResource("/com/ramussoft/server/create.sql");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/server/create2.sql");
        } catch (Exception e) {
        }
        try {
            template.executeResource("/com/ramussoft/server/create-log.sql", "ramus_");
        } catch (Exception e) {
        }
        journaledEngine = createJournaledEngine(new DirectoryJournalFactory(null));
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        throw new RuntimeException(e);
    }
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SQLException(java.sql.SQLException)

Example 3 with DirectoryJournalFactory

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

the class Runner method recoverySession.

public boolean recoverySession(final String sessionPath, final File sourceFile) {
    Window rFrame = new Window(null);
    String recovering = GlobalResourcesManager.getString("File.Recovering");
    rFrame.add(new Label(MessageFormat.format(recovering, ((sourceFile == null) ? GlobalResourcesManager.getString("Session.NoName") : sourceFile.getName()))));
    rFrame.pack();
    rFrame.setLocationRelativeTo(null);
    rFrame.setVisible(true);
    final String s = sessionPath + File.separator + "source.rms";
    MemoryDatabase database = new MemoryDatabase() {

        @Override
        protected Collection<? extends PluginProvider> getAdditionalSuits() {
            ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
            initAdditionalPluginSuits(ps);
            return ps;
        }

        @Override
        protected File getFile() {
            File file = new File(s);
            if (file.exists())
                return file;
            return null;
        }

        protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
            return new FileIEngineImpl(0, template, factory, sessionPath);
        }
    };
    final Engine engine = database.getEngine(null);
    DirectoryJournalFactory factory = database.getJournalFactory();
    Journal[] journals = factory.loadJournals(database.getJournaledEngine());
    if (journals.length == 0)
        return false;
    boolean exist = false;
    Journal.RedoCallback redoCallback = new Journal.RedoCallback() {

        boolean hadStartUserTransaction;

        @Override
        public boolean execute(Command command) {
            if (command instanceof StartUserTransactionCommand) {
                hadStartUserTransaction = true;
            }
            return hadStartUserTransaction;
        }
    };
    for (Journal journal : journals) {
        try {
            Command command = null;
            while (journal.canRedo()) {
                command = journal.redo(redoCallback);
            }
            if ((journal.getPointer() == 0l) || (command instanceof StopUndoPointCommand)) {
                rFrame.setVisible(false);
                continue;
            } else
                exist = true;
            if (!(command instanceof EndUserTransactionCommand))
                throw new Exception();
        } catch (Exception e) {
            e.printStackTrace();
            while (journal.canUndo()) {
                if (journal.undo() instanceof StartUserTransactionCommand)
                    break;
            }
        }
    }
    if (!exist) {
        try {
            ((FileIEngineImpl) engine.getDeligate()).close();
            for (Journal journal : journals) journal.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    ((FileIEngineImpl) engine.getDeligate()).recoveryStreams();
    engine.setPluginProperty(CORE, "Changed", Boolean.TRUE);
    engine.setActiveBranch(-1l);
    final AccessRules accessor = database.getAccessRules(null);
    rFrame.setVisible(false);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            SplashScreen screen = new SplashScreen() {

                /**
                 */
                private static final long serialVersionUID = -2727237354089088151L;

                @Override
                protected String getImageName() {
                    return Runner.this.getSplashImageName();
                }
            };
            screen.setLocationRelativeTo(null);
            screen.setVisible(true);
            final JFrame frame = openInNewWindows(engine, accessor, sourceFile, true);
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    String recovered = GlobalResourcesManager.getString("File.Recovered");
                    frame.setTitle(frame.getTitle() + " " + recovered);
                }
            });
            screen.setVisible(false);
        }
    };
    recoveredCount++;
    Thread thread = new Thread(runnable);
    thread.start();
    return true;
}
Also used : Label(java.awt.Label) ArrayList(java.util.ArrayList) Journal(com.ramussoft.common.journal.Journal) JFrame(javax.swing.JFrame) SplashScreen(com.ramussoft.gui.common.SplashScreen) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) Window(java.awt.Window) DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) StopUndoPointCommand(com.ramussoft.common.journal.StopUndoPointCommand) PluginProvider(com.ramussoft.common.PluginProvider) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) FileMinimumVersionException(com.ramussoft.core.impl.FileMinimumVersionException) IOException(java.io.IOException) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) StopUndoPointCommand(com.ramussoft.common.journal.StopUndoPointCommand) MemoryDatabase(com.ramussoft.database.MemoryDatabase) AccessRules(com.ramussoft.common.AccessRules) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 4 with DirectoryJournalFactory

use of com.ramussoft.common.journal.DirectoryJournalFactory 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 5 with DirectoryJournalFactory

use of com.ramussoft.common.journal.DirectoryJournalFactory 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

DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)6 Engine (com.ramussoft.common.Engine)3 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)3 File (java.io.File)3 PluginFactory (com.ramussoft.common.PluginFactory)2 PluginProvider (com.ramussoft.common.PluginProvider)2 Journal (com.ramussoft.common.journal.Journal)2 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 AccessRules (com.ramussoft.common.AccessRules)1 IEngine (com.ramussoft.common.IEngine)1 CachedEngine (com.ramussoft.common.cached.CachedEngine)1 Journaled (com.ramussoft.common.journal.Journaled)1 StopUndoPointCommand (com.ramussoft.common.journal.StopUndoPointCommand)1 SuperEngineFactory (com.ramussoft.common.journal.SuperEngineFactory)1 Command (com.ramussoft.common.journal.command.Command)1 EndUserTransactionCommand (com.ramussoft.common.journal.command.EndUserTransactionCommand)1 StartUserTransactionCommand (com.ramussoft.common.journal.command.StartUserTransactionCommand)1