<style>
/* Changing the layout to use less space for mobiles */
@media screen and (max-device-width: 480px), screen and (-webkit-min-device-pixel-ratio: 2) {
    #email-body { min-width: 30em !important; }
    #email-page { padding: 8px !important; }
    #email-banner { padding: 8px 8px 0 8px !important; }
    #email-avatar { margin: 1px 8px 8px 0 !important; padding: 0 !important; }
    #email-fields { padding: 0 8px 8px 8px !important; }
    #email-gutter { width: 0 !important; }
}
</style>
<div id="email-body">
<table id="email-wrap" align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#f0f0f0;color:#000000;width:100%;">
    <tr valign="top">
        <td id="email-page" style="padding:16px !important;">
            <table align="center" border="0" cellpadding="0" cellspacing="0" style="background-color:#ffffff;border:1px solid #bbbbbb;color:#000000;width:100%;">
                <tr valign="top">
                    <td bgcolor="#3e4c4e" style="background-color:#3e4c4e;color:#ffffff;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;line-height:1;"><img src="https://www.jboss.org/dms/hibernate/images/jira/jiraheader_hibernate.png" alt="" style="vertical-align:top;" /></td>
                </tr><tr valign="top">
    <td id="email-banner" style="padding:32px 32px 0 32px;">

                
        
        
            <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" style="width:100%;">
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;padding:0;">
                                        <img id="email-avatar" src="https://hibernate.onjira.com/secure/useravatar?ownerId=emmanuel&avatarId=10641" alt="" height="48" width="48" border="0" align="left" style="padding:0;margin: 0 16px 16px 0;" />
                        <div id="email-action" style="padding: 0 0 8px 0;font-size:12px;line-height:18px;">
                                    <a class="user-hover" rel="emmanuel" id="email_emmanuel" href="https://hibernate.onjira.com/secure/ViewProfile.jspa?name=emmanuel" style="color:#6c797f;">Emmanuel Bernard</a>
     commented on <img src="https://hibernate.onjira.com/images/icons/bug.gif" height="16" width="16" border="0" align="absmiddle" alt="Bug"> <a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/OGM-208'>OGM-208</a>
            </div>
                        <div id="email-summary" style="font-size:16px;line-height:20px;padding:2px 0 16px 0;">
                <a style='color:#6c797f;text-decoration:none;' href='https://hibernate.onjira.com/browse/OGM-208'><strong>Create facility for OGM core and Dialects to receive custom metadata (annotation, programmatic) associated to entities, properties or associations</strong></a>
            </div>
                    </td>
    </tr>
</table>
    </td>
</tr>
<tr valign="top">
    <td id="email-fields" style="padding:0 32px 32px 32px;">
        <table border="0" cellpadding="0" cellspacing="0" style="padding:0;text-align:left;width:100%;" width="100%">
            <tr valign="top">
                <td id="email-gutter" style="width:64px;white-space:nowrap;"></td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr valign="top">
    <td colspan="2" style="color:#000000;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:12px;padding:0 0 16px 0;width:100%;">
        <div class="comment-block" style="background-color:#edf5ff;border:1px solid #dddddd;color:#000000;padding:12px;"><h2><a name="Internalmodel"></a>Internal model</h2>

<p>The internal model can be type-safe or not.<br/>
We need a way to identify an option from another.</p>

<p>Each option needs a uniquely identifying key object.<br/>
This will tell if an option is overridden by another context<br/>
or merely duplicated by other values.</p>

<p>For example a named query using different names are not overlapping<br/>
but a named query with the same name is replaced by a more specific context.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">/**
     * Interface required to be returned by the generator classes
     * It represents a tuple of the option and the value associated
     *
     * Option can be of any type, in particular it could be represented as
     * 
     * - an <span class="code-keyword">enum</span> value
     * - a <span class="code-object">Class</span> object in particular an annotation class object
     * - a <span class="code-object">String</span>
     *
     * What is important is that the Option is unique according to
     * the `equals()` operation amongst the realm of possible options.
     * 
     * Likewise, Value can be of any type.
     */
    <span class="code-keyword">public</span> <span class="code-keyword">interface</span> OptionValueTuple&lt;Option,Value&gt; {
        Option getOption();
        Value getValue();
    }

    <span class="code-comment">// most likely an anonymous class in a generator implementation
