net.sf.aguacate.context.spi.sql.impl.SentenceSqlStaticCountZero Maven / Gradle / Ivy
package net.sf.aguacate.context.spi.sql.impl;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.util.parameter.Parameter;
import net.sf.aguacate.util.parameter.Prm;
import net.sf.aguacate.util.type.Num;
public class SentenceSqlStaticCountZero extends AbstractSentenceSql {
private final String sql;
private final Parameter[] required;
private final Parameter[] optional;
public SentenceSqlStaticCountZero(Collection methods, String name, String message, String sql,
Collection required) {
super(name, message, methods);
this.sql = sql;
this.required = Prm.toArray(required);
this.optional = Prm.toArray(null);
}
@Override
public FunctionEvalResult evaluate0(FunctionContext functionContext, Map context)
throws SQLException {
boolean success = Num.isZero((Number) functionContext.databaseInterface().executeSqlSelectValue(getName(),
getMessage(), functionContext.acquireConnection(), sql, context, required, optional));
if (success) {
return SUCCESS;
} else {
return new FunctionEvalResult(false, "One or more registries was found", null);
}
}
}