Skip to content

Instantly share code, notes, and snippets.

@h4t0n
Created December 5, 2018 22:02
Show Gist options
  • Save h4t0n/09c782bcfeeab96c9dd8bd4ca033c46b to your computer and use it in GitHub Desktop.
Save h4t0n/09c782bcfeeab96c9dd8bd4ca033c46b to your computer and use it in GitHub Desktop.
[Gemini] EntityRecordException
public class EntityRecordException extends GeminiException {
public enum Code {
MULTIPLE_LK_FOUND,
LK_NOTFOUND,
INSERTED_RECORD_NOT_FOUND
}
private final Entity entity;
private final Collection<? extends Record.FieldValue> lk;
private final Code errorCode;
public EntityRecordException(Code errorCode, Entity entity, Collection<? extends Record.FieldValue> lk, String message) {
super(errorCode.name(), message);
this.errorCode = errorCode;
this.entity = entity;
this.lk = lk;
}
public Code getErrorCode() {
return errorCode;
}
public Entity getEntity() {
return entity;
}
public Collection<? extends Record.FieldValue> getLk() {
return lk;
}
public static EntityRecordException MULTIPLE_LK_FOUND(EntityReferenceRecord referenceRecord) {
Entity entity = referenceRecord.getEntity();
Record logicalKeyRecord = referenceRecord.getLogicalKeyRecord();
return MULTIPLE_LK_FOUND(entity, logicalKeyRecord.getFieldValues());
}
public static EntityRecordException MULTIPLE_LK_FOUND(EntityRecord entityRecord) {
return MULTIPLE_LK_FOUND(entityRecord.getEntity(), entityRecord.getLogicalKeyValue());
}
public static EntityRecordException MULTIPLE_LK_FOUND(Entity entity, Collection<? extends Record.FieldValue> lk) {
return new EntityRecordException(MULTIPLE_LK_FOUND, entity, lk, String.format("Found multiple Record for Logical Key of %s : %s", entity.getName(), lk.toString()));
}
public static EntityRecordException LK_NOTFOUND(Entity entity, Collection<? extends Record.FieldValue> lk) {
return new EntityRecordException(LK_NOTFOUND, entity, lk, String.format("Logical Key for entity %s not found: %s ", entity.getName(), lk.toString()));
}
public static EntityRecordException INSERTED_RECORD_NOT_FOUND(Entity entity, Set<EntityRecord.EntityFieldValue> lk) {
return new EntityRecordException(INSERTED_RECORD_NOT_FOUND, entity, lk, String.format("Inserted record for entity %s not found: %s ", entity.getName(), lk.toString()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment