A problem with CMP is that it is an all or nothing approach regarding
data access from the database. Ie. If you want to process a series of
single fields from a selection of CMP entity beans you have no choice
but to query for them and let the container load in all their data -
even though you are interested in only the one field per entity bean.

The spec should introduce data containers (I suppose 'value objects')
that are views of a CMP entity bean.  When defining a finder method,
rather than it always returning a single CMP bean or a collection of CMP
beans you can elect to return one of your data containers instead.  The
data container will simply be a subset of the fields of your CMP entity
bean.

Examples of possible XML definitions for data containers might be like
this (all the fields must have been previously defined for the CMP EJB
otherwise the compiler will reject it):

<view-object>
        <view-name>accountBalance</view-name>
        <view-field>
                <field-name>accountId</field-name>
        </view-field>
        <view-field>
                <field-name>balance</field-name>
        </view-field>
</view-object>

<view-object>
        <view-name>accountSummary</view-name>
        <view-field>
                <field-name>accountId</field-name>
        </view-field>
        <view-field>
                <field-name>accountType</field-name>
        </view-field>
        <view-field>
                <field-name>accountName</field-name>
        </view-field>
</view-object>

A query definition might look like this:

<query>
        <query-method>
                <method-name>findBigAccounts</method-name>
                <method-params>
                        <method-param>double</method-param>
                </method-params>
                <returns-view>
                        accountBalance
                </returns-view>
        </query-method>
        <ejb-ql>
                <![CDATA[FROM AccountBean AS a WHERE a.balance > ?1]]>
        </ejb-ql>
</query>

Note that the important lines above are these:

                <returns-view>
                        accountBalance
                </returns-view>

The name of the data container to return is defined between the
<returns-view> tags. Sample class definitions for these data containers
would be very straight forward:

public class accountBalance implements Serializable
{
        int    accountId;
        double balance  ;
}

public class accountSummary implements Serializable
{
        int    accountId  ;
        String accountType;
        Strint accountName;
}

Obviously the view data returned would be read-only in nature and the
actual CMP entity bean would have to be looked up in order to operate on
it.  But from the point of view of just arbitrarily looking up subsets
of data for a CMP entity bean they would be ideal.

Myles Jeffery

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to