@Override @SuppressWarnings("unchecked") protected Object transformToSource(Object o) { List<Map<String, Object>> valueList = new ArrayList<>(); if (o instanceof Map) { ((Map<String, List<String>>) o).forEach((key, value) -> valueList.add(Context.create() .set(KEY, key) .set(VALUE, value))); } return valueList; } }
@Override @SuppressWarnings("unchecked") protected Object transformToSource(Object o) { List<Map<String, Object>> valueList = new ArrayList<>(); if (o instanceof Map) { ((Map<String, String>) o).forEach((key, value) -> valueList.add(Context.create() .set(KEY, key) .set(VALUE, value))); } return valueList; }
/** * Boilerplate method to use {@link #insertRow(String, sirius.kernel.commons.Context)} with plan maps. * * @param table the target table to insert a row * @param row contains names and values to insert into the database * @return a Row containing all generated keys * @throws SQLException in case of a database error */ public Row insertRow(String table, Map<String, Object> row) throws SQLException { Context context = Context.create(); context.putAll(row); return insertRow(table, context); }
/** * Returns all values defined in this extension as {@link Context}. * * @return a context containing all values defined by this extension or the <tt>default</tt> extension. */ @Nonnull public Context getContext() { Context ctx = Context.create(); for (Map.Entry<String, ConfigValue> entry : config.entrySet()) { ctx.put(entry.getKey(), get(entry.getKey()).get()); } return ctx; }
private Script computeUpdateScript(Entity parent, boolean updateParent) { sirius.kernel.commons.Context ctx = sirius.kernel.commons.Context.create(); StringBuilder sb = new StringBuilder(); for (Reference ref : references) { sb.append("ctx._source."); sb.append(ref.getLocalProperty().getName()); sb.append("=params."); sb.append(ref.getLocalProperty().getName()); sb.append(";"); ctx.put(ref.getLocalProperty().getName(), parent == null ? null : ref.getRemoteProperty().writeToSource(parent)); } if (updateParent) { sb.append("ctx._source."); sb.append(getName()); sb.append("=params."); sb.append(getName()); sb.append(";"); ctx.put(getName(), parent != null ? parent.getId() : null); } return new Script(ScriptType.INLINE, LANGUAGE_PAINLESS, sb.toString(), ctx); }
@Override @Nonnull public Context getContext() { Context ctx = Context.create(); if (defaultConfig != null) { for (String key : defaultConfig.keySet()) { ctx.put(key, get(key).get()); } } for (String key : configObject.keySet()) { ctx.put(key, get(key).get()); } ctx.put("id", id); return ctx; }
@Override protected void createEntity(SQLEntity entity, EntityDescriptor ed) throws Exception { Context insertData = Context.create(); for (Property p : ed.getProperties()) { if (!SQLEntity.ID.getName().equals(p.getName())) { insertData.set(p.getPropertyName(), p.getValueForDatasource(OMA.class, entity)); } } if (ed.isVersioned()) { insertData.set(VERSION, 1); } Row keys = getDatabase(ed.getRealm()).insertRow(ed.getRelationName(), insertData); loadCreatedId(entity, keys); entity.setVersion(1); }