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();
}
}
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();
}
}
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();
}
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;
}
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;
}
Aggregations