Search in sources :

Example 1 with IDEF0PluginProvider

use of com.ramussoft.idef0.IDEF0PluginProvider 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 2 with IDEF0PluginProvider

use of com.ramussoft.idef0.IDEF0PluginProvider 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 3 with IDEF0PluginProvider

use of com.ramussoft.idef0.IDEF0PluginProvider 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

Engine (com.ramussoft.common.Engine)3 IEngine (com.ramussoft.common.IEngine)3 PluginProvider (com.ramussoft.common.PluginProvider)3 IDEF0PluginProvider (com.ramussoft.idef0.IDEF0PluginProvider)3 PluginFactory (com.ramussoft.common.PluginFactory)2 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)2 MemoryDatabase (com.ramussoft.database.MemoryDatabase)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 AbstractPlugin (com.ramussoft.common.AbstractPlugin)1 AccessRules (com.ramussoft.common.AccessRules)1 Plugin (com.ramussoft.common.Plugin)1 CachedEngine (com.ramussoft.common.cached.CachedEngine)1 Journaled (com.ramussoft.common.journal.Journaled)1 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)1 EngineLogExtension (com.ramussoft.common.logger.EngineLogExtension)1 Event (com.ramussoft.common.logger.Event)1 ILog (com.ramussoft.common.logger.ILog)1 Log (com.ramussoft.common.logger.Log)1