SmartGWT Version: 3.0p Pro
I'm running through some use cases that my previous projects using LGPL had and trying to re-implement them in the Pro edition making use of the server side data integration features.
Example I'm trying achieve: two ListGrids, 1 showing a list of countries. When a country is selected, the database is interrogated for a list of country's cities to show in the second grid
Caveats:
1) Using HibernateDataSource purely as a learning experience, and I may have ties to Hibernate still in the future to avoid writing straight SQL in exceptional cases
2) The city grid I'm trying to request from the server rather than have the client side load the whole set and filter because I may be dealing with much larger datasets.
Here is a snippet from the GUI:
Unfortunately because I'm on Pro, I don't have customHQL to simply do this within the datasource (or am I wrong?). The approach I've taken is to:
1) The GUI passes in the countryId as criteria to gridCity's fetchData
2) DMI is used on the City datasource, which executes some handwritten DAO code to retrieve the relevant cities based on the countryId passed.
City DS:
City DMI:
City DAO:
Country DS:
This works and the city grid loads up with the correct cities when a country is selected.
Question:
In the logs I'm seeing:
Are these valid concerns? I would've expected by explicitly defining the relationship in the ds.xml files there wouldn't be any problems.
I believe the last one is about the country having the cities which then have a country in it again, and can be avoided by removing "type" from either the city or country DS (http://www.smartclient.com/smartgwte...tegration.html)
Question:
Given the restriction of needing to use Hibernate and Pro edition, is this already the most code-less approach? How different might this be if it was a plain SQLDataSource?
I'm running through some use cases that my previous projects using LGPL had and trying to re-implement them in the Pro edition making use of the server side data integration features.
Example I'm trying achieve: two ListGrids, 1 showing a list of countries. When a country is selected, the database is interrogated for a list of country's cities to show in the second grid
Caveats:
1) Using HibernateDataSource purely as a learning experience, and I may have ties to Hibernate still in the future to avoid writing straight SQL in exceptional cases
2) The city grid I'm trying to request from the server rather than have the client side load the whole set and filter because I may be dealing with much larger datasets.
Here is a snippet from the GUI:
Code:
// tell the other grid to go load something gridCountry.addRecordClickHandler(new RecordClickHandler() { @Override public void onRecordClick(RecordClickEvent event) { Criteria criteria = new Criteria(); criteria.addCriteria("countryId", event.getRecord().getAttribute("id")); gridCity.fetchData(criteria); } });
1) The GUI passes in the countryId as criteria to gridCity's fetchData
2) DMI is used on the City datasource, which executes some handwritten DAO code to retrieve the relevant cities based on the countryId passed.
City DS:
Code:
<DataSource ID="cityHibernate" serverType="hibernate" autoDeriveSchema="true" schemaBean="test.shared.models.City" > <fields> <field name="country" type="countryHibernate" foreignKey="country.id"/> </fields> <!-- override fetch to select cities for a given country --> <operationBindings> <binding operationType="fetch" serverMethod="fetch"> <serverObject lookupStyle="new" className="test.server.dmi.CityDMI" /> </binding> </operationBindings> </DataSource>
Code:
public DSResponse fetch(DSRequest dsRequest) throws Exception { Integer countryId = Integer.parseInt(((String)dsRequest.getCriteriaValue("countryId"))); List<City> cities = CityDAO.getCitiesByCountryId(countryId); DSResponse response = new DSResponse(); response.setStartRow(0); response.setEndRow(cities.size()-1); response.setTotalRows(cities.size()); response.setStatus(DSResponse.STATUS_SUCCESS); response.setData(cities); return response; }
Code:
public static List<City> getCitiesByCountryId(int countryId) throws Exception { Session session = getSession(); String hql = "FROM City c WHERE c.country.id=:countryId ORDER BY c.name ASC"; Query query = session.createQuery(hql); query = query.setInteger("countryId", countryId); return (List<City>)query.list(); }
Code:
<DataSource ID="countryHibernate" serverType="hibernate" autoDeriveSchema="true" schemaBean="test.shared.models.Country"> <fields> <field name="cities" multiple="true" type="cityHibernate" foreignKey="city.id"/> </fields> </DataSource>
Question:
In the logs I'm seeing:
Code:
=== 2011-12-29 15:24:39,934 [l0-2] WARN BasicDataSource - Can not load related data source 'test.shared.models.Country' for field 'country'. Treating as simple field. === 2011-12-29 15:24:39,935 [l0-2] WARN BasicDataSource - Can not load related data source 'country' for field 'country'. Treating as simple field. === 2011-12-29 15:24:39,935 [l0-2] WARN BasicDataSource - Can not load related data source 'country' for field 'country'. Treating as simple field. === 2011-12-29 15:24:39,942 [l0-2] DEBUG XML - Parsed XML from C:\countryHibernate.ds.xml: 1ms === 2011-12-29 15:24:39,948 [l0-2] WARN BasicDataSource - Can not load related data source 'java.util.Set' for field 'cities'. Treating as simple field. === 2011-12-29 15:24:39,948 [l0-2] WARN BasicDataSource - Can not load related data source 'city' for field 'cities'. Treating as simple field. === 2011-12-29 15:24:39,949 [l0-2] WARN BasicDataSource - Can not load related data source 'city' for field 'cities'. Treating as simple field. ... === 2011-12-29 15:24:45,068 [l0-2] WARN DataSource - test.shared.models.Country contains a (potentially indirect) looping reference to itself. Returning null for recursed value.
I believe the last one is about the country having the cities which then have a country in it again, and can be avoided by removing "type" from either the city or country DS (http://www.smartclient.com/smartgwte...tegration.html)
Question:
Given the restriction of needing to use Hibernate and Pro edition, is this already the most code-less approach? How different might this be if it was a plain SQLDataSource?
Comment