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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations