Search in sources :

Example 11 with IEngine

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

the class RamusService method close.

public void close() {
    if (myThread != null)
        server.getLogins().remove(myThread);
    Engine engine = userEngineFactory.getJournaledEngine();
    if (engine instanceof CachedEngine) {
        ((CachedEngine) engine).removeBranchCache();
    }
    IEngine deligate = engine.getDeligate();
    if (deligate instanceof IEngineImpl) {
        try {
            ((IEngineImpl) deligate).getTemplate().close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    if (directoryJournalFactory != null) {
        directoryJournalFactory.close();
        delete(directoryJournalFactory.getDirectory());
    }
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl) ServerIEngineImpl(com.ramussoft.server.ServerIEngineImpl) SQLException(java.sql.SQLException) CachedEngine(com.ramussoft.common.cached.CachedEngine) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine)

Example 12 with IEngine

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

use of com.ramussoft.common.IEngine 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 14 with IEngine

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

the class CurrencyPlugin method getAttributeConverter.

@Override
public AttributeConverter getAttributeConverter() {
    return new SimpleAttributeConverter() {

        @SuppressWarnings("unchecked")
        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            if (elementId < 0) {
                if (object == null)
                    return new List[] { new ArrayList(0) };
                else {
                    List list = new ArrayList(1);
                    list.add(object);
                    return new List[] { list };
                }
            }
            return super.toPersistens(object, elementId, attributeId, engine);
        }

        public Object toObject(java.util.List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
            if (elementId < 0) {
                List<Persistent> list = persistents[0];
                if (list.size() == 0)
                    return null;
                else
                    return list.get(0);
            }
            return super.toObject(persistents, elementId, attributeId, engine);
        }

        @Override
        protected Persistent toPersistent(Object value) {
            CurrencyPersistent cp = new CurrencyPersistent();
            cp.setValue(((Number) value).doubleValue());
            return cp;
        }

        @Override
        protected Object toObject(Persistent persistent) {
            return ((CurrencyPersistent) persistent).getValue();
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Persistent(com.ramussoft.common.persistent.Persistent)

Example 15 with IEngine

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

the class AbstractTemplate method close.

@Override
public void close() {
    if (dataPlugin != null) {
        IEngine i = dataPlugin.getEngine().getDeligate();
        ((FileIEngineImpl) i).setClearSessionPath(false);
        try {
            ((FileIEngineImpl) i).close();
            ((FileIEngineImpl) i).getConnection().close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        dataPlugin = null;
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) IEngine(com.ramussoft.common.IEngine)

Aggregations

IEngine (com.ramussoft.common.IEngine)15 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Engine (com.ramussoft.common.Engine)6 Persistent (com.ramussoft.common.persistent.Persistent)6 AbstractAttributeConverter (com.ramussoft.common.attribute.AbstractAttributeConverter)5 IOException (java.io.IOException)4 PluginProvider (com.ramussoft.common.PluginProvider)3 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)3 SQLException (java.sql.SQLException)3 Attribute (com.ramussoft.common.Attribute)2 Element (com.ramussoft.common.Element)2 PluginFactory (com.ramussoft.common.PluginFactory)2 Qualifier (com.ramussoft.common.Qualifier)2 CachedEngine (com.ramussoft.common.cached.CachedEngine)2 Command (com.ramussoft.common.journal.command.Command)2 CreateAttributeCommand (com.ramussoft.common.journal.command.CreateAttributeCommand)2 CreateElementCommand (com.ramussoft.common.journal.command.CreateElementCommand)2 CreateQualifierCommand (com.ramussoft.common.journal.command.CreateQualifierCommand)2 DeleteAttributeCommand (com.ramussoft.common.journal.command.DeleteAttributeCommand)2