Skip to main content

Quick Reference for XEP .NET Classes

This chapter is a quick reference for members of the InterSystems.XEP namespace, which contains the public classes described in Using XEP Event Persistence.

Note:

This is not the definitive reference for XEP. For the most complete and up-to-date information, see the help file, located in <install-dir>/dev/dotnet/help/IrisXEP.chm.

XEP Quick Reference

This section is a reference for XEP classes (namespace InterSystems.XEP). See Using XEP Event Persistence for more details and examples. XEP provides the following classes and interfaces:

  • Class PersisterFactory — provides a factory method to create EventPersister objects.

  • Class EventPersister — encapsulates an XEP database connection. It provides methods that set XEP options, establish a connection or get an existing connection object, import schema, produce XEP Event objects, and control transactions.

  • Class Event — encapsulates a reference to an XEP persistent event. It provides methods to store or delete events, create a query, and start or stop index creation.

  • Class EventQuery<T> — encapsulates a query that retrieves individual events of target class T from the database for update or deletion.

  • Interface InterfaceResolver — resolves the actual type of a property during flat schema importation if the property was declared as an interface.

  • Class XEPException — is the exception thrown by most XEP methods.

List of XEP Methods

The following XEP classes and methods are described in this reference:

PersisterFactory
EventPersister
Event
  • Close() — releases all resources held by this instance.

  • CreateQuery() — creates an EventQuery<T> instance.

  • DeleteObject() — deletes an event given its database Id or IdKey.

  • GetObject() — returns an event given its database Id or IdKey.

  • IsEvent() — checks whether an object (or class) is an event in the XEP sense.

  • StartIndexing() — starts index building for the underlying class.

  • StopIndexing() — stops index building for the underlying class.

  • Store() — stores the specified object or array of objects.

  • UpdateObject() — updates an event given its database Id or IdKey.

  • WaitForIndexing() — waits for asynchronous indexing to be completed for this class.

EventQuery<T>
InterfaceResolver
  • GetImplementationClass() — if a property was declared as an interface, an implementation of this method can be used to resolve the actual property type during schema importation.

Class PersisterFactory

Class InterSystems.XEP.PersisterFactory creates a new EventPersister object.

PersisterFactory() Constructor

Creates a new instance of PersisterFactory.

PersisterFactory()
CreatePersister()

PersisterFactory.CreatePersister() returns an instance of EventPersister.

static EventPersister CreatePersister()

see also:

Creating and Connecting an EventPersister

Class EventPersister

Class InterSystems.XEP.EventPersister is the main entry point for the XEP module. It provides methods that can be used to control XEP options, establish a connection, import schema, and produce XEP Event objects. It also provides methods to control transactions and perform other tasks.

Close()

EventPersister.Close() releases all resources held by this instance. Always call Close() on the EventPersister object before it goes out of scope to ensure that all locks, licenses, and other resources associated with the connection are released.

void Close()
Commit()

EventPersister.Commit() commits one level of transaction

void Commit()
Connect()

EventPersister.Connect() establishes a connection to the specified InterSystems IRIS namespace.

void Connect(string host, int port, string nmspace, string username, string password)

parameters:

  • nmspace — namespace to be accessed.

  • username — username for this connection.

  • password — password for this connection.

  • host — host address for TCP/IP connection.

  • port — port number for TCP/IP connection.

If the host address is 127.0.0.1 or localhost, the connection will default to a shared memory connection, which is faster than the standard TCP/IP connection (see “Shared Memory Connections” in Using the InterSystems Managed Provider for .NET).

see also:

Creating and Connecting an EventPersister

DeleteClass()

EventPersister.DeleteClass() deletes an InterSystems IRIS class definition. It does not delete objects associated with the extent (since objects can belong to more than one extent), and does not delete any dependencies (for example, inner or embedded classes).

void DeleteClass(string className)

parameter:

  • className — name of the class to be deleted.

If the specified class does not exist, the call silently fails (no error is thrown).

see also:

“Deleting Test Data” in Accessing Stored Events

DeleteExtent()

EventPersister.DeleteExtent() deletes the extent definition associated with a .NET event, but does not destroy associated data (since objects can belong to more than one extent). See “Extents” in Defining and Using Classes for more information on managing extents.

void DeleteExtent(string className)
  • className — name of the extent.

