Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » AbstractComposerAttribute.getConfiguredStatement
AbstractComposerAttribute.getConfiguredStatement [message #579709] Tue, 06 April 2010 08:22 Go to next message
Alex Schroeder is currently offline Alex Schroeder
Messages: 38
Registered: February 2010
Location: Zürich, Switzerland
Member

Hi dev team! :)

I'm looking at a search form for "persons" that can be either active or inactive. The search form itself has an Active field with three states: Yes, No, All. The SQL code is created using execAddSearchTerms.

@Override
public void execAddSearchTerms(SearchFilter search){
if(getValue()==null){
search.addWhereToken("P.ACTIVE IN(0,1)");
}
else if(getValue()==0){
search.addWhereToken("P.ACTIVE=0");
}
else if(getValue()==1){
search.addWhereToken("P.ACTIVE=1 AND C.ACTIVE IN (-1,1)");
}
search.addDisplayText(getPersonStateBox().getLabel()
+"="+getSelectedButton().getLabel().replace("&", ""));
}


That's cool and works.

At the same time, I have an advanced search tab using an AbstractPersonComposerField that inherits from AbstractComposerField. There, I have an attribute called Active using the Boolean code type. The SQL Statement is generated a bit differently, unfortunately:

@Override
public String getConfiguredStatement(){
return "(<attribute>P.ACTIVE</attribute> "+
"AND <attribute>C.ACTIVE</attribute>) ";
}


And preliminary testing shows that showing the active or inactive persons shows a different result set depending on whether the standard Active attribute or the advanced search constraint is used.

My question is this: What's the exact effect of the attribute tag in an AbstractComposerAttribute.getConfiguredStatement?

What I need to do, I think, is to rewrite one of the two pieces to result in the same SQL as the the other piece such that there is no result set difference no matter what code is being used.
Re: AbstractComposerAttribute.getConfiguredStatement [message #579742 is a reply to message #579709] Tue, 06 April 2010 08:42 Go to previous messageGo to next message
Alex Schroeder is currently offline Alex Schroeder
Messages: 38
Registered: February 2010
Location: Zürich, Switzerland
Member

Well, it turns out that I no longer need the answer to the above question in order to solve my problem (the SQL based solution follows below), but I'm still curious.

And I'd love to know whether there are other magic tags to be used! :)

/**
* This code mimics the PersonSearchForm.
* If the person is not active: P.ACTIVE=0 (and thus C.ACTIVE=C.ACTIVE is always true).
* If the person is active: P.ACTIVE=1 AND C.ACTIVE IN (-1,1).
*/
@Override
public String getConfiguredStatement(){
return "(<attribute>P.ACTIVE</attribute> "+
"AND C.ACTIVE=DECODE(P.ACTIVE, 0, C.ACTIVE," +
" 1, DECODE(C.ACTIVE, 1, C.ACTIVE," +
" -1, C.ACTIVE))) ";
}
Re: AbstractComposerAttribute.getConfiguredStatement [message #580247 is a reply to message #579742] Thu, 08 April 2010 06:16 Go to previous message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
Above is pre eclipse-scout code and also has legacy status.
Sql fragments on client side is not supported and not recommenden in applications.

For performing search and find processing logic based on search forms, eclipse scout also makes use of form data classes as in normal forms.
The above example search form PersonSearchForm has a form data PersonSearchFormData that can be passed to the back-end as search criteria set.

When used for example in the PersonTablePage, the following parts are normally of interest:
The SearchFilter object has the three properties
completed boolean if the search is complete e.g. valid to obtain search results
displayTexts list of strings of verbose description of the search elements
formData object containing the non-empty values of the form

When saved, the search form is automatically collecting all verbose search texts on the form fields
and calling execResetSearchFilter(...)

In the PersonSearchForm override the method execResetSearchFilter to set the form data to the search filter object:

@Override
protected void execResetSearchFilter(final SearchFilter searchFilter) throws ProcessingException{
super.execResetSearchFilter(searchFilter);
PersonSearchFormData data=new PersonSearchForm();
exportFormData(data);
searchFilter.setFormData(data);
}


The PersonTablePage populates its table using a back-end service call that directly delivers a data matrix (for simplicity here).
The only argument is the search filter (containing the form data).

@Override
protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException{
Object[][] tableData=SERVICES.getService(IPersonProcessService.class).g etPersonTableData(filter);
return tableData;
}


The IPersonProcessService.getPersonTableData operation uses the search filter and retrieves the data from the data stores.
This might be using hibernate, eclipse link or direct jdbc access.
When using direct jdbc access there is a helper base class to easily create jdbc statement builders based on a form data.
We create a subclass PersonSearchStatementBuilder.
As in Alex's example the composer attribute "Active" is just mapped to a sql part and the three-state radio button "Active" is implemented as java code in the "buildeConstraintsFor" method override.

public class PersonSearchStatementBuilder extends FormDataStatementBuilder{

public PersonSearchStatementBuilder(ISqlStyle style){
super(style);
//for each formdata inner type add a statement mapping
...
addStatementMapping(AbstractPersonComposer.ActiveAttribute,"( <attribute>P.ACTIVE</attribute> AND <attribute>C.ACTIVE</attribute>)");
...
}

@Override
protected void buildConstraintsFor(AbstractFormFieldData f){
if(f.getClass==PersonSearchFormData.Active.class){
Integer value=((PersonSearchFormData.Active)f).getValue();
if(value==null){
addWhereToken("P.ACTIVE IN(0,1)");
}
else if(value==0){
addWhereToken("P.ACTIVE=0");
}
else if(value==1){
addWhereToken("P.ACTIVE=1 AND C.ACTIVE IN (-1,1)");
}
}
else{
super.buildConstraintsFor(f);
}
}

}


The person service performing the search now simply has the code:

public class PersonProcessService extends AbstractService implements IPersonProcessService{

...

public Object[][] getPersonTableData(SearchFilter filter) throws ProcessingException{
PersonSearchFormData formData=(PersonSearchFormData)filter.getFormData();
PersonSearchStatementBuilder builder=new PersonSearchStatementBuilder(SQL.getStyle());
builder.build(formData);
return SQL.select(
"SELECT .... "+
"FROM ... "+
"WHERE ... "+
builder.getWhereConstraints(),
builder.getBindMap()
);
}

...

}
Previous Topic:AbstractComposerAttribute.getConfiguredStatement
Next Topic:Interested Parties
Goto Forum:
  


Current Time: Sat Jul 26 01:09:33 EDT 2014

Powered by FUDForum. Page generated in 0.02653 seconds