4.3.1.19 Interface Session

4.3.1.19.1 Synopsis
4.3.1.19.2 close()
4.3.1.19.3 createQuery(QueryDefinition<T>)
4.3.1.19.4 currentTransaction()
4.3.1.19.5 deletePersistent(Class<T>, Object)
4.3.1.19.6 deletePersistent(Object)
4.3.1.19.7 deletePersistentAll(Class<T>)
4.3.1.19.8 deletePersistentAll(Iterable<?>)
4.3.1.19.9 find(Class<T>, Object)
4.3.1.19.10 flush()
4.3.1.19.11 found(Object)
4.3.1.19.12 getQueryBuilder()
4.3.1.19.13 isClosed()
4.3.1.19.14 load(T)
4.3.1.19.15 makePersistent(T)
4.3.1.19.16 makePersistentAll(Iterable<?>)
4.3.1.19.17 markModified(Object, String)
4.3.1.19.18 newInstance(Class<T>)
4.3.1.19.19 newInstance(Class<T>, Object)
4.3.1.19.20 persist(Object)
4.3.1.19.21 remove(Object)
4.3.1.19.22 savePersistent(T)
4.3.1.19.23 savePersistentAll(Iterable<?>)
4.3.1.19.24 setLockMode(LockMode)
4.3.1.19.25 setPartitionKey(Class<?>, Object)
4.3.1.19.26 unloadSchema(Class<?>)
4.3.1.19.27 updatePersistent(Object)
4.3.1.19.28 updatePersistentAll(Iterable<?>)

Session is the primary user interface to the cluster.

4.3.1.19.1 Synopsis
 public interface Session {
// Public Methods  public void close();
  public Query<T> createQuery(QueryDefinition<T> qd);
  public Transaction currentTransaction();
  public void deletePersistent(Class<T> cls,
                               Object key);

  public void deletePersistent(Object instance);
  public int deletePersistentAll(Class<T> cls);
  public void deletePersistentAll(Iterable<?> instances);
  public find(Class<T> cls,
                Object key);

  public void flush();
  public Boolean found(Object instance);
  public QueryBuilder getQueryBuilder();
  public boolean isClosed();
  public load(instance);
  public makePersistent(instance);
  public Iterable<?> makePersistentAll(Iterable<?> instances);
  public void markModified(Object instance,
                           String fieldName);

  public newInstance(Class<T> cls);
  public newInstance(Class<T> cls,
                       Object key);

  public void persist(Object instance);
  public void remove(Object instance);
  public savePersistent(instance);
  public Iterable<?> savePersistentAll(Iterable<?> instances);
  public void setLockMode(LockMode lockmode);
  public void setPartitionKey(Class<?> cls,
                              Object key);

  public String unloadSchema(Class<?> cls);
  public void updatePersistent(Object instance);
  public void updatePersistentAll(Iterable<?> instances);
}
4.3.1.19.2 close()
public void close();

Close this session.

4.3.1.19.3 createQuery(QueryDefinition<T>)
public Query<T> createQuery(QueryDefinition<T> qd);

Create a Query from a QueryDefinition.

Parameters

qd

the query definition

return

the query instance

4.3.1.19.4 currentTransaction()
public Transaction currentTransaction();

Get the current com.mysql.clusterj.Transaction.

Parameters

return

the transaction

4.3.1.19.5 deletePersistent(Class<T>, Object)
public 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.

Parameters

cls

the interface or dynamic class

key

the primary key

4.3.1.19.6 deletePersistent(Object)
public 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.

Parameters

instance

the instance to delete

4.3.1.19.7 deletePersistentAll(Class<T>)
public 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.

Parameters

cls

the interface or dynamic class

return

the number of instances deleted

4.3.1.19.8 deletePersistentAll(Iterable<?>)
public void deletePersistentAll(Iterable<?> instances);

Delete all parameter instances from the database.

Parameters

instances

the instances to delete

4.3.1.19.9 find(Class<T>, Object)
public 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.

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

4.3.1.19.10 flush()
public void flush();

Flush deferred changes to the back end. Inserts, deletes, loads, and updates are sent to the back end.

4.3.1.19.11 found(Object)
public Boolean found(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

  • null if the instance is null or was created via newInstance and never loaded;

  • true if the instance was returned from a find or query or created via newInstance and successfully loaded;

  • false if the instance was created via newInstance and not found.

4.3.1.19.12 getQueryBuilder()
public QueryBuilder getQueryBuilder();

Get a QueryBuilder.

Parameters

return

the query builder

4.3.1.19.13 isClosed()
public boolean isClosed();

Is this session closed?

Parameters

return

true if the session is closed

4.3.1.19.14 load(T)
public load(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

4.3.1.19.15 makePersistent(T)
public makePersistent(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

4.3.1.19.16 makePersistentAll(Iterable<?>)
public Iterable<?> makePersistentAll(Iterable<?> instances);

Insert the instances into the database.

Parameters

instances

the instances to insert.

return

the instances

4.3.1.19.17 markModified(Object, String)
public void markModified(Object instance,
                         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

4.3.1.19.18 newInstance(Class<T>)
public newInstance(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

4.3.1.19.19 newInstance(Class<T>, Object)
public 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.

Parameters

cls

the interface for which to create an instance

return

an instance that implements the interface

4.3.1.19.20 persist(Object)
public void persist(Object instance);

Insert the instance into the database. This method has identical semantics to makePersistent.

Parameters

instance

the instance to insert

4.3.1.19.21 remove(Object)
public void remove(Object instance);

Delete the instance from the database. This method has identical semantics to deletePersistent.

Parameters

instance

the instance to delete

4.3.1.19.22 savePersistent(T)
public savePersistent(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

4.3.1.19.23 savePersistentAll(Iterable<?>)
public Iterable<?> savePersistentAll(Iterable<?> instances);

Update all parameter instances in the database.

Parameters

instances

the instances to update

4.3.1.19.24 setLockMode(LockMode)
public 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.

Parameters

lockmode

the LockMode

4.3.1.19.25 setPartitionKey(Class<?>, Object)
public 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.

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

4.3.1.19.26 unloadSchema(Class<?>)
public 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.

Parameters

cls

the class for which the schema is unloaded

return

the name of the schema that was unloaded

4.3.1.19.27 updatePersistent(Object)
public 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.

Parameters

instance

the instance to update

4.3.1.19.28 updatePersistentAll(Iterable<?>)
public void updatePersistentAll(Iterable<?> instances);

Update all parameter instances in the database.

Parameters

instances

the instances to update