public interface Session
Session is the central client-interfaced object to control
NoSQL datastore on Acid House and represents interactive session between
client and NoSQL datastore.
Basic CRUD operations are like this, in App Engine example:
import org.eiichiro.acidhouse.Session;
import org.eiichiro.acidhouse.appengine.AppEngineDatastoreSession;
...
// Creating entity.
Entity1 entity11 = new Entity1();
entity11.id = "Key11";
entity11.i = 11;
Entity1 entity12 = new Entity1();
entity12.id = "Key12";
entity12.i = 12;
Session session = new AppEngineDatastoreSession();
Transaction transaction = session.beginTransaction();
try {
session.put(entity11);
session.put(entity12);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
throw e;
} finally {
session.close();
}
// Reading entity.
Session session = new AppEngineDatastoreSession();
Entity1 entity11 = session.get(Entity1.class, "Key11");
Entity1 entity12 = session.get(Entity1.class, "Key12");
session.close();
// Updating entity.
Session session = new AppEngineDatastoreSession();
Transaction transaction = session.beginTransaction();
try {
Entity1 entity11 = session.get(Entity1.class, "Key11");
Entity1 entity12 = session.get(Entity1.class, "Key12");
entity11.i = 1111;
entity12.i = 1222;
session.update(entity11);
session.update(entity12);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
throw e;
} finally {
session.close();
}
// Deleting entity.
Session session = new AppEngineDatastoreSession();
Transaction transaction = session.beginTransaction();
try {
Entity1 entity11 = session.get(Entity1.class, "Key11");
Entity1 entity12 = session.get(Entity1.class, "Key12");
session.delete(entity11);
session.delete(entity12);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
throw e;
} finally {
session.close();
}
| Modifier and Type | Method and Description |
|---|---|
Transaction |
beginTransaction()
Begins transaction.
|
void |
close()
Closes this session.
|
<E> Delete<E> |
delete(Metamodel<E> metamodel)
Returns
Delete for the specified entity metamodel. |
void |
delete(Object entity)
Deletes the specified entity from datastore.
|
<E,R> GetScalar<E,R> |
get(Aggregation<R> aggregation)
Returns
GetScalar for the specified Aggregation. |
<E> E |
get(Class<E> clazz,
Object key)
Returns the entity instance corresponding to the specified key.
|
<E> GetList<E> |
get(Metamodel<E> metamodel)
Returns
GetList for the specified entity metamodel. |
void |
put(Object entity)
Puts the specified entity instance into datastore newly.
|
<E> Update<E> |
update(Metamodel<E> metamodel)
Returns
Update for the specified entity metamodel. |
void |
update(Object entity)
Updates entity with the specified entity instance.
|
Transaction beginTransaction()
void close()
<E> E get(Class<E> clazz, Object key) throws ConcurrentModificationException
null is returned if the entity is not found.E - The entity type.clazz - The entity type that you want to get.key - The key corresponding to the entity that you want to get.ConcurrentModificationException - If the entity corresponding to
the specified key is being modified by the other transaction.void put(Object entity) throws EntityExistsException
EntityExistsException.entity - The entity instance to be put into Session.EntityExistsException - If the entity that has the same key as the
specified entity has already existed.void update(Object entity)
entity - The entity instance to be updated.void delete(Object entity)
entity - The entity to be deleted.<E> GetList<E> get(Metamodel<E> metamodel)
GetList for the specified entity metamodel.
This method is the entry point for getting-list Command Builder API.E - The entity type to get with this GetList.metamodel - The metamodel of the entity to get with this
GetList.GetList for the specified entity class.<E,R> GetScalar<E,R> get(Aggregation<R> aggregation)
GetScalar for the specified Aggregation.
This method is the entry point for aggregation Command Builder API.R - The property value type to aggregate with this
GetScalar.aggregation - The Aggregation this method executes.GetScalar for the specified Aggregation
instance.<E> Update<E> update(Metamodel<E> metamodel)
Update for the specified entity metamodel.
This method is the entry point for updating Command Builder API.E - The type of entity updated by this Update.metamodel - The metamodel of the entity updated by this
Update.Update for the specified entity class.<E> Delete<E> delete(Metamodel<E> metamodel)
Delete for the specified entity metamodel.
This method is the entry point for deleting Command Builder API.E - The type of entity deleted by this Delete.metamodel - The metamodel of the entity deleted by this
Delete.Delete for the specified entity class.Copyright © 2009-2014 Eiichiro Uchiumi. All Rights Reserved.