All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.aguacate.context.spi.sql.impl.SentenceSqlArrayIterator Maven / Gradle / Ivy

There is a newer version: 0.10.9
Show newest version
package net.sf.aguacate.context.spi.sql.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.sf.aguacate.function.Function;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;

/**
 * 
 * "name": "...",
 * "type": "ARRAY_ITERATOR",
 * "sentences": {
 *     ...
 * },
 * "methods": [
 *     ...
 * ]
 * 
*/ public class SentenceSqlArrayIterator extends AbstractSentenceSql { private static final Logger LOGGER = LogManager.getLogger(SentenceSqlArrayIterator.class); private final Function[] sentences; private final String initialContext; private final String[] complement; public SentenceSqlArrayIterator(String name, String message, List methods, List required, List optional, List sentences) { super(name, message, methods); this.sentences = sentences.toArray(new Function[sentences.size()]); initialContext = required.get(0); if (optional.size() == 0) { complement = new String[0]; } else { complement = optional.toArray(new String[optional.size()]); } } @Override public String getOutputName() { return null; } @Override public FunctionEvalResult evaluate0(FunctionContext functionContext, Map context) throws SQLException { @SuppressWarnings("unchecked") List> list = (List>) context.get(initialContext); LOGGER.trace("initialContext: {}", list); int size = list.size(); for (int i = 0; i < size; i++) { Map temp = list.get(i); Map subcontext = new HashMap<>(temp); for (String name : complement) { subcontext.put(name, context.get(name)); } LOGGER.trace("subcontext: {}", subcontext); for (Function sentence : sentences) { FunctionEvalResult result = sentence.evaluate(functionContext, subcontext); if (!result.isSuccess()) { return result; } } } return new FunctionEvalResult(true); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy