WebSphere® eXtreme Scale uses transactions. After an application has a connection to a data grid, you can access and interact with data in the data grid.
When an application interacts with a Session, it must be in the context of a transaction. A transaction is begun and committed or rolled back using the Session.begin, Session.commit, and Session.rollback methods on the Session object. Applications can also work in auto-commit mode, where the Session automatically begins and commits a transaction whenever the application interacts with Maps. However, the auto-commit mode is slower.
A thread in a Java application needs its own Session. When you want your application to use the ObjectGrid on a thread, call one of the getSession methods to obtain a Session. After the application is finished with the Session, call the Session.close() method. This method closes the session, returning it to the pool and releasing its resources. Closing a session is optional, but improves the performance of subsequent calls to the getSession() method. If the application is using a dependency injection framework such as Spring, you can inject a Session into an application bean when necessary.
After you obtain a Session, the application can access data stored in maps in the ObjectGrid. If the ObjectGrid uses entities, you can use the EntityManager API, which you can obtain with the Session.getEntityManager method. Because it is closer to Java specifications, the EntityManager interface is simpler than the map-based API. However, the EntityManager API carries a performance overhead because it tracks changes in objects. The map-based API is obtained by using the Session.getMap method.
You can customize how much transaction support is needed. Your application can turn off rollback support and locking but at a cost to the application. The application must handle the lack of these features. Examples of how the application can manage transaction support follow:
For example, if the transaction called the ObjectMap.get (Java) or IGridMapPessimisticTx.Get (.NET) method for the object at T1, it got the value at that point in time. If it calls the get method again within that transaction at a later time T2, another thread might have changed the value. Because the value was changed by another thread, the application sees a different value.
If the application modifies an object
retrieved using a NONE CopyMode value, it is changing the committed
copy of that object directly. Rolling back the transaction has no
meaning in this mode. You are changing the only copy in the ObjectGrid.
Although using the NONE CopyMode is fast, be aware of its consequences.
An application that uses a NONE CopyMode must never roll back the
transaction. If the application rolls back the transaction, the indexes
are not updated with the changes and the changes are not replicated
if replication is turned on.
The default values are easy to use and less prone to errors. If you start trading performance in exchange for less reliable data, the application needs to be aware of what it is doing to avoid unintended problems.
Transactions in Java applications can update a single or multiple partitions, however updating a single partition is the default behavior. .NET applications can only update a single partition.
If a transaction has already searched for an Entity, the transaction is associated with the partition for that Entity. Any queries that run on a transaction that is associated with an Entity are routed to the associated partition.
If a query is run on a transaction before it is associated with a partition, you must set the partition ID to use for the query. The partition ID is an integer value. The query is then routed to that partition. This only applies if the transaction is configured to use a one-phase commitment protocol.
Queries only search within a single partition. However, if the session is set using a two-phase commitment protocol, then set the partition ID for the query to -1. This fetches results from all partitions. You can use the DataGrid APIs to run the same query in parallel on all partitions or a subset of partitions. Use the DataGrid APIs to find an entry that might be in any partition.