- 4.3.1.20.1 Synopsis
- 4.3.1.20.2 close()
- 4.3.1.20.3 createQuery(QueryDefinition<T>)
- 4.3.1.20.4 currentTransaction()
- 4.3.1.20.5 deletePersistent(Class<T>, Object)
- 4.3.1.20.6 deletePersistent(Object)
- 4.3.1.20.7 deletePersistentAll(Class<T>)
- 4.3.1.20.8 deletePersistentAll(Iterable<?>)
- 4.3.1.20.9 find(Class<T>, Object)
- 4.3.1.20.10 flush()
- 4.3.1.20.11 found(Object)
- 4.3.1.20.12 getQueryBuilder()
- 4.3.1.20.13 isClosed()
- 4.3.1.20.14 load(T)
- 4.3.1.20.15 makePersistent(T)
- 4.3.1.20.16 makePersistentAll(Iterable<?>)
- 4.3.1.20.17 markModified(Object, String)
- 4.3.1.20.18 newInstance(Class<T>)
- 4.3.1.20.19 newInstance(Class<T>, Object)
- 4.3.1.20.20 persist(Object)
- 4.3.1.20.21 release(T)
- 4.3.1.20.22 remove(Object)
- 4.3.1.20.23 savePersistent(T)
- 4.3.1.20.24 savePersistentAll(Iterable<?>)
- 4.3.1.20.25 setLockMode(LockMode)
- 4.3.1.20.26 setPartitionKey(Class<?>, Object)
- 4.3.1.20.27 unloadSchema(Class<?>)
- 4.3.1.20.28 updatePersistent(Object)
- 4.3.1.20.29 updatePersistentAll(Iterable<?>)
Session is the primary user interface to the cluster. Session extends AutoCloseable so it can be used in the try-with-resources pattern. This pattern allows the application to create a session in the try declaration and regardless of the outcome of the try/catch/finally block, clusterj will clean up and close the session. If the try block exits with an open transaction, the transaction will be rolled back before the session is closed.
public interface Session extends, AutoCloseable {
// Public Methodspublic abstract void close();
public abstract Query<T> createQuery(QueryDefinition<T> qd);
public abstract Transaction currentTransaction();
public abstract void deletePersistent(Class<T> cls,
Object key);public abstract void deletePersistent(Object instance);
public abstract int deletePersistentAll(Class<T> cls);
public abstract void deletePersistentAll(Iterable<?> instances);
public abstract T find(Class<T> cls,
Object key);public abstract void flush();
public abstract Boolean found(Object instance);
public abstract QueryBuilder getQueryBuilder();
public abstract boolean isClosed();
public abstract T load(T instance);
public abstract T makePersistent(T instance);
public abstract Iterable<?> makePersistentAll(Iterable<?> instances);
public abstract void markModified(Object instance,
String fieldName);public abstract T newInstance(Class<T> cls);
public abstract T newInstance(Class<T> cls,
Object key);public abstract void persist(Object instance);
public abstract T release(T obj);
public abstract void remove(Object instance);
public abstract T savePersistent(T instance);
public abstract Iterable<?> savePersistentAll(Iterable<?> instances);
public abstract void setLockMode(LockMode lockmode);
public abstract void setPartitionKey(Class<?> cls,
Object key);public abstract String unloadSchema(Class<?> cls);
public abstract void updatePersistent(Object instance);
public abstract void updatePersistentAll(Iterable<?> instances);
}
public abstract void close();
Specified by: Method
close
in interface
AutoCloseable
Close this session.
public abstract Query<T> createQuery(QueryDefinition<T> qd);
Create a Query from a QueryDefinition.
Table 4.45 createQuery(QueryDefinition<T>)
Parameter | Description |
---|---|
qd | the query definition |
return | the query instance |
public abstract void deletePersistent(Class<T> cls,
Object key);
Delete an instance of a class from the database given its primary key. For single-column keys, the key parameter is a wrapper (e.g. Integer). For multi-column keys, the key parameter is an Object[] in which elements correspond to the primary keys in order as defined in the schema.
Table 4.47 deletePersistent(Class<T>, Object)
Parameter | Description |
---|---|
cls | the interface or dynamic class |
key | the primary key |
public abstract void deletePersistent(Object instance);
Delete the instance from the database. Only the id field is used to determine which instance is to be deleted. If the instance does not exist in the database, an exception is thrown.
public abstract int deletePersistentAll(Class<T> cls);
Delete all instances of this class from the database. No exception is thrown even if there are no instances in the database.
Table 4.49 deletePersistentAll(Class<T>)
Parameter | Description |
---|---|
cls | the interface or dynamic class |
return | the number of instances deleted |
public abstract void deletePersistentAll(Iterable<?> instances);
Delete all parameter instances from the database.
public abstract T find(Class<T> cls,
Object key);
Find a specific instance by its primary key. The key must be of the same type as the primary key defined by the table corresponding to the cls parameter. The key parameter is the wrapped version of the primitive type of the key, e.g. Integer for INT key types, Long for BIGINT key types, or String for char and varchar types. For multi-column primary keys, the key parameter is an Object[], each element of which is a component of the primary key. The elements must be in the order of declaration of the columns (not necessarily the order defined in the CONSTRAINT ... PRIMARY KEY clause) of the CREATE TABLE statement.
Table 4.51 find(Class<T>, Object)
Parameter | Description |
---|---|
cls | the interface or dynamic class to find an instance of |
key | the key of the instance to find |
return | the instance of the interface or dynamic class with the specified key |
public abstract void flush();
Flush deferred changes to the back end. Inserts, deletes, loads, and updates are sent to the back end.
public abstract Boolean found(Object instance);
Was the row corresponding to this instance found in the database?
Table 4.52 found(Object)
Parameter | Description |
---|---|
instance | the instance corresponding to the row in the database |
return |
|
public abstract QueryBuilder getQueryBuilder();
Get a QueryBuilder.
public abstract boolean isClosed();
Is this session closed?
public abstract T load(T instance);
Load the instance from the database into memory. Loading is asynchronous and will be executed when an operation requiring database access is executed: find, flush, or query. The instance must have been returned from find or query; or created via session.newInstance and its primary key initialized.
- See Also
- found(java.lang.Object)
public abstract T makePersistent(T instance);
Insert the instance into the database. If the instance already exists in the database, an exception is thrown.
Table 4.56 makePersistent(T)
Parameter | Description |
---|---|
instance | the instance to insert |
return | the instance |
- See Also
- savePersistent(T)
public abstract Iterable<?> makePersistentAll(Iterable<?> instances);
Insert the instances into the database.
Table 4.57 makePersistentAll(Iterable<?>)
Parameter | Description |
---|---|
instances | the instances to insert. |
return | the instances |
public abstract void markModified(Object instance,
String fieldName);
Mark the field in the object as modified so it is flushed.
Table 4.58 markModified(Object, String)
Parameter | Description |
---|---|
instance | the persistent instance |
fieldName | the field to mark as modified |
public abstract T newInstance(Class<T> cls);
Create an instance of an interface or dynamic class that maps to a table.
Table 4.59 newInstance(Class<T>)
Parameter | Description |
---|---|
cls | the interface for which to create an instance |
return | an instance that implements the interface |
public abstract T newInstance(Class<T> cls,
Object key);
Create an instance of an interface or dynamic class that maps to a table and set the primary key of the new instance. The new instance can be used to create, delete, or update a record in the database.
Table 4.60 newInstance(Class<T>, Object)
Parameter | Description |
---|---|
cls | the interface for which to create an instance |
return | an instance that implements the interface |
public abstract void persist(Object instance);
Insert the instance into the database. This method has identical semantics to makePersistent.
public abstract T release(T obj);
Release resources associated with an instance. The instance must be a domain object obtained via session.newInstance(T.class), find(T.class), or query; or Iterable, or array T[]. Resources released can include direct buffers used to hold instance data. Released resources may be returned to a pool.
Table 4.62 release(T)
Parameter | Description |
---|---|
obj | a domain object of type T, an Iterable, or array T[] |
return | the input parameter |
Exceptions
-
ClusterJUserException
if the instance is not a domain object T, Iterable, or array T[], or if the object is used after calling this method.
public abstract void remove(Object instance);
Delete the instance from the database. This method has identical semantics to deletePersistent.
public abstract T savePersistent(T instance);
Save the instance in the database without checking for existence. The id field is used to determine which instance is to be saved. If the instance exists in the database it will be updated. If the instance does not exist, it will be created.
public abstract Iterable<?> savePersistentAll(Iterable<?> instances);
Update all parameter instances in the database.
public abstract void setLockMode(LockMode lockmode);
Set the lock mode for read operations. This will take effect immediately and will remain in effect until this session is closed or this method is called again.
public abstract void setPartitionKey(Class<?> cls,
Object key);
Set the partition key for the next transaction. The key must be of the same type as the primary key defined by the table corresponding to the cls parameter. The key parameter is the wrapped version of the primitive type of the key, e.g. Integer for INT key types, Long for BIGINT key types, or String for char and varchar types. For multi-column primary keys, the key parameter is an Object[], each element of which is a component of the primary key. The elements must be in the order of declaration of the columns (not necessarily the order defined in the CONSTRAINT ... PRIMARY KEY clause) of the CREATE TABLE statement.
Table 4.67 setPartitionKey(Class<?>, Object)
Parameter | Description |
---|---|
key | the primary key of the mapped table |
Exceptions
-
ClusterJUserException
if a transaction is enlisted
-
ClusterJUserException
if a partition key is null
-
ClusterJUserException
if called twice in the same transaction
-
ClusterJUserException
if a partition key is the wrong type
public abstract String unloadSchema(Class<?> cls);
Unload the schema definition for a class. This must be done after the schema definition has changed in the database due to an alter table command. The next time the class is used the schema will be reloaded.
Table 4.68 unloadSchema(Class<?>)
Parameter | Description |
---|---|
cls | the class for which the schema is unloaded |
return | the name of the schema that was unloaded |
public abstract void updatePersistent(Object instance);
Update the instance in the database without necessarily retrieving it. The id field is used to determine which instance is to be updated. If the instance does not exist in the database, an exception is thrown. This method cannot be used to change the primary key.