Codota Logo
Context
Code IndexAdd Codota to your IDE (free)

How to use
Context
in
sirius.kernel.commons

Best Java code snippets using sirius.kernel.commons.Context (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
FileOutputStream f =
  • Codota IconFile file;new FileOutputStream(file)
  • Codota IconString name;new FileOutputStream(name)
  • Codota IconFile file;new FileOutputStream(file, true)
  • Smart code suggestions by Codota
}
origin: com.scireum/sirius-search

  @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;
  }
}
origin: com.scireum/sirius-db

/**
 * Adds a parameter.
 *
 * @param parameter the name of the parameter as referenced in the SQL statement (${name} or #{name}).
 * @param value     the value of the parameter
 * @return the query itself to support fluent calls
 */
public SQLQuery set(String parameter, Object value) {
  params.put(parameter, value);
  return this;
}
origin: com.scireum/sirius-db

@Override
protected void writeBlobToParameter(String name, Blob blob) throws SQLException {
  OutputStream out = (OutputStream) params.get(name);
  if (out == null) {
    return;
  }
  try (InputStream in = blob.getBinaryStream()) {
    ByteStreams.copy(in, out);
  } catch (IOException e) {
    throw new SQLException(e);
  }
}
origin: com.scireum/sirius-db

/**
 * 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);
}
origin: com.scireum/sirius-kernel

/**
 * 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;
}
origin: com.scireum/sirius-kernel

@Override
public Object put(String key, Object value) {
  set(key, value);
  return value;
}
origin: com.scireum/sirius-kernel

/**
 * Puts all name-value-pairs stored in the given map.
 *
 * @param data the name value pairs to be put into the context
 * @return <tt>this</tt> to permit fluent method calls
 */
public Context setAll(Map<String, Object> data) {
  putAll(data);
  return this;
}
origin: com.scireum/sirius-kernel

/**
 * Writes all parameters into the given {@link javax.script.ScriptContext}
 *
 * @param ctx the context to be filled with the internally stored name value pairs
 */
public void applyTo(ScriptContext ctx) {
  for (Entry<String, Object> e : entrySet()) {
    ctx.setAttribute(e.getKey(), e.getValue(), ScriptContext.ENGINE_SCOPE);
  }
}
origin: com.scireum/sirius-kernel

/**
 * Creates a new context
 *
 * @return a newly created and empty context
 */
public static Context create() {
  return new Context();
}
origin: com.scireum/sirius-kernel

@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;
}
origin: com.scireum/sirius-kernel

/**
 * Sets the given value (its string representation), mit limits this to <tt>limit</tt> characters.
 *
 * @param key   the key to which the value should be associated
 * @param value the value which string representation should be put into the context
 * @param limit the maximal number of characters to put into the map. Everything after that will be discarded
 */
public void putLimited(String key, Object value, int limit) {
  set(key, Strings.limit(value, limit));
}
origin: com.scireum/sirius-db

/**
 * Sets all parameters of the given context.
 *
 * @param ctx the containing pairs of names and values to add to the query
 * @return the query itself to support fluent calls
 */
public SQLQuery set(Map<String, Object> ctx) {
  params.putAll(ctx);
  return this;
}
origin: com.scireum/sirius-kernel

/**
 * Sents the given context as POST to the designated server.
 *
 * @param params  the data to POST
 * @param charset the charset to use when encoding the post data
 * @return the outcall itself for fluent method calls
 * @throws IOException in case of any IO error
 */
public Outcall postData(Context params, Charset charset) throws IOException {
  connection.setRequestMethod(REQUEST_METHOD_POST);
  connection.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_FORM_URLENCODED);
  this.charset = charset;
  OutputStreamWriter writer = new OutputStreamWriter(getOutput(), charset.name());
  StringBuilder sb = new StringBuilder();
  boolean first = true;
  for (Map.Entry<String, Object> entry : params.entrySet()) {
    if (!first) {
      sb.append("&");
    }
    first = false;
    sb.append(URLEncoder.encode(entry.getKey(), charset.name()));
    sb.append("=");
    sb.append(URLEncoder.encode(NLS.toMachineString(entry.getValue()), charset.name()));
  }
  writer.write(sb.toString());
  writer.flush();
  return this;
}
origin: com.scireum/sirius-search

@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;
}
origin: com.scireum/sirius-search

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);
}
origin: com.scireum/sirius-kernel

/**
 * Provides the value associated with the given key as {@link Value}
 *
 * @param key the key for which the value should ne returned
 * @return a value wrapping the internally associated value for the given key
 */
@Nonnull
public Value getValue(Object key) {
  return Value.of(get(key));
}
origin: com.scireum/sirius-db

ctx.putAll(ext.getContext());
this.name = name;
this.driver = ext.get(KEY_DRIVER).isEmptyString() ?
origin: com.scireum/sirius-db

protected void prepareValues(Context ctx, StringBuilder fields, StringBuilder values, List<Object> valueList) {
  for (Map.Entry<String, Object> entry : ctx.entrySet()) {
    if (entry.getValue() != null) {
      if (fields.length() > 0) {
        fields.append(", ");
        values.append(", ");
      }
      if (!SANE_COLUMN_NAME.matcher(entry.getKey()).matches()) {
        throw Exceptions.handle()
                .to(Databases.LOG)
                .withSystemErrorMessage("Cannot use '%s' as column name for an insert. "
                            + "Only characters, digits and '_' is allowed!",
                            entry.getKey())
                .handle();
      }
      fields.append(entry.getKey());
      values.append("?");
      valueList.add(Databases.convertValue(entry.getValue()));
    }
  }
}
origin: com.scireum/sirius-db

@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);
}
origin: com.scireum/sirius-db

private Object computeEffectiveParameterValue(String fullParameterName) throws SQLException {
  String accessPath = null;
  String parameterName = fullParameterName;
  if (fullParameterName.contains(".")) {
    accessPath = parameterName.substring(parameterName.indexOf('.') + 1);
    parameterName = parameterName.substring(0, parameterName.indexOf('.'));
  }
  Object paramValue = context.get(parameterName);
  if (accessPath == null || paramValue == null) {
    return paramValue;
  }
  try {
    return Reflection.evalAccessPath(accessPath, paramValue);
  } catch (Exception e) {
    throw new SQLException(NLS.fmtr("StatementCompiler.cannotEvalAccessPath")
                 .set("name", parameterName)
                 .set("path", accessPath)
                 .set("value", paramValue)
                 .set("query", originalSQL)
                 .format(), e);
  }
}
sirius.kernel.commonsContext

Javadoc

Provides an execution context to scripts etc.

This is basically a wrapper for Map<String, Object>

Most used methods

  • create
    Creates a new context
  • put
  • set
    Associates the given value to the given key, while returning this to permit fluent method chains
  • entrySet
  • get
  • putAll
  • <init>

Popular in Java

  • Running tasks concurrently on multiple threads
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • JComboBox (javax.swing)
  • JLabel (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now