Search in sources :

Example 26 with Journaled

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

the class CreateOrEditElementListDialog method onOk.

@Override
protected void onOk() {
    if (!isOk()) {
        JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SomeNeededPreferenciesAreNotSeted"));
        return;
    }
    ((Journaled) engine).startUserTransaction();
    Attribute attribute = getAttribute();
    if (attribute == null)
        attribute = engine.createAttribute(getAttributeType());
    attribute.setName(nameField.getText());
    editor.apply(attribute, engine, rules);
    engine.updateAttribute(attribute);
    Qualifier q1 = editor.getQualifier1();
    Qualifier q2 = editor.getQualifier2();
    q1.getAttributes().add(attribute);
    q2.getAttributes().add(attribute);
    engine.updateQualifier(q1);
    engine.updateQualifier(q2);
    ((Journaled) engine).commitUserTransaction();
    super.onOk();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) Attribute(com.ramussoft.common.Attribute) Qualifier(com.ramussoft.common.Qualifier)

Example 27 with Journaled

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

the class ElistTableModel method setValueAt.

@Override
public void setValueAt(Object value, int rowIndex, int columnIndex) {
    Element element = left.getElement(rowIndex);
    List<ElementListPersistent> list = data.get(element);
    Element c = top.getElement(columnIndex);
    ElementListPersistent p = new ElementListPersistent();
    if (revert) {
        p.setElement1Id(c.getId());
        p.setElement2Id(element.getId());
    } else {
        p.setElement1Id(element.getId());
        p.setElement2Id(c.getId());
    }
    if (value != null) {
        if (value instanceof Boolean) {
            if ((Boolean) value)
                list.add(p);
            else
                list.remove(p);
        } else {
            int index = list.indexOf(p);
            p.setConnectionType(value.toString());
            if (p.getConnectionType().length() == 0) {
                if (index >= 0)
                    list.remove(index);
            } else {
                if (index >= 0)
                    list.get(index).setConnectionType(value.toString());
                else
                    list.add(p);
            }
        }
    } else {
        list.remove(p);
    }
    ((Journaled) engine).startUserTransaction();
    engine.setAttribute(element, attribute, new ArrayList(list));
    ((Journaled) engine).commitUserTransaction();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList)

Example 28 with Journaled

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

the class SetFormulaDialog method onOk.

@Override
protected void onOk() {
    if (editor.getText().equals("")) {
        info.setFormula(null);
        ((Journaled) engine).startUserTransaction();
        engine.setCalculateInfo(info);
        ((Journaled) engine).commitUserTransaction();
        super.onOk();
        return;
    }
    Util utils = Util.getUtils(engine);
    try {
        try {
            info.setFormula(utils.compile(editor.getText(), engine.getElement(info.getElementId()), engine.getAttribute(info.getAttributeId())));
        } catch (UnknownValuesException e) {
            StringBuffer sb = new StringBuffer();
            sb.append("<html><body>");
            for (String value : e.getValues()) {
                sb.append(MessageFormat.format(GlobalResourcesManager.getString("Eval.UnknowValue"), value));
                sb.append("<br>");
            }
            sb.append("</body></html>");
            JOptionPane.showMessageDialog(null, sb.toString());
        }
        Eval eval = new Eval(info.getFormula());
        List<String> rec = new ArrayList<String>();
        for (String function : eval.getFunctions()) if (!utils.isFunctionExists(function)) {
            JOptionPane.showMessageDialog(null, MessageFormat.format(GlobalResourcesManager.getString("Eval.UnknowFunction"), function));
            return;
        }
        rec.add(utils.toValue(info.getElementId(), info.getAttributeId()));
        if (recCheck(rec, eval, utils)) {
            JOptionPane.showMessageDialog(null, GlobalResourcesManager.getString("Recursive.Link"));
        } else {
            ((Journaled) engine).startUserTransaction();
            engine.setCalculateInfo(info);
            ((Journaled) engine).commitUserTransaction();
            super.onOk();
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, MessageFormat.format(GlobalResourcesManager.getString("Eval.Error"), editor.getText()));
        return;
    }
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) UnknownValuesException(com.ramussoft.eval.UnknownValuesException) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) Eval(com.ramussoft.eval.Eval) UnknownValuesException(com.ramussoft.eval.UnknownValuesException)

Example 29 with Journaled

use of com.ramussoft.common.journal.Journaled 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 30 with Journaled

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

the class QualifierPreferencesPanel method ok.

public boolean ok() {
    if (box.getSelectedItem() == null) {
        JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("Error.SetAttributeForName"));
        return false;
    }
    String[] errors = new String[] {};
    for (QualifierSetupEditor editor : editors) {
        String[] add = editor.getErrors();
        int start = errors.length;
        errors = Arrays.copyOf(errors, errors.length + add.length);
        for (int i = start; i < errors.length; i++) {
            errors[i] = add[i - start];
        }
    }
    if (errors.length > 0) {
        StringBuffer sb = new StringBuffer();
        sb.append("<html><body>");
        for (String error : errors) {
            sb.append(error);
            sb.append("<br>");
        }
        sb.append("</body></html>");
        JOptionPane.showMessageDialog(this, sb.toString());
        return false;
    }
    if (engine instanceof Journaled) {
        ((Journaled) engine).startUserTransaction();
    }
    engine.setAttribute(element, attribute, attributeEditor.getValue());
    long id = (Long) engine.getAttribute(element, (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.QUALIFIER_ID));
    Qualifier qualifier = engine.getQualifier(id);
    updateAttributesInOrder(attributeOrderEditPanel.getAttributes());
    qualifier.setAttributes(attributeOrderEditPanel.getAttributes());
    if (box.getSelectedItem() == null) {
        qualifier.setAttributeForName(-1l);
    } else {
        Attribute attributeId = (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID);
        Long id2 = (Long) engine.getAttribute((Element) box.getSelectedItem(), attributeId);
        Attribute a = engine.getAttribute(id2);
        qualifier.setAttributeForName(a.getId());
    }
    engine.updateQualifier(qualifier);
    IconPersistent selectedValue = open.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setOpenIcon(engine, selectedValue, qualifier);
    selectedValue = leaf.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setLeafIcon(engine, selectedValue, qualifier);
    selectedValue = closed.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setClosedIcon(engine, selectedValue, qualifier);
    for (QualifierSetupEditor editor : editors) {
        editor.save(engine, qualifier);
    }
    if (engine instanceof Journaled) {
        ((Journaled) engine).commitUserTransaction();
    }
    return true;
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) QualifierSetupEditor(com.ramussoft.gui.common.QualifierSetupEditor)

Aggregations

Journaled (com.ramussoft.common.journal.Journaled)34 Engine (com.ramussoft.common.Engine)9 Attribute (com.ramussoft.common.Attribute)7 Element (com.ramussoft.common.Element)7 Qualifier (com.ramussoft.common.Qualifier)7 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Row (com.ramussoft.database.common.Row)5 DataPlugin (com.ramussoft.pb.DataPlugin)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)4 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)4 AttributeType (com.ramussoft.common.AttributeType)3 MemoryDatabase (com.ramussoft.database.MemoryDatabase)3 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)3 ModelParaleler (com.ramussoft.idef0.ModelParaleler)3 Function (com.ramussoft.pb.Function)3 Row (com.ramussoft.pb.Row)3 TreePath (javax.swing.tree.TreePath)3 AccessRules (com.ramussoft.common.AccessRules)2 IEngine (com.ramussoft.common.IEngine)2