Search in sources :

Example 1 with Engine

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

the class InternetClient method getEngine.

@SuppressWarnings("unused")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory pf) {
    File tmp = new File(System.getProperty("java.io.tmpdir"), "ramus-" + String.valueOf(System.currentTimeMillis()));
    String tmpPath = tmp.getAbsolutePath() + Math.round(Math.random() * 1000);
    try {
        try {
            Class.forName("org.h2.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:h2:" + tmpPath + File.separator + "client-cache" + ";";
        Connection conn = DriverManager.getConnection(url, "sa", "");
        template = MemoryDatabase.createStaticTemplate(conn);
        String dump = tmpPath + File.separator + "dump.rsf";
        new File(tmpPath).mkdirs();
        load(dump, factory);
        impl = new FileIEngineImpl(0, template, factory, tmpPath) {

            @Override
            protected boolean deleteStreamBytes(String path) {
                try {
                    return (Boolean) connection.invoke("deleteStream", new Object[] { path });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public byte[] getStream(String path) {
                try {
                    return (byte[]) connection.invoke("getStream", new Object[] { path });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            protected void writeStream(String path, byte[] bytes) {
                try {
                    connection.invoke("setStream", new Object[] { path, bytes });
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public long nextValue(String sequence) {
                try {
                    return (Long) connection.invoke("nextValue", new Object[] { sequence });
                } catch (Exception e) {
                    return super.nextValue(sequence);
                }
            }
        };
        AccessRules accessor = impl.getAccessor();
        String jName = getJournalFileName(impl.getTmpPath() + File.separator);
        BinaryAccessFile accessFile = null;
        if (jName != null) {
            accessFile = new BinaryAccessFile(jName, "rw");
        }
        final InternetHookJournal journal = new InternetHookJournal(accessFile) {

            @Override
            public void onUndo(byte[] bs) {
                try {
                    connection.invoke("undo", new Object[] { bs });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onRedo(byte[] bs) {
                try {
                    connection.invoke("redo", new Object[] { bs });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        if (true)
            throw new RuntimeException("Not implementated");
        InternetEngine internetEngine = new InternetEngine(factory, impl, impl.getPersistentFactory().getRows(), null, accessor) {

            @Override
            public void replaceElements(Element[] oldElements, Element newElement) {
                try {
                    byte[] bs = (byte[]) connection.invoke("replaceElements", new Object[] { oldElements, newElement });
                    journal.serverCopy(bs, this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        BinaryAccessFile binaryAccessFile = new BinaryAccessFile(new File(impl.getTmpPath() + File.separator + "hook.tmp"), "rw");
        syncJournal = new InternetSyncJournal(binaryAccessFile);
        syncJournal.registerEngine(internetEngine);
        Engine engine = internetEngine;
        if (accessFile != null)
            journal.setEnable(true);
        engine = (Engine) SuperEngineFactory.createTransactionalEngine(engine, journal);
        engine.setPluginProperty("Core", "PluginList", factory.getPlugins());
        engine.setPluginProperty("Core", "PluginFactory", factory);
        synchronized (startLock) {
            for (Object object : runCallbacks) asyncCall(object);
            runCallbacks = null;
        }
        return engine;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) InternetEngine(com.ramussoft.net.common.internet.InternetEngine) Element(com.ramussoft.common.Element) Connection(java.sql.Connection) InternetSyncJournal(com.ramussoft.net.common.internet.InternetSyncJournal) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) SQLException(java.sql.SQLException) IOException(java.io.IOException) BinaryAccessFile(com.ramussoft.common.journal.BinaryAccessFile) AccessRules(com.ramussoft.common.AccessRules) RedoObject(com.ramussoft.net.common.internet.RedoObject) UndoObject(com.ramussoft.net.common.internet.UndoObject) ZipFile(java.util.zip.ZipFile) BinaryAccessFile(com.ramussoft.common.journal.BinaryAccessFile) File(java.io.File) InternetHookJournal(com.ramussoft.net.common.internet.InternetHookJournal) Engine(com.ramussoft.common.Engine) InternetEngine(com.ramussoft.net.common.internet.InternetEngine)

Example 2 with Engine

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

the class ElementEventTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Event event = getEvent(rowIndex);
    switch(columnIndex) {
        case 0:
            return getType(event);
        case 1:
            Long id = (Long) event.getAttribute("attribute_id");
            if (id == null)
                return null;
            Engine engine = getEngine();
            Attribute attribute = engine.getAttribute(id);
            if (attribute == null)
                return null;
            return attribute.getName();
        case 2:
            return event.getOldValue();
        case 3:
            return event.getNewValue();
        case 4:
            return event.eventTime;
        case 5:
            return getUser(event);
        default:
            break;
    }
    return null;
}
Also used : Attribute(com.ramussoft.common.Attribute) Event(com.ramussoft.common.logger.Event) Engine(com.ramussoft.common.Engine)

Example 3 with Engine

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

the class ElistTableTabView method createComponent.

@Override
public JComponent createComponent() {
    pane = new JScrollPane();
    left = new ElistTablePanel(framework, q1);
    top = new ElistTablePanel(framework, q2);
    this.model = createModel();
    this.table = new ElistTable() {

        /**
         */
        private static final long serialVersionUID = 5056893447852539087L;

        @Override
        protected Engine getEngine() {
            return framework.getEngine();
        }

        @Override
        protected Attribute getAttribute() {
            return attribute;
        }
    };
    this.table.setModel(model);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    tableHeader = new TopTablePanel(top, table);
    table.setTableHeader(tableHeader);
    table.setRowHeight(CELL_BORDER);
    table.setColumnSelectionAllowed(true);
    TableColumnModel columnModel = table.getColumnModel();
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
        TableColumn column = columnModel.getColumn(i);
        column.setMaxWidth(CELL_BORDER);
        column.setMinWidth(CELL_BORDER);
    }
    table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            int column = table.getSelectedColumn();
            if (column >= 0) {
                top.setSelectionRow(column);
                tableHeader.repaint();
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int row = table.getSelectedRow();
            if (row >= 0) {
                left.setSelectionRow(row);
            }
        }
    });
    pane.setViewportView(table);
    pane.setRowHeaderView(left);
    updateHeadders();
    pane.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            updateHeadders();
        }
    });
    return pane;
}
Also used : JScrollPane(javax.swing.JScrollPane) TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) Attribute(com.ramussoft.common.Attribute) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn) ListSelectionListener(javax.swing.event.ListSelectionListener) ChangeEvent(javax.swing.event.ChangeEvent) ComponentEvent(java.awt.event.ComponentEvent) Engine(com.ramussoft.common.Engine) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 4 with Engine

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

the class ElistTable method updateShowBoolean.

private void updateShowBoolean() {
    Engine engine = getEngine();
    ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, getAttribute());
    String connectionTypes = pp.getConnectionTypes();
    showBoolean = connectionTypes == null || connectionTypes.trim().length() == 0;
    cached = getAttribute();
}
Also used : ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) Engine(com.ramussoft.common.Engine)

Example 5 with Engine

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

the class RowTreeTableModel method setValueAt.

@Override
public void setValueAt(Object value, Object node, int column) {
    if (!saveValues[column])
        return;
    TreeTableNode row = (TreeTableNode) node;
    if (row.getRow() == null)
        return;
    Attribute a = row.getRow().getRowAttributes()[column + 1];
    Engine engine = row.getRow().getRowSet().getEngine();
    Qualifier q = engine.getQualifier(row.getRow().getElement().getQualifierId());
    if ((q.getAttributeForName() == a.getId()) && (value instanceof String)) {
        List<Element> list = engine.findElements(q.getId(), a, value);
        for (Element element : list) {
            if (element.getId() != row.getRow().getElementId()) {
                if (JOptionPane.showConfirmDialog(table, GlobalResourcesManager.getString("Warning.ElementsExists"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
                    return;
                break;
            }
        }
    }
    row.getRow().startUserTransaction();
    row.getRow().setAttribute(column, value);
    row.getRow().endUserTransaction();
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) 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