[+/-]
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.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 com.mysql.clusterj.query.QueryBuilder getQueryBuilder();
public boolean isClosed();
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 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 setPartitionKey(java.lang.Class<?> domainClass,
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.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 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.
Parameters | |
cls |
the class to find an instance of |
key |
the key of the instance to find |
return |
the instance of the class with the specified key |
public void flush();
Flush deferred changes to the back end. Inserts, deletes, and updates made when the deferred update flag is true are sent to the back end.
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 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 that maps to a table.
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 setPartitionKey(java.lang.Class<?> domainClass,
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. 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 primary key declaration.
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.
Parameters | |
instance |
the instance to update |