Search in sources :

Example 51 with ClassInfo

use of siena.ClassInfo in project siena by mandubian.

the class SdbMappingUtils method mapSelectResultToListOrderedFromKeys.

public static <T> void mapSelectResultToListOrderedFromKeys(SelectResult res, List<T> resList, Class<T> clazz, Iterable<?> keys) {
    List<Item> items = res.getItems();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    boolean found;
    for (Object key : keys) {
        found = false;
        for (Item item : items) {
            if (item.getName().equals(getItemNameFromKey(clazz, key))) {
                T obj = Util.createObjectInstance(clazz);
                fillModel(item, clazz, info, obj);
                resList.add(obj);
                items.remove(item);
                found = true;
                break;
            }
        }
        if (!found) {
            // if not found, puts NULL in the list
            resList.add(null);
        }
    }
}
Also used : DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) Item(com.amazonaws.services.simpledb.model.Item) ClassInfo(siena.ClassInfo)

Example 52 with ClassInfo

use of siena.ClassInfo in project siena by mandubian.

the class SdbMappingUtils method getDomainName.

public static String getDomainName(Class<?> clazz, String prefix) {
    ClassInfo ci = ClassInfo.getClassInfo(clazz);
    if (ClassInfo.isAutoIncrement(ci.getIdField())) {
        throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
    }
    String domain = prefix + ci.tableName;
    return domain;
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) ClassInfo(siena.ClassInfo)

Example 53 with ClassInfo

use of siena.ClassInfo in project siena by mandubian.

the class SdbMappingUtils method mapSelectResultToList.

public static <T> void mapSelectResultToList(SelectResult res, List<T> resList, Class<T> clazz, int offset) {
    List<Item> items = res.getItems();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    for (int i = offset; i < items.size(); i++) {
        Item item = items.get(i);
        T obj = Util.createObjectInstance(clazz);
        fillModel(item, clazz, info, obj);
        resList.add(obj);
    }
}
Also used : DeletableItem(com.amazonaws.services.simpledb.model.DeletableItem) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) Item(com.amazonaws.services.simpledb.model.Item) ClassInfo(siena.ClassInfo)

Example 54 with ClassInfo

use of siena.ClassInfo in project siena by mandubian.

the class SdbPersistenceManager method update.

public void update(Object obj) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    String domain = SdbMappingUtils.getDomainName(clazz, prefix);
    try {
        checkDomain(domain);
        sdb.putAttributes(SdbMappingUtils.createPutRequest(domain, clazz, info, obj));
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) SienaException(siena.SienaException) ClassInfo(siena.ClassInfo)

Example 55 with ClassInfo

use of siena.ClassInfo in project siena by mandubian.

the class SdbPersistenceManager method save.

@Override
public void save(Object obj) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    Field idField = info.getIdField();
    //Entity entity;
    Object idVal = Util.readField(obj, idField);
    // id with null value means insert
    if (idVal == null) {
        insert(obj);
    } else // id with not null value means update
    {
        update(obj);
    }
}
Also used : Field(java.lang.reflect.Field) ClassInfo(siena.ClassInfo)

Aggregations

ClassInfo (siena.ClassInfo)68 Field (java.lang.reflect.Field)33 ArrayList (java.util.ArrayList)24 Key (com.google.appengine.api.datastore.Key)23 SienaException (siena.SienaException)21 Entity (com.google.appengine.api.datastore.Entity)17 QueryResultList (com.google.appengine.api.datastore.QueryResultList)10 List (java.util.List)10 DeletableItem (com.amazonaws.services.simpledb.model.DeletableItem)6 Item (com.amazonaws.services.simpledb.model.Item)6 ReplaceableItem (com.amazonaws.services.simpledb.model.ReplaceableItem)6 SQLException (java.sql.SQLException)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 SienaRestrictedApiException (siena.SienaRestrictedApiException)5 Relation (siena.core.Relation)5 IOException (java.io.IOException)4 QueryFilterSearch (siena.QueryFilterSearch)4 Many4PM (siena.core.Many4PM)4 SienaFutureContainer (siena.core.async.SienaFutureContainer)4