Do not confuse this method with the deprecated Event.DeleteExtent(), which destroys all extent data as well as with the extent definition.

see also:

“Deleting Test Data” in Accessing Stored Events

GetAdoConnection()

EventPersister.GetAdoNetConnection() returns the ADO.NET connection underlying an EventPersister connection.

System.Data.Common.DbConnection GetAdoNetConnection()

see also:

Creating and Connecting an EventPersister

Important:

The ADO.NET connection is also used by the XEP engine, so the users should be careful not to close or corrupt the connection obtained by this method as that might cause the XEP engine to fail.

GetEvent()

EventPersister.GetEvent() returns an Event object that corresponds to the class name supplied, and optionally specifies the indexing mode to be used.

Event GetEvent(string className)
Event GetEvent(string className, int indexMode)

parameter:

  • className — class name of the object to be returned.

  • indexMode — indexing mode to be used.

The following indexMode options are available:

  • Event.INDEX_MODE_ASYNC_ON — enables asynchronous indexing. This is the default when the indexMode parameter is not specified.

  • Event.INDEX_MODE_ASYNC_OFF — no indexing will be performed unless the StartIndexing() method is called.

  • Event.INDEX_MODE_SYNC — indexing will be performed each time the extent is changed, which can be inefficient for large numbers of transactions. This index mode must be specified if the class has a user-assigned IdKey.

The same instance of Event can be used to store or retrieve all instances of a class, so a process should only call the GetEvent() method once per class. Avoid instantiating multiple Event objects for a single class, since this can affect performance and may cause memory leaks.

see also:

Creating Event Instances and Storing Persistent Events, Controlling Index Updating

GetInterfaceResolver()

EventPersister.GetInterfaceResolver() — returns the currently set instance of InterfaceResolver that will be used by ImportSchema() (see “Implementing an InterfaceResolver”). Returns null if no instance has been set.

InterfaceResolver GetInterfaceResolver()

see also:

SetInterfaceResolver(), ImportSchema()

GetTransactionLevel()

EventPersister.GetTransactionLevel() returns the current transaction level (0 if not in a transaction)

int GetTransactionLevel()
ImportSchema()

EventPersister.ImportSchema() produces a flat schema (see “Schema Import Models”) that embeds all referenced objects as serialized objects. The method imports the schema of each event declared in the class or a .dll file specified (including dependencies), and returns an array of class names for the imported events.

string[] ImportSchema(string classOrDLLName)
string[] ImportSchema(string[] classes)

parameters:

  • classes — an array containing the names of the classes to be imported.

  • classOrDLLName — a class name or the name of a .dll file containing the classes to be imported. If a .dll file is specified, all classes in the file will be imported.

If the argument is a class name, the corresponding class and any dependencies will be imported. If the argument is a .dll file, all classes in the file and any dependencies will be imported. If such schema already exists, and it appears to be in sync with the .NET schema, import will be skipped. Should a schema already exist, but it appears different, a check will be performed to see if there is any data. If there is no data, a new schema will be generated. If there is existing data, an exception will be thrown.

see also:

Importing a Schema

ImportSchemaFull()

EventPersister.ImportSchemaFull() — produces a full schema (see “Schema Import Models”) that preserves the object hierarchy of the source classes. The method imports the schema of each event declared in the class or .dll file specified (including dependencies), and returns an array of class names for the imported events.

string[] ImportSchemaFull(string classOrDLLName)
string[] ImportSchemaFull(string[] classes)

parameters:

  • classes — an array containing the names of the classes to be imported.

  • classOrDLLName — a class name or the name of a .dll file containing the classes to be imported. If a .dll file is specified, all classes in the file will be imported.

If the argument is a class name, the corresponding class and any dependencies will be imported. If the argument is a .dll file, all classes in the file and any dependencies will be imported. If such schema already exists, and it appears to be in sync with the .NET schema, import will be skipped. Should a schema already exist, but it appears different, a check will be performed to see if there is any data. If there is no data, a new schema will be generated. If there is existing data, an exception will be thrown.

see also:

Importing a Schema

Rollback()

EventPersister.Rollback() rolls back the specified number of levels of transaction, where level is a positive integer, or roll back all levels of transaction if no level is specified.

void Rollback()
void Rollback(int level)

