javadocumentumdfcdocumentum-dfc

Reading a custom double value from a Documentum query


I am trying to calculate an average value with the Documentum API, like this:

final IDfQuery checkMediaDocs = (IDfQuery) new DfQuery();
IDfCollection mediaDocs = null;
checkMediaDocs.setDQL("select sum(tot_doc_daily)/count(*) as mediaglobale from my_table");
mediaDocs = checkTodayDocs.execute(session, IDfQuery.DF_READ_QUERY);
int media = 0;
while (mediaDocs.next()) {
    media = (int) mediaDocs.getDouble("mediaglobale");
}

However, the application does not work, returning this error:

101884 [SchedulerFactoryBean_Worker-1] ERROR it.reply.square.isa.daemon.DatExporterWorker  - [DM_API_E_BADATTRNAME]error:  "Bad attribute name 'mediaglobale' for document/object."
DfTypedObjectException:: THREAD: SchedulerFactoryBean_Worker-1; MSG: [DM_API_E_BADATTRNAME]error:  "Bad attribute name 'mediaglobale' for document/object."; ERRORCODE: 100; NEXT: null
    at com.documentum.fc.client.impl.typeddata.LiteType.getAttr(LiteType.java:171)
    at com.documentum.fc.client.impl.typeddata.LiteType.getAttrIndex(LiteType.java:226)
    at com.documentum.fc.client.impl.typeddata.AbstractTypedData.getAttrIndex(AbstractTypedData.java:697)
    at com.documentum.fc.client.impl.typeddata.AbstractTypedData.get(AbstractTypedData.java:129)
    at com.documentum.fc.client.impl.typeddata.AbstractTypedData.getString(AbstractTypedData.java:159)
    at com.documentum.fc.client.DfTypedObject.getStringRaw(DfTypedObject.java:655)
    at com.documentum.fc.client.DfTypedObject.doGetString(DfTypedObject.java:623)
    at com.documentum.fc.client.impl.collection.TypedDataCollection.doGetString(TypedDataCollection.java:91)

How can I properly retrieve the custom double value? If "mediaglobale" would be a simple count, I could retrieve that with getInt(), without error: so, it seems to be a problem of the getDouble(), here.

Thanks.


Solution

  • You're defining checkMediaDocs and setting the DQL in that DfQuery, but then you're running checkTodayDocs, which is not the DfQuery with your DQL.

    If that is not the actual problem, just use doubleValue = col.getValueAt(0).asDouble();