Search in sources :

Example 1 with SimpleAttributePluginSuit

use of com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit in project ramus by Vitaliy-Yakovchuk.

the class EngineConnection method init.

public void init(String[] args) throws Exception {
    try {
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        java.sql.Connection jdbcConnection = null;
        Properties ps = EngineFactory.getPropeties();
        if (ps != null) {
            try {
                Class.forName(ps.getProperty("driver"));
                jdbcConnection = DriverManager.getConnection(ps.getProperty("url"), ps.getProperty("user"), ps.getProperty("password"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (jdbcConnection == null)
            jdbcConnection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1/ramus_public", "postgres", "postgres");
        template = new JDBCTemplate(jdbcConnection);
        userFactory = new UserFactoryImpl(template);
        JDBCTemplate template = new JDBCTemplate(jdbcConnection);
        String password = template.queryForObjects("SELECT \"password\" FROM users WHERE \"login\"=?", new RowMapper() {

            @Override
            public Object mapRow(ResultSet rs, int index) throws SQLException {
                return rs.getString(1);
            }
        }, new Object[] { "admin" }, true).toString().trim();
        connection = new TcpClientConnection("127.0.0.1", Metadata.TCP_PORT) {

            @Override
            protected void objectReaded(Object object) {
                if (tcpClientEngine != null)
                    tcpClientEngine.call((EvenstHolder) object);
            }
        };
        connection.start();
        connection.invoke("login", new Object[] { "admin", password });
        tcpClientEngine = new TcpClientEngine((EngineInvocker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EngineInvocker.class }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return connection.invoke(method.getName(), args);
            }
        }), connection);
        List<Class> interfaces = new ArrayList<Class>();
        interfaces.add(Engine.class);
        interfaces.add(Journaled.class);
        List<PluginProvider> suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        initAdditionalPluginSuits(suits);
        PluginFactory factory = createPluginFactory(suits);
        for (Plugin plugin : factory.getPlugins()) if (plugin.getFunctionalInterface() != null)
            interfaces.add(plugin.getFunctionalInterface());
        final Engine engine1 = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), tcpClientEngine);
        // new CachedEngine(engine1);
        final Engine cachedEngine = engine1;
        final Hashtable<Method, Object> hashtable = new Hashtable<Method, Object>();
        for (Method m : Engine.class.getMethods()) {
            hashtable.put(m, cachedEngine);
        }
        for (Method m : Cached.class.getMethods()) {
            hashtable.put(m, cachedEngine);
        }
        interfaces.add(Cached.class);
        Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object o = hashtable.get(method);
                if (o == null)
                    return tcpClientEngine.invoke(proxy, method, args);
                return method.invoke(o, args);
            }
        });
        tcpClientEngine.setEngine(engine);
        for (Plugin plugin : factory.getPlugins()) plugin.init(engine, rules);
        rules = (AccessRules) createDeligate(AccessRules.class);
        this.engine = engine;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) EngineInvocker(com.ramussoft.net.common.tcp.EngineInvocker) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TcpClientEngine(com.ramussoft.client.TcpClientEngine) UserFactoryImpl(com.ramussoft.server.UserFactoryImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) PluginFactory(com.ramussoft.common.PluginFactory) TcpClientEngine(com.ramussoft.client.TcpClientEngine) Engine(com.ramussoft.common.Engine) RowMapper(com.ramussoft.jdbc.RowMapper) Hashtable(java.util.Hashtable) Method(java.lang.reflect.Method) PluginProvider(com.ramussoft.common.PluginProvider) InvocationHandler(java.lang.reflect.InvocationHandler) SQLException(java.sql.SQLException) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) TcpClientConnection(com.ramussoft.client.TcpClientConnection) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) Plugin(com.ramussoft.common.Plugin)

Example 2 with SimpleAttributePluginSuit

use of com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit in project ramus by Vitaliy-Yakovchuk.

the class Client method run.

