public ReadyCSVStatementTemplate(String name, String stmtTemplate, Map<String, String> bindingSpecs) { this.name = name; this.stmtTemplate = stmtTemplate; this.bindingsTemplate = new BindingsTemplate(AllDataMapperLibraries.get(), bindingSpecs); }
public CSVBindings resolve() { Bindings bindings = bindingsTemplate.resolveBindings(); return new CSVBindings(bindings); } }
/** * Generate all values in the bindings template, and set each of them in * the map according to their bind point name. * * @param donorMap - a user-provided Map<String,Object> * @param cycle - the cycle for which to generate the values */ public void setMap(Map<String, Object> donorMap, long cycle) { Object[] all = getAll(cycle); for (int i = 0; i < all.length; i++) { donorMap.put(template.getBindPointNames().get(i), all[i]); } }
/** * Create a new instance of {@link StringBindings}, preferably in the thread context that will use it. * @return a new StringBindings */ public StringBindings resolve() { StringCompositor compositor = new StringCompositor(stringTemplate); HashSet<String> unqualifiedNames = new HashSet<>(compositor.getBindPointNames()); unqualifiedNames.removeAll(new HashSet<>(bindingsTemplate.getBindPointNames())); if (unqualifiedNames.size()>0) { throw new RuntimeException("Named anchors were specified in the template which were not provided in the bindings: " + unqualifiedNames.toString()); } Bindings bindings = bindingsTemplate.resolveBindings(); return new StringBindings(compositor,bindings); } }
public String toString() { return template.toString() + dataMappers; }
/** * TODO: Doc how this is different, and semantically useful * @param value the spec value, not the generated data value * @return true if the spec exists in the bindings */ @Override public boolean containsValue(Object value) { return bindings.getTemplate().getDataMapperSpecs().contains((String) value); }
/** * Use the data mapping library and the specifier to create instances of data mapping functions. * If you need thread-aware mapping, be sure to call this in the proper thread. Each time this method * is called, it creates a new instance. * @return A set of bindings that can be used to yield mapped data values later. */ public Bindings resolveBindings() { List<DataMapper<?>> dataMappers = new ArrayList<>(); for (String specifier : specifiers) { Optional<DataMapper<Object>> optionalDataMapper = VirtData.getOptionalMapper(specifier); if (optionalDataMapper.isPresent()) { dataMappers.add(optionalDataMapper.get()); } else { logAvailableDataMappers(); throw new RuntimeException( "data mapper binding was unsuccessful for " + ", spec:" + specifier + ", see log for known data mapper names."); } } return new Bindings(this, dataMappers); }
@Override public R bind(long value) { Map<String,Object> generatedValues = new HashMap<String,Object>(); bindings.setMap(generatedValues, value); try { // Provide bindings context data where it may be useful return valuesMapBinder.bindValues(context, generatedValues); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString() + ": " + generatedValues, e); } } }
public ReadyFileStatementTemplate(String name, String stmtTemplate, Map<String, String> bindingSpecs) { this.name = name; this.stmtTemplate = stmtTemplate; this.bindingsTemplate = new BindingsTemplate(AllDataMapperLibraries.get(), bindingSpecs); }
public ReadyFileStatement resolve() { return new ReadyFileMapStatement(stmtTemplate,bindingsTemplate.resolveBindings()); } }
@Override public boolean isEmpty() { return bindings.getTemplate().getBindPointNames().isEmpty(); }
@Override public R bind(long value) { Object[] allGeneratedValues = bindings.getAll(value); try { // Provide bindings context data where it may be useful return valuesArrayBinder.bindValues(context, allGeneratedValues); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString(allGeneratedValues), e); } } }
/** * Create a bindings template from the provided map, ensuring that * the syntax of the bindings specs is parsable first. * * @param namedBindings The named bindings map * @return a bindings template */ public static BindingsTemplate getTemplate(Map<String, String> namedBindings) { for (String bindingSpec : namedBindings.values()) { VirtDataDSL.ParseResult parseResult = VirtDataDSL.parse(bindingSpec); if (parseResult.throwable != null) { throw new RuntimeException(parseResult.throwable); } } return new BindingsTemplate(namedBindings); }
public ContextualArrayBindings<C, R> resolveBindings() { Bindings bindings = bindingsTemplate.resolveBindings(); return new ContextualArrayBindings<C, R>(bindings, context, valuesArrayBinder); }
@Override public boolean containsKey(Object key) { return bindings.getTemplate().getBindPointNames().contains((String) key); }
@Override public R bind(long value) { Object[] allGeneratedValues = bindings.getAll(value); try { // Provide bindings context data where it may be useful return valuesBinder.bindValues(context, bindings, value); } catch (Exception e) { throw new RuntimeException("Binding error:" + bindings.getTemplate().toString(allGeneratedValues), e); } } }
if (stmts.size() > 0) { for (StmtDef stmt : stmts) { BindingsTemplate bt = new BindingsTemplate(stmt.getBindings()); String statement = stmt.getStmt(); Objects.requireNonNull(statement); String generatedStmt = genStatementTemplate(stmtsDocList.getDocBindings().keySet()); BindingsTemplate bt = new BindingsTemplate(stmtsDocList.getDocBindings()); StringBindingsTemplate sbt = new StringBindingsTemplate(generatedStmt, bt); StringBindings sb = sbt.resolve();
public ContextualBindings<C, R> resolveBindings() { Bindings bindings = bindingsTemplate.resolveBindings(); return new ContextualBindings<C, R>(bindings, context, valuesBinder); }
@Override public int size() { return bindings.getTemplate().getBindPointNames().size(); }
public ReadyCSVStatement resolve() { return new ReadyCSVMapStatement(stmtTemplate,bindingsTemplate.resolveBindings()); } }