Search in sources :

Example 71 with Engine

use of com.ramussoft.common.Engine 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 72 with Engine

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

the class ClientServiceImpl method replaceElements.

@Override
public byte[] replaceElements(Element[] oldElements, Element newElement) {
    Journal journal;
    Engine engine = server.getEngine();
    if (engine instanceof JournaledEngine) {
        journal = ((JournaledEngine) engine).getJournal();
    } else {
        journal = ((JournaledEngine) ((CachedEngine) engine).getSource()).getJournal();
    }
    synchronized (server) {
        try {
            journal.startUserTransaction();
            server.getEngine().replaceElements(oldElements, newElement);
            journal.commitUserTransaction();
            byte[] remove = server.getCalls().remove(Thread.currentThread());
            journal.undoUserTransaction();
            return remove;
        } catch (Exception e) {
            server.getCalls().remove(Thread.currentThread());
            journal.rollbackUserTransaction();
            throw new RuntimeException(e);
        }
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Journal(com.ramussoft.common.journal.Journal) InternetSyncJournal(com.ramussoft.net.common.internet.InternetSyncJournal) Engine(com.ramussoft.common.Engine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 73 with Engine

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

the class StartCommand method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        System.setProperty("catalina.base", args[0]);
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        Properties ps = EngineFactory.getPropeties();
        String command = args[1];
        String fileName = (String) ps.get(command);
        EngineFactory engineFactory = new EngineFactory();
        engineFactory.createJournaledEngine(new DirectoryJournalFactory(null));
        final Engine engine1 = (Engine) SuperEngineFactory.createTransactionalEngine(engineFactory.journaledEngine, ((JournaledEngine) ((CachedEngine) engineFactory.journaledEngine).getSource()).getJournal());
        engine.getContext().setAttribute("engine", engine1, ScriptContext.ENGINE_SCOPE);
        engine.eval(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
        System.exit(0);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) SuperEngineFactory(com.ramussoft.common.journal.SuperEngineFactory) InputStreamReader(java.io.InputStreamReader) ScriptEngineManager(javax.script.ScriptEngineManager) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) ScriptEngine(javax.script.ScriptEngine) FileInputStream(java.io.FileInputStream) ScriptException(javax.script.ScriptException) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) ScriptEngine(javax.script.ScriptEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine)

Example 74 with Engine

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

the class InternetServer method loadAllData.

public byte[] loadAllData() {
    synchronized (saveLock) {
        MemoryDatabase database = new MemoryDatabase() {

            @Override
            protected void loadSuits(List<PluginProvider> suits) {
                suits.addAll(engineFactory.getSuits());
            }

            @Override
            protected File getFile() {
                return null;
            }

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

            @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();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ZipOutputStream out;
        try {
            out = impl.writeToStream(stream);
            out.close();
            return stream.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ZipOutputStream(java.util.zip.ZipOutputStream) MemoryDatabase(com.ramussoft.database.MemoryDatabase) ArrayList(java.util.ArrayList) List(java.util.List) PluginFactory(com.ramussoft.common.PluginFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Engine(com.ramussoft.common.Engine)

Example 75 with Engine

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

the class GroupRootCreater method createChildren.

private Vector<TreeTableNode> createChildren(int i, GroupNode parent) {
    List<Row> rows = parent.getRows();
    Vector<TreeTableNode> res = new Vector<TreeTableNode>();
    if (i >= attrs.length) {
        for (Row row : rows) {
            if (hierarchy.isShowBaseHierarchy()) {
                RowNode rowNode = new RowNode(createRowChildren(row), row);
                rowNode.setParent();
                res.add(rowNode);
            } else {
                RowNode rowNode = new RowNode(new Vector<TreeTableNode>(), row);
                rowNode.setParent();
                res.add(rowNode);
            }
        }
    } else {
        if (attrs[i].getAttributeType().toString().equals("Core.ElementList")) {
            Hashtable<Long, Element> hash = new Hashtable<Long, Element>();
            for (Row row : rows) {
                Engine engine = row.getEngine();
                long[] ids = ElementListPlugin.getElements(engine, attrs[i], row.getElement());
                if (ids.length == 0) {
                    Object value = null;
                    GroupNode groupNode = new GroupNode(this, attrs[i], value);
                    int index;
                    if ((index = res.indexOf(groupNode)) >= 0) {
                        ((GroupNode) res.get(index)).getRows().add(row);
                    } else {
                        groupNode.createRowsList();
                        groupNode.getRows().add(row);
                        res.add(groupNode);
                    }
                }
                for (long id : ids) {
                    Object value = getElement(hash, id, engine);
                    GroupNode groupNode = new GroupNode(this, attrs[i], value);
                    int index;
                    if ((index = res.indexOf(groupNode)) >= 0) {
                        ((GroupNode) res.get(index)).getRows().add(row);
                    } else {
                        groupNode.createRowsList();
                        groupNode.getRows().add(row);
                        res.add(groupNode);
                    }
                }
            }
        } else
            for (Row row : rows) {
                Object value = row.getAttribute(attrs[i]);
                GroupNode groupNode = new GroupNode(this, attrs[i], value);
                int index;
                if ((index = res.indexOf(groupNode)) >= 0) {
                    ((GroupNode) res.get(index)).getRows().add(row);
                } else {
                    groupNode.createRowsList();
                    groupNode.getRows().add(row);
                    res.add(groupNode);
                }
            }
        Object[] objects = res.toArray();
        Arrays.sort(objects);
        for (int j = 0; j < objects.length; j++) {
            res.set(j, (TreeTableNode) objects[j]);
        }
        for (TreeTableNode node : res) {
            GroupNode groupNode = (GroupNode) node;
            Vector<TreeTableNode> children = createChildren(i + 1, groupNode);
            groupNode.setChildren(children);
            groupNode.setParent();
        }
    }
    return res;
}
Also used : Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) Row(com.ramussoft.database.common.Row) Vector(java.util.Vector) Engine(com.ramussoft.common.Engine)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5