Search in sources :

Example 1 with Element

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

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

the class CachedEngine method loadQualifier.

private CachedQualifier loadQualifier(Long id) {
    CachedQualifier q = new CachedQualifier();
    q.qualifier = deligate.getQualifier(id);
    if (q.qualifier == null)
        return null;
    List<Attribute> attributes = q.buildAttributes();
    q.setAllAttributes(attributes.toArray(new Attribute[attributes.size()]));
    Hashtable<Element, Object[]> hashtable = deligate.getElements(q.qualifier, attributes);
    List<CachedElement> elements = q.elements;
    for (Entry<Element, Object[]> entry : hashtable.entrySet()) {
        Element key = entry.getKey();
        CachedElement e = new CachedElement(key, entry.getValue(), q);
        elements.add(e);
        this.elements.put(key.getId(), e);
    }
    return q;
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element)

Example 3 with Element

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

the class EvalQualifierSetupEditor method save.

@Override
public void save(Engine engine, Qualifier qualifier) {
    final String e = GlobalResourcesManager.getString("Eval.Element");
    Element element = StandardAttributesPlugin.getElement(engine, qualifier.getId());
    List<FunctionPersistent> list = new ArrayList<FunctionPersistent>();
    Util utils = Util.getUtils(engine);
    for (FunctionPersistent fp : functions) if (fp != null) {
        String function = fp.getFunction();
        Eval eval = new Eval(function);
        eval.replaceValueNames(new Replacementable() {

            @Override
            public String getNewName(String oldName) {
                if (e.equals(oldName))
                    return "ELEMENT";
                return oldName;
            }
        });
        fp.setFunction(utils.compile(qualifier, eval.toString()));
        list.add(fp);
    }
    EvalPlugin.setFunctionAttribute(engine, element, list);
}
Also used : Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Util(com.ramussoft.eval.Util) Replacementable(com.ramussoft.eval.Replacementable) FunctionPersistent(com.ramussoft.eval.FunctionPersistent) Eval(com.ramussoft.eval.Eval)

Example 4 with Element

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

the class QualifierPreferencesPanel method updateAttributesInOrder.

@SuppressWarnings("unchecked")
private void updateAttributesInOrder(List<Attribute> qAttributes) {
    Attribute attributeId = (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID);
    List<ElementListPersistent> list = (List<ElementListPersistent>) attributeEditor.getValue();
    List<Attribute> attributes = new ArrayList<Attribute>(list.size());
    for (ElementListPersistent pr : list) {
        Element element2 = engine.getElement(pr.getElement2Id());
        Long id2 = (Long) engine.getAttribute(element2, attributeId);
        Attribute attribute = engine.getAttribute(id2);
        attributes.add(attribute);
        if (qAttributes.indexOf(attribute) < 0)
            qAttributes.add(attribute);
    }
    List<Attribute> rem = new ArrayList<Attribute>();
    for (Attribute a : qAttributes) if (attributes.indexOf(a) < 0)
        rem.add(a);
    for (Attribute r : rem) qAttributes.remove(r);
}
Also used : ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with Element

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

the class QualifierView method moveElements.

private void moveElements(Row row, long parentElementId, long prevParentId, Qualifier dest) {
    long qualifierId = StandardAttributesPlugin.getQualifierId(engine, row.getElement());
    framework.propertyChanged("CloseQualifier", qualifierId);
    Attribute hAttribute = StandardAttributesPlugin.getHierarchicalAttribute(engine);
    List<Element> elements = engine.getElements(qualifierId);
    for (Element element : elements) {
        engine.setElementQualifier(element.getId(), dest.getId());
        element.setQualifierId(dest.getId());
        HierarchicalPersistent hp = (HierarchicalPersistent) engine.getAttribute(element, hAttribute);
        if ((hp != null) && (hp.getParentElementId() == -1l)) {
            hp.setParentElementId(row.getElementId());
            engine.setAttribute(element, hAttribute, hp);
        }
    }
    long prevId = -1l;
    for (Row row2 : toArray(row.getChildren())) {
        moveElements(row2, row.getElementId(), prevId, dest);
        prevId = row2.getId();
    }
    String name = row.getName();
    engine.setElementQualifier(row.getElementId(), dest.getId());
    HierarchicalPersistent hp = new HierarchicalPersistent();
    hp.setPreviousElementId(prevParentId);
    hp.setParentElementId(parentElementId);
    engine.setAttribute(row.getElement(), hAttribute, hp);
    Attribute nameAttribute = engine.getAttribute(dest.getAttributeForName());
    if (nameAttribute != null)
        engine.setAttribute(row.getElement(), nameAttribute, name);
}
Also used : Attribute(com.ramussoft.common.Attribute) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow)

Aggregations

Element (com.ramussoft.common.Element)142 Attribute (com.ramussoft.common.Attribute)70 Qualifier (com.ramussoft.common.Qualifier)59 ArrayList (java.util.ArrayList)48 Engine (com.ramussoft.common.Engine)27 SQLException (java.sql.SQLException)14 List (java.util.List)14 Hashtable (java.util.Hashtable)13 Row (com.ramussoft.database.common.Row)12 ElementEvent (com.ramussoft.common.event.ElementEvent)11 HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)11 Eval (com.ramussoft.eval.Eval)9 AttributeEvent (com.ramussoft.common.event.AttributeEvent)8 ElementListPersistent (com.ramussoft.core.attribute.simple.ElementListPersistent)8 Row (com.ramussoft.pb.Row)8 Journaled (com.ramussoft.common.journal.Journaled)7 FunctionPersistent (com.ramussoft.eval.FunctionPersistent)7 Util (com.ramussoft.eval.Util)7 EObject (com.ramussoft.eval.EObject)6 IOException (java.io.IOException)6