Session is the primary user interface to the cluster.
public interface com.mysql.clusterj.Session {
// Public Methodspublic void close();public com.mysql.clusterj.Query<T> createQuery(com.mysql.clusterj.query.QueryDefinition<T> qd);public com.mysql.clusterj.Transaction currentTransaction();public void deletePersistent(java.lang.Class<T> cls,
java.lang.Object key);public void deletePersistent(java.lang.Object instance);public int deletePersistentAll(java.lang.Class<T> cls);public void deletePersistentAll(java.lang.Iterable<?> instances);public T find(java.lang.Class<T> cls,
java.lang.Object key);public void flush();public java.lang.Boolean found(java.lang.Object instance);public com.mysql.clusterj.query.QueryBuilder getQueryBuilder();public boolean isClosed();public T load(T instance);public T makePersistent(T instance);public java.lang.Iterable<?> makePersistentAll(java.lang.Iterable<?> instances);public void markModified(java.lang.Object instance,
java.lang.String fieldName);public T newInstance(java.lang.Class<T> cls);public T newInstance(java.lang.Class<T> cls,
java.lang.Object key);public void persist(java.lang.Object instance);public void remove(java.lang.Object instance);public T savePersistent(T instance);public java.lang.Iterable<?> savePersistentAll(java.lang.Iterable<?> instances);public void setLockMode(com.mysql.clusterj.LockMode lockmode);public void setPartitionKey(java.lang.Class<?> cls,
java.lang.Object key);public void updatePersistent(java.lang.Object instance);public void updatePersistentAll(java.lang.Iterable<?> instances);
}

public com.mysql.clusterj.Query<T> createQuery(com.mysql.clusterj.query.QueryDefinition<T> qd);Create a Query from a QueryDefinition.
Parameters | |
qd |
the query definition |
return |
the query instance |
public com.mysql.clusterj.Transaction currentTransaction();
Get the current
com.mysql.clusterj.Transaction.
Parameters | |
return |
the transaction |
public void deletePersistent(java.lang.Class<T> cls,
java.lang.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.
Parameters | |
cls |
the interface or dynamic class |
key |
the primary key |
public void deletePersistent(java.lang.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.
Parameters | |
instance |
the instance to delete |
public int deletePersistentAll(java.lang.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.
Parameters | |
cls |
the interface or dynamic class |
return |
the number of instances deleted |
public void deletePersistentAll(java.lang.Iterable<?> instances);Delete all parameter instances from the database.
Parameters | |
instances |
the instances to delete |
public T find(java.lang.Class<T> cls,
java.lang.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.
Parameters | |
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 void flush();Flush deferred changes to the back end. Inserts, deletes, loads, and updates are sent to the back end.
public java.lang.Boolean found(java.lang.Object instance);Was the row corresponding to this instance found in the database?
Parameters | |
instance |
the instance corresponding to the row in the database |
return |
|
public com.mysql.clusterj.query.QueryBuilder getQueryBuilder();Get a QueryBuilder.
Parameters | |
return |
the query builder |
public boolean isClosed();Is this session closed?
Parameters | |
return |
true if the session is closed |
public 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.
Parameters | |
instance |
the instance to load |
return |
the instance |
public T makePersistent(T instance);Insert the instance into the database. If the instance already exists in the database, an exception is thrown.
Parameters | |
instance |
the instance to insert |
return |
the instance |
public java.lang.Iterable<?> makePersistentAll(java.lang.Iterable<?> instances);Insert the instances into the database.
Parameters | |
instances |
the instances to insert. |
return |
the instances |
public void markModified(java.lang.Object instance,
java.lang.String fieldName);Mark the field in the object as modified so it is flushed.
Parameters | |
instance |
the persistent instance |
fieldName |
the field to mark as modified |
public T newInstance(java.lang.Class<T> cls);Create an instance of an interface or dynamic class that maps to a table.
Parameters | |
cls |
the interface for which to create an instance |
return |
an instance that implements the interface |
public T newInstance(java.lang.Class<T> cls,
java.lang.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.
Parameters | |
cls |
the interface for which to create an instance |
return |
an instance that implements the interface |
public void persist(java.lang.Object instance);Insert the instance into the database. This method has identical semantics to makePersistent.
Parameters | |
instance |
the instance to insert |
public void remove(java.lang.Object instance);Delete the instance from the database. This method has identical semantics to deletePersistent.
Parameters | |
instance |
the instance to delete |
public 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.
Parameters | |
instance |
the instance to update |
public java.lang.Iterable<?> savePersistentAll(java.lang.Iterable<?> instances);Update all parameter instances in the database.
Parameters | |
instances |
the instances to update |
public void setLockMode(com.mysql.clusterj.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.
Parameters | |
lockmode |
the LockMode |
public void setPartitionKey(java.lang.Class<?> cls,
java.lang.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.
Parameters | |
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 void updatePersistent(java.lang.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.
Parameters | |
instance |
the instance to update |
