Search in sources :

Example 1 with FileIEngineImpl

use of com.ramussoft.core.impl.FileIEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class InternetClient method getEngine.

@SuppressWarnings("unused")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory pf) {
    File tmp = new File(System.getProperty("java.io.tmpdir"), "ramus-" + String.valueOf(System.currentTimeMillis()));
    String tmpPath = tmp.getAbsolutePath() + Math.round(Math.random() * 1000);
    try {
        try {
            Class.forName("org.h2.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:h2:" + tmpPath + File.separator + "client-cache" + ";";
        Connection conn = DriverManager.getConnection(url, "sa", "");
        template = MemoryDatabase.createStaticTemplate(conn);
        String dump = tmpPath + File.separator + "dump.rsf";
        new File(tmpPath).mkdirs();
        load(dump, factory);
        impl = new FileIEngineImpl(0, template, factory, tmpPath) {

            @Override
            protected boolean deleteStreamBytes(String path) {
                try {
                    return (Boolean) connection.invoke("deleteStream", new Object[] { path });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public byte[] getStream(String path) {
                try {
                    return (byte[]) connection.invoke("getStream", new Object[] { path });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            protected void writeStream(String path, byte[] bytes) {
                try {
                    connection.invoke("setStream", new Object[] { path, bytes });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public long nextValue(String sequence) {
                try {
                    return (Long) connection.invoke("nextValue", new Object[] { sequence });
                } catch (Exception e) {
                    return super.nextValue(sequence);
                }
            }
        };
        AccessRules accessor = impl.getAccessor();
        String jName = getJournalFileName(impl.getTmpPath() + File.separator);
        BinaryAccessFile accessFile = null;
        if (jName != null) {
            accessFile = new BinaryAccessFile(jName, "rw");
        }
        final InternetHookJournal journal = new InternetHookJournal(accessFile) {

            @Override
            public void onUndo(byte[] bs) {
                try {
                    connection.invoke("undo", new Object[] { bs });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onRedo(byte[] bs) {
                try {
                    connection.invoke("redo", new Object[] { bs });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        if (true)
            throw new RuntimeException("Not implementated");
        InternetEngine internetEngine = new InternetEngine(factory, impl, impl.getPersistentFactory().getRows(), null, accessor) {

            @Override
            public void replaceElements(Element[] oldElements, Element newElement) {
                try {
                    byte[] bs = (byte[]) connection.invoke("replaceElements", new Object[] { oldElements, newElement });
                    journal.serverCopy(bs, this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        BinaryAccessFile binaryAccessFile = new BinaryAccessFile(new File(impl.getTmpPath() + File.separator + "hook.tmp"), "rw");
        syncJournal = new InternetSyncJournal(binaryAccessFile);
        syncJournal.registerEngine(internetEngine);
        Engine engine = internetEngine;
        if (accessFile != null)
            journal.setEnable(true);
        engine = (Engine) SuperEngineFactory.createTransactionalEngine(engine, journal);
        engine.setPluginProperty("Core", "PluginList", factory.getPlugins());
        engine.setPluginProperty("Core", "PluginFactory", factory);
        synchronized (startLock) {
            for (Object object : runCallbacks) asyncCall(object);
            runCallbacks = null;
        }
        return engine;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) InternetEngine(com.ramussoft.net.common.internet.InternetEngine) Element(com.ramussoft.common.Element) Connection(java.sql.Connection) InternetSyncJournal(com.ramussoft.net.common.internet.InternetSyncJournal) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BinaryAccessFile(com.ramussoft.common.journal.BinaryAccessFile) AccessRules(com.ramussoft.common.AccessRules) RedoObject(com.ramussoft.net.common.internet.RedoObject) UndoObject(com.ramussoft.net.common.internet.UndoObject) ZipFile(java.util.zip.ZipFile) BinaryAccessFile(com.ramussoft.common.journal.BinaryAccessFile) File(java.io.File) InternetHookJournal(com.ramussoft.net.common.internet.InternetHookJournal) Engine(com.ramussoft.common.Engine) InternetEngine(com.ramussoft.net.common.internet.InternetEngine)

Example 2 with FileIEngineImpl

use of com.ramussoft.core.impl.FileIEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class BaseExporter method export.

/**
 * @param args
 * @throws IOException
 */
public void export(final File file) throws IOException {
    MemoryDatabase database = new MemoryDatabase() {

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

        @Override
        protected File getFile() {
            return null;
        }

        @Override
        public Connection createConnection() throws SQLException {
            return EngineFactory.createNewConnection();
        }

        @Override
        protected String getJournalDirectoryName(String tmp) {
            return null;
        }

        @Override
        protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
            return new FileIEngineImpl(0, template, factory, null);
        }
    };
    Engine s = database.getEngine(null);
    FileIEngineImpl impl = (FileIEngineImpl) s.getDeligate();
    EngineFactory factory = new EngineFactory();
    IEngine d = factory.getEngine();
    ZipOutputStream out = impl.saveToFileNotCloseFile(file);
    for (String streamName : d.getStreamNames()) {
        byte[] bs = d.getStream(streamName);
        if (bs == null) {
        } else {
            if (streamName.startsWith("/"))
                streamName = streamName.substring(1);
            out.putNextEntry(new ZipEntry(streamName));
            out.write(bs);
        }
    }
    out.close();
    try {
        factory.getTemplate().getConnection().close();
        impl.getConnection().close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IEngine(com.ramussoft.common.IEngine) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ZipOutputStream(java.util.zip.ZipOutputStream) MemoryDatabase(com.ramussoft.database.MemoryDatabase) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine)

Example 3 with FileIEngineImpl

use of com.ramussoft.core.impl.FileIEngineImpl 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 FileIEngineImpl

use of com.ramussoft.core.impl.FileIEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class AbstractDataPlugin method loadFromParalel.

public void loadFromParalel(final DataPlugin dataPlugin, final Function base, final File file, final GUIFramework framework) throws IOException {
    Thread t = new Thread("Paralel-DataLoader") {

        @Override
        public void run() {
            try {
                framework.showAnimation(ResourceLoader.getString("Wait.Message"));
                MemoryDatabase md = new MemoryDatabase() {

                    protected String getJournalDirectoryName(String tmp) {
                        return null;
                    }

                    @Override
                    protected File getFile() {
                        return file;
                    }
                };
                LoadFromParalelDialog dialog = new LoadFromParalelDialog(framework.getMainFrame(), md.getEngine("idef0"));
                if (dialog.showModal()) {
                    ((Journaled) getEngine()).startUserTransaction();
                    try {
                        framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, false);
                        framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, true);
                        DataPlugin fdp = NDataPluginFactory.getDataPlugin(null, md.getEngine("idef0"), md.getAccessRules("idef0"));
                        ModelParaleler paraleler = new ModelParaleler(fdp, dataPlugin, framework);
                        paraleler.loadFromParalel(base, dialog.isImportAll(), dialog.getSelected());
                    } finally {
                        framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, false);
                        ((Journaled) getEngine()).commitUserTransaction();
                        framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, true);
                        framework.propertyChanged(ModelsView.REFRESH_ALL_MODELS);
                    }
                }
                FileIEngineImpl impl = (FileIEngineImpl) md.getEngine("idef0").getDeligate();
                impl.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                framework.hideAnimation();
            }
        }
    };
    t.start();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ModelParaleler(com.ramussoft.idef0.ModelParaleler) LoadFromParalelDialog(com.ramussoft.pb.idef.frames.LoadFromParalelDialog) MemoryDatabase(com.ramussoft.database.MemoryDatabase) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) IOException(java.io.IOException)

Example 5 with FileIEngineImpl

use of com.ramussoft.core.impl.FileIEngineImpl in project ramus by Vitaliy-Yakovchuk.

the class HTMLEditPanel method setValue.

@Override
public Object setValue(Object value) {
    page = (HTMLPage) value;
    if (value == null) {
        jTextPane.setText(emptyValue);
        GUIPatchFactory.patchHTMLTextPane(jTextPane);
        emptyValue = jTextPane.getText();
        return null;
    }
    updateEditing();
    if (engine.getDeligate() instanceof FileIEngineImpl) {
        FileIEngineImpl impl = (FileIEngineImpl) engine.getDeligate();
        try {
            jTextPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
            jTextPane.setPage(impl.getFileForPath(page.getPath()).toURI().toURL());
            GUIPatchFactory.patchHTMLTextPane(jTextPane);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        loadPageText();
    }
    emptyValue = jTextPane.getText();
    return value;
}
Also used : MalformedURLException(java.net.MalformedURLException) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) IOException(java.io.IOException)

Aggregations

FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)13 IOException (java.io.IOException)11 MemoryDatabase (com.ramussoft.database.MemoryDatabase)7 Engine (com.ramussoft.common.Engine)5 ArrayList (java.util.ArrayList)5 Journaled (com.ramussoft.common.journal.Journaled)4 ZipException (java.util.zip.ZipException)4 IEngine (com.ramussoft.common.IEngine)3 PluginFactory (com.ramussoft.common.PluginFactory)3 PluginProvider (com.ramussoft.common.PluginProvider)3 ModelParaleler (com.ramussoft.idef0.ModelParaleler)3 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)3 File (java.io.File)3 AccessRules (com.ramussoft.common.AccessRules)2 FileMinimumVersionException (com.ramussoft.core.impl.FileMinimumVersionException)2 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)2 IDEF0PluginProvider (com.ramussoft.idef0.IDEF0PluginProvider)2 DataPlugin (com.ramussoft.pb.DataPlugin)2 LoadFromParalelDialog (com.ramussoft.pb.idef.frames.LoadFromParalelDialog)2 SQLException (java.sql.SQLException)2