parameter:

  • level — optional number of levels to roll back.

This method does nothing if level is less than 0, and stops rolling back once the transaction level reaches 0 if level is greater than the initial transaction level.

SetInterfaceResolver()

EventPersister.SetInterfaceResolver() — sets the instance of InterfaceResolver to be used by ImportSchema() (see “Implementing an InterfaceResolver”). All instances of Event created by this EventPersiser will share the specified InterfaceResolver (which defaults to null if this method is not called).

void SetInterfaceResolver(InterfaceResolver interfaceResolver)

parameters:

  • interfaceResolver — an implementation of InterfaceResolver that will be used by ImportSchema() to determine the actual type of properties declared as interfaces. This argument can be null.

see also:

GetInterfaceResolver(), ImportSchema()

Class Event

Class InterSystems.XEP.Event provides methods that operate on XEP events (storing events, creating a query, indexing etc.). It is created by the EventPersister.GetEvent() method.

Close()

Event.Close() releases all resources held by this instance. Always call Close() on the Event object before it goes out of scope to ensure that all locks, licenses, and other resources associated with the connection are released.

void Close()
CreateQuery()

Event.CreateQuery() takes a String argument containing the text of the SQL query and returns an instance of EventQuery<T>, where parameter T is the target class of the parent Event.

EventQuery<T> CreateQuery(string sqlText)

parameter:

  • sqlText — text of the SQL query.

see also:

Creating and Executing a Query

DeleteObject()

Event.DeleteObject() deletes an event identified by its database object ID or IdKey.

void DeleteObject(long id)
void DeleteObject(object[] idkeys)

parameter:

  • id — database object ID

  • idkeys — an array of objects that make up the IdKey (see “Using IdKeys”). An XEPException will be thrown if the underlying class has no IdKeys or if any of the keys supplied is equal to null or of an invalid type.

see also:

Accessing Stored Events

GetObject()

Event.GetObject() fetches an event identified by its database object ID or IdKey. Returns null if the specified object does not exist.

object GetObject(long id)
object GetObject(object[] idkeys)

parameter:

  • id — database object ID

  • idkeys — an array of objects that make up the IdKey (see “Using IdKeys”). An XEPException will be thrown if the underlying class has no IdKeys or if any of the keys supplied is equal to null or of an invalid type.

see also:

Accessing Stored Events

IsEvent()

Event.IsEvent() throws an XEPException if the object (or class) is not an event in the XEP sense (see “Requirements for Imported Classes”). The exception message will explain why the object is not an XEP event.

static void IsEvent(object objectOrClass)

parameter:

  • objectOrClass — the object to be tested.

StartIndexing()

Event.StartIndexing() starts asynchronous index building for the extent of the target class. Throws an exception if the index mode is Event.INDEX_MODE_SYNC (see “Controlling Index Updating”).

void StartIndexing()
StopIndexing()

Event.StopIndexing() stops asynchronous index building for the extent. If you do not want the index to be updated when the Event instance is closed, call this method before calling Event.Close().

void StopIndexing()

see also:

Controlling Index Updating

Store()

Event.Store() stores a .NET object or array of objects as persistent events. Returns a long database ID for each newly inserted object, or 0 if the ID could not be returned or the event uses an IdKey.

long Store(object obj)
long[] Store(object[] objects)

parameters:

  • obj — .NET object to be added to the database.

  • objects — array of .NET objects to be added to the database. All objects must be of the same type.

UpdateObject()

Event.UpdateObject() updates an event identified by its database ID or IdKey.

void UpdateObject(long id, object obj)
void UpdateObject(object[] idkeys, object obj)

parameter:

  • id — database object ID

  • idkeys — an array of objects that make up the IdKey (see “Using IdKeys”). An XEPException will be thrown if the underlying class has no IdKeys or if any of the keys supplied is equal to null or of an invalid type.

  • obj — new object that will replace the specified event.

see also:

Accessing Stored Events

WaitForIndexing()

Event.WaitForIndexing() waits for asynchronous indexing to be completed, returning true if indexing has been completed, or false if the wait timed out before indexing was completed. Throws an exception if the index mode is Event.INDEX_MODE_SYNC.

bool WaitForIndexing(int timeout)

parameter:

  • timeout — number of seconds to wait before timing out (wait forever if -1, return immediately if 0).

