use of io.vertigo.dynamo.task.metamodel.TaskAttribute in project vertigo by KleeGroup.
the class WhereInPreProcessor method doEvaluate.
private String doEvaluate(final String sqlQuery) {
final StringBuilder buildQuery = new StringBuilder(sqlQuery.length());
int lastMatchOffset = 0;
final Matcher matcher = JAVA_PATTERN.matcher(sqlQuery);
while (matcher.find()) {
// The first matched char is a blank, we keep it (matcher.start+1)
buildQuery.append(sqlQuery.substring(lastMatchOffset, matcher.start() + 1));
lastMatchOffset = matcher.end();
final String fkFieldName = matcher.group(MASTER_TABLE_FK_GROUP);
final String pkFieldName = matcher.group(DTC_INPUT_PK_GROUP);
final String inputParamName = matcher.group(DTC_INPUTNAME_GROUP);
// null if not found
final boolean isNotIn = matcher.group(OPTIONNAL_NOT_GROUP) != null;
final TaskAttribute attribute = obtainInTaskAttribute(inputParamName);
Assertion.checkState(attribute.getDomain().isMultiple(), "Attribute {0} can't be use in WherInPreProcessor. Check it was declared as IN and is DtList type.", inputParamName);
// -----
final List<?> listObject = (List<?>) inTaskAttributes.get(attribute);
if (listObject.isEmpty()) {
// where XX not in <<empty>> => always true
// where XX in <<empty>> => always false
buildQuery.append(isNotIn ? "1=1" : "1=2");
} else {
// -----
final boolean moreThanOneWhereIn = listObject.size() > NB_MAX_WHERE_IN_ITEM;
if (moreThanOneWhereIn) {
buildQuery.append("( ");
}
appendValuesToSqlQuery(buildQuery, fkFieldName, pkFieldName, inputParamName, isNotIn, listObject, attribute.getDomain().getScope().isPrimitive(), moreThanOneWhereIn);
if (moreThanOneWhereIn) {
buildQuery.append(')');
}
}
}
Assertion.checkState(lastMatchOffset > 0, "WhereInPreProcessor not applied. Keywords found but query doesn't match. Check syntaxe : XXX_ID <<not>> in (#YYY.ROWNUM.ZZZ_ID#) of {0}", sqlQuery);
buildQuery.append(sqlQuery.substring(lastMatchOffset));
return buildQuery.toString();
}
use of io.vertigo.dynamo.task.metamodel.TaskAttribute in project vertigo by KleeGroup.
the class AbstractTaskEngineSQL method preProcessQuery.
/**
* Permet de créer du SQL dynamiquement interprété.
* Les paramètres IN de la tache peuvent être invoqués pour construire
* la requête SQL.
* Exemple :
* request = " Select *
* From PRODUIT
* <%if (dtoProduitCritere.getPrdLibelle()!=null) {%>
* Where PRD_LIBELLE like #DTO_PRODUIT_CRITERE.PRD_LIBELLE#||'%%'
* <%}%> order by <%=1%>";
* @param sqlQuery Requete à évaluer
* @return Requete évaluée
*/
protected final String preProcessQuery(final String sqlQuery) {
final Collection<TaskAttribute> inAttributes = getTaskDefinition().getInAttributes();
final Map<TaskAttribute, Object> inTaskAttributes = new HashMap<>(inAttributes.size());
for (final TaskAttribute taskAttribute : inAttributes) {
inTaskAttributes.put(taskAttribute, getValue(taskAttribute.getName()));
}
// -----
final ScriptPreProcessor scriptPreProcessor = new ScriptPreProcessor(scriptManager, inTaskAttributes, SeparatorType.CLASSIC);
final TrimPreProcessor trimPreProcessor = new TrimPreProcessor(SeparatorType.BEGIN_SEPARATOR_CLASSIC, SeparatorType.END_SEPARATOR_CLASSIC);
final WhereInPreProcessor whereInPreProcessor = new WhereInPreProcessor(inTaskAttributes);
// --
String sql = sqlQuery;
sql = scriptPreProcessor.evaluate(sql);
sql = trimPreProcessor.evaluate(sql);
sql = whereInPreProcessor.evaluate(sql);
return sql;
}
use of io.vertigo.dynamo.task.metamodel.TaskAttribute in project vertigo by KleeGroup.
the class ScriptPreProcessor method createParameters.
private static List<ExpressionParameter> createParameters(final ScriptManager scriptManager, final Map<TaskAttribute, Object> inTaskAttributes) {
Assertion.checkNotNull(scriptManager);
Assertion.checkNotNull(inTaskAttributes);
// -----
final List<ExpressionParameter> tmpParameters = new ArrayList<>(inTaskAttributes.size());
// ==========Initialisation des types et noms de paramètre==============
ExpressionParameter scriptEvaluatorParameter;
for (final Entry<TaskAttribute, Object> entry : inTaskAttributes.entrySet()) {
final TaskAttribute taskAttribute = entry.getKey();
final Class<?> clazz = taskAttribute.getDomain().getTargetJavaClass();
scriptEvaluatorParameter = new ExpressionParameter(StringUtil.constToLowerCamelCase(taskAttribute.getName()), clazz, entry.getValue());
tmpParameters.add(scriptEvaluatorParameter);
}
return tmpParameters;
}
use of io.vertigo.dynamo.task.metamodel.TaskAttribute in project vertigo by KleeGroup.
the class TaskBuilder method addValue.
/**
* adds a value to an attribute.
*
* @param attributeName the name of the attribute
* @param value the values
* @return this builder
*/
public TaskBuilder addValue(final String attributeName, final Object value) {
final TaskAttribute taskAttribute = taskDefinition.getInAttribute(attributeName);
taskAttributesBuilder.putNullable(taskAttribute, value);
return this;
}
Aggregations