Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Application attributes - an associative array of Strings specified on an application side. Business logic might depend on such attributes - application language, application name, date/time formats, debug tokens, etc ([2], [4]).
  2. SecuritySubject can be used to provide fine-grained access control to cache data. For example, CacheInterceptor saves the subject id it along with data and it can be used for filtering.

...

Application context mechanism exists in Oracle [1] and it's widely used [6]. Support similar mechanisms (custom session variables) exist in multiple DBMS (e.g. SQLServer [8], Snowflake [7], MySQL [9]).

Description

Accessing application attributes

  1. ApplicationContext is an entrypoint for accessing all non-tabular data.
  2. The access requires static methods, because objects injection isn't possible for user functions (QuerySqlFunction are static, CacheInterceptor is a cache singleton).
  3. User can easily create own QuerySqlFunction  to get access to the attribute from attributes in SQL queries if needed (see example below).


Code Block
languagejava
/** ApplicationContext interface. It's an entrypoint for all non-tabular data. */
public class ApplicationContext {
    /** @return Application attributes set for current thread. */
    public static @Nullable Map<String, String> getAttributes();

    /** @return Current SecuritySubject. */
	public static @Nullable SecuritySubject getSecuritySubject();
 }
 
/** Example, use it in QuerySqlFunction. */
public static class UserDefinedFunctions {
    /** @return Session ID set with application attributes. */
    @QuerySqlFunction
    public static @Nullable String sessionId() {
        Map<String, String> appAttrs = ApplicationContext.getAttributes();
 
        return appAttrs == null ? null : appAttr.get("SESSION_ID");
    }
}

Setting application attributes

IgniteClient (Java)

...

  1. Users set attributes with ClientCache#withApplicationAttributes  and must clean it by selfClient should mirror the logic of Ignite node.
  2. New feature is needed in the ClientBitmaskFeature protocol.

...

Code Block
languagejava
// Example of usage.
try (IgniteClient cln = Ignition.startClient(clnCfg)) {
    Map<String, String> appAttrs = F.asMap("SESSION_ID", "1234");

	ClientCache<?,    try (ClientTransaction tx?> cache = cln.transactionscache("CACHE").withApplicationAttributes(appAttrs).txStart(;	

 	...
}

JDBC


IgniteClient (Java). 

  1. Users set attributes with ClientCache#withApplicationAttributes  and must clean it by self.
  2. New feature is needed in the ClientBitmaskFeature protocol.


Code Block
languagejava
// Example of usage.
try (IgniteClient cln = Ignition.startClient(clnCfg)) {
    Map<String, String> appAttrs = ...
    }F.asMap("SESSION_ID", "1234");

	ClientCache<?, ?> cache = cln.cache("CACHE").withApplicationAttributes(appAttrs);	

 	...
}

JDBC

The standard jdbc protocol describes the methods Connection#setClientInfo, which allow changing the values ​​of client attributes during the life of the connection [3]. Implementation features:

...