Search in sources :

Example 11 with PluginProvider

use of com.ramussoft.common.PluginProvider 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 12 with PluginProvider

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

the class EngineFactory method createPluginFactory.

protected PluginFactory createPluginFactory(List<PluginProvider> list) {
    ArrayList<Plugin> plugins = new ArrayList<Plugin>();
    for (PluginProvider suit : list) {
        plugins.addAll(suit.getPlugins());
    }
    plugins.add(new AbstractPlugin() {

        @Override
        public String getName() {
            return "Log";
        }

        @Override
        public Class getFunctionalInterface() {
            return ILog.class;
        }

        @Override
        public Object createFunctionalInterfaceObject(Engine engine, IEngine iEngine) {
            return log;
        }
    });
    PluginFactory factory = new PluginFactory(plugins);
    return factory;
}
Also used : ArrayList(java.util.ArrayList) IEngine(com.ramussoft.common.IEngine) AbstractPlugin(com.ramussoft.common.AbstractPlugin) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) 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 13 with PluginProvider

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

the class EngineFactory method createUniversalPersistentFactory.

private void createUniversalPersistentFactory(JDBCTemplate template, String pluginsString) throws SQLException {
    UniversalPersistentFactory factory = new UniversalPersistentFactory(template);
    Collection<PersistentsPlugin> pls = getPersistentPlugins();
    ArrayList<PersistentsPlugin> plugins = new ArrayList<PersistentsPlugin>();
    plugins.addAll(pls);
    if (pluginsString != null) {
        StringTokenizer st = new StringTokenizer(pluginsString, ", ");
        while (st.hasMoreTokens()) {
            try {
                String className = st.nextToken();
                Class<?> clazz = Class.forName(className);
                PersistentsPluginProvider plugin = (PersistentsPluginProvider) clazz.newInstance();
                plugins.addAll(plugin.getPersistentsPlugins());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    for (PluginProvider pp : suits) {
        if (pp instanceof PersistentsPluginProvider) {
            plugins.addAll(((PersistentsPluginProvider) pp).getPersistentsPlugins());
        }
    }
    for (PersistentsPlugin pp : plugins) {
        List<Class> list = new ArrayList<Class>();
        pp.addPersistents(list, factory);
        factory.addClasses(list);
    }
    factory.rebuild();
}
Also used : UniversalPersistentFactory(com.ramussoft.core.persistent.UniversalPersistentFactory) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) PersistentsPlugin(com.ramussoft.core.persistent.PersistentsPlugin) ArrayList(java.util.ArrayList) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) SQLException(java.sql.SQLException) StringTokenizer(java.util.StringTokenizer)

Example 14 with PluginProvider

use of com.ramussoft.common.PluginProvider 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)

Example 15 with PluginProvider

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

the class H2Database method createEngines.

private void createEngines() {
    try {
        JDBCTemplate template = createTemplate();
        List<PluginProvider> suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        PluginFactory factory = createPluginFactory(suits);
        IEngineImpl impl = new IEngineImpl(0, template, PREFIX, factory) {

            @Override
            protected boolean deleteStreamBytes(String path) {
                return false;
            }

            @Override
            public byte[] getStream(String path) {
                return null;
            }

            @Override
            protected void writeStream(String path, byte[] bytes) {
            }
        };
        accessor = impl.getAccessor();
        PersistentFactory persistentFactory = new PersistentFactory(PREFIX, factory.getAttributePlugins(), template);
        persistentFactory.rebuild();
        String tmp = System.getProperty("java.io.tmpdir");
        engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(new File(tmp)), accessor);
    } catch (Exception e) {
        if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        throw new RuntimeException();
    }
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) ArrayList(java.util.ArrayList) PluginProvider(com.ramussoft.common.PluginProvider) IOException(java.io.IOException) SQLException(java.sql.SQLException) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) PluginFactory(com.ramussoft.common.PluginFactory) File(java.io.File)

Aggregations

PluginProvider (com.ramussoft.common.PluginProvider)16 ArrayList (java.util.ArrayList)15 PluginFactory (com.ramussoft.common.PluginFactory)13 Engine (com.ramussoft.common.Engine)8 Plugin (com.ramussoft.common.Plugin)7 IDEF0PluginProvider (com.ramussoft.idef0.IDEF0PluginProvider)6 SQLException (java.sql.SQLException)6 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5 IOException (java.io.IOException)5 AccessRules (com.ramussoft.common.AccessRules)4 IEngine (com.ramussoft.common.IEngine)4 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)4 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)4 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)3 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)3 PersistentsPlugin (com.ramussoft.core.persistent.PersistentsPlugin)3 PersistentsPluginProvider (com.ramussoft.core.persistent.PersistentsPluginProvider)3 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)3 GUIPluginFactory (com.ramussoft.gui.core.GUIPluginFactory)3 SimleGUIPluginFactory (com.ramussoft.gui.core.simple.SimleGUIPluginFactory)3