Search in sources :

Example 21 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class BaseTestNoAutoInc_2_FETCH method testOrderLongAutoId.

public void testOrderLongAutoId() {
    if (supportsAutoincrement()) {
        List<PersonLongAutoID> people = queryPersonLongAutoIDOrderBy("id", "", false).fetch();
        assertNotNull(people);
        assertEquals(3, people.size());
        PersonLongAutoID[] array = new PersonLongAutoID[] { LongAutoID_TESLA, LongAutoID_CURIE, LongAutoID_EINSTEIN };
        int i = 0;
        for (PersonLongAutoID person : people) {
            assertEquals(array[i], person);
            i++;
        }
    } else {
        try {
            List<PersonLongAutoID> people = queryPersonLongAutoIDOrderBy("id", "", false).fetch();
        } catch (SienaRestrictedApiException ex) {
            return;
        }
        fail();
    }
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) PersonLongAutoID(siena.base.test.model.PersonLongAutoID)

Example 22 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class GaeMappingUtils method createEntityInstance.

public static Entity createEntityInstance(Field idField, ClassInfo info, Object obj) {
    Entity entity = null;
    Id id = idField.getAnnotation(Id.class);
    Class<?> type = idField.getType();
    if (id != null) {
        switch(id.value()) {
            case NONE:
                Object idVal = null;
                idVal = Util.readField(obj, idField);
                if (idVal == null)
                    throw new SienaException("Id Field " + idField.getName() + " value null");
                String keyVal = Util.toString(idField, idVal);
                entity = new Entity(info.tableName, keyVal);
                break;
            case AUTO_INCREMENT:
                // manages String ID as not long!!!
                if (Long.TYPE == type || Long.class.isAssignableFrom(type)) {
                    entity = new Entity(info.tableName);
                } else {
                    Object idStringVal = null;
                    idStringVal = Util.readField(obj, idField);
                    if (idStringVal == null)
                        throw new SienaException("Id Field " + idField.getName() + " value null");
                    String keyStringVal = Util.toString(idField, idStringVal);
                    entity = new Entity(info.tableName, keyStringVal);
                }
                break;
            case UUID:
                entity = new Entity(info.tableName, UUID.randomUUID().toString());
                break;
            default:
                throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator " + id.value() + " not supported");
        }
    } else
        throw new SienaException("Field " + idField.getName() + " is not an @Id field");
    return entity;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) SienaRestrictedApiException(siena.SienaRestrictedApiException) Id(siena.Id) SienaException(siena.SienaException)

Example 23 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class JdbcTest method testSearchSingleTwiceInTheSameQuery.

// 2 searches in the same query is not available in Postgres for the time being
public void testSearchSingleTwiceInTheSameQuery() {
    Discovery4Search[] discs = new Discovery4Search[100];
    for (int i = 0; i < 100; i++) {
        discs[i] = new Discovery4Search("Disc_" + i + " " + (100 - i) + "_csid", LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<Discovery4Search> query = pm.createQuery(Discovery4Search.class).search("Disc_5", "name").search("95_csid");
    try {
        List<Discovery4Search> res = query.fetch();
    } catch (SienaRestrictedApiException ex) {
        return;
    }
    fail();
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) Discovery4Search(siena.base.test.model.Discovery4Search)

Aggregations

SienaRestrictedApiException (siena.SienaRestrictedApiException)23 PersonLongAutoID (siena.base.test.model.PersonLongAutoID)11 SienaException (siena.SienaException)6 Id (siena.Id)5 Field (java.lang.reflect.Field)4 Entity (com.google.appengine.api.datastore.Entity)2 Date (java.util.Date)2 DateTime (siena.DateTime)2 Json (siena.Json)2 SimpleDate (siena.SimpleDate)2 Discovery4Search (siena.base.test.model.Discovery4Search)2 DecimalPrecision (siena.core.DecimalPrecision)2 Polymorphic (siena.core.Polymorphic)2 Embedded (siena.embed.Embedded)2 Key (com.google.appengine.api.datastore.Key)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1