Skip to content
Snippets Groups Projects
Commit a0c50a6f authored by S.Listl's avatar S.Listl
Browse files

Attribute filter extension performance fix

parent b242f02c
No related branches found
No related tags found
No related merge requests found
......@@ -147,7 +147,7 @@
</entityActionField>
<entityActionField>
<name>newOrder</name>
<title>Order</title>
<title>Receipt</title>
<onActionProcess>%aditoprj%/entity/360Degree_entity/entityfields/newmodule/children/neworder/onActionProcess.js</onActionProcess>
<iconId>VAADIN:DOLLAR</iconId>
<stateProcess>%aditoprj%/entity/360Degree_entity/entityfields/newmodule/children/neworder/stateProcess.js</stateProcess>
......
import("system.SQLTYPES");
import("system.translate");
import("Entity_lib");
import("system.vars");
......@@ -100,8 +101,7 @@ AttributeFilterExtensionMaker.makeFilterValues = function()
AttributeFilterExtensionMaker.getFilterCondition = function(pObjectType, pFilterName, pCondition, pRawValue, pOperatorName, pIdTableName, pIdColumnName)
{
var resSql;
var preparedValues = [];
var resSql;
var name = pFilterName;
name = AttributeSearchNameCoder.decode(name);
var attributeId = name.id;
......@@ -109,19 +109,17 @@ AttributeFilterExtensionMaker.getFilterCondition = function(pObjectType, pFilter
if (attributeType == $AttributeTypes.VOID.toString() || (attributeType == $AttributeTypes.BOOLEAN.toString() && (pOperatorName == "IS NOT NULL" || pOperatorName == "IS NULL")))
{
preparedValues.push([pObjectType, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.OBJECT_TYPE")]);
preparedValues.push([attributeId, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")]);
resSql = newSelect("count(*)")
.from("AB_ATTRIBUTERELATION")
.where("OBJECT_ROWID = " + pIdTableName + "." + pIdColumnName)
.and("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType)
.and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", attributeId);
resSql = "(select count(*) \n\
from AB_ATTRIBUTERELATION \n\
where OBJECT_ROWID = " + pIdTableName + "." + pIdColumnName +" \n\
and OBJECT_TYPE = ? \n\
and AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = ?)";
var cond = SqlBuilder.EQUAL();
if (pOperatorName == "IS NOT NULL" || pRawValue == "1" && pOperatorName == "LIKE" || pRawValue == "0" && pOperatorName == "NOT LIKE")
resSql += " > 0 ";
else
resSql += " = 0 ";
cond = SqlBuilder.GREATER();
resSql = newWhere(resSql, 0, cond, SQLTYPES.INTEGER).toString();
}
else
{
......@@ -129,23 +127,22 @@ AttributeFilterExtensionMaker.getFilterCondition = function(pObjectType, pFilter
var condition = pCondition;
if (attributeType == $AttributeTypes.BOOLEAN.toString())
condition = dbField + (pOperatorName == "LIKE" ? " = " : " != ") + pRawValue;
condition = newWhere(["AB_ATTRIBUTERELATION", dbField], pRawValue, pOperatorName == "LIKE" ? SqlBuilder.EQUAL() : SqlBuilder.NOT_EQUAL());
else
{
condition = pCondition;
condition = condition.replace("{'table.column'}", dbField, "g");
}
preparedValues.push([pObjectType, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.OBJECT_TYPE")]);
preparedValues.push([attributeId, SqlUtils.getSingleColumnType("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID")]);
resSql = pIdTableName + "." + pIdColumnName + " in (select " + pIdTableName + "." + pIdColumnName + " \n\
from " + pIdTableName + " \n\
left join AB_ATTRIBUTERELATION on (AB_ATTRIBUTERELATION.OBJECT_ROWID = " + pIdTableName + "." + pIdColumnName + " \n\
and AB_ATTRIBUTERELATION.OBJECT_TYPE = ? \n\
and AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID = ?) \n\
where " + condition + " )";
//a SqlBuilder.IN() in a newWhere is not used here since the subselect can contain a placeholder
//(the variable condition) that would break the function
resSql = pIdTableName + "." + pIdColumnName + " in (" + newSelect("AB_ATTRIBUTERELATION.OBJECT_ROWID")
.from("AB_ATTRIBUTERELATION")
.where("AB_ATTRIBUTERELATION.OBJECT_ROWID = " + pIdTableName + "." + pIdColumnName)
.and("AB_ATTRIBUTERELATION.OBJECT_TYPE", pObjectType)
.and("AB_ATTRIBUTERELATION.AB_ATTRIBUTE_ID", attributeId)
.and(condition) + ")";
}
resSql = SqlUtils.translateConditionWithQuotes([resSql, preparedValues]);
return resSql;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment