Class UserAttributesContext
- All Implemented Interfaces:
AutoCloseable
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
-
Constructor Summary
ConstructorDescriptionUserAttributesContext
(AGRepositoryConnection connection, String attrs) Instantiate a UserAttributesContext object.UserAttributesContext
(AGRepositoryConnection connection, JSONObject attrs) Instantiate a UserAttributesContext object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
restore, via conn.setUserAttributes() the user attributes that were defined on the AGRepositoryConnection object passed to the constructor of this instance.
-
Field Details
-
conn
-
-
Constructor Details
-
UserAttributesContext
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 AGRepositoryConnectionattrs
- , a String representing a JSON object comprising a collection of attribute/value pairs.
-
UserAttributesContext
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 AGRepositoryConnectionattrs
- , 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 interfaceAutoCloseable
-