[ 
http://issues.ops4j.org/browse/QI-264?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13559#action_13559
 ] 

Rickard Öberg commented on QI-264:
----------------------------------

Niclas and I already resolved this over chat, but here's the longer version for 
others reading this issue.

The visitor interface itself is declared as:
    interface EntityStateVisitor<ThrowableType extends Exception>
    {
        void visitEntityState( EntityState entityState )
            throws ThrowableType;
    }
Meaning, provide an exception type that you want the visitEntityState 
implementation to be able to throw, such as SQLException. Then the visitor 
method becomes:
    <ThrowableType extends Exception> EntityStoreUnitOfWork visitEntityStates( 
EntityStateVisitor<ThrowableType> visitor, ModuleSPI module )
        throws ThrowableType;
---
The implementation loops through the EntityStates and call visitEntityState for 
each one. If ThrowableType is thrown then the implementation can catch that and 
close any open resources before rethrowing it to the caller of 
visitEntityStates. The caller can then use try/catch(SQLException) to handle 
the exception.

> Use exception handling pattern in visitors
> ------------------------------------------
>
>                 Key: QI-264
>                 URL: http://issues.ops4j.org/browse/QI-264
>             Project: Qi4j
>          Issue Type: Improvement
>    Affects Versions: 1.1
>            Reporter: Rickard Öberg
>            Assignee: Rickard Öberg
>             Fix For: 1.2
>
>
> Stanislav suggested that we use an exception handling pattern in our 
> visitors. Basically the visitor interface/method is declared with 
> "ThrowableType extends Exception". If the visitor needs to throw a particular 
> type of exception, like SQLException, then that is specified during 
> instantiation. If not, then RuntimeException can be used. This provides a 
> natural way to "cancel" a visitation.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.ops4j.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to