</span>    <span class="code-keyword">public</span> class QuorumOptionValueTuple <span class="code-keyword">implements</span> OptionValueTuple&lt;OptionEnum,Quorum&gt; {
        <span class="code-keyword">private</span> <span class="code-keyword">final</span> <span class="code-object">int</span> read;
        <span class="code-keyword">private</span> <span class="code-keyword">final</span> <span class="code-object">int</span> write;

        <span class="code-keyword">public</span> QuorumOptionValueTuple(<span class="code-object">int</span> read, <span class="code-object">int</span> write) { <span class="code-keyword">this</span>.read = read; <span class="code-keyword">this</span>.write = write; }

        <span class="code-keyword">public</span> OptionEnum getOption() { <span class="code-keyword">return</span> OptionEnum.QUORUM; }
        <span class="code-keyword">public</span> Quorum getValue() { <span class="code-keyword">return</span> <span class="code-keyword">new</span> Quorum(read, write); }
    }
    
    <span class="code-comment">//an example of possible Option identifier
</span>    <span class="code-keyword">public</span> <span class="code-keyword">enum</span> OptionEnum {
        QUORUM;
    }
    
    <span class="code-comment">// the object model representing the QUORUM value
</span>    <span class="code-keyword">public</span> class Quorum {
        <span class="code-keyword">private</span> <span class="code-keyword">final</span> <span class="code-object">int</span> read;
        <span class="code-keyword">private</span> <span class="code-keyword">final</span> <span class="code-object">int</span> write;
        <span class="code-keyword">public</span> Quorum(<span class="code-object">int</span> read, <span class="code-object">int</span> write) { <span class="code-keyword">this</span>.read = read; <span class="code-keyword">this</span>.write = write }
    }</pre>
</div></div>

<p>`OptionValueTuple` will be used by Hibernate OGM to collect a map of option / option value and expose that to <br/>
the `GridDialect`.</p>

<p>Problem, there is a notion of Option <b>Type</b> and a unique identifier made of option type and some other unique<br/>
identifier like in a named query. We uniquely define a named query by it's NamedQuery type and its actual name.</p>

<p>The Option object could be a subtype of `MultiOption`</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">/**
     * Common <span class="code-keyword">interface</span> <span class="code-keyword">for</span> options that can receive multiple values
     * like named queries.
     * TODO: are generics useful?
     */
    <span class="code-keyword">public</span> class MultiOption&lt;Type,Id&gt; {
        /**
         * <span class="code-object">Class</span> of option, <span class="code-keyword">this</span> type can be any type but typically is an
         * <span class="code-keyword">enum</span>, a <span class="code-object">Class</span> instance or a <span class="code-object">String</span>.
         */
        <span class="code-keyword">abstract</span> Type getType();
        /**
         * Uniquely identify an option <span class="code-keyword">for</span> a given type
         */ 
        <span class="code-keyword">abstract</span> Id getUniqueIdentifier();

        <span class="code-keyword">public</span> <span class="code-object">boolean</span> equals(<span class="code-object">Object</span> that) {
            <span class="code-comment">//TODO implementation using getType and getUniqueIdentifier
</span>        }

        <span class="code-keyword">public</span> <span class="code-object">int</span> hashCode() {
            <span class="code-comment">//TODO implementation using getType and getUniqueIdentifier
</span>        }
    }

    /**
     * Example of implementation
     */
    <span class="code-keyword">public</span> NamedQueryOption <span class="code-keyword">extends</span> MultiOption&lt;<span class="code-object">Class</span>&lt;?&gt;,<span class="code-object">String</span>&gt; {
        <span class="code-keyword">private</span> <span class="code-keyword">final</span> <span class="code-object">String</span> queryName;
        <span class="code-keyword">public</span> NamedQueryOption(<span class="code-object">String</span> queryName) { <span class="code-keyword">this</span>.queryName = queryName; }
        <span class="code-object">Class</span>&lt;?&gt; getType() { <span class="code-keyword">return</span> NamedQuery.class; }
        <span class="code-object">String</span> getUniqueIdentifier() { <span class="code-keyword">return</span> queryName; }
    }

    <span class="code-keyword">public</span> class NamedQuery {
        <span class="code-keyword">private</span> <span class="code-object">String</span> name;
        <span class="code-keyword">private</span> <span class="code-object">String</span> hql;
        ...
    }

    <span class="code-comment">// most likely an anonymous class in a generator implementation
