ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MCCORMICK, Paul" <Paul.McCORM...@doir.wa.gov.au>
Subject RE: How to support read-only fields/paramters
Date Mon, 07 May 2007 07:35:34 GMT

Ibatis can use the private methods. 

E.g.  If you define the method as "private void setId(Integer id) {..}"
then ibatis can call it.

Hope this helps,

Paul  

-----Original Message-----
From: Gordon Ross [mailto:G.Ross@ccw.gov.uk]
Sent: Monday, 7 May 2007 3:24 PM
To: user-java@ibatis.apache.org
Subject: How to support read-only fields/paramters

(This may not be totally iBatis realated, I'm not sure. Feel free to
point me elsewhere)

Often when working with objects, you have fields that should never be
changed (e.g. an "id" field which is generated by the database). The
usual way (as I understand it) that you achieve this, is to specify the
parameter value in the objects constructor, and only provide a get()
method, with no corresponding set() method (or a final private one so
that it can't be over-ridden)

However, iBatis does not use the parmaterised constructor to build an
object. Instead, it uses the null constructor, and then calls the
individual set() methods - which have to be public for iBatis to be able
to call them. This means that anyone could call the set() method and
change the value.

There are two ways that I can see to achieve this:

1) Only allow the set() method to be called once. (Use some internal
boolean flag to see if it the set() method has been called before)

2) Somehow configure/change iBatis so that it would use the constructor
to set the request fields.

Anyone got any thoughts or comments on this ?

Thanks,

GTG

Gordon Ross,
Network Manager/Rheolwr Rhydwaith
Countryside Council for Wales/Cyngor Cefn Gwlad Cymru

"DISCLAIMER: This email, including any attachments, is intended only for use by the addressee(s)
and may contain confidential and/or personal information and may also be the subject of legal
privilege. If you are not the intended recipient, you must not disclose or use the information
contained in it. In this case, please let me know by return email, delete the message permanently
from your system and destroy any copies.

Before you take any action based upon advice and/or information contained in this email you
should carefully consider the advice and information and consider obtaining relevant independent
advice.

Mime
View raw message