see also:

Controlling Index Updating

Class EventQuery<T>

Class InterSystems.XEP.EventQuery<T> can be used to retrieve, update and delete individual events from the database.

AddParameter()

EventQuery<T>.AddParameter() binds the next parameter in sequence for the SQL query associated with this EventQuery<T>.

void AddParameter(object val)

parameter:

  • val — the value to be used for the next parameter in this query string.

see also:

Creating and Executing a Query

Close()

EventQuery<T>.Close() releases all resources held by this instance. Always call Close() before the EventQuery<T> object goes out of scope to ensure that all locks, licenses, and other resources associated with the connection are released.

void Close()
DeleteCurrent()

EventQuery<T>.DeleteCurrent() deletes the event most recently fetched by GetNext().

void DeleteCurrent()

see also:

Processing Query Data

Execute()

EventQuery<T>.Execute() executes the SQL query associated with this EventQuery<T>. If the query is successful, this EventQuery<T> will contain a resultset that can be accessed by other EventQuery<T> methods.

void Execute()

see also:

Creating and Executing a Query

GetAll()

EventQuery<T>.GetAll() returns objects of target class T from all rows in the resultset as a single list.

System.Collections.Generic.List<T> GetAll()

Uses GetNext() to get all target class T objects in the resultset, and returns them in a List. The list cannot be used for updating or deleting (although Event methods UpdateObject() and DeleteObject() can be used if you have some way of obtaining the Id or IdKey of each object). GetAll() and GetNext() cannot access the same resultset — once either method has been called, the other method cannot be used until Execute() is called again.

This method is more resource-intensive than a loop that explicitly calls GetNext() for each item, since there is a high cost associated with maintaining a list of objects.

see also:

Processing Query Data, Event.UpdateObject(), Event.DeleteObject()

GetFetchLevel()

EventQuery<T>.GetFetchLevel() returns the current fetch level (see “Defining the Fetch Level”).

int GetFetchLevel()
GetNext()

EventQuery<T>.GetNext() returns an object of target class T from the next row of the resultset. Returns null if there are no more items in the resultset.

E GetNext()

see also:

Processing Query Data

SetFetchLevel()

EventQuery<T>.SetFetchLevel() controls the amount of data returned by setting a fetch level (see “Defining the Fetch Level”).

For example, by setting the fetch level to Event.FETCH_LEVEL_DATATYPES_ONLY, objects returned by this query will only have their datatype properties set, and any object type, array, or collection properties will not get populated. Using this option can dramatically improve query performance.

void SetFetchLevel(int level)

parameter:

  • level — fetch level constant (defined in the Event class).

Supported fetch levels are:

  • Event.FETCH_LEVEL_ALL —default, all properties populated

  • Event.FETCH_LEVEL_DATATYPES_ONLY —only datatype properties filled in

  • Event.FETCH_LEVEL_NO_ARRAY_TYPES —all arrays will be skipped

  • Event.FETCH_LEVEL_NO_OBJECT_TYPES —all object types will be skipped

  • Event.FETCH_LEVEL_NO_COLLECTIONS —all collections will be skipped

UpdateCurrent()

EventQuery<T>.UpdateCurrent() updates the object most recently fetched by GetNext().

void UpdateCurrent(T obj)

parameter:

  • obj — the .NET object that will replace the current event.

see also:

Processing Query Data

Interface InterfaceResolver

By default, properties declared as interfaces are ignored during schema generation. To change this behavior, an implementation of InterfaceResolver can be passed to the ImportSchema() method, providing it with information that allows it to replace an interface type with the correct concrete type.

GetImplementationClass()

InterfaceResolver.GetImplementationClass() returns the actual type of a property declared as an interface. See “Implementing an InterfaceResolver” for details.

Type GetImplementationType(Type declaringClass, string fieldName, Type interfaceClass)

parameters:

  • declaringClass — class where fieldName is declared as interfaceClass.

  • fieldName — name of the property in declaringClass that has been declared as an interface.

  • interfaceClass — the interface to be resolved.

Class XEPException

Class InterSystems.XEP.XEPException implements the exception thrown by most methods of Event, EventPersister, and EventQuery<T>. This class inherits methods and properties from System.SystemException.

FeedbackOpens in a new tab