</span>    <span class="code-keyword">public</span> class NamedQueryOptionValueTuple <span class="code-keyword">implements</span> OptionValueTuple&lt;NamedQueryOption, NamedQuery&gt; {
        <span class="code-keyword">public</span> NamedQueryOptionValueTuple(<span class="code-object">String</span> name, <span class="code-object">String</span> hsql) { ... }
        <span class="code-keyword">public</span> NamedQueryOption getOption() { <span class="code-keyword">return</span> <span class="code-keyword">new</span> NamedQueryOption(name); }
        <span class="code-keyword">public</span> NamedQuery getValue() { <span class="code-keyword">return</span> <span class="code-keyword">new</span> NamedQuery(name, hql);
    }</pre>
</div></div>

<p>We could offer the ability to filter options by option or option type to help navigate them.<br/>
Wrt overriding, an option is overridden by a closer scope. Same for an option type with the same<br/>
unique identifier.</p>

<h3><a name="UsagefromaGridDialect"></a>Usage from a GridDialect</h3>

<p>We could imagine the following usage</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Quorum quorum = (Quorum) context.inGlobalContext().getOption( QUORUM );
    List&lt;NamedQuery&gt; queries = (List&lt;NamedQuery&gt;) context.inEntityContext().getOptionByType(NamedQuery.class);</pre>
</div></div>

<h3><a name="Observations"></a>Observations</h3>

<p>It seems the model is fairly verbose and I am willing to simplify it if we can. I am especially concerned<br/>
about the amount of concepts and classes the designer of an option needs to provide.</p>

<p>Paradoxically, there is not type-safe link between an option and its value besides the `OptionValueTuple`<br/>
which is not meant to be used by consumers of options. The `GridDialect` is force to downcast the data<br/>
which is not ideal.</p>

<p>I am also concerned about the fact that the set of options is quite dispersed due:</p>

<ul class="alternate" type="square">
        <li>the ability to define the option (or option type) type freely</li>
        <li>the fact that some options are specific to a given datastore provider</li>
</ul>


<p>The design seems to need refinement but I have been working on it for some time now and need a fresh look at it.</p></div>
        <div style="color:#505050;padding:4px 0 0 0;">                </div>
    </td>
</tr>
                    </table>
                </td>
            </tr>
        </table>
    </td>
</tr>













            </table>
        </td><!-- End #email-page -->
    </tr>
    <tr valign="top">
        <td style="color:#505050;font-family:Arial,FreeSans,Helvetica,sans-serif;font-size:10px;line-height:14px;padding: 0 16px 16px 16px;text-align:center;">
            This message is automatically generated by JIRA.<br />
            If you think it was sent incorrectly, please contact your <a style='color:#6c797f;' href='https://hibernate.onjira.com/secure/ContactAdministrators!default.jspa'>JIRA administrators</a>.<br />
            For more information on JIRA, see: <a style='color:#6c797f;' href='http://www.atlassian.com/software/jira'>http://www.atlassian.com/software/jira</a>
        </td>
    </tr>
</table><!-- End #email-wrap -->
</div><!-- End #email-body -->