Search in sources :

Example 91 with Element

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

the class JournaledEngine method findElements.

@Override
public List<Element> findElements(long qualifierId, Attribute attribute, Object object) {
    AttributeConverter converter = pluginFactory.getAttributeConverter(attribute.getAttributeType());
    FindObject[] findObjects = converter.getFindObjects(object);
    if (findObjects != null)
        return deligate.getElements(qualifierId, attribute, findObjects);
    List<Attribute> list = new ArrayList<Attribute>(1);
    list.add(attribute);
    Hashtable<Element, Object[]> elements = getElements(getQualifier(qualifierId), list);
    ArrayList<Element> res = new ArrayList<Element>();
    Enumeration<Element> e = elements.keys();
    while (e.hasMoreElements()) {
        Element element = e.nextElement();
        if (objectEquals(object, elements.get(element)[0])) {
            res.add(element);
        }
    }
    Collections.sort(res, new Comparator<Element>() {

        @Override
        public int compare(Element o1, Element o2) {
            if (o1.getId() < o2.getId())
                return -1;
            if (o1.getId() > o2.getId())
                return 1;
            return 0;
        }
    });
    return res;
}
Also used : AttributeConverter(com.ramussoft.common.attribute.AttributeConverter) FindObject(com.ramussoft.common.attribute.FindObject) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList)

Example 92 with Element

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

the class DeleteElementCommand method undo.

@Override
public void undo(IEngine iEngine) {
    Qualifier qualifier = iEngine.getQualifier(qualifierId);
    Element element = iEngine.createElement(qualifierId, elementId);
    ElementEvent event = new ElementEvent(engine, null, element, qualifierId, true);
    engine.elementCreated(event);
    List<Attribute> attrs = qualifier.getAttributes();
    attrs.addAll(qualifier.getSystemAttributes());
    int i = 0;
    for (Attribute attr : attrs) {
        iEngine.setBinaryAttribute(elementId, attr.getId(), data[i]);
        Object object = engine.getAttribute(element, attr);
        if ((attr.getId() == qualifier.getAttributeForName()) && (object != null)) {
            element.setName(object.toString());
        }
        AttributeEvent event2 = new AttributeEvent(engine, element, attr, null, object, true);
        engine.attributeChanged(event2);
        i++;
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) ElementEvent(com.ramussoft.common.event.ElementEvent) AttributeEvent(com.ramussoft.common.event.AttributeEvent)

Example 93 with Element

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

the class UpdateQualifierCommand method undo.

@Override
public void undo(IEngine iEngine) {
    iEngine.updateQualifier(oldQualifier);
    QualifierEvent event = new QualifierEvent(engine, newQualifier, oldQualifier, true);
    for (Attribute attribute : deletedAttributes) {
        for (Entry<Long, Transaction> entry : hashtable.get(attribute.getId()).entrySet()) {
            iEngine.setBinaryAttribute(entry.getKey(), attribute.getId(), entry.getValue());
            Element element = iEngine.getElement(entry.getKey());
            AttributeEvent event2 = new AttributeEvent(engine, element, attribute, null, engine.getAttribute(element, attribute), true);
            engine.attributeChanged(event2);
        }
    }
    if (oldQualifier.getAttributeForName() != newQualifier.getAttributeForName())
        getEngine().updateElementNames(newQualifier, oldQualifier);
    engine.qualifierUpdated(event);
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) QualifierEvent(com.ramussoft.common.event.QualifierEvent) AttributeEvent(com.ramussoft.common.event.AttributeEvent)

Example 94 with Element

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

the class CreateElementCommand method undo.

@Override
public void undo(IEngine iEngine) {
    Element element = iEngine.getElement(elementId);
    ElementEvent event = new ElementEvent(engine, element, null, qualifierId, true);
    engine.beforeElementDeleted(event);
    iEngine.deleteElement(elementId);
    engine.elementDeleted(event);
}
Also used : Element(com.ramussoft.common.Element) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 95 with Element

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

the class SetElementQualifierCommand method redo.

@Override
public void redo(IEngine iEngine) {
    Element old = iEngine.getElement(elementId);
    Element newElement = new Element(old.getId(), newQualifierId, old.getName());
    ElementEvent event = new ElementEvent(engine, old, newElement, oldQualifierId, true);
    engine.beforeElementDeleted(event);
    iEngine.setElementQualifier(elementId, newQualifierId);
    engine.removeElementQualifierFromBuffer(elementId);
    engine.elementDeleted(event);
    engine.elementCreated(event);
}
Also used : Element(com.ramussoft.common.Element) ElementEvent(com.ramussoft.common.event.ElementEvent)

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