Learning
Community
Open Exchange
Global Masters
InterSystems IRIS Data Platform 2019.3 / Application Development / Persisting Java Objects with InterSystems XEP / XEP Quick Reference
Previous section   

XEP Quick Reference

This chapter is a quick reference for the com.intersystems.xep package, which contains the public API described in this book.
Note:
This chapter is intended as a convenience for readers of this book, but it is not the definitive reference for XEP. For the most complete and up-to-date information on these classes, see the XEP API online documentation.

XEP Quick Reference

This section is a reference for the XEP API (namespace com.intersystems.xep). See Using XEP Event Persistence for a details on how to use the API. It contains 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 a specific type from the database for update or deletion.
  • Class EventQueryIterator<T> — provides an alternative to EventQuery<T> for retrieving, updating and deleting XEP events, using methods similar to those in Java Iterator.
  • Interface InterfaceResolver — resolves the actual type of a field during flat schema importation if the field was declared as an interface.
  • Class XEPException — is the exception thrown by most XEP methods.

List of XEP Methods

The following classes and methods of the XEP API are described in this reference:
PersisterFactory
EventPersister
Event
  • close() — releases all resources held by this instance.
  • createQuery() — creates a 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>
EventQueryIterator<T>
  • hasNext() — returns true if the query resultset has more items.
  • next() — fetches the next event in the resultset.
  • remove() — deletes the event most recently fetched by next().
  • set() — assigns a new value to the event most recently fetched by next().
InterfaceResolver
  • getImplementationClass() — if a field was declared as an interface, an implementation of this method can be used to resolve the actual field type during schema importation.

Class PersisterFactory

PersisterFactory() Constructor
Creates a new instance of PersisterFactory.
PersisterFactory()
createPersister()
PersisterFactory.createPersister() returns an instance of EventPersister.
static EventPersister createPersister()  [inline, static] 
see also:

Class EventPersister

Class com.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.
In most applications, instances of EventPersister should be created by PersisterFactory.createPersister(). The constructor should only be used to extend the class.
EventPersister() Constructor
Creates a new instance of EventPersister.
EventPersister()
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 namespace, String username, String password) 
parameters:
  • host — host address for TCP/IP connection.
  • port — port number for TCP/IP connection.
  • namespace — namespace to be accessed.
  • username — username for this connection.
  • password — password for this 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 Java with the InterSystems JDBC Driver).
see also:
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 Java 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
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:
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:
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 .jar file specified (including dependencies), and returns an array of class names for the imported events.
String[] importSchema(String classOrJarFileName)
String[] importSchema(String[] classes)
parameters:
  • classes — an array containing the names of the classes to be imported.
  • classOrJarFileName — a class name or the name of a .jar file containing the classes to be imported. If a .jar 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 .jar 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 Java 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:
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 .jar file specified (including dependencies), and returns an array of class names for the imported events.
String[] importSchemaFull(String classOrJarFileName)
String[] importSchemaFull(String[] classes)
parameters:
  • classes — an array containing the names of the classes to be imported.
  • classOrJarFileName — a class name or the name of a .jar file containing the classes to be imported. If a .jar 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 .jar 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 Java 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:
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 fields declared as interfaces. This argument can be null.
see also:

Class Event

Class com.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.
<T> EventQuery<T> createQuery (String sqlText)
parameter:
  • sqlText — text of the SQL query.
see also:
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:
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:
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:
store()
Event.store() stores a Java 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 object)
long[] store(Object[] objects)
parameters:
  • object — Java object to be added to the database.
  • objects — array of Java 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 object)
void updateObject(Object[] idkeys, Object object)
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.
  • object — new object that will replace the specified event.
see also:
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.
boolean waitForIndexing(int timeout)
parameter:
  • timeout — number of seconds to wait before timing out (wait forever if -1, return immediately if 0).
see also:

Class EventQuery<T>

Class com.intersystems.xep.EventQuery<T> can be used to retrieve, update and delete individual events from the database.
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:
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> or EventQueryIterator<T> methods.
void execute()
see also:
getAll()
EventQuery<T>.getAll() returns objects of target class T from all rows in the resultset as a single list.
java.util.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.
see also:
getFetchLevel()
EventQuery<T>.getFetchLevel() returns the current fetch level (see “Defining the Fetch Level”).
int getFetchLevel()
getIterator()
EventQuery<T>.getIterator() returns an EventQueryIterator<T> that can be used to iterate over query results (see “Processing Query Data”).
EventQueryIterator<T> getIterator()
getNext()
EventQuery<T>.getNext() returns an object of target class T from the resultset. It returns the first item in the resultset if the argument is null, or takes the object returned by the previous call to getNext() as an argument and returns the next item in the resultset. Returns null if there are no more items in the resultset.
E getNext(E obj)
parameter:
  • obj — the object returned by the previous call to getNext() (or null to return the first item in the resultset).
see also:
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 fields set, and any object type, array, or collection fields 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 fields populated
  • Event.FETCH_LEVEL_DATATYPES_ONLY —only datatype fields 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
setParameter()
EventQuery<T>.setParameter() binds a parameter for the SQL query associated with this EventQuery<T>.
void setParameter(int index, java.lang.Object value)
parameters:
  • index — the index of this parameter within the query statement.
  • value — the value to be used for this query.
see also:
updateCurrent()
EventQuery<T>.updateCurrent() updates the event most recently fetched by getNext().
void updateCurrent(E obj)
parameter:
  • obj — the Java object that will replace the current event.
see also:

Class EventQueryIterator<T>

Class com.intersystems.xep.EventQueryIterator<T> is the primary way to retrieve, update and delete XEP events (the same task can be also achieved by direct use of EventQuery<T> methods).
hasNext()
EventQueryIterator<T>.hasNext() returns true if the query resultset has more items.
boolean hasNext()
next()
EventQueryIterator<T>.next() fetches the next event in the query resultset.
E next()
remove()
EventQueryIterator<T>.remove() deletes the last event fetched by next().
void remove()
set()
EventQueryIterator<T>.set() replaces the last event fetched by next().
void set(E obj)
parameter:
  • obj — an object of the target class that will replace the last event fetched by next(). .

Interface InterfaceResolver

By default, fields 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 field declared as an interface. See “Implementing an InterfaceResolver” for details.
Class<?>  getImplementationClass (Class declaringClass, String fieldName, Class<?> interfaceClass) 
parameters:
  • declaringClass — class where fieldName is declared as interfaceClass.
  • fieldName — name of the field in declaringClass that has been declared as an interface.
  • interfaceClass — the interface to be resolved.

Class XEPException

Class com.intersystems.xep.XEPException implements the exception thrown by most methods of Event, EventPersister, and EventQuery<T>. This class inherits from java.lang.RuntimeException.
Constructors
  XEPException (String message)
  XEPException (Throwable x, String message)
  XEPException (Throwable x) 
Previous section