public void run(final String[] args) {
    final SplashScreen screen = new SplashScreen() {

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

        @Override
        protected String getImageName() {
            for (String s : args) if (s.equals("-season"))
                return "/com/ramussoft/season/about.png";
            return "/com/ramussoft/gui/about.png";
        }
    };
    if (Metadata.CLIENT) {
        Metadata.REGISTERED_FOR = ClientConnection.getName();
        Metadata.DEMO_REGISTERED = ClientConnection.getName() != null;
    }
    screen.setLocationRelativeTo(null);
    boolean hide = false;
    for (String s : args) if ("--hide-splash".equals(s))
        hide = true;
    if (!hide)
        screen.setVisible(true);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            List<PluginProvider> suits = new ArrayList<PluginProvider>();
            suits.add(new SimpleAttributePluginSuit());
            initAdditionalPluginSuits(suits);
            PluginFactory factory = createPluginFactory(suits);
            PersistentFactory persistentFactory = new PersistentFactory(null, factory.getAttributePlugins(), null);
            persistentFactory.reinit();
            Engine engine = getEngine(factory, persistentFactory);
            AccessRules rules = getAccessRules();
            e = engine;
            e.setPluginProperty("Core", "PluginList", factory.getPlugins());
            e.setPluginProperty("Core", "PluginFactory", factory);
            LightClient.staticEngine = e;
            LightClient.staticAccessRules = rules;
            List<GUIPlugin> list = new ArrayList<GUIPlugin>();
            QualifierPluginSuit.addPlugins(list, e, rules);
            initAdditionalGuiPlugins(list);
            User me = getMe();
            List<Group> groups = me.getGroups();
            String[] grps = new String[groups.size()];
            for (int i = 0; i < grps.length; i++) grps[i] = groups.get(i).getName();
            AbstractGUIPluginFactory factory1;
            String ws = Options.getString("WindowsControl", "simple");
            if (ws.equals("simple"))
                factory1 = new SimleGUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
            else
                factory1 = new GUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
            framework = factory1.getFramework();
            framework.addCloseMainFrameListener(new CloseMainFrameAdapter() {

                @Override
                public void afterClosed() {
                    Client.this.close();
                }
            });
            final JFrame frame = factory1.getMainFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            String title = getTitle();
            frame.setTitle(title);
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    frame.setVisible(true);
                    screen.setVisible(false);
                }
            });
        }
    });
    t.start();
    Thread thread = new Thread("Icons-buffer-cleaner") {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(20000);
                    IconFactory.clearIconsBuffer(LightClient.staticEngine);
                    IconFactory.clearQualifierIconsBuffer(LightClient.staticEngine);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    thread.setDaemon(true);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) User(com.ramussoft.net.common.User) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginProvider(com.ramussoft.common.PluginProvider) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JFrame(javax.swing.JFrame) SplashScreen(com.ramussoft.gui.common.SplashScreen) AccessRules(com.ramussoft.common.AccessRules) ArrayList(java.util.ArrayList) List(java.util.List) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory)

Example 3 with SimpleAttributePluginSuit

use of com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit in project ramus by Vitaliy-Yakovchuk.

the class MemoryDatabase method loadSuits.

protected void loadSuits(List<PluginProvider> suits) {
    suits.add(new SimpleAttributePluginSuit());
    suits.addAll(getAdditionalSuits());
    AdditionalPluginLoader.loadAdditionalSuits(suits);
}
Also used : SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)

Example 4 with SimpleAttributePluginSuit

use of com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit 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 5 with SimpleAttributePluginSuit

use of com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit 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

SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)5 PluginFactory (com.ramussoft.common.PluginFactory)4 PluginProvider (com.ramussoft.common.PluginProvider)4 Engine (com.ramussoft.common.Engine)3 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)3 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 AccessRules (com.ramussoft.common.AccessRules)2 Plugin (com.ramussoft.common.Plugin)2 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)2 Properties (java.util.Properties)2 TcpClientConnection (com.ramussoft.client.TcpClientConnection)1 TcpClientEngine (com.ramussoft.client.TcpClientEngine)1 AbstractPlugin (com.ramussoft.common.AbstractPlugin)1 IEngine (com.ramussoft.common.IEngine)1 CachedEngine (com.ramussoft.common.cached.CachedEngine)1 DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)1 Journaled (com.ramussoft.common.journal.Journaled)1 EngineLogExtension (com.ramussoft.common.logger.EngineLogExtension)1