Search in sources :

Example 16 with Qualifier

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

the class IEngineImpl method getElements.

@SuppressWarnings("unchecked")
@Override
public List<Element> getElements(long qualifierId) {
    throwExaptionIfNotCan(getAccessor().canReadQualifier(qualifierId), "Can not get qualifier.");
    Qualifier qualifier = getQualifier(qualifierId);
    if (qualifier == null)
        return new ArrayList<Element>(0);
    long attr = qualifier.getAttributeForName();
    String where = " AND attribute_id=" + attr + " AND elmts.element_id=element_id";
    long branchId = getActiveBranchId();
    return template.query("SELECT elmts.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 q.qualifier_id=elmts.qualifier_id AND elmts.created_branch_id <=? " + "AND (elmts.removed_branch_id >?) ORDER BY ELEMENT_ID", new ElementRowMapper(), new Object[] { branchId, branchId, qualifierId, branchId, branchId }, true);
}
Also used : Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier)

Example 17 with Qualifier

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

the class IEngineImpl method getQualifiers.

@SuppressWarnings("unchecked")
@Override
public List<Qualifier> getQualifiers(boolean system) {
    long branch = getActiveBranchId();
    List<Qualifier> list = template.query("SELECT * FROM " + prefix + "qualifiers WHERE QUALIFIER_SYSTEM=? AND created_branch_id <=? " + "AND removed_branch_id>? ORDER BY qualifier_name", new QualifierRowMapper(branch), new Object[] { system, branch, branch }, true);
    List<Qualifier> res = new ArrayList<Qualifier>();
    for (Qualifier qualifier : list) if (getAccessor().canReadQualifier(qualifier.getId()))
        res.add(qualifier);
    return res;
}
Also used : ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier)

Example 18 with Qualifier

use of com.ramussoft.common.Qualifier 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 19 with Qualifier

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

the class IEngineImpl method getSystemQualifier.

@Override
public Qualifier getSystemQualifier(String qualifierName) {
    long branch = getActiveBranchId();
    Qualifier qualifier = (Qualifier) template.queryForObjects("SELECT * FROM " + prefix + "qualifiers WHERE QUALIFIER_NAME=? AND qualifier_system=TRUE AND removed_branch_id>? AND created_branch_id <=? ", new QualifierRowMapper(branch), new Object[] { qualifierName, branch, branch }, true);
    if (qualifier != null) {
        Qualifier q = getQualifier(qualifier.getId());
        if (!q.getName().equals(qualifierName))
            qualifier = null;
    }
    if (branch > 0l) {
        Long l = (Long) template.queryForObjects("SELECT QUALIFIER_ID FROM " + prefix + "qualifiers_history qh WHERE QUALIFIER_NAME=? AND created_branch_id IN (" + "SELECT MAX(created_branch_id) FROM " + prefix + "qualifiers_history WHERE QUALIFIER_NAME=qh.QUALIFIER_NAME AND created_branch_id<=?)", new RowMapper() {

            @Override
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rs.getLong(1);
            }
        }, new Object[] { qualifierName, branch }, false);
        if (l != null)
            return getQualifier(l);
    }
    if (qualifier == null)
        return null;
    throwExaptionIfNotCan(getAccessor().canReadQualifier(qualifier.getId()), "Can not get qualifier.");
    return qualifier;
}
Also used : ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) FindObject(com.ramussoft.common.attribute.FindObject) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 20 with Qualifier

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

the class IEngineImpl method getElement.

@Override
public Element getElement(long id) {
    throwExaptionIfNotCan(getAccessor().canReadQualifier(id), "Can not get element.");
    Qualifier qualifier = getQualifier(getQualifierIdForElement(id));
    if (qualifier == null)
        return null;
    long attr = qualifier.getAttributeForName();
    String where = " AND attribute_id=" + attr + " AND elmts.element_id=element_id";
    long branchId = getActiveBranchId();
    return (Element) template.queryForObjects("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 ELEMENT_ID=? AND elmts.qualifier_id=q.qualifier_id AND elmts.created_branch_id<= ? " + "AND elmts.removed_branch_id >?", new ElementRowMapper(), new Object[] { branchId, branchId, id, branchId, branchId }, true);
}
Also used : Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) FindObject(com.ramussoft.common.attribute.FindObject)

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6