Search in sources :

Example 11 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class BaseTestNoAutoInc_7_BATCH method testGetByKeyLongAutoID.

public void testGetByKeyLongAutoID() {
    if (supportsAutoincrement()) {
        PersonLongAutoID curie = getByKeyPersonLongAutoID(LongAutoID_CURIE.id);
        assertEquals(LongAutoID_CURIE, curie);
    } else {
        try {
            PersonLongAutoID curie = getByKeyPersonLongAutoID(LongAutoID_CURIE.id);
        } catch (SienaRestrictedApiException ex) {
            return;
        }
        fail();
    }
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) PersonLongAutoID(siena.base.test.model.PersonLongAutoID)

Example 12 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class BaseTestNoAutoInc_7_BATCH method testGetByKeyNonExisting.

public void testGetByKeyNonExisting() {
    if (supportsAutoincrement()) {
        PersonLongAutoID pers = getByKeyPersonLongAutoID(12345678L);
        assertNull(pers);
    } else {
        try {
            PersonLongAutoID pers = getByKeyPersonLongAutoID(12345678L);
        } catch (SienaRestrictedApiException ex) {
            return;
        }
        fail();
    }
}
Also used : SienaRestrictedApiException(siena.SienaRestrictedApiException) PersonLongAutoID(siena.base.test.model.PersonLongAutoID)

Example 13 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class PostgresqlTest 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)

Example 14 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class SdbMappingUtils method getItemName.

public static String getItemName(Class<?> clazz, Object obj) {
    Field idField = ClassInfo.getIdField(clazz);
    Id id = idField.getAnnotation(Id.class);
    String keyVal = null;
    if (id != null) {
        switch(id.value()) {
            case NONE:
                {
                    Object idVal = Util.readField(obj, idField);
                    if (idVal == null)
                        throw new SienaException("Id Field " + idField.getName() + " value null");
                    keyVal = toString(idField, idVal);
                    break;
                }
            case AUTO_INCREMENT:
                // manages String ID as not long!!!
                throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
            case UUID:
                {
                    Object idVal = Util.readField(obj, idField);
                    if (idVal == null) {
                        UUID uuid = UUID.randomUUID();
                        keyVal = uuid.toString();
                        if (idField.getType() == UUID.class) {
                            Util.setField(obj, idField, uuid);
                        } else if (idField.getType() == String.class) {
                            Util.setField(obj, idField, uuid.toString());
                        } else {
                            throw new SienaRestrictedApiException("DB", "getItemName", "@Id UUID must be of type String or UUID");
                        }
                    } else {
                        keyVal = toString(idField, idVal);
                    }
                    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 keyVal;
}
Also used : Field(java.lang.reflect.Field) SienaRestrictedApiException(siena.SienaRestrictedApiException) Id(siena.Id) SienaException(siena.SienaException) UUID(java.util.UUID)

Example 15 with SienaRestrictedApiException

use of siena.SienaRestrictedApiException in project siena by mandubian.

the class SdbMappingUtils method getItemNameFromKey.

public static String getItemNameFromKey(Class<?> clazz, Object key) {
    Field idField = ClassInfo.getIdField(clazz);
    Id id = idField.getAnnotation(Id.class);
    String keyVal = null;
    if (id != null) {
        switch(id.value()) {
            case NONE:
                {
                    keyVal = toString(idField, key);
                    break;
                }
            case AUTO_INCREMENT:
                // manages String ID as not long!!!
                throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
            case UUID:
                {
                    keyVal = toString(idField, key);
                    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 keyVal;
}
Also used : Field(java.lang.reflect.Field) SienaRestrictedApiException(siena.SienaRestrictedApiException) Id(siena.Id) SienaException(siena.SienaException)

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