Search in sources :

Example 6 with MemoryDatabase

use of com.ramussoft.database.MemoryDatabase 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 7 with MemoryDatabase

use of com.ramussoft.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method createTemplateDataPlugin.

private static DataPlugin createTemplateDataPlugin() {
    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 String getJournalDirectoryName(String tmp) {
            return null;
        }

        @Override
        protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
            return createNotSessionedFileIEngine(factory);
        }
    };
    Engine e = database.getEngine(null);
    AccessRules rules = database.getAccessRules(null);
    Qualifier q = e.createQualifier();
    IDEF0Plugin.installFunctionAttributes(q, e);
    return getDataPlugin(q, e, rules);
}
Also used : MemoryDatabase(com.ramussoft.database.MemoryDatabase) ArrayList(java.util.ArrayList) AccessRules(com.ramussoft.common.AccessRules) Qualifier(com.ramussoft.common.Qualifier) PluginProvider(com.ramussoft.common.PluginProvider) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine)

Example 8 with MemoryDatabase

use of com.ramussoft.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.

the class AbstractDataPlugin method loadFromParalel.

public void loadFromParalel(final File file, final GUIFramework framework) throws IOException {
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, false);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, true);
                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 {
                        DataPlugin fdp = NDataPluginFactory.getDataPlugin(null, md.getEngine("idef0"), md.getAccessRules("idef0"));
                        ModelParaleler paraleler = new ModelParaleler(fdp, AbstractDataPlugin.this, framework);
                        paraleler.loadFromParalel(dialog.isImportAll(), dialog.getSelected());
                    } finally {
                        ((Journaled) getEngine()).commitUserTransaction();
                    }
                }
                FileIEngineImpl impl = (FileIEngineImpl) md.getEngine("idef0").getDeligate();
                impl.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, true);
                framework.propertyChanged(ModelsView.REFRESH_ALL_MODELS);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, false);
                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 9 with MemoryDatabase

use of com.ramussoft.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.

the class AbstractDataPlugin method createParalel.

public boolean createParalel(final Function base, final boolean copyAllRows, final boolean clearElements, final File file, final GUIFramework framework, final DataPlugin dataPlugin) throws IOException {
    Thread thread = new Thread("Model-paraleler") {

        public void run() {
            try {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, false);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, true);
                framework.showAnimation(ResourceLoader.getString("Wait.Message"));
                MemoryDatabase md = new MemoryDatabase() {

                    protected String getJournalDirectoryName(String tmp) {
                        return null;
                    }
                };
                final NDataPlugin fdp = new NDataPlugin(md.getEngine("idef0"), md.getAccessRules("idef0"));
                final ModelParaleler paraleler = new ModelParaleler(AbstractDataPlugin.this, fdp, framework);
                paraleler.createParalel(base, copyAllRows);
                FileIEngineImpl impl = (FileIEngineImpl) md.getEngine("idef0").getDeligate();
                impl.saveToFile(file);
                impl.close();
                if (clearElements) {
                    ((Journaled) getEngine()).startUserTransaction();
                    try {
                        paraleler.clear(base);
                    } finally {
                        ((Journaled) getEngine()).commitUserTransaction();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
            } finally {
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, false);
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, true);
                framework.propertyChanged(ModelsView.REFRESH_ALL_MODELS);
                framework.hideAnimation();
            }
        }
    };
    thread.start();
    return true;
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ModelParaleler(com.ramussoft.idef0.ModelParaleler) MemoryDatabase(com.ramussoft.database.MemoryDatabase) IOException(java.io.IOException)

Example 10 with MemoryDatabase

use of com.ramussoft.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.

the class BaseImporter method main.

/**
 * @param args
 */
public static void main(final String[] args) {
    if (args.length == 0) {
        System.err.println("Enter input file as parameter");
        return;
    }
    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 new File(args[0]);
        }

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

        @Override
        protected String getJournalDirectoryName(String tmp) {
            return null;
        }
    };
    EngineFactory factory = new EngineFactory();
    Engine s = database.getEngine(null);
    IEngine d = factory.getEngine();
    for (String streamName : s.getStreamNames()) {
        byte[] bs = s.getStream(streamName);
        if (bs == null) {
            System.err.println("WARNING: stream " + streamName + " not found in the source");
        } else
            d.setStream(streamName, bs);
    }
    try {
        ((FileIEngineImpl) (database.getEngine(null).getDeligate())).close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ArrayList(java.util.ArrayList) IEngine(com.ramussoft.common.IEngine) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) IOException(java.io.IOException) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) MemoryDatabase(com.ramussoft.database.MemoryDatabase) File(java.io.File) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine)

Aggregations

MemoryDatabase (com.ramussoft.database.MemoryDatabase)11 IOException (java.io.IOException)8 Engine (com.ramussoft.common.Engine)7 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)7 ArrayList (java.util.ArrayList)6 PluginProvider (com.ramussoft.common.PluginProvider)5 AccessRules (com.ramussoft.common.AccessRules)4 PluginFactory (com.ramussoft.common.PluginFactory)4 Journaled (com.ramussoft.common.journal.Journaled)3 ModelParaleler (com.ramussoft.idef0.ModelParaleler)3 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)3 File (java.io.File)3 IEngine (com.ramussoft.common.IEngine)2 IDEF0PluginProvider (com.ramussoft.idef0.IDEF0PluginProvider)2 DataPlugin (com.ramussoft.pb.DataPlugin)2 LoadFromParalelDialog (com.ramussoft.pb.idef.frames.LoadFromParalelDialog)2 ZipException (java.util.zip.ZipException)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 Qualifier (com.ramussoft.common.Qualifier)1 DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)1