Search in sources :

Example 1 with OptionalThingExceptionThrower

use of org.dbflute.optional.OptionalThingExceptionThrower in project dbflute-core by dbflute.

the class AbstractBehaviorReadable method toRelationOptional.

// ===================================================================================
// Optional Handling
// =================
/**
 * Create present or null entity as relation optional.
 * @param relationTitle The title of relation for exception message. (NotNull)
 * @param relationRow The entity instance of relation row. (NullAllowed)
 * @return The optional object for the entity, which has present or null entity. (NotNull)
 */
protected Object toRelationOptional(final String relationTitle, Object relationRow) {
    assertObjectNotNull("relationTitle", relationTitle);
    final RelationOptionalFactory factory = xgetROpFactory();
    final Object result;
    if (relationRow != null) {
        result = factory.createOptionalPresentEntity(relationRow);
    } else {
        result = factory.createOptionalNullEntity(new OptionalThingExceptionThrower() {

            public void throwNotFoundException() {
                String msg = "Not found the relation row for: " + relationTitle;
                throw new EntityAlreadyDeletedException(msg);
            }
        });
    }
    return result;
}
Also used : OptionalThingExceptionThrower(org.dbflute.optional.OptionalThingExceptionThrower) RelationOptionalFactory(org.dbflute.optional.RelationOptionalFactory) EntityAlreadyDeletedException(org.dbflute.exception.EntityAlreadyDeletedException)

Aggregations

EntityAlreadyDeletedException (org.dbflute.exception.EntityAlreadyDeletedException)1 OptionalThingExceptionThrower (org.dbflute.optional.OptionalThingExceptionThrower)1 RelationOptionalFactory (org.dbflute.optional.RelationOptionalFactory)1