|
From: Ken K. <kk...@kk...> - 2003-07-12 16:01:35
|
Jean-Pierre,
It's definitely best to avoid adding instance variables or
synchronization into what should be a threadsafe, reusable query object.
Won't the following do the trick ? I thought this is exactly what
MappingSqlQueryWithParameters is for. Am I missing something ?
// in SpringQuery client class
Object[] params = new Object[] {
userLocale,
// more param objects
}
springQuery.execute(params);
// etc...
public class SpringQuery extends MappingSqlQueryWithParameters {
public SpringQuery(DataSource ds) {
super(ds, "select col1, col2 from table");
compile();
}
protected Object mapRow(ResultSet rs, int rownum, Object[] params) throws SQLException {
Locale userLocale = (Locale) params[0];
if (userLocale.equals("xxx")) {
...
}
...
}
}
Regards,
Ken
jp....@ti... wrote:
>Hello Thomas,
>
>This is very close to what I made until a few days. What is wrong in this?
>
>If two users request the same and have different contexts (ie Locales), the last will change on the road the context to use for the first. For avoiding this, I used a "run" method setting the context like in your exeample and calling the "execute method. The "run" method being "synchronized".
>In this manner, it works. But I would eliminate the need of synchronizing due to performance reasons and for clarity. The context lifecycle is really tied to the execute method and setting it as an Instance variable is a workaround threadsafe only with synchronizing.
>
>As long as no consensus will be, I simply will use the three changed classes in a private package. They don't break any backward compatibility, so I will use them instead of standard ones. The problem is only that I will have to check from time to time if the original have not changed. Secondly, I guess it's not a common need but nevertheless a general one and early or later, passing so contextual information will be requested by developers.
>
>Jean-Pierre
>
>---------- Initial Header -----------
>
>>From : tri...@tr...
>To : "jp....@ti..." <jp....@ti...>
>Cc : "jp.pawlak" <jp....@ti...>, "rod.johnson" <rod...@in...>, kk <kk...@kk...>, springframework-developer <spr...@li...>
>Date : Sat, 12 Jul 2003 10:49:56 -0400
>Subject : Re: Re:[Springframework-developer] Re: [Springframework-developer] Locale in rowmap?
>
>Jean-Pierre,
>
>Could you not do this without modifying the JDBC layer? Maybe declare a
>UserContext in the custom class and set that via a bean setter.
>
>Something like:
>
>public class SpringQuery extends MappingSqlQuery {
>
> private UserContext userContext;
>
> public SpringQuery(DataSource ds) {
> super(ds, "select col1, col2 from table");
> compile();
> }
>
> protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
> ....
> if (userContext.getLocale().equals("xxx"))
> ....
> ....
> }
>
> public setUserContext(UserContext uc) {
> userContext = uc;
> }
>
>}
>
>
>Thomas
>
>
>
>>What I used also in the past is letting the DAO create a 'data-layer' list
>>and after that in business layer, iterate the list to replace data-layer
>>elements by business-layer ones knowing the contextual information.
>>
>>This is certainly a better school-approach, but has clearly a performance
>>drawback.
>>
>>Letting rowmap being able to create definitive objects (indeed having a user
>>defined contextual info), seems to me, for now, a better solution.
>>
>>Jean-Pierre
>>
>>---------- Initial Header -----------
>>
>>From : spr...@li...
>>To : "rod.johnson" <rod...@in...>
>>Cc : "trisberg" <tri...@tr...>,"kk"
>><kk...@kk...>,"springframework-developer"
>><spr...@li...>
>>Date : Sat, 12 Jul 2003 12:05:19 +0200
>>Subject : [Springframework-developer] Re: [Springframework-developer] Locale
>>in rowmap?
>>
>>Hi Ken, Thomas, Rod,
>>
>>It seems be a general miscomprehension.
>>
>>1) I have no intend to put any dependency between WEB and JDBC.
>>My request is only at being able to add an optional 'Object' supplemental
>>attribute in execute method. The intend of this attribute is simply to be
>>passed on rowmap.
>>
>>2) Why cannot this object be passed simply on the current methods?
>>Just because JDBC has nothing to do with. It is only for rowmap method as
>>this method is responsible for creating (business) objects.
>>
>>3) Typical example:
>>Searching adresses.
>>
>>a)Consider the searched adresses are not localized on the database and
>>contain a country information.
>>
>>b)The database contain only the country code of the address.
>>
>>c)With this country code is read from the database, the rowmap method will
>>have to create a Country Object to put in the Address one. This Country
>>object will have a name property matching with the current user to serve and
>>has nothing to do with the JDBC record.
>>
>>For creating the correct Country Object, rowmap has to know the Locale to
>>serve. In this case the new 'Object' parameter would be filled with the User
>>Locale and casted so in rowmap. But in others cases, it could be another
>>information as the Locale.
>>
>>The main need is:
>>ROWMAP IS RESPONSIBLE FOR CREATING OBJECTS AND FOR THIS IT CAN HAVE TO KNOW
>>OTHER INFORMATION AS JUST THESE READ IN THE DATABASE.
>>
>>This other information can be just right during the 'execution' call and
>>cannot be in this case an instance variable.
>>
>>
>>Regards,
>>Jean-Pierre
>>
>>---------- Initial Header -----------
>>
>>From : "Rod Johnson" <rod...@in...>
>>To : <tri...@tr...>, "Ken Krebs" <kk...@kk...>
>>Cc : "JP Pawlak" <jp....@ti...>,
>>"'springframework-developer'"
>><spr...@li...>
>>Date : Thu, 10 Jul 2003 17:55:12 +0100
>>Subject : Re: [Springframework-developer] Locale in rowmap?
>>
>>
>>
>>>I would agree with Ken here - we must avoid any dependencies between the
>>>
>>>
>>JDBC
>>
>>
>>>framework and the Web framework.
>>>
>>>
>>+1. I know of several companies in the UK using JDBC only at this point.
>>It's a great route in for Spring.
>>
>>
>>
>>
>>********** L'ADSL A 20 EUR/MOIS**********
>>Tiscali propose l'ADSL le moins cher du marché : 20 EUR/mois et le modem ADSL
>>offert !
>>Pour profiter de cette offre exceptionnelle, cliquez ici :
>>http://register.tiscali.fr/adsl/
>>Offre soumise à conditions.
>>
>>
>>
>>
>>-------------------------------------------------------
>>This SF.Net email sponsored by: Parasoft
>>Error proof Web apps, automate testing & more.
>>Download & eval WebKing and get a free book.
>>www.parasoft.com/bulletproofapps1
>>_______________________________________________
>>Springframework-developer mailing list
>>Spr...@li...
>>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>>
>>
>>********** L'ADSL A 20 EUR/MOIS**********
>>Tiscali propose l'ADSL le moins cher du marché : 20 EUR/mois et le modem ADSL
>>offert !
>>Pour profiter de cette offre exceptionnelle, cliquez ici :
>>http://register.tiscali.fr/adsl/
>>Offre soumise à conditions.
>>
>>
>>
>>
>>
>
>
>
>
>
>********** L'ADSL A 20 EUR/MOIS**********
>Tiscali propose l'ADSL le moins cher du marché : 20 EUR/mois et le modem ADSL offert !
>Pour profiter de cette offre exceptionnelle, cliquez ici : http://register.tiscali.fr/adsl/
>Offre soumise à conditions.
>
>
>
>
>
>
|