|
|
|
@ -23,7 +23,11 @@ import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.search.Condition;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.*;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.InvalidOperatorException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.QueryBuilder;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.QueryHolder;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.ValueType;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -93,8 +97,8 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|
|
|
|
intArr[0] = 1;
|
|
|
|
|
//int x = 1;
|
|
|
|
|
String query = this.getGenericQueryPart(valueTypeArray) +
|
|
|
|
|
this.processAND(andColumns, valueTypeArray, intArr) +
|
|
|
|
|
this.processOR(orColumns, valueTypeArray, intArr);
|
|
|
|
|
this.processAND(andColumns, valueTypeArray, intArr) +
|
|
|
|
|
this.processOR(orColumns, valueTypeArray, intArr);
|
|
|
|
|
List<QueryHolder> queryHolders = new ArrayList<>();
|
|
|
|
|
QueryHolder queryHolder = new QueryHolder();
|
|
|
|
|
queryHolder.setQuery(query);
|
|
|
|
@ -135,20 +139,13 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|
|
|
|
+ " LIKE ? ";
|
|
|
|
|
ValueType type = new ValueType();
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setStringValue("%"+con.getValue()+"%");
|
|
|
|
|
type.setStringValue("%" + con.getValue() + "%");
|
|
|
|
|
valueType[x] = type;
|
|
|
|
|
x++;
|
|
|
|
|
} else {
|
|
|
|
|
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con
|
|
|
|
|
.getOperator() + " ? ";
|
|
|
|
|
ValueType type = new ValueType();
|
|
|
|
|
if (Utils.checkColumnType(con.getKey())) {
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setStringValue(con.getValue());
|
|
|
|
|
} else {
|
|
|
|
|
type.setColumnType(ValueType.columnType.INTEGER);
|
|
|
|
|
type.setIntValue(Integer.parseInt(con.getValue()));
|
|
|
|
|
}
|
|
|
|
|
ValueType type = this.getValueType(con);
|
|
|
|
|
valueType[x] = type;
|
|
|
|
|
x++;
|
|
|
|
|
}
|
|
|
|
@ -182,21 +179,15 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|
|
|
|
+ " LIKE ? ";
|
|
|
|
|
ValueType type = new ValueType();
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setStringValue("%"+con.getValue()+"%");
|
|
|
|
|
type.setStringValue("%" + con.getValue() + "%");
|
|
|
|
|
valueType[x] = type;
|
|
|
|
|
x++;
|
|
|
|
|
} else {
|
|
|
|
|
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + con
|
|
|
|
|
.getOperator() + " ? ";
|
|
|
|
|
|
|
|
|
|
ValueType type = new ValueType();
|
|
|
|
|
if (Utils.checkColumnType(con.getKey())) {
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setStringValue(con.getValue());
|
|
|
|
|
} else {
|
|
|
|
|
type.setColumnType(ValueType.columnType.INTEGER);
|
|
|
|
|
type.setIntValue(Integer.parseInt(con.getValue()));
|
|
|
|
|
}
|
|
|
|
|
ValueType type = this.getValueType(con);
|
|
|
|
|
|
|
|
|
|
valueType[x] = type;
|
|
|
|
|
x++;
|
|
|
|
|
}
|
|
|
|
@ -386,4 +377,35 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|
|
|
|
throw new InvalidOperatorException("Error occurred while building the sql", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a Value type based on the Condition data.
|
|
|
|
|
*
|
|
|
|
|
* @param con : The condition that passed.
|
|
|
|
|
* @re
|
|
|
|
|
*/
|
|
|
|
|
private ValueType getValueType(Condition con) {
|
|
|
|
|
ValueType type = new ValueType();
|
|
|
|
|
String colValue = Utils.checkColumnType(con.getKey());
|
|
|
|
|
|
|
|
|
|
switch (colValue) {
|
|
|
|
|
case "String":
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setStringValue(con.getValue());
|
|
|
|
|
break;
|
|
|
|
|
case "Double":
|
|
|
|
|
type.setColumnType(ValueType.columnType.DOUBLE);
|
|
|
|
|
type.setDoubleValue(Double.parseDouble(con.getValue()));
|
|
|
|
|
break;
|
|
|
|
|
case "Integer":
|
|
|
|
|
type.setColumnType(ValueType.columnType.INTEGER);
|
|
|
|
|
type.setIntValue(Integer.parseInt(con.getValue()));
|
|
|
|
|
break;
|
|
|
|
|
case "Long":
|
|
|
|
|
type.setColumnType(ValueType.columnType.STRING);
|
|
|
|
|
type.setLongValue(Long.parseLong(con.getValue()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
}
|