UserAttributesContext (agraph-java-client 5.0.4-SNAPSHOT API)
Description: declaration: package: com.franz.agraph.repository, class: UserAttributesContext

Package com.franz.agraph.repository

# Class UserAttributesContext

java.lang.Object
com.franz.agraph.repository.UserAttributesContext

All Implemented Interfaces:
  `AutoCloseable`

public class UserAttributesContext extends Object implements AutoCloseable
A nestable class for defining a scope over which user attributes are set on an AGRepositoryConnection.

A UserAttributeContext can be used with a try-with-resources statement to automate the saving, setting and restoring of userAttributes on an AGRepositoryConnection object. It is intended as an aid to help ensure a specific set of user attributes are not leaked outside the scope of their intended use.

Any request made between instantiation of this class and a call to the close() method will automatically have an x-user-attributes header added to each request sent to via the AGRepositoryConnection object passed as an argument to one of the constructors. While the context instance is live, and before close() is called, the AGRepositoryConnection can be use directly, or referenced via the `conn' field of the context itself.

See example25() for sample code demonstrating its use.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `AGRepositoryConnection`
  `conn`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UserAttributesContext(AGRepositoryConnection connection, String attrs)`
  Instantiate a UserAttributesContext object.
  `UserAttributesContext(AGRepositoryConnection connection, JSONObject attrs)`
  Instantiate a UserAttributesContext object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  restore, via conn.setUserAttributes() the user attributes that were defined on the AGRepositoryConnection object passed to the constructor of this instance.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### conn

    public AGRepositoryConnection conn

- ## Constructor Details

  - ### UserAttributesContext

    public UserAttributesContext(AGRepositoryConnection connection, String attrs)
    Instantiate a UserAttributesContext object. Saves any existing userAttributes set on the argument connection object via connection.getUserAttributes() and then calls connection.setUserAttributes(attrs).
    Parameters:
      `connection` - , an instance of AGRepositoryConnection
      `attrs` - , a String representing a JSON object comprising a collection of attribute/value pairs.

  - ### UserAttributesContext

    public UserAttributesContext(AGRepositoryConnection connection, JSONObject attrs)
    Instantiate a UserAttributesContext object. Saves any existing userAttributes set on the argument connection object via connection.getUserAttributes() and then calls connection.setUserAttributes(attrs).
    Parameters:
      `connection` - , an instance of AGRepositoryConnection
      `attrs` - , a JSONObject comprising a collection of attribute/value pairs.

- ## Method Details

  - ### close

    public void close()
    restore, via conn.setUserAttributes() the user attributes that were defined on the AGRepositoryConnection object passed to the constructor of this instance.
    Specified by:
      `close` in interface `AutoCloseable`