yes, report queries are extent aware. the method below is taken from the testcase QueryTest and it produces the query shown further down.
public void testReportPathExpressionForExtents()
{
ArrayList list = new java.util.ArrayList();
Criteria crit = new Criteria();
crit.addEqualTo("groupId", new Integer(5));
ReportQueryByCriteria q = QueryFactory.newReportQuery(ProductGroup.class, crit, true);
q.setColumns(new String[]{"groupId", "groupName", "allArticlesInGroup.articleId", "allArticlesInGroup.articleName"});
Iterator iter = broker.getReportQueryIteratorByQuery(q);
while (iter.hasNext())
{
list.add(iter.next());
}
// 7 Articles, 2 Books, 3 Cds
assertEquals("check size", list.size(), 7);
}
SELECT DISTINCT A0.Kategorie_Nr,A0.KategorieName,A1.Artikel_Nr,A1.Artikelname FROM Kategorien A0 LEFT OUTER JOIN Artikel A1 ON A0.Kategorie_Nr=A1.Kategorie_Nr LEFT OUTER JOIN BOOKS A1E0 ON A0.Kategorie_Nr=A1E0.Kategorie_Nr LEFT OUTER JOIN CDS A1E1 ON A0.Kategorie_Nr=A1E1.Kategorie_Nr WHERE A0.Kategorie_Nr = '5'
hth
jakob
Mark Rowell wrote:
Hi
I was wondering if report queries on extents work where I am selecting out
a/some column(s) from a table
related to the extent classes. A concrete example may help (!)
I have an extent class called Bond with concrete implementations called
FixedCouponBond and FRN.
There is a 1 to n relationship a single Bond and the priceDetails class
(which is concrete). In my
repository_user.xml file they mappings are setup as follows (I only show
themapping for the FixedCouponBond class as it is identical for the FRN class)
<class-descriptor
class="com.credittrade.instruments.securities.BBGBondModel"
table="Bonds"
>
<field-descriptor id="1"
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
etc
<collection-descriptor
name="priceDetails"
element-class-ref="com.credittrade.market.PriceDetail"
auto-retrieve="true"
auto-update="false"
auto-delete="false"
proxy="true" >
<inverse-foreignkey field-id-ref="2"/>
</collection-descriptor>
etc
</class-descriptor>
priceDetail is mapped as follows:
<class-descriptor
class="com.credittrade.market.PriceDetail"
table="PriceDetails">
<field-descriptor id="1"
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
/>
<field-descriptor id="2"
name="instrumentID"
column="InstrumentID"
jdbc-type="INTEGER"
/>
<field-descriptor id="3"
name="priceValueType"
column="typeID"
etc...
</class-descriptor>
I run the following report query to retrieve the ISIN field from the
FixedCouponBond and the
ID of the associated price details. I do this using the OJB API thus:
// Java snippet
Criteria criteria = new Criteria();
criteria.addEqualTo("priceDetails.PriceSource", ps.getLabel());
criteria.addEqualTo("priceDetails.TypeID",
PriceValueType.price.toString());
criteria.addEqualTo("priceDetails.PriceTypeID",
PriceType.market.toString()); criteria.addIn("priceDetails.QuoteTypeID", Arrays.asList( new
String[]{ QuoteType.bid.toString(),
QuoteType.offer.toString(),
QuoteType.high.toString(),
QuoteType.low.toString()}));
criteria.addIn("ISIN", isins); Iterator iter = broker.getReportQueryIteratorByQuery(
QueryFactory.newReportQuery(
Bond.class, new String[]{"ISIN", "priceDetails.ID",
"priceDetails.QuoteTypeID"}, criteria, false));
Note in the method call to newReportQuery I ask for the ISIN field from the
Bond class (no qualifier as it is the
class in the query), and the ID and QuoteTypeID columns from the related
priceDetails instances.
The problem I get is that the generated SQL strips out the identifiers and
because I have an ID column on my
Bond tables I get a SQL error complaining that ID is not a unique column
name.
I do this sort of report query elsewhere, on concrete classes directly and
it works -- hence I assume it is a problem with
the SQL generator (?) for extents.
I can get round it by specifying A1 as the qualifier for the ID and
QuoteTypeID columns (as this, I noticed, is the
table alias used by the SQL generator for the PriceDetails table.
So, the questions I have are:
(a) is this a bug, or
(b) am Idoing something wrong...
Regards,
Mark Rowel
----------------------------------------------------------------
Mark Rowell
CreditTrade
T: +44 (020) 7400 5078
M: mailto:[EMAIL PROTECTED]
CreditTrade Limited is regulated by the FSA. (c) CreditTrade 2002. All rights reserved. The information and data contained in this email is provided for the information purposes of the addressee only and should not be reproduced and/or distributed to any other person. It is provided without any warranty whatsoever and unless stated otherwise consists purely of indicative market prices and other information.
Any opinion or comments expressed or assumption made in association with the data or information provided in this email is a reflection of CreditTrades judgement at the time of compiling the data and is subject to change. CreditTrade hereby makes no representation and accepts no responsibility or liability as to the completeness or accuracy of this email.
The content of this email is not intended as an offer or solicitation for, or recommendation of, the purchase or sale of any financial instrument, or as an official confirmation of any transaction, and should not be construed as investment advice.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
