- 4.3.1.20.1 概要
- 4.3.1.20.2 关闭()
- 4.3.1.20.3 创建查询(查询定义<T>)
- 4.3.1.20.4 当前交易()
- 4.3.1.20.5 deletePersistent(Class<T>, Object)
- 4.3.1.20.6 deletePersistent(对象)
- 4.3.1.20.7 deletePersistentAll(类<T>)
- 4.3.1.20.8 deletePersistentAll(可迭代<?>)
- 4.3.1.20.9 查找(类<T>,对象)
- 4.3.1.20.10 冲洗()
- 4.3.1.20.11 找到(对象)
- 4.3.1.20.12 getQueryBuilder()
- 4.3.1.20.13 isClosed()
- 4.3.1.20.14 负载(T)
- 4.3.1.20.15 持久化(T)
- 4.3.1.20.16 makePersistentAll(可迭代<?>)
- 4.3.1.20.17 标记修改(对象,字符串)
- 4.3.1.20.18 新实例(类<T>)
- 4.3.1.20.19 新实例(类<T>,对象)
- 4.3.1.20.20 坚持(对象)
- 4.3.1.20.21 发布(T)
- 4.3.1.20.22 删除(对象)
- 4.3.1.20.23 保存持久性(T)
- 4.3.1.20.24 savePersistentAll(可迭代<?>)
- 4.3.1.20.25 设置锁定模式(锁定模式)
- 4.3.1.20.26 setPartitionKey(Class<?>, Object)
- 4.3.1.20.27 unloadSchema(类<?>)
- 4.3.1.20.28 更新持久性(对象)
- 4.3.1.20.29 updatePersistentAll(可迭代<?>)
会话是集群的主要用户界面。Session 扩展了 AutoCloseable,所以它可以用在 try-with-resources 模式中。这种模式允许应用程序在 try 声明中创建一个会话,无论 try/catch/finally 块的结果如何,clusterj 都会清理并关闭会话。如果 try 块以打开的事务退出,则事务将在会话关闭之前回滚。
public interface Session extends, AutoCloseable {
// 公共方法}public 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 Query<T> createQuery(QueryDefinition<T> qd);
从 QueryDefinition 创建查询。
public abstract void deletePersistent(Class<T> cls,
Object key);
给定主键从数据库中删除一个类的实例。对于单列键,键参数是一个包装器(例如 Integer)。对于多列键,键参数是一个 Object[],其中元素按模式中定义的顺序对应于主键。
public abstract void deletePersistent(Object instance);
从数据库中删除实例。只有 id 字段用于确定要删除哪个实例。如果数据库中不存在该实例,则抛出异常。
public abstract int deletePersistentAll(Class<T> cls);
从数据库中删除此类的所有实例。即使数据库中没有实例也不会抛出异常。
public abstract void deletePersistentAll(Iterable<?> instances);
从数据库中删除所有参数实例。
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.