Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Selection criteria in any mapping
Selection criteria in any mapping [message #1282041] Tue, 01 April 2014 19:55
Senen de Diego is currently offline Senen de DiegoFriend
Messages: 1
Registered: April 2014
Junior Member
I'm trying to use Eclipselink with dbase tables (*.dbf files) where there are some indexes defined with expressions such as "STR(ID,7)".

I'm using a jdbc driver that is able to use those indexes, but only when the SQL sentence executed contains the same exact expression in the WHERE clause.

That is, a SQL sentence like
SELECT * FROM MASTER WHERE STR(MASTER_ID,7)=STR(?,7)
would use the index, but
SELECT * FROM MASTER WHERE MASTER_ID=?
won't.

Without using the indexes the queries can be really slow, and I'm trying to force the platform to generate the right SQL sentences.

I'm failing miserably...

In a DescriptorCustomizer I can attach a selection criteria to certain classes of mappings (collections) such as this:
public class MasterCustomizer implements DescriptorCustomizer {

    @Override
    public void customize(ClassDescriptor descriptor) throws Exception {
        OneToManyMapping detailsMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("details");
        ExpressionBuilder eb= new ExpressionBuilder(detailsMapping.getReferenceClass());
        Expression where = eb.getField("MASTER_ID").getFunction("str", 7).equal(eb.getParameter("MASTER_ID").getFunction("str", 7));
        detailsMapping.setSelectionCriteria(where);
    }
}
and that allows me to retrieve the Master.details collection using an index (defined as "str(MASTER_ID,7)") in the DETAIL table.

But that's all I've got. I haven't found a way of attaching such a selection criteria to a DirectToFieldMapping for the Master.id attribute which is what, I think, would allow me to retrieve/update/delete a Master entity by its primary key using the index.

I've also found that the ObjectBuilder has a primaryKeyExpression attribute that could also be used to this purpose, if not in a general way (for any filtering where the attribute with the index appears) at least to find entities by its primary key, and I've tried to populate this attribute inside the MasterCustomizer.customize method:
       ExpressionBuilder eb = new ExpressionBuilder(descriptor.getJavaClass());
       Expression where = eb.getField("MASTER_ID").getFunction("str", 7).equal(eb.getParameter("MASTER_ID").getFunction("str", 7));
       descriptor.getObjectBuilder().setPrimaryKeyExpression(where);
but that does not work either because the MasterCustomizer.customize method is called before the ObjectBuilder.createPrimaryKeyExpresion, where that value is overwritten with the standard expression "MASTER_ID=?".

So my question is:

Is it possible to customize the mapping to a column in a way that any filtering by that column is done using an expression?
Previous Topic:JPA Caching and NPE
Next Topic:CacheType.NONE
Goto Forum:
  


Current Time: Sun Nov 23 14:55:36 GMT 2014

Powered by FUDForum. Page generated in 0.02291 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software