Search in sources :

Example 1 with FindObject

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

the class IEngineImpl method getElements.

@SuppressWarnings("unchecked")
@Override
public List<Element> getElements(long qualifierId, Attribute attribute, FindObject[] findObjects) {
    AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
    Class<? extends Persistent> clazz = plugin.getAttributePersistents()[0];
    String name = prefix + "attribute_" + clazz.getAnnotation(Table.class).name();
    String w = findObjects[0].getField() + "=?";
    for (int i = 1; i < findObjects.length; i++) {
        w += " AND " + findObjects[i].getField() + "=?";
    }
    List<Object> objects = new ArrayList<Object>(findObjects.length + 1);
    long branchId = getActiveBranchId();
    objects.add(branchId);
    objects.add(branchId);
    objects.add(qualifierId);
    for (int i = 0; i < findObjects.length; i++) {
        objects.add(findObjects[i].getObject());
    }
    Qualifier qualifier = getQualifier(qualifierId);
    long attr = qualifier.getAttributeForName();
    String where = " AND attribute_id=" + attr + " AND elmts.element_id=element_id";
    objects.add(branchId);
    objects.add(branchId);
    return template.query("SELECT ELEMENT_ID, elmts.QUALIFIER_ID, (SELECT value FROM " + prefix + "attribute_texts WHERE element_id=elmts.element_id AND attribute_id=" + attr + " " + " AND (value_branch_id IN (SELECT MAX(branch_id) FROM " + prefix + "attributes_data_metadata WHERE branch_id<=? " + where + ") OR ((SELECT MAX(branch_id) FROM " + prefix + "attributes_data_metadata WHERE branch_id <=?" + where + ") IS NULL AND value_branch_id=0))) AS ELEMENT_TEXT_NAME FROM " + prefix + "elements elmts, " + prefix + "qualifiers q WHERE elmts.QUALIFIER_ID=? AND elmts.qualifier_id=q.qualifier_id " + "AND elmts.ELEMENT_ID IN (SELECT ELEMENT_ID FROM " + name + " WHERE " + w + ") AND elmts.created_branch_id <=? " + "AND (elmts.removed_branch_id>? ) ORDER BY ELEMENT_ID", new ElementRowMapper(), objects.toArray(), true);
}
Also used : AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) ArrayList(java.util.ArrayList) FindObject(com.ramussoft.common.attribute.FindObject) Qualifier(com.ramussoft.common.Qualifier)

Example 2 with FindObject

use of com.ramussoft.common.attribute.FindObject 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)

Aggregations

FindObject (com.ramussoft.common.attribute.FindObject)2 ArrayList (java.util.ArrayList)2 Attribute (com.ramussoft.common.Attribute)1 Element (com.ramussoft.common.Element)1 Qualifier (com.ramussoft.common.Qualifier)1 AttributeConverter (com.ramussoft.common.attribute.AttributeConverter)